Log messages sent to ASL do not appear in query - ios

I am trying to query log messages sent via ASL and the NSLog wrapper. Running the below code on an iOS 9 device, I get one response from the ASL query and that is the first log string sent via NSLog. The second string "Hello from asl_log" is not returned by the query, even though it goes to the default ASL client. Any suggestions on what I might be doing wrong with the query or the asl_log call?
// Send test data
NSLog(#"Hello from NSLog");
asl_log(NULL, NULL, ASL_LEVEL_EMERG, "Hello from asl_log");
// Query all logged strings
aslmsg query = asl_new(ASL_TYPE_QUERY);
aslresponse response = asl_search(NULL, query);
asl_free(query);
// Only one message found: "Hello from NSLog"
aslmsg message;
while((message = asl_next(response))) {
const char *msg = asl_get(message, ASL_KEY_MSG);
}

After trying several ways to set ASL_KEY_READ_UID to "-1", following the hint of bk138, I finally came up with the following:
asl_object_t msg = asl_new(ASL_TYPE_MSG);
asl_set(msg, ASL_KEY_READ_UID, "-1");
asl_log(NULL, msg, ASL_LEVEL_EMERG, "Hello from asl_log");
This will make the logs appear in the asl query results.

Related

How to parse an Incoming stream of caller id through a modem, if data come as chunked?

I am developing a dart application where I want to read the Caller Id from an incoming phone call. Hence I did the following minimalistic example:
import 'package:libserialport/flutter_libserialport.dart';
void main(){
final SerialPort port = SerialPort("/dev/ttyACM0");
if(!port.openReadWrite()){
print(SerialPort.lastError);
exit(-1);
}
port.write("ATZ\r\n");
port.write("AT+VCID=1\r\n");
final reader = SerialPortReader(port);
reader.stream.listen((data) {
String response = String.fromCharCodes(data);
RegExp regExp = new RegExp("NMBR[\s=]*(?<phoneNumber>\+*[0-9\s]+)");
Iterable<RegExpMatch> matches = regExp.allMatches(response);
for (final m in matches) {
print "Matched Number $m";
}
});
}
The issue is that I want to retrieve a full phone number from a continuous input stream of data.
A case that I may have that I receive the following from the serial device:
blahblayblahblah\r\n
34321123\r\n
4456634\r\n
blahblayblahblahblahblayblahblahblahblayblahblahblahblayblahblahblahblayblahblahblahblayblahblah\r\n
NMBR=0030003045655566\r\n
\r\n
OK\r\n
\r\n
And the incoming data bay be called like this:
data "blahblayblahblah\r\n"
data "4456634\r\n"
data "blahblayblahblahblahblay"
....
data "NMBR=00304565"
data "5566\r\n"
As you can see I expect that from the string NMBR=0030003045655566 that I want to extract the number 0030003045655566 may not come as a whole but in chinked parts.
How I can manage this?
An approach that I though is to keep a buffer of data
String dataWhereIcanExtractPhoneNumbers = ""
reader.stream.listen((data) {
String response = String.fromCharCodes(data);
dataWhereIcanExtractPhoneNumbers += response;
RegExp regExp = new RegExp("NMBR[\s=]*(?<phoneNumber>\+*[0-9\s]+)");
Iterable<RegExpMatch> matches = regExp.allMatches(dataWhereIcanExtractPhoneNumbers);
for (final m in matches) {
print "Matched Number $m";
}
});
But how I can clean it up from all unnecessary junk (responses that do not contain caller Id)?

Send MMS using Twilio.TwimlResponse()

I'm using a node server with a webhook for handling receiving Twilio messages to one of my numbers. I use this number to forward communications between users, essentially anonymizing things for them (they communicate with our number so they don't have to give theirs to the other user).
In my handler, I currently basically do this:
var sendTo = /* other user's number */;
var sendFrom = /* sender number in received message */;
var body = /* body of message received */;
twimlResponse(body, {
to: sendTo,
from: sendFrom
});
response.send(twimlResponse.toString());
This works perfect for text messages. However, my debug log is showing errors for media messages with no body (also not forwarding the media in general, since I'm not currently telling it to).
So, I'm trying to update to send the media messages as well. This is not working well.
I found this documentation: https://www.twilio.com/docs/guides/how-to-receive-and-reply-in-node-js#respond-with-media-mms-message
However, it doesn't work. I get an error saying 'this' has no method 'To'.
I tried modifying my code a bit,
var sendTo = /* other user's number */;
var sendFrom = /* sender number in received message */;
var body = /* body of message received */;
var mediaUrl = /* mediaUrl0 of the received message */
if( body && mediaUrl ) {
twimlResponse(body, {
to: sendTo,
from: sendFrom,
mediaUrl: mediaUrl
});
}
else if( body ) {
twimlResponse(body, {
to: sendTo,
from: sendFrom
});
}
else if( mediaUrl ) {
twimlResponse(nil, {
to: sendTo,
from: sendFrom,
mediaUrl: mediaUrl
});
}
response.send(twimlResponse.toString());
I haven't yet verified that last one is correct for sending a message with no body, but my issue is that I can't figure out how to tell the twiml response to include the media. I've tried Media, media, MediaUrl, MediaUrl0, mediaUrl0, and mediaUrl. Each time I get a warning in my debugger saying it was an invalid noun. The Twiml Documentation says the nouns should be case sensitive and capitalized, though for some reason to and from are taken lower case. That part all works fine. I just can't figure out how to attach the media url.
Any tips are appreciated!
Edit -
Here is one attempt based on the linked documentation, which I thought wasn't working at all, but re-arranging the order of properties I set, I see I'm just not setting the to / from number appropriately. I know a twiml without those passed in automatically responds to the number that sent a message, from the number that received it. I need to specify both those values since I'm forwarding one user's message to another.
twimlResp.message(function() {
this.body(body);
this.media(media0);
this.to(sendTo);
this.from(sendFrom);
});
This snippet works fine for body and media, similar to the documentation, but crashes when setting to
Edit - I've tried changing this.to and this.from to this.To and this.From, but those don't work.
I've also tried this:
twimlResp.message(function() {
this.body(body);
this.media(media0);
});
twimlResp.to = sendTo;
twimlResp.from = sendFrom;
Which also does not work - .to and .from are ignored, causing the response to go back to the sending user from the number that received the original message.
I think you've gotten confused between the 2.0 and the 3.0 SDK. You can change between SDK versions by clicking in the top right of the example screen.
With your example provided, using the 3.0 SDK you can achieve this by:
var MessagingResponse = require('twilio').twiml.MessagingResponse;
var twiml = new MessagingResponse();
// Place your constraints here
var message = twiml.message({ to: sendTo, from: sendFrom });
if( body && mediaUrl ) {
message.body(body);
message.media(mediaUrl);
}
else if( body ) {
messsage.body(body);
}
else if( mediaUrl ) {
messsage.media(mediaUrl);
}
response.send(twiml.toString());
If you need a more in-depth detail on how I formulated this code, check out the MessagingResposne.js source. I'm assuming you have no restrictions on switching SDK versions, the reason I gave an example with the 3.0 SDK is because Twilio will be ending support for the 2.0 SDK as of 8/31/2017.
Howto with SDK 2.0
Since some users will need to migrate a large part of their codebase, here is how you can set a different to and from numbers with the SDK 2.0.
twimlResp.message(function() {
this.body(body);
this.media(media0);
}, {
to: sendTo,
from: sendFrom
});

Delphi Send Device to Device message using firebase [duplicate]

Is there any way to send Upstream notification message through FCM from one android device to another devices connected with Firebase database.
I know that XMPP server can then receive the upstream messages and send the notifications to the other devices.To receive messages sent with the upstream API i need to implement an XMPP server but there is any other way???
Is there any way to send Upstream notification message through FCM
from one android device to another devices connected with Firebase
database?
Currently it's NOT possible to send messages directly from one device to another.
(or at least it's not possible without introducing a HUGE security vulnerability: more details below)
Full details:
Sending messages to a user device is a pretty serious action!
based on the payload a message can result in spam, phishing, execution of internal methods.
You want this operation to be allowed only be trusted entities, this is why the FCM send API requires the SERVER-API-KEY in the authentication header.
Adding the SERVER-API-KEY in your app code (or communicating it to the app in some other way) IS NOT SAFE. This because apk can be extracted, decompiled, inspected, executed on emulators, executed under debugging and so on.
The best way to implement this today: is to have some sort of server between the two devices:
[DeviceA] -- please send message to B --> [SERVER] -- fcmSendAPI --> [DeviceB]
The server can be as simple as a PHP page, or a more complex XMPP implementation.
An example in Node.js can be found here:
Sending notifications between devices with Firebase Database and Cloud Messaging
Finally, after 2 months of trying to maintain reliable server script myself, I suddenly found OneSignal. It's completely free, supports device-to-device push messages on iOS, Android, WP and browsers.
Hope, I won't get flag for promotion spam, but it's currently the only (and easiest) way to be completely "backendless".
Also, it's completely secure way. Nobody can send push unless he knows special OS user id, which you can store in Firebase Database protected by rules.
UPD: It's not a replacement for Firebase. It has only push service and nothing else
UPD2: Firebase now has Functions, and examples of it usage has sending FCM. You now don't need any other server or service. Read more in official samples https://github.com/firebase/functions-samples
After lots of try finally i got one solution and its work perfectly
Step 1 :Include two library.
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.google.firebase:firebase-messaging:9.2.0'
Step 2 : In your MainActivity or from where you want to send notifications.
OkHttpClient mClient = new OkHttpClient();
String refreshedToken = "";//add your user refresh tokens who are logged in with firebase.
JSONArray jsonArray = new JSONArray();
jsonArray.put(refreshedToken);
Step 3: Create one async task which sends notifications to all devices.
public void sendMessage(final JSONArray recipients, final String title, final String body, final String icon, final String message) {
new AsyncTask<String, String, String>() {
#Override
protected String doInBackground(String... params) {
try {
JSONObject root = new JSONObject();
JSONObject notification = new JSONObject();
notification.put("body", body);
notification.put("title", title);
notification.put("icon", icon);
JSONObject data = new JSONObject();
data.put("message", message);
root.put("notification", notification);
root.put("data", data);
root.put("registration_ids", recipients);
String result = postToFCM(root.toString());
Log.d("Main Activity", "Result: " + result);
return result;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(String result) {
try {
JSONObject resultJson = new JSONObject(result);
int success, failure;
success = resultJson.getInt("success");
failure = resultJson.getInt("failure");
Toast.makeText(MainActivity.this, "Message Success: " + success + "Message Failed: " + failure, Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, "Message Failed, Unknown error occurred.", Toast.LENGTH_LONG).show();
}
}
}.execute();
}
String postToFCM(String bodyString) throws IOException {
public static final String FCM_MESSAGE_URL = "https://fcm.googleapis.com/fcm/send";
final MediaType JSON
= MediaType.parse("application/json; charset=utf-8");
RequestBody body = RequestBody.create(JSON, bodyString);
Request request = new Request.Builder()
.url(Url.FCM_MESSAGE_URL)
.post(body)
.addHeader("Authorization", "key=" + "your server key")
.build();
Response response = mClient.newCall(request).execute();
return response.body().string();
}
Step 4 : Call in onclick of your button
btnSend.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sendMessage(jsonArray,"Hello","How r u","Http:\\google.com","My Name is Vishal");
}
});

Need Help on IMAP INBOX Search based on received date

I am using a Open source IMAP C# library IMapX (http://hellowebapps.com/products/imapx/).
When I trying to get the emails from INBOX it is taking lot of time. Is there any way to Filter inbox based on received date?
The below code is a sample. The search is based on UNSEEN. I want to filter based on received date is Greater than given date.
ImapX.ImapClient client = new ImapX.ImapClient("imap.gmail.com", 993, true);
bool result = false;
result = client.Connection();
if (result)
MessageBox.Show("Connection Established");
result = client.LogIn(textBox1.Text, textBox2.Text);
if (result)
{
MessageBox.Show("Logged in");
ImapX.FolderCollection folders = client.Folders;
ImapX.MessageCollection messages = client.Folders["INBOX"].Search("UNSEEN", true); //true - means all message parts will be received from server
int unread = messages.Count;
string unseen = unread.ToString();
button1.Text = unseen;
}
You can use IMAP search data item SINCE. Example: "SINCE 18-Nov-2011".
Or if you interested in UNSEEN too then: "SINCE 18-Nov-2011 UNSEEN"

how to retrieve data from incoming message in blackberry 5.0

could any one please help us to retrieve data from incoming message in blackberry 8520 and to store the retrived data in to the shared preferences
We can use the listener to listen the messages before coming into the inbox. But you cannot read the messages that are already received. You can use the below sample code:
try{
dc = (DatagramConnection) Connector.open("sms://");
for(;;){
if(stop){
return;
}
Datagram d = dc.newDatagram(dc.getMaximumLength());
dc.receive(d);
String address = new String(d.getAddress());
String msg = new String(d.getData());
MyScreen.update(msg,address);
}
}catch(Exception e){
System.err.println(e.toString());
}
You can find more information BlackBerry_Application_Developer_Guide_Volume_1 book

Resources