From fd93cf56442c884e1545bd388cf48928d4ae93a1 Mon Sep 17 00:00:00 2001 From: Jakub Adam Date: Sun, 28 Mar 2010 17:34:57 +0200 Subject: [PATCH] audio: compilation fixes after rebase --- src/api/sipe-mime.h | 2 +- src/core/sipe-media.c | 38 +++++++++------------- src/core/sipe-utils.c | 39 ---------------------- src/core/sipe-utils.h | 3 -- src/core/sipe.c | 84 ++++++++++++++++++++---------------------------- src/core/sipmsg.c | 3 +- src/purple/purple-mime.c | 24 +++++++++++++- 7 files changed, 76 insertions(+), 117 deletions(-) diff --git a/src/api/sipe-mime.h b/src/api/sipe-mime.h index 5a7cb063..dd4d88af 100644 --- a/src/api/sipe-mime.h +++ b/src/api/sipe-mime.h @@ -29,7 +29,7 @@ * @param length length of the body text. */ typedef void (*sipe_mime_parts_cb)(gpointer user_data, - const gchar *type, + const GSList *fields, const gchar *body, gsize length); diff --git a/src/core/sipe-media.c b/src/core/sipe-media.c index 94c842e7..56c53a5c 100644 --- a/src/core/sipe-media.c +++ b/src/core/sipe-media.c @@ -22,10 +22,13 @@ #include "mediamanager.h" +#include "sip-sec.h" #include "sipe.h" +#include "sipmsg.h" #include "sipe-media.h" #include "sipe-dialog.h" #include "sipe-utils.h" +#include "sipe-common.h" //#include #include "../../../libnice/agent/agent.h" @@ -510,9 +513,6 @@ sipe_media_session_ready_cb(sipe_media_call *call) if (!purple_media_accepted(media, NULL, NULL)) { call->sdp_response = sipe_media_create_sdp(call, FALSE); - // TODO: put away? - sipmsg_add_header(call->invitation, "Require", "100rel"); - sipmsg_add_header(call->invitation, "RSeq", "1"); send_sip_response(account->gc, call->invitation, 183, "Session Progress", call->sdp_response); } else { send_sip_response(account->gc, call->invitation, 200, "OK", call->sdp_response); @@ -520,7 +520,7 @@ sipe_media_session_ready_cb(sipe_media_call *call) } static void -sipe_media_stream_info_cb(SIPE_UNUSED_PARAMETER PurpleMedia *media, +sipe_media_stream_info_cb(PurpleMedia *media, PurpleMediaInfoType type, SIPE_UNUSED_PARAMETER gchar *sid, SIPE_UNUSED_PARAMETER gchar *name, @@ -569,9 +569,16 @@ void sipe_media_incoming_invite(struct sipe_account_data *sip, struct sipmsg *ms sipe_media_call *call; struct sip_dialog *dialog; + gchar *newTag; + const gchar *oldHeader; + gchar *newHeader; + + GParameter *params; + if (sip->media_call) { const gchar *incoming_callid = sipmsg_find_header(msg, "Call-ID"); if (sipe_strequal(sip->media_call->dialog->callid, incoming_callid)) { + gchar *rsp; sipe_media_call *call = sip->media_call; sipe_utils_nameval_free(call->sdp_attrs); call->sdp_attrs = NULL; @@ -586,7 +593,7 @@ void sipe_media_incoming_invite(struct sipe_account_data *sip, struct sipmsg *ms call->remote_codecs) == FALSE) printf("ERROR SET REMOTE CODECS"); // TODO - gchar *rsp = sipe_media_create_sdp(sip->media_call, TRUE); + rsp = sipe_media_create_sdp(sip->media_call, TRUE); send_sip_response(sip->gc, msg, 200, "OK", rsp); g_free(rsp); } else { @@ -596,9 +603,9 @@ void sipe_media_incoming_invite(struct sipe_account_data *sip, struct sipmsg *ms return; } - gchar *newTag = gentag(); - const gchar *oldHeader = sipmsg_find_header(msg, "To"); - gchar *newHeader = g_strdup_printf("%s;tag=%s", oldHeader, newTag); + newTag = gentag(); + oldHeader = sipmsg_find_header(msg, "To"); + newHeader = g_strdup_printf("%s;tag=%s", oldHeader, newTag); sipmsg_remove_header_now(msg, "To"); sipmsg_add_header_now(msg, "To", newHeader); g_free(newHeader); @@ -624,7 +631,7 @@ void sipe_media_incoming_invite(struct sipe_account_data *sip, struct sipmsg *ms g_signal_connect_swapped(G_OBJECT(media), "candidates-prepared", G_CALLBACK(sipe_media_session_ready_cb), call); - GParameter *params = g_new0(GParameter, 2); + params = g_new0(GParameter, 2); params[0].name = "controlling-mode"; g_value_init(¶ms[0].value, G_TYPE_BOOLEAN); g_value_set_boolean(¶ms[0].value, FALSE); @@ -637,19 +644,6 @@ void sipe_media_incoming_invite(struct sipe_account_data *sip, struct sipmsg *ms purple_media_add_stream(media, "sipe-voice", dialog->with, PURPLE_MEDIA_AUDIO, FALSE, "nice", 2, params); -/* FsConference* fs_conference; - g_object_get(media, "conference", &fs_conference, NULL); - - // TODO: substring function - size_t contact_len = strlen(sip->contact); - gchar* contact = g_malloc(contact_len - 1); - memcpy(contact, sip->contact + 1, contact_len - 2); - contact[contact_len - 2] = 0; - - g_object_set(fs_conference, "sdes-cname", contact, NULL); - - g_free(contact);*/ - call->remote_candidates = sipe_media_parse_remote_candidates(call->sdp_attrs); if (!call->remote_candidates) { // TODO: error no remote candidates diff --git a/src/core/sipe-utils.c b/src/core/sipe-utils.c index 9b667a6d..00dac868 100644 --- a/src/core/sipe-utils.c +++ b/src/core/sipe-utils.c @@ -440,45 +440,6 @@ void sipe_utils_shrink_buffer(struct sipe_transport_connection *conn, memmove(conn->buffer, unread, conn->buffer_used + 1); } -GSList * sipe_utils_mime_multipart_find_parts(struct sipmsg *msg) -{ - const gchar *contenttype = sipmsg_find_header(msg, "Content-Type"); - gchar *boundary; - GSList *parts = NULL; - gchar *part_ptr; - - if (contenttype && g_str_has_prefix(contenttype, "multipart/alternative")) { - const gchar BOUNDARY[] = "boundary=\""; - gchar *boundary_begin = g_strstr_len(contenttype, strlen(contenttype), BOUNDARY); - gchar *boundary_end; - gchar *tmp; - - if (!boundary_begin) - return NULL; - boundary_begin += sizeof(BOUNDARY) - 1; - - boundary_end = boundary_begin; - while (*boundary_end != 0 && *boundary_end != '"') - ++boundary_end; - - boundary = g_malloc0(boundary_end - boundary_begin + 1); - memcpy(boundary, boundary_begin, boundary_end - boundary_begin); - - tmp = g_strdup_printf("--%s\r\n", boundary); - g_free(boundary); - boundary = tmp; - } else - return NULL; - - part_ptr = msg->body; - while ((part_ptr = strstr(part_ptr, boundary))) { - part_ptr += strlen(boundary); - parts = g_slist_append(parts, part_ptr); - } - - return parts; -} - /* * Calling sizeof(struct ifreq) isn't always correct on * Mac OS X (and maybe others). diff --git a/src/core/sipe-utils.h b/src/core/sipe-utils.h index a700c898..9178368a 100644 --- a/src/core/sipe-utils.h +++ b/src/core/sipe-utils.h @@ -366,9 +366,6 @@ sipe_utils_nameval_find_instance(const GSList *list, const gchar *name, int whic void sipe_utils_nameval_free(GSList *list); -GSList * -sipe_utils_mime_multipart_find_parts(struct sipmsg *msg); - /** * Given a string, this replaces one substring with another * and returns a newly allocated string. diff --git a/src/core/sipe.c b/src/core/sipe.c index 089c07fb..4a0d8b47 100644 --- a/src/core/sipe.c +++ b/src/core/sipe.c @@ -4606,6 +4606,35 @@ static void process_incoming_message(struct sipe_core_private *sipe_private, g_free(from); } +static void sipe_invite_mime_cb(gpointer user_data, const GSList *fields, + const gchar *body, SIPE_UNUSED_PARAMETER gsize length) +{ + const gchar *type = sipe_utils_nameval_find(fields, "Content-Type"); + const gchar *cd = sipe_utils_nameval_find(fields, "Content-Disposition"); + + if (!g_str_has_prefix(type, "application/sdp")) + return; + + if (cd && !strstr(cd, "ms-proxy-2007fallback")) { + struct sipmsg *msg = user_data; + const gchar* msg_ct = sipmsg_find_header(msg, "Content-Type"); + + if (g_str_has_prefix(msg_ct, "application/sdp")) { + /* We have already found suitable alternative and set message's body + * and Content-Type accordingly */ + return; + } + + sipmsg_remove_header_now(msg, "Content-Type"); + sipmsg_add_header_now(msg, "Content-Type", type); + + /* Replace message body with chosen alternative, so we can continue to + * process it as a normal single part message. */ + g_free(msg->body); + msg->body = g_strndup(body, length); + } +} + static void process_incoming_invite(struct sipe_core_private *sipe_private, struct sipmsg *msg) { @@ -4632,52 +4661,8 @@ static void process_incoming_invite(struct sipe_core_private *sipe_private, SIPE_DEBUG_INFO("process_incoming_invite: body:\n%s!", msg->body ? tmp = fix_newlines(msg->body) : ""); g_free(tmp); - // TODO: OCS2007 native media call negotiation - /* Invitation to media call from OC2007 R2. Sending this response should - * force legacy mode */ if (g_str_has_prefix(content_type, "multipart/alternative")) { -// send_sip_response(sip->gc, msg, 415, "Unsupported Media Type", NULL); -// return; - - GSList *parts = sipe_utils_mime_multipart_find_parts(msg); - GSList *part = parts; - gboolean found = FALSE; - - while (!found && part) { - const char *tmp = strstr(part->data, "\r\n\r\n"); - gchar *header = g_strndup(part->data, tmp - (gchar *)part->data); - gchar **lines = g_strsplit(header, "\r\n", 0); - GSList *headers = NULL; - - sipe_utils_parse_lines(&headers, lines, ":"); - - g_free(header); - g_strfreev(lines); - - const gchar * disposition = sipe_utils_nameval_find(headers, "Content-Disposition"); - if (!strstr(disposition, "ms-proxy-2007fallback")) { - GSList *it = headers; - const char *body_end = strstr(tmp + 4, "\r\n\r\n") + 2; - sipmsg_remove_header_now(msg, "Content-Type"); - - while (it) { - struct sipnameval *nv = it->data; - sipmsg_add_header_now(msg, nv->name, nv->value); - it = it->next; - } - - g_free(msg->body); - msg->body = g_strndup(tmp + 4, body_end - tmp + 4); - - found = TRUE; - } - - g_slist_free(headers); - - part = part->next; - } - - g_slist_free(parts); + sipe_mime_parts_foreach(content_type, msg->body, sipe_invite_mime_cb, msg); } /* Invitation to join conference */ @@ -4689,9 +4674,6 @@ static void process_incoming_invite(struct sipe_core_private *sipe_private, /* Invitation to audio call */ if (msg->body && strstr(msg->body, "m=audio")) { sipe_media_incoming_invite(sip, msg); - /*sipmsg_add_header(msg, "User-Agent", "UCCAPI/3.5.6907.0 OC/3.5.6907.0 (Microsoft Office Communicator 2007 R2)"); - sipmsg_remove_header_now(msg, "Content-Type"); - sipmsg_remove_header_now(msg, "Contact");*/ return; } @@ -6263,10 +6245,12 @@ static void process_incoming_notify_msrtc(struct sipe_core_private *sipe_private } static void sipe_presence_mime_cb(gpointer user_data, /* sipe_core_private */ - const gchar *type, + const GSList *fields, const gchar *body, gsize length) { + const gchar *type = sipe_utils_nameval_find(fields, "Content-Type"); + if (strstr(type,"application/rlmi+xml")) { process_incoming_notify_rlmi_resub(user_data, body, length); } else if (strstr(type, "text/xml+msrtc.pidf")) { @@ -6311,7 +6295,7 @@ static void sipe_process_presence(struct sipe_core_private *sipe_private, } static void sipe_presence_timeout_mime_cb(gpointer user_data, - SIPE_UNUSED_PARAMETER const gchar *type, + SIPE_UNUSED_PARAMETER const GSList *fields, const gchar *body, gsize length) { diff --git a/src/core/sipmsg.c b/src/core/sipmsg.c index b1b82026..c1782146 100644 --- a/src/core/sipmsg.c +++ b/src/core/sipmsg.c @@ -447,10 +447,11 @@ struct html_message_data { }; static void get_html_message_mime_cb(gpointer user_data, - const gchar *type, + const GSList *fields, const gchar *body, gsize length) { + const gchar *type = sipe_utils_nameval_find(fields, "Content-Type"); struct html_message_data *data = user_data; if (!data->preferred) { diff --git a/src/purple/purple-mime.c b/src/purple/purple-mime.c index c9706f3b..1e602e4e 100644 --- a/src/purple/purple-mime.c +++ b/src/purple/purple-mime.c @@ -25,6 +25,25 @@ #include "mime.h" #include "sipe-mime.h" +#include "../core/sipe-utils.h" + +static +GSList * mime_fields_to_nameval(PurpleMimePart* part) +{ + GList *keys = purple_mime_part_get_fields(part); + GSList *fields = NULL; + + while (keys) { + const char *key = keys->data; + const char *value = purple_mime_part_get_field(part, key); + + fields = sipe_utils_nameval_add(fields, key, value); + + keys = keys->next; + } + + return fields; +} void sipe_mime_parts_foreach(const gchar *type, const gchar *body, @@ -43,8 +62,11 @@ void sipe_mime_parts_foreach(const gchar *type, if (content_type) { const gchar *content = purple_mime_part_get_data(parts->data); gsize length = purple_mime_part_get_length(parts->data); + GSList *fields = mime_fields_to_nameval(parts->data); + + (*callback)(user_data, fields, content, length); - (*callback)(user_data, content_type, content, length); + sipe_utils_nameval_free(fields); } parts = parts->next; } -- 2.11.4.GIT