Changes in protocols/msn/msn_util.c [913a663:5ebff60]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/msn/msn_util.c
r913a663 r5ebff60 55 55 56 56 *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 57 99 58 100 if (!((bu = bee_user_by_handle(ic->bee, ic, who)) || … … 90 132 91 133 *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 92 145 93 146 if (!(bu = bee_user_by_handle(ic->bee, ic, who)) || … … 121 174 }; 122 175 123 static void msn_buddy_ask_ free(void *data)176 static void msn_buddy_ask_yes(void *data) 124 177 { 125 178 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); 126 183 127 184 g_free(bla->handle); … … 130 187 } 131 188 132 static void msn_buddy_ask_ yes(void *data)189 static void msn_buddy_ask_no(void *data) 133 190 { 134 191 struct msn_buddy_ask_data *bla = data; 135 192 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 143 static void msn_buddy_ask_no(void *data)144 {145 struct msn_buddy_ask_data *bla = data;146 147 193 msn_buddy_list_add(bla->ic, MSN_BUDDY_BL, bla->handle, bla->realname, NULL); 148 194 149 msn_buddy_ask_free(bla); 195 g_free(bla->handle); 196 g_free(bla->realname); 197 g_free(bla); 150 198 } 151 199 … … 168 216 "The user %s (%s) wants to add you to his/her buddy list.", 169 217 bu->handle, bu->fullname); 170 171 imcb_ask_with_free(bu->ic, buf, bla, msn_buddy_ask_yes, msn_buddy_ask_no, msn_buddy_ask_free); 172 } 173 174 void 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 } 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); 185 252 } 186 253 … … 193 260 1: OK */ 194 261 195 int msn_handler(struct msn_data *h) 196 { 197 int st = 1; 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 } 198 278 199 279 while (st) { … … 207 287 208 288 cmd_text = g_strndup(h->rxq, i); 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); 289 cmd = msn_linesplit(cmd_text); 290 for (count = 0; cmd[count]; count++) { 291 ; 292 } 293 st = h->exec_command(h, cmd, count); 215 294 g_free(cmd_text); 216 295 … … 235 314 /* If we reached the end of the buffer, there's still an incomplete command there. 236 315 Return and wait for more data. */ 237 if (i && i== h->rxlen && h->rxq[i - 1] != '\r' && h->rxq[i - 1] != '\n') {316 if (i == h->rxlen && h->rxq[i - 1] != '\r' && h->rxq[i - 1] != '\n') { 238 317 break; 239 318 } … … 248 327 249 328 msg = g_strndup(h->rxq, h->msglen); 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); 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); 257 335 g_free(msg); 258 336 g_free(h->cmd_text); … … 288 366 } 289 367 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 290 408 /* Copied and heavily modified from http://tmsnc.sourceforge.net/chl.c */ 291 409 char *msn_p11_challenge(char *challenge) … … 411 529 int msn_ns_set_display_name(struct im_connection *ic, const char *value) 412 530 { 413 // TODO, implement this through msn_set_away's method 414 return 1; 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); 415 540 } 416 541
Note: See TracChangeset
for help on using the changeset viewer.