jingle-ibb/ibb.c
changeset 156 653fa009fea3
parent 148 cb40539b88b7
child 157 8ec7ce3ecaac
equal deleted inserted replaced
155:35e603b584a3 156:653fa009fea3
    38 
    38 
    39 #include "ibb.h"
    39 #include "ibb.h"
    40 
    40 
    41 static LmMessageHandler* jingle_ibb_handler = NULL;
    41 static LmMessageHandler* jingle_ibb_handler = NULL;
    42 
    42 
    43 static gconstpointer check(JingleContent *cn, GError **err);
    43 static gconstpointer newfrommessage(JingleContent *cn, GError **err);
       
    44 static JingleHandleStatus handle(JingleAction action, gconstpointer data,
       
    45                                  LmMessageNode *node, GError **err);
    44 static void tomessage(gconstpointer data, LmMessageNode *node);
    46 static void tomessage(gconstpointer data, LmMessageNode *node);
    45 static gconstpointer new(void);
    47 static gconstpointer new(void);
    46 static void send(session_content *sc, gconstpointer data, gchar *buf, gsize size);
    48 static void send(session_content *sc, gconstpointer data, gchar *buf, gsize size);
    47 static void init(session_content *sc, gconstpointer data);
    49 static void init(session_content *sc);
    48 static void end(session_content *sc, gconstpointer data);
    50 static void end(session_content *sc, gconstpointer data);
    49 static gchar *info(gconstpointer data);
    51 static gchar *info(gconstpointer data);
    50 
    52 
    51 static void _send_internal(session_content *sc, const gchar *to, gchar *buf,
    53 static void _send_internal(session_content *sc, const gchar *to, gchar *buf,
    52                            gsize size, const gchar *sid, gint64 *seq);
    54                            gsize size, const gchar *sid, gint64 *seq);
    59 static guint disconn_hid = 0;
    61 static guint disconn_hid = 0;
    60 
    62 
    61 const gchar *deps[] = { "jingle", NULL };
    63 const gchar *deps[] = { "jingle", NULL };
    62 
    64 
    63 static JingleTransportFuncs funcs = {
    65 static JingleTransportFuncs funcs = {
    64   .check     = check,
    66   .newfrommessage = newfrommessage,
    65   .tomessage = tomessage,
    67   .handle         = handle,
    66   .new       = new,
    68   .tomessage      = tomessage,
    67   .send      = send,
    69   .new            = new,
    68   .init      = init,
    70   .send           = send,
    69   .end       = end,
    71   .init           = init,
    70   .info      = info
    72   .end            = end,
       
    73   .info           = info
    71 };
    74 };
    72 
    75 
    73 module_info_t  info_jingle_ibb = {
    76 module_info_t  info_jingle_ibb = {
    74   .branch          = MCABBER_BRANCH,
    77   .branch          = MCABBER_BRANCH,
    75   .api             = MCABBER_API_VERSION,
    78   .api             = MCABBER_API_VERSION,
    82 };
    85 };
    83 
    86 
    84 /* Hash-Table of all emited JingleIBB struct */
    87 /* Hash-Table of all emited JingleIBB struct */
    85 static GHashTable *JingleIBBs = NULL;
    88 static GHashTable *JingleIBBs = NULL;
    86 
    89 
    87 static gconstpointer check(JingleContent *cn, GError **err)
    90 static gconstpointer newfrommessage(JingleContent *cn, GError **err)
    88 {
    91 {
    89   JingleIBB *ibb = NULL;
    92   JingleIBB *ibb = NULL;
    90   LmMessageNode *node = cn->transport;
    93   LmMessageNode *node = cn->transport;
    91   const gchar *blocksize;
    94   const gchar *blocksize;
    92 
    95 
   117     return NULL;
   120     return NULL;
   118   }
   121   }
   119 
   122 
   120   g_hash_table_insert(JingleIBBs, ibb->sid, ibb);
   123   g_hash_table_insert(JingleIBBs, ibb->sid, ibb);
   121   return (gconstpointer) ibb;
   124   return (gconstpointer) ibb;
       
   125 }
       
   126 
       
   127 static JingleHandleStatus handle(JingleAction action, gconstpointer data,
       
   128                                  LmMessageNode *node, GError **err)
       
   129 {
       
   130   JingleIBB *jibb = (JingleIBB *)data;
       
   131   const gchar *blocksizestr;
       
   132   guint64 blocksize;
       
   133 
       
   134   if (action == JINGLE_SESSION_ACCEPT) {
       
   135     const gchar *xmlns = lm_message_node_get_attribute(node, "xmlns");
       
   136     if (!g_strcmp0(xmlns, NS_JINGLE_TRANSPORT_IBB)) {
       
   137       /* If the responder wishes to use a smaller block-size, the responder can
       
   138        * specify that in the session-accept by returning a different value for
       
   139        * the 'block-size' attribute. */
       
   140       blocksizestr = lm_message_node_get_attribute(node, "block-size");
       
   141       blocksize = g_ascii_strtoll(blocksizestr, NULL, 10);
       
   142       jibb->blocksize = (blocksize < jibb->blocksize) ? blocksize : jibb->blocksize; 
       
   143       return JINGLE_STATUS_HANDLED;
       
   144 	}
       
   145   }
       
   146   return JINGLE_STATUS_NOT_HANDLED;
   122 }
   147 }
   123 
   148 
   124 LmHandlerResult jingle_ibb_handle_iq(LmMessageHandler *handler,
   149 LmHandlerResult jingle_ibb_handle_iq(LmMessageHandler *handler,
   125                                  LmConnection *connection, LmMessage *message,
   150                                  LmConnection *connection, LmMessage *message,
   126                                  gpointer user_data)
   151                                  gpointer user_data)
   309   
   334   
   310     g_free(buffer);
   335     g_free(buffer);
   311   }
   336   }
   312 }
   337 }
   313 
   338 
   314 static void init(session_content *sc, gconstpointer data)
   339 static void init(session_content *sc)
   315 {
   340 {
   316   JingleIBB *jibb = (JingleIBB*)data;
   341   return;
   317   JingleSession *sess = session_find_by_sid(sc->sid, sc->from);
       
   318   SessionContent *sc2 = session_find_sessioncontent(sess, sc->name);
       
   319   JingleIBB *jibb2 = (JingleIBB*)sc2->transport;
       
   320   
       
   321   jibb2->blocksize = (jibb->blocksize < jibb2->blocksize)?jibb->blocksize:jibb2->blocksize;
       
   322 }
   342 }
   323 
   343 
   324 static void end(session_content *sc, gconstpointer data)
   344 static void end(session_content *sc, gconstpointer data)
   325 {
   345 {
   326   JingleIBB *jibb = (JingleIBB*)data;
   346   JingleIBB *jibb = (JingleIBB*)data;