Ignore:
Timestamp:
2015-05-04T21:58:50Z (9 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
5726a0d
Parents:
531eabd (diff), 5ca1416 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Catch up with master.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/msn_util.c

    r531eabd rb1dc403  
    5555
    5656        *groupid = '\0';
    57 #if 0
    58         if (group) {
    59                 int i;
    60                 for (i = 0; i < md->groupcount; i++) {
    61                         if (g_strcasecmp(md->grouplist[i], group) == 0) {
    62                                 g_snprintf(groupid, sizeof(groupid), " %d", i);
    63                                 break;
    64                         }
    65                 }
    66 
    67                 if (*groupid == '\0') {
    68                         /* Have to create this group, it doesn't exist yet. */
    69                         struct msn_groupadd *ga;
    70                         GSList *l;
    71 
    72                         for (l = md->grpq; l; l = l->next) {
    73                                 ga = l->data;
    74                                 if (g_strcasecmp(ga->group, group) == 0) {
    75                                         break;
    76                                 }
    77                         }
    78 
    79                         ga = g_new0(struct msn_groupadd, 1);
    80                         ga->who = g_strdup(who);
    81                         ga->group = g_strdup(group);
    82                         md->grpq = g_slist_prepend(md->grpq, ga);
    83 
    84                         if (l == NULL) {
    85                                 char groupname[strlen(group) + 1];
    86                                 strcpy(groupname, group);
    87                                 http_encode(groupname);
    88                                 g_snprintf(buf, sizeof(buf), "ADG %d %s %d\r\n", ++md->trId, groupname, 0);
    89                                 return msn_write(ic, buf, strlen(buf));
    90                         } else {
    91                                 /* This can happen if the user's doing lots of adds to a
    92                                    new group at once; we're still waiting for the server
    93                                    to confirm group creation. */
    94                                 return 1;
    95                         }
    96                 }
    97         }
    98 #endif
    9957
    10058        if (!((bu = bee_user_by_handle(ic->bee, ic, who)) ||
     
    13290
    13391        *groupid = '\0';
    134 #if 0
    135         if (group) {
    136                 int i;
    137                 for (i = 0; i < md->groupcount; i++) {
    138                         if (g_strcasecmp(md->grouplist[i], group) == 0) {
    139                                 g_snprintf(groupid, sizeof(groupid), " %d", i);
    140                                 break;
    141                         }
    142                 }
    143         }
    144 #endif
    14592
    14693        if (!(bu = bee_user_by_handle(ic->bee, ic, who)) ||
     
    174121};
    175122
    176 static void msn_buddy_ask_yes(void *data)
     123static void msn_buddy_ask_free(void *data)
    177124{
    178125        struct msn_buddy_ask_data *bla = data;
    179 
    180         msn_buddy_list_add(bla->ic, MSN_BUDDY_AL, bla->handle, bla->realname, NULL);
    181 
    182         imcb_ask_add(bla->ic, bla->handle, NULL);
    183126
    184127        g_free(bla->handle);
     
    187130}
    188131
     132static void msn_buddy_ask_yes(void *data)
     133{
     134        struct msn_buddy_ask_data *bla = data;
     135
     136        msn_buddy_list_add(bla->ic, MSN_BUDDY_AL, bla->handle, bla->realname, NULL);
     137
     138        imcb_ask_add(bla->ic, bla->handle, NULL);
     139
     140        msn_buddy_ask_free(bla);
     141}
     142
    189143static void msn_buddy_ask_no(void *data)
    190144{
     
    193147        msn_buddy_list_add(bla->ic, MSN_BUDDY_BL, bla->handle, bla->realname, NULL);
    194148
    195         g_free(bla->handle);
    196         g_free(bla->realname);
    197         g_free(bla);
     149        msn_buddy_ask_free(bla);
    198150}
    199151
     
    216168                   "The user %s (%s) wants to add you to his/her buddy list.",
    217169                   bu->handle, bu->fullname);
    218         imcb_ask(bu->ic, buf, bla, msn_buddy_ask_yes, msn_buddy_ask_no);
    219 }
    220 
    221 /* *NOT* thread-safe, but that's not a problem for now... */
    222 char **msn_linesplit(char *line)
    223 {
    224         static char **ret = NULL;
    225         static int size = 3;
    226         int i, n = 0;
    227 
    228         if (ret == NULL) {
    229                 ret = g_new0(char*, size);
    230         }
    231 
    232         for (i = 0; line[i] && line[i] == ' '; i++) {
    233                 ;
    234         }
    235         if (line[i]) {
    236                 ret[n++] = line + i;
    237                 for (i++; line[i]; i++) {
    238                         if (line[i] == ' ') {
    239                                 line[i] = 0;
    240                         } else if (line[i] != ' ' && !line[i - 1]) {
    241                                 ret[n++] = line + i;
    242                         }
    243 
    244                         if (n >= size) {
    245                                 ret = g_renew(char*, ret, size += 2);
    246                         }
    247                 }
    248         }
    249         ret[n] = NULL;
    250 
    251         return(ret);
     170
     171        imcb_ask_with_free(bu->ic, buf, bla, msn_buddy_ask_yes, msn_buddy_ask_no, msn_buddy_ask_free);
     172}
     173
     174void msn_queue_feed(struct msn_data *h, char *bytes, int st)
     175{
     176        h->rxq = g_renew(char, h->rxq, h->rxlen + st);
     177        memcpy(h->rxq + h->rxlen, bytes, st);
     178        h->rxlen += st;
     179
     180        if (getenv("BITLBEE_DEBUG")) {
     181                fprintf(stderr, "\n\x1b[92m<<< ");
     182                write(2, bytes , st);
     183                fprintf(stderr, "\x1b[97m");
     184        }
    252185}
    253186
     
    260193                   1: OK */
    261194
    262 int msn_handler(struct msn_handler_data *h)
    263 {
    264         int st;
    265 
    266         h->rxq = g_renew(char, h->rxq, h->rxlen + 1024);
    267         st = read(h->fd, h->rxq + h->rxlen, 1024);
    268         h->rxlen += st;
    269 
    270         if (st <= 0) {
    271                 return(-1);
    272         }
    273 
    274         if (getenv("BITLBEE_DEBUG")) {
    275                 write(2, "->C:", 4);
    276                 write(2, h->rxq + h->rxlen - st, st);
    277         }
     195int msn_handler(struct msn_data *h)
     196{
     197        int st = 1;
    278198
    279199        while (st) {
     
    287207
    288208                                        cmd_text = g_strndup(h->rxq, i);
    289                                         cmd = msn_linesplit(cmd_text);
    290                                         for (count = 0; cmd[count]; count++) {
    291                                                 ;
    292                                         }
    293                                         st = h->exec_command(h, cmd, count);
     209                                        cmd = g_strsplit_set(cmd_text, " ", -1);
     210                                        count = g_strv_length(cmd);
     211
     212                                        st = msn_ns_command(h, cmd, count);
     213
     214                                        g_strfreev(cmd);
    294215                                        g_free(cmd_text);
    295216
     
    314235                        /* If we reached the end of the buffer, there's still an incomplete command there.
    315236                           Return and wait for more data. */
    316                         if (i == h->rxlen && h->rxq[i - 1] != '\r' && h->rxq[i - 1] != '\n') {
     237                        if (i && i == h->rxlen && h->rxq[i - 1] != '\r' && h->rxq[i - 1] != '\n') {
    317238                                break;
    318239                        }
     
    327248
    328249                        msg = g_strndup(h->rxq, h->msglen);
    329                         cmd = msn_linesplit(h->cmd_text);
    330                         for (count = 0; cmd[count]; count++) {
    331                                 ;
    332                         }
    333 
    334                         st = h->exec_message(h, msg, h->msglen, cmd, count);
     250
     251                        cmd = g_strsplit_set(h->cmd_text, " ", -1);
     252                        count = g_strv_length(cmd);
     253
     254                        st = msn_ns_message(h, msg, h->msglen, cmd, count);
     255
     256                        g_strfreev(cmd);
    335257                        g_free(msg);
    336258                        g_free(h->cmd_text);
     
    366288}
    367289
    368 void msn_msgq_purge(struct im_connection *ic, GSList **list)
    369 {
    370         struct msn_message *m;
    371         GString *ret;
    372         GSList *l;
    373         int n = 0;
    374 
    375         l = *list;
    376         if (l == NULL) {
    377                 return;
    378         }
    379 
    380         m = l->data;
    381         ret = g_string_sized_new(1024);
    382         g_string_printf(ret, "Warning: Cleaning up MSN (switchboard) connection with unsent "
    383                         "messages to %s:", m->who ? m->who : "unknown recipient");
    384 
    385         while (l) {
    386                 m = l->data;
    387 
    388                 if (strncmp(m->text, "\r\r\r", 3) != 0) {
    389                         g_string_append_printf(ret, "\n%s", m->text);
    390                         n++;
    391                 }
    392 
    393                 g_free(m->who);
    394                 g_free(m->text);
    395                 g_free(m);
    396 
    397                 l = l->next;
    398         }
    399         g_slist_free(*list);
    400         *list = NULL;
    401 
    402         if (n > 0) {
    403                 imcb_log(ic, "%s", ret->str);
    404         }
    405         g_string_free(ret, TRUE);
    406 }
    407 
    408290/* Copied and heavily modified from http://tmsnc.sourceforge.net/chl.c */
    409291char *msn_p11_challenge(char *challenge)
     
    529411int msn_ns_set_display_name(struct im_connection *ic, const char *value)
    530412{
    531         struct msn_data *md = ic->proto_data;
    532         char fn[strlen(value) * 3 + 1];
    533 
    534         strcpy(fn, value);
    535         http_encode(fn);
    536 
    537         /* Note: We don't actually know if the server accepted the new name,
    538            and won't give proper feedback yet if it doesn't. */
    539         return msn_ns_write(ic, -1, "PRP %d MFN %s\r\n", ++md->trId, fn);
     413        // TODO, implement this through msn_set_away's method
     414        return 1;
    540415}
    541416
Note: See TracChangeset for help on using the changeset viewer.