jingle-ibb/ibb.c
changeset 73 6f061c11acfb
parent 72 277778138b4b
child 81 8b6320ad470b
equal deleted inserted replaced
72:277778138b4b 73:6f061c11acfb
    36 static LmMessageHandler* jingle_ibb_handler = NULL;
    36 static LmMessageHandler* jingle_ibb_handler = NULL;
    37 
    37 
    38 gconstpointer jingle_ibb_check(JingleContent *cn, GError **err);
    38 gconstpointer jingle_ibb_check(JingleContent *cn, GError **err);
    39 gboolean jingle_ibb_cmp(gconstpointer data1, gconstpointer data2);
    39 gboolean jingle_ibb_cmp(gconstpointer data1, gconstpointer data2);
    40 void jingle_ibb_handle(JingleAction act, gconstpointer data, LmMessageNode *node);
    40 void jingle_ibb_handle(JingleAction act, gconstpointer data, LmMessageNode *node);
       
    41 const gchar* jingle_ibb_xmlns(void);
       
    42 gconstpointer jingle_ibb_new(void);
    41 
    43 
    42 static void jingle_ibb_init(void);
    44 static void jingle_ibb_init(void);
    43 static void jingle_ibb_uninit(void);
    45 static void jingle_ibb_uninit(void);
    44 
    46 
    45 
    47 
    46 const gchar *deps[] = { "jingle", NULL };
    48 const gchar *deps[] = { "jingle", NULL };
    47 
    49 
    48 JingleTransportFuncs funcs = {jingle_ibb_check, jingle_ibb_handle, jingle_ibb_cmp};
    50 JingleTransportFuncs funcs = {jingle_ibb_xmlns, jingle_ibb_check, jingle_ibb_handle, jingle_ibb_cmp, jingle_ibb_new};
    49 
    51 
    50 module_info_t  info_jingle_inbandbytestream = {
    52 module_info_t  info_jingle_inbandbytestream = {
    51   .branch          = MCABBER_BRANCH,
    53   .branch          = MCABBER_BRANCH,
    52   .api             = MCABBER_API_VERSION,
    54   .api             = MCABBER_API_VERSION,
    53   .version         = PROJECT_VERSION,
    55   .version         = PROJECT_VERSION,
    57   .uninit          = jingle_ibb_uninit,
    59   .uninit          = jingle_ibb_uninit,
    58   .next            = NULL,
    60   .next            = NULL,
    59 };
    61 };
    60 
    62 
    61 
    63 
       
    64 const gchar* jingle_ibb_xmlns(void)
       
    65 {
       
    66   return NS_JINGLE_TRANSPORT_IBB;
       
    67 }
       
    68 
    62 gconstpointer jingle_ibb_check(JingleContent *cn, GError **err)
    69 gconstpointer jingle_ibb_check(JingleContent *cn, GError **err)
    63 {
    70 {
    64   JingleIBB *ibb = NULL;
    71   JingleIBB *ibb = NULL;
    65   LmMessageNode *node = cn->transport;
    72   LmMessageNode *node = cn->transport;
    66   const gchar *blocksize;
    73   const gchar *blocksize;
    76   }
    83   }
    77   
    84   
    78   ibb->blocksize = g_ascii_strtoll(blocksize, NULL, 10);
    85   ibb->blocksize = g_ascii_strtoll(blocksize, NULL, 10);
    79 
    86 
    80   // the size attribute is a xs:short an therefore can be negative.
    87   // the size attribute is a xs:short an therefore can be negative.
    81   if (ibb->blocksize < 0) {
    88   if (ibb->blocksize < 0 || ibb->blocksize > IBB_BLOCK_SIZE_MAX) {
    82     g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_BADVALUE,
    89     g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_BADVALUE,
    83                 "block-size is negative");
    90                 "block-size is negative");
    84     g_free(ibb);
    91     g_free(ibb);
    85     return NULL;
    92     return NULL;
    86   }
    93   }
   132   if(g_strcmp0(ibb1->sid, ibb2->sid))
   139   if(g_strcmp0(ibb1->sid, ibb2->sid))
   133     return FALSE;
   140     return FALSE;
   134   return TRUE;
   141   return TRUE;
   135 }
   142 }
   136 
   143 
       
   144 static gchar *new_ibb_sid(void)
       
   145 {
       
   146   gchar *sid;
       
   147   gchar car[] = "azertyuiopqsdfghjklmwxcvbn1234567890AZERTYUIOPQSDFGHJKLMWXCVBN";
       
   148   int i;
       
   149   sid = g_new0(gchar, 7);
       
   150   for (i = 0; i < 6; i++)
       
   151     sid[i] = car[g_random_int_range(0, sizeof(car)/sizeof(car[0]))];
       
   152 
       
   153   sid[6] = '\0';
       
   154   
       
   155   return sid;
       
   156 }
       
   157 
       
   158 gconstpointer jingle_ibb_new(void)
       
   159 {
       
   160   JingleIBB *ibb = g_new0(JingleIBB, 1);
       
   161   ibb->blocksize = IBB_BLOCK_SIZE_MAX;
       
   162   ibb->sid = new_ibb_sid();
       
   163   ibb->seq = 0;
       
   164   
       
   165   return ibb;
       
   166 }
   137 
   167 
   138 int jingle_ibb_check_session(gconstpointer data, gconstpointer session)
   168 int jingle_ibb_check_session(gconstpointer data, gconstpointer session)
   139 {
   169 {
   140   const JingleIBB *ibb1 = data, *ibb2 = session;
   170   const JingleIBB *ibb1 = data, *ibb2 = session;
   141   if(!g_strcmp0(ibb1->sid, ibb2->sid) && ibb1->seq == ibb2->seq + 1) {
   171   if(!g_strcmp0(ibb1->sid, ibb2->sid) && ibb1->seq == ibb2->seq + 1) {