X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=src%2Fro%2Fieval%2Ffonbot%2FUtils.java;h=849848bd592133f731cb8629d31ee29198d1aad8;hb=35ad85f01d2755a81575278714fc3b96a4d9a2a1;hp=117c528f6408d8cea153b5f665544009935329c0;hpb=a97d31fb5c1bc1725079b5329168b22db3cf9cf3;p=fonbot.git diff --git a/src/ro/ieval/fonbot/Utils.java b/src/ro/ieval/fonbot/Utils.java index 117c528..849848b 100644 --- a/src/ro/ieval/fonbot/Utils.java +++ b/src/ro/ieval/fonbot/Utils.java @@ -316,8 +316,8 @@ public final class Utils { public static void sendMessage(final Context context, final Address address, final String message){ switch(address.protocol){ case HTTP: - new SendHttpMessageAsyncTask(toNonNull(Arrays.asList( - new Header("X-Action", "SEND "+address.data))), context).execute(message); + new HttpCallExecutableRunnable("/send", toNonNull(Arrays.asList( + new Header("X-Destination", toNonNull(address.data)))), context, null, true, message).execute(); break; case SMS: @@ -335,19 +335,6 @@ public final class Utils { } } - /** - * Parses a HTTP response message of the form (part1) part2, returning part2. - * - * @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; - return toNonNull(message.substring(indexOfParen+2)); - } - /** * Splits a string into words. * @@ -417,12 +404,31 @@ public final class Utils { * @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 int port=Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString("port", "7777")); - final URL url=new URL("http", hostname, port, path); + final String hostname=PreferenceManager.getDefaultSharedPreferences(context).getString("hostname", "fonbot.ieval.ro"); + final int port=Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString("port", "443")); + final URL url=new URL("https", hostname, port, path); return url; } + /** + * 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), 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 * @@ -433,7 +439,7 @@ public final class Utils { */ private static void processCommand(final Context context, final Command cmd,final String[] args,final Address replyTo){ if(Heavy.isCommandDisabled(context, cmd)){ - sendMessage(context, replyTo, command_disabled); + sendMessage(context, replyTo, command_disabled, cmd.toString()); return; } @@ -1004,6 +1010,7 @@ public final class Utils { case NOTIFY: if(args.length!=1 && args.length!=3){ Heavy.help(context, replyTo, toNonNull(Command.NOTIFY)); + return; } final int id;