switch(address.protocol){
case HTTP:
new HttpCallExecutableRunnable("/send", toNonNull(Arrays.asList(
- new Header("X-Destination", toNonNull(address.data)))), context, null, message).execute();
+ new Header("X-Destination", toNonNull(address.data)))), context, null, true, message).execute();
break;
case SMS:
}
}
- /**
- * Parses a HTTP response message of the form <code>(part1) part2</code>, returning <code>part2</code>.
- *
- * @param message the raw HTTP response message
- * @return the extracted part
- */
- public static String parseHttpMessage(final String message){
- final int indexOfParen=message.indexOf(')');
- if(indexOfParen==-1)
- return message;
- if(indexOfParen == message.length()-1)
- return toNonNull(message.substring(1, indexOfParen));
- return toNonNull(message.substring(indexOfParen+2));
- }
-
/**
* Splits a string into words.
*
* @throws MalformedURLException if the user preferences create an invalid URL
*/
public static URL getServerURL(final Context context, final String path) throws MalformedURLException{
- final String hostname=PreferenceManager.getDefaultSharedPreferences(context).getString("hostname", "ieval.ro");
+ final String hostname=PreferenceManager.getDefaultSharedPreferences(context).getString("hostname", "fonbot.ieval.ro");
final int port=Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString("port", "7777"));
- final URL url=new URL("http", hostname, port, path);
+ final URL url=new URL("https", hostname, port, path);
return url;
}
/**
- * Poll the server for pending commands.
+ * Poll the server for pending commands. This function must not be called from BroadcastReceivers
*
* @param context Context instance
*/
public static void pollServer(final Context context){
- new HttpCallExecutableRunnable("/get", null, context, new PollResultCallback(context)).execute();
+ new HttpCallExecutableRunnable("/get", null, context, new PollResultCallback(context), false).execute();
}
+ /**
+ * Poll the server for pending commands from {@link FonBotMainService}. This function should be used from BroadcastReceviers instead of {@link #pollServer}
+ *
+ * @param context Context instance
+ */
+ public static void safePollServer(final Context context){
+ final Intent intent=new Intent(context, FonBotMainService.class);
+ intent.setAction(FonBotMainService.ACTION_TRIGGER_POLL);
+ context.startService(intent);
+ }
/**
* Executes a given command
*
case NOTIFY:
if(args.length!=1 && args.length!=3){
Heavy.help(context, replyTo, toNonNull(Command.NOTIFY));
+ return;
}
final int id;