Changes in protocols/msn/msn_util.c [098a75b:913a663]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/msn/msn_util.c
r098a75b r913a663 55 55 56 56 *groupid = '\0'; 57 #if 058 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 a92 new group at once; we're still waiting for the server93 to confirm group creation. */94 return 1;95 }96 }97 }98 #endif99 57 100 58 if (!((bu = bee_user_by_handle(ic->bee, ic, who)) || … … 132 90 133 91 *groupid = '\0'; 134 #if 0135 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 #endif145 92 146 93 if (!(bu = bee_user_by_handle(ic->bee, ic, who)) || … … 225 172 } 226 173 227 /* *NOT* thread-safe, but that's not a problem for now... */ 228 char **msn_linesplit(char *line) 229 { 230 static char **ret = NULL; 231 static int size = 3; 232 int i, n = 0; 233 234 if (ret == NULL) { 235 ret = g_new0(char*, size); 236 } 237 238 for (i = 0; line[i] && line[i] == ' '; i++) { 239 ; 240 } 241 if (line[i]) { 242 ret[n++] = line + i; 243 for (i++; line[i]; i++) { 244 if (line[i] == ' ') { 245 line[i] = 0; 246 } else if (line[i] != ' ' && !line[i - 1]) { 247 ret[n++] = line + i; 248 } 249 250 if (n >= size) { 251 ret = g_renew(char*, ret, size += 2); 252 } 253 } 254 } 255 ret[n] = NULL; 256 257 return(ret); 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 } 258 185 } 259 186 … … 266 193 1: OK */ 267 194 268 int msn_handler(struct msn_handler_data *h) 269 { 270 int st; 271 272 h->rxq = g_renew(char, h->rxq, h->rxlen + 1024); 273 st = read(h->fd, h->rxq + h->rxlen, 1024); 274 h->rxlen += st; 275 276 if (st <= 0) { 277 return(-1); 278 } 279 280 if (getenv("BITLBEE_DEBUG")) { 281 write(2, "->C:", 4); 282 write(2, h->rxq + h->rxlen - st, st); 283 } 195 int msn_handler(struct msn_data *h) 196 { 197 int st = 1; 284 198 285 199 while (st) { … … 293 207 294 208 cmd_text = g_strndup(h->rxq, i); 295 cmd = msn_linesplit(cmd_text); 296 for (count = 0; cmd[count]; count++) { 297 ; 298 } 299 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); 300 215 g_free(cmd_text); 301 216 … … 320 235 /* If we reached the end of the buffer, there's still an incomplete command there. 321 236 Return and wait for more data. */ 322 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') { 323 238 break; 324 239 } … … 333 248 334 249 msg = g_strndup(h->rxq, h->msglen); 335 cmd = msn_linesplit(h->cmd_text); 336 for (count = 0; cmd[count]; count++) { 337 ; 338 } 339 340 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); 341 257 g_free(msg); 342 258 g_free(h->cmd_text); … … 372 288 } 373 289 374 void msn_msgq_purge(struct im_connection *ic, GSList **list)375 {376 struct msn_message *m;377 GString *ret;378 GSList *l;379 int n = 0;380 381 l = *list;382 if (l == NULL) {383 return;384 }385 386 m = l->data;387 ret = g_string_sized_new(1024);388 g_string_printf(ret, "Warning: Cleaning up MSN (switchboard) connection with unsent "389 "messages to %s:", m->who ? m->who : "unknown recipient");390 391 while (l) {392 m = l->data;393 394 if (strncmp(m->text, "\r\r\r", 3) != 0) {395 g_string_append_printf(ret, "\n%s", m->text);396 n++;397 }398 399 g_free(m->who);400 g_free(m->text);401 g_free(m);402 403 l = l->next;404 }405 g_slist_free(*list);406 *list = NULL;407 408 if (n > 0) {409 imcb_log(ic, "%s", ret->str);410 }411 g_string_free(ret, TRUE);412 }413 414 290 /* Copied and heavily modified from http://tmsnc.sourceforge.net/chl.c */ 415 291 char *msn_p11_challenge(char *challenge) … … 535 411 int msn_ns_set_display_name(struct im_connection *ic, const char *value) 536 412 { 537 struct msn_data *md = ic->proto_data; 538 char fn[strlen(value) * 3 + 1]; 539 540 strcpy(fn, value); 541 http_encode(fn); 542 543 /* Note: We don't actually know if the server accepted the new name, 544 and won't give proper feedback yet if it doesn't. */ 545 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; 546 415 } 547 416
Note: See TracChangeset
for help on using the changeset viewer.