comparison src/protocols/simple/simple.c @ 12754:d37adb7af391

[gaim-migrate @ 15101] Fix for [ 1397936 ] SIP/SIMPLE generates bad 501 Content-Length may have been wrong if the body is different in a numeric response. committer: Tailor Script <tailor@pidgin.im>
author Thomas Butter <tbutter>
date Sat, 07 Jan 2006 18:50:37 +0000
parents ddae10386677
children 505bc707b641
comparison
equal deleted inserted replaced
12753:ddae10386677 12754:d37adb7af391
454 454
455 static void send_sip_response(GaimConnection *gc, struct sipmsg *msg, int code, char *text, char *body) { 455 static void send_sip_response(GaimConnection *gc, struct sipmsg *msg, int code, char *text, char *body) {
456 GSList *tmp = msg->headers; 456 GSList *tmp = msg->headers;
457 gchar *name; 457 gchar *name;
458 gchar *value; 458 gchar *value;
459 gchar zero[2] = {'0', '\0'};
460 GString *outstr = g_string_new(""); 459 GString *outstr = g_string_new("");
460
461 /* When sending the acknowlegements and errors, the content length from the original
462 message is still here, but there is no body; we need to make sure we're sending the
463 correct content length */
464 sipmsg_remove_header(msg, "Content-Length");
465 if(body) {
466 gchar len[12];
467 sprintf(len, "%" G_GSIZE_FORMAT , strlen(body));
468 sipmsg_add_header(msg, "Content-Length",len);
469 }
470 else
471 sipmsg_add_header(msg, "Content-Length", "0");
461 g_string_append_printf(outstr, "SIP/2.0 %d %s\r\n", code, text); 472 g_string_append_printf(outstr, "SIP/2.0 %d %s\r\n", code, text);
462 while(tmp) { 473 while(tmp) {
463 name = ((struct siphdrelement*) (tmp->data))->name; 474 name = ((struct siphdrelement*) (tmp->data))->name;
464 value = ((struct siphdrelement*) (tmp->data))->value; 475 value = ((struct siphdrelement*) (tmp->data))->value;
465
466 /* When sending the acknowlegements and errors, the content length from the original
467 message is still here, but there is no body; we need to make sure we're sending the
468 correct content length */
469 if(strcmp(name, "Content-Length") == 0 && !body) {
470 value = zero;
471 }
472 476
473 g_string_append_printf(outstr, "%s: %s\r\n", name, value); 477 g_string_append_printf(outstr, "%s: %s\r\n", name, value);
474 tmp = g_slist_next(tmp); 478 tmp = g_slist_next(tmp);
475 } 479 }
476 g_string_append_printf(outstr, "\r\n%s", body ? body : ""); 480 g_string_append_printf(outstr, "\r\n%s", body ? body : "");