--- a/libpurple/protocols/simple/simple.c Tue May 19 10:14:43 2020 +0000
+++ b/libpurple/protocols/simple/simple.c Tue May 19 10:29:23 2020 +0000
@@ -605,52 +605,33 @@
-static void sendout_sipmsg(struct simple_account_data *sip, struct sipmsg *msg) {
- GSList *tmp = msg->headers;
- GString *outstr = g_string_new("");
- g_string_append_printf(outstr, "%s %s SIP/2.0\r\n", msg->method, msg->target);
- name = ((struct siphdrelement*) (tmp->data))->name;
- value = ((struct siphdrelement*) (tmp->data))->value;
- g_string_append_printf(outstr, "%s: %s\r\n", name, value);
- tmp = g_slist_next(tmp);
- g_string_append_printf(outstr, "\r\n%s", msg->body ? msg->body : "");
- sendout_pkt(sip->gc, outstr->str);
- g_string_free(outstr, TRUE);
-static void send_sip_response(PurpleConnection *gc, struct sipmsg *msg, int code,
- const char *text, const char *body) {
- GSList *tmp = msg->headers;
- GString *outstr = g_string_new("");
+send_sip_response(PurpleConnection *gc, struct sipmsg *msg, gint code, + const gchar *text, const gchar *body) /* When sending the acknowlegements and errors, the content length from the original
message is still here, but there is no body; we need to make sure we're sending the
correct content length */
sipmsg_remove_header(msg, "Content-Length");
+ g_clear_pointer(&msg->body, g_free); - sprintf(len, "%" G_GSIZE_FORMAT , strlen(body));
+ msg->bodylen = strlen(body); + sprintf(len, "%d", msg->bodylen); sipmsg_add_header(msg, "Content-Length", len);
+ msg->body = g_strdup(body); sipmsg_add_header(msg, "Content-Length", "0");
- g_string_append_printf(outstr, "SIP/2.0 %d %s\r\n", code, text);
- name = ((struct siphdrelement*) (tmp->data))->name;
- value = ((struct siphdrelement*) (tmp->data))->value;
- g_string_append_printf(outstr, "%s: %s\r\n", name, value);
- tmp = g_slist_next(tmp);
- g_string_append_printf(outstr, "\r\n%s", body ? body : "");
- sendout_pkt(gc, outstr->str);
- g_string_free(outstr, TRUE);
+ outstr = sipmsg_to_string(msg, text); + sendout_pkt(gc, outstr); @@ -1027,8 +1008,11 @@
if((currtime - trans->time > 2) && trans->retries == 0) {
- sendout_sipmsg(sip, trans->msg);
+ outstr = sipmsg_to_string(trans->msg, NULL); + sendout_pkt(sip->gc, outstr); @@ -1595,7 +1579,7 @@
sipmsg_remove_header(trans->msg, "Proxy-Authorization");
sipmsg_add_header(trans->msg, "Proxy-Authorization", auth);
- resend = sipmsg_to_string(trans->msg);
+ resend = sipmsg_to_string(trans->msg, NULL); sendout_pkt(sip->gc, resend);
@@ -1639,7 +1623,7 @@
sipmsg_remove_header(trans->msg, "Authorization");
sipmsg_add_header(trans->msg, "Authorization", auth);
- resend = sipmsg_to_string(trans->msg);
+ resend = sipmsg_to_string(trans->msg, NULL); sendout_pkt(sip->gc, resend);
--- a/libpurple/protocols/simple/sipmsg.c Tue May 19 10:14:43 2020 +0000
+++ b/libpurple/protocols/simple/sipmsg.c Tue May 19 10:29:23 2020 +0000
@@ -134,35 +134,42 @@
void sipmsg_print(const struct sipmsg *msg) {
- struct siphdrelement *elem;
- purple_debug(PURPLE_DEBUG_MISC, "simple", "SIP MSG\n");
- purple_debug(PURPLE_DEBUG_MISC, "simple", "response: %d\nmethod: %s\nbodylen: %d\n",msg->response,msg->method,msg->bodylen);
- if(msg->target) purple_debug(PURPLE_DEBUG_MISC, "simple", "target: %s\n",msg->target);
+ PurpleKeyValuePair *elem; + purple_debug_misc("simple", "SIP MSG"); + purple_debug_misc("simple", "response: %d\nmethod: %s\nbodylen: %d", + msg->response, msg->method, msg->bodylen); + purple_debug_misc("simple", "target: %s", msg->target); - purple_debug(PURPLE_DEBUG_MISC, "simple", "name: %s value: %s\n",elem->name, elem->value);
+ purple_debug_misc("simple", "name: %s value: %s", elem->key, -char *sipmsg_to_string(const struct sipmsg *msg) {
+sipmsg_to_string(const struct sipmsg *msg, const gchar *status_text) GString *outstr = g_string_new("");
- struct siphdrelement *elem;
+ PurpleKeyValuePair *elem;
- g_string_append_printf(outstr, "SIP/2.0 %d Unknown\r\n",
+ g_string_append_printf(outstr, "SIP/2.0 %d %s\r\n", msg->response, + status_text ? status_text : "Unknown"); g_string_append_printf(outstr, "%s %s SIP/2.0\r\n",
msg->method, msg->target);
- g_string_append_printf(outstr, "%s: %s\r\n", elem->name,
+ g_string_append_printf(outstr, "%s: %s\r\n", elem->key, @@ -170,44 +177,49 @@
return g_string_free(outstr, FALSE);
-void sipmsg_add_header(struct sipmsg *msg, const gchar *name, const gchar *value) {
- struct siphdrelement *element = g_new(struct siphdrelement,1);
- element->name = g_strdup(name);
- element->value = g_strdup(value);
+sipmsg_add_header(struct sipmsg *msg, const gchar *name, const gchar *value) + PurpleKeyValuePair *element = + purple_key_value_pair_new_full(name, g_strdup(value), g_free); msg->headers = g_slist_append(msg->headers, element);
-sipmsg_free_header(struct siphdrelement *elem)
void sipmsg_free(struct sipmsg *msg) {
- g_slist_free_full(msg->headers, (GDestroyNotify)sipmsg_free_header);
+ g_slist_free_full(msg->headers, (GDestroyNotify)purple_key_value_pair_free); -void sipmsg_remove_header(struct sipmsg *msg, const gchar *name) {
- GSList *tmp = g_slist_find_custom(msg->headers, name, (GCompareFunc)g_ascii_strcasecmp);
- struct siphdrelement *elem = tmp->data;
+compare_header_names(gconstpointer a, gconstpointer b) + const PurpleKeyValuePair *kvpa = a; + return g_ascii_strcasecmp(kvpa->key, name); +sipmsg_remove_header(struct sipmsg *msg, const gchar *name) + GSList *tmp = g_slist_find_custom(msg->headers, name, compare_header_names); + PurpleKeyValuePair *elem = tmp->data; msg->headers = g_slist_delete_link(msg->headers, tmp);
- sipmsg_free_header(elem);
+ purple_key_value_pair_free(elem); -const gchar *sipmsg_find_header(struct sipmsg *msg, const gchar *name) {
- GSList *tmp = g_slist_find_custom(msg->headers, name, (GCompareFunc)g_ascii_strcasecmp);
- struct siphdrelement *elem = tmp->data;
+sipmsg_find_header(struct sipmsg *msg, const gchar *name) + GSList *tmp = g_slist_find_custom(msg->headers, name, compare_header_names); + PurpleKeyValuePair *elem = tmp->data;
--- a/libpurple/protocols/simple/sipmsg.h Tue May 19 10:14:43 2020 +0000
+++ b/libpurple/protocols/simple/sipmsg.h Tue May 19 10:29:23 2020 +0000
@@ -32,11 +32,6 @@
struct sipmsg *sipmsg_parse_msg(const gchar *msg);
struct sipmsg *sipmsg_parse_header(const gchar *header);
void sipmsg_add_header(struct sipmsg *msg, const gchar *name, const gchar *value);
@@ -44,6 +39,6 @@
const gchar *sipmsg_find_header(struct sipmsg *msg, const gchar *name);
void sipmsg_remove_header(struct sipmsg *msg, const gchar *name);
void sipmsg_print(const struct sipmsg *msg);
-char *sipmsg_to_string(const struct sipmsg *msg);
+gchar *sipmsg_to_string(const struct sipmsg *msg, const gchar *status_text); #endif /* PURPLE_SIMPLE_SIPMSG_H */