]> sjero.net Git - linphone/blobdiff - coreapi/sal_eXosip2.c
add support of external-body for SIP message
[linphone] / coreapi / sal_eXosip2.c
index 695d8568d4bddef4203fcb83e680bb5c313fc2ae..30b0f286dafb59c73ec2b28859793de9f9bebd3f 100644 (file)
@@ -341,6 +341,8 @@ void sal_set_callbacks(Sal *ctx, const SalCallbacks *cbs){
                ctx->callbacks.text_received=(SalOnTextReceived)unimplemented_stub;
        if (ctx->callbacks.ping_reply==NULL)
                ctx->callbacks.ping_reply=(SalOnPingReply)unimplemented_stub;
+       if (ctx->callbacks.message_external_body==NULL)
+               ctx->callbacks.message_external_body=(SalOnMessageExternalBodyReceived)unimplemented_stub;
 }
 
 int sal_unlisten_ports(Sal *ctx){
@@ -1701,15 +1703,44 @@ static bool_t comes_from_local_if(osip_message_t *msg){
 static void text_received(Sal *sal, eXosip_event_t *ev){
        osip_body_t *body=NULL;
        char *from=NULL,*msg;
+       osip_content_type_t* content_type;
+       osip_uri_param_t* external_body_url; 
+       char unquoted_external_body_url [256];
+       int external_body_size=0;
        
+       content_type= osip_message_get_content_type(ev->request);
+       if (!content_type) {
+               ms_error("Could not get message because no content type");
+               return;
+       }
+       osip_from_to_str(ev->request->from,&from);
+       if (content_type->type 
+               && strcmp(content_type->type, "text")==0 
+               && content_type->subtype
+               && strcmp(content_type->subtype, "plain")==0 ) {
        osip_message_get_body(ev->request,0,&body);
        if (body==NULL){
                ms_error("Could not get text message from SIP body");
                return;
        }
        msg=body->body;
-       osip_from_to_str(ev->request->from,&from);
        sal->callbacks.text_received(sal,from,msg);
+       } if (content_type->type 
+                 && strcmp(content_type->type, "message")==0 
+                 && content_type->subtype
+                 && strcmp(content_type->subtype, "external-body")==0 ) {
+               
+               osip_content_type_param_get_byname(content_type, "URL", &external_body_url);
+               /*remove both first and last character*/
+               strncpy(unquoted_external_body_url
+                               ,&external_body_url->gvalue[1]
+                               ,external_body_size=MIN(strlen(external_body_url->gvalue)-1,sizeof(unquoted_external_body_url)));
+               unquoted_external_body_url[external_body_size-1]='\0';
+               sal->callbacks.message_external_body(sal,from,unquoted_external_body_url);
+               
+       } else {
+               ms_warning("Unsupported content type [%s/%s]",content_type->type,content_type->subtype);
+       }
        osip_free(from);
 }