killpresence/killpresence.c
changeset 46 3bb3be085858
parent 45 8e4d38e667ef
child 47 dcef1b8f2e05
equal deleted inserted replaced
45:8e4d38e667ef 46:3bb3be085858
    43 #include <mcabber/utils.h>
    43 #include <mcabber/utils.h>
    44 #include <mcabber/xmpp.h>
    44 #include <mcabber/xmpp.h>
    45 
    45 
    46 static void killpresence_init(void);
    46 static void killpresence_init(void);
    47 static void killpresence_uninit(void);
    47 static void killpresence_uninit(void);
    48 
       
    49 static void do_probe(char *);
       
    50 
    48 
    51 /* Module description */
    49 /* Module description */
    52 module_info_t info_killpresence = {
    50 module_info_t info_killpresence = {
    53         .branch         = MCABBER_BRANCH,
    51         .branch         = MCABBER_BRANCH,
    54         .api            = MCABBER_API_VERSION,
    52         .api            = MCABBER_API_VERSION,
    66 
    64 
    67 #ifdef MCABBER_API_HAVE_CMD_ID
    65 #ifdef MCABBER_API_HAVE_CMD_ID
    68 static gpointer killpresence_cmdid, killchatstates_cmdid, probe_cmdid;
    66 static gpointer killpresence_cmdid, killchatstates_cmdid, probe_cmdid;
    69 #endif
    67 #endif
    70 
    68 
       
    69 static void do_probe(char *args)
       
    70 {
       
    71   char *jid_utf8;
       
    72   LmMessage *m;
       
    73   const char *targetjid = NULL;
       
    74 
       
    75   if (!args || !*args) {
       
    76     scr_log_print(LPRINT_NORMAL, "I need a JID.");
       
    77     return;
       
    78   }
       
    79   if (strchr(args, JID_RESOURCE_SEPARATOR)) {
       
    80     scr_log_print(LPRINT_NORMAL, "I need a *bare* JID.");
       
    81     // XXX We could just drop the resource...
       
    82     return;
       
    83   }
       
    84 
       
    85   if (!xmpp_is_online())
       
    86     return;
       
    87 
       
    88   jid_utf8 = to_utf8(args);
       
    89   if (!jid_utf8)
       
    90     return;
       
    91 
       
    92   if (!strcmp(jid_utf8, ".")) {
       
    93     if (current_buddy)
       
    94       targetjid = CURRENT_JID;
       
    95   } else {
       
    96     targetjid = jid_utf8;
       
    97   }
       
    98 
       
    99   // Create presence message with type "probe"
       
   100   m = lm_message_new(targetjid, LM_MESSAGE_TYPE_PRESENCE);
       
   101   lm_message_node_set_attribute(m->node, "type", "probe");
       
   102   lm_connection_send(lconnection, m, NULL);
       
   103   lm_message_unref(m);
       
   104   scr_log_print(LPRINT_LOGNORM, "Presence probe sent to <%s>.", targetjid);
       
   105   g_free(jid_utf8);
       
   106 }
       
   107 
    71 static void do_killpresence(char *args)
   108 static void do_killpresence(char *args)
    72 {
   109 {
    73   char *jid_utf8, *res;
   110   char *jid_utf8, *res;
    74   const char *targetjid = NULL;
   111   const char *targetjid = NULL;
    75   bool probe = false;
   112   bool probe = false;
   197   reset_chat_states(jid_utf8);
   234   reset_chat_states(jid_utf8);
   198   g_free(jid_utf8);
   235   g_free(jid_utf8);
   199 #else
   236 #else
   200   scr_log_print(LPRINT_NORMAL, "No Chat State support.");
   237   scr_log_print(LPRINT_NORMAL, "No Chat State support.");
   201 #endif
   238 #endif
   202 }
       
   203 
       
   204 static void do_probe(char *args)
       
   205 {
       
   206   char *jid_utf8;
       
   207   LmMessage *m;
       
   208   const char *targetjid = NULL;
       
   209 
       
   210   if (!args || !*args) {
       
   211     scr_log_print(LPRINT_NORMAL, "I need a JID.");
       
   212     return;
       
   213   }
       
   214   if (strchr(args, JID_RESOURCE_SEPARATOR)) {
       
   215     scr_log_print(LPRINT_NORMAL, "I need a *bare* JID.");
       
   216     // XXX We could just drop the resource...
       
   217     return;
       
   218   }
       
   219 
       
   220   if (!xmpp_is_online())
       
   221     return;
       
   222 
       
   223   jid_utf8 = to_utf8(args);
       
   224   if (!jid_utf8)
       
   225     return;
       
   226 
       
   227   if (!strcmp(jid_utf8, ".")) {
       
   228     if (current_buddy)
       
   229       targetjid = CURRENT_JID;
       
   230   } else {
       
   231     targetjid = jid_utf8;
       
   232   }
       
   233 
       
   234   // Create presence message with type "probe"
       
   235   m = lm_message_new(targetjid, LM_MESSAGE_TYPE_PRESENCE);
       
   236   lm_message_node_set_attribute(m->node, "type", "probe");
       
   237   lm_connection_send(lconnection, m, NULL);
       
   238   lm_message_unref(m);
       
   239   scr_log_print(LPRINT_LOGNORM, "Presence probe sent to <%s>.", targetjid);
       
   240   g_free(jid_utf8);
       
   241 }
   239 }
   242 
   240 
   243 
   241 
   244 /* Initialization */
   242 /* Initialization */
   245 static void killpresence_init(void)
   243 static void killpresence_init(void)