~ubuntu-branches/ubuntu/utopic/linphone/utopic-proposed

« back to all changes in this revision

Viewing changes to coreapi/chat.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2010-05-23 10:04:07 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100523100407-wev5qrmhwwbs0whh
Tags: 3.3.0-1
* New upstream release

* debian/control: s/is a is an/is an/ (Closes: #582661)
* debian/control s/It main/Its main/ (Closes: #582665) 
* configure --disable-strict (Closes: 561708)
* Cleanup arches libv4l-dev libasound2-dev (Closes: #542595)
* Cleanup debian/watch
* Drop fix_desktop_section.dpatch - included upstream
* Drop desktop-icon.dpatch - included upstream
* Drop always_ipv4_for_ipv4_hosts.dpatch - included upstream
* Drop dpatch
* Upstream dropped /usr/bin/sipomatic

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
 #include "linphonecore.h"
26
26
 #include "private.h"
27
 
 #include <eXosip2/eXosip.h>
28
27
 
29
28
 LinphoneChatRoom * linphone_core_create_chat_room(LinphoneCore *lc, const char *to){
30
 
        char *real_url=NULL;
31
 
        osip_from_t *parsed_url=NULL;
32
 
        char *route;
33
 
        if (linphone_core_interpret_url(lc,to,&real_url,&parsed_url,&route)){
 
29
        LinphoneAddress *parsed_url=NULL;
 
30
 
 
31
        if ((parsed_url=linphone_core_interpret_url(lc,to))!=NULL){
34
32
                LinphoneChatRoom *cr=ms_new0(LinphoneChatRoom,1);
35
33
                cr->lc=lc;
36
 
                cr->peer=real_url;
 
34
                cr->peer=linphone_address_as_string(parsed_url);
37
35
                cr->peer_url=parsed_url;
38
 
                cr->route=route;
 
36
                cr->route=ms_strdup(linphone_core_get_route(lc));
39
37
                lc->chatrooms=ms_list_append(lc->chatrooms,(void *)cr);
40
38
                return cr;
41
39
        }
46
44
 void linphone_chat_room_destroy(LinphoneChatRoom *cr){
47
45
        LinphoneCore *lc=cr->lc;
48
46
        lc->chatrooms=ms_list_remove(lc->chatrooms,(void *) cr);
49
 
        osip_from_free(cr->peer_url);
 
47
        linphone_address_destroy(cr->peer_url);
50
48
        ms_free(cr->peer);
51
49
        ms_free(cr->route);
52
50
 }
53
51
 
54
52
void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg){
55
53
        const char *identity=linphone_core_get_identity(cr->lc);
56
 
        osip_message_t *sip=NULL;
57
 
        eXosip_message_build_request(&sip,"MESSAGE",cr->peer,identity,cr->route);
58
 
        osip_message_set_content_type(sip,"text/plain");
59
 
        osip_message_set_body(sip,msg,strlen(msg));
60
 
        eXosip_message_send_request(sip);
 
54
        SalOp *op;
 
55
        if(linphone_core_is_in_communication_with(cr->lc,cr->peer))
 
56
        {
 
57
                ms_message("send SIP message into the call\n");
 
58
                op = cr->lc->call->op;
 
59
        }
 
60
        else
 
61
        {
 
62
                op = sal_op_new(cr->lc->sal);
 
63
                sal_op_set_route(op,cr->route);
 
64
        }
 
65
        sal_text_send(op,identity,cr->peer,msg);
61
66
}
62
67
 
63
 
bool_t linphone_chat_room_matches(LinphoneChatRoom *cr, osip_from_t *from){
64
 
        if (cr->peer_url->url->username && from->url->username && 
65
 
                strcmp(cr->peer_url->url->username,from->url->username)==0) return TRUE;
 
68
bool_t linphone_chat_room_matches(LinphoneChatRoom *cr, const LinphoneAddress *from){
 
69
        if (linphone_address_get_username(cr->peer_url) && linphone_address_get_username(from) && 
 
70
                strcmp(linphone_address_get_username(cr->peer_url),linphone_address_get_username(from))==0) return TRUE;
66
71
        return FALSE;
67
72
}
68
73
 
70
75
        if (lc->vtable.text_received!=NULL) lc->vtable.text_received(lc, cr, from, msg);
71
76
}
72
77
 
73
 
void linphone_core_text_received(LinphoneCore *lc, eXosip_event_t *ev){
 
78
void linphone_core_text_received(LinphoneCore *lc, const char *from, const char *msg){
74
79
        MSList *elem;
75
 
        const char *msg;
76
80
        LinphoneChatRoom *cr=NULL;
 
81
        LinphoneAddress *addr;
77
82
        char *cleanfrom;
78
 
        osip_from_t *from_url=ev->request->from;
79
 
        osip_body_t *body=NULL;
80
83
 
81
 
        osip_message_get_body(ev->request,0,&body);
82
 
        if (body==NULL){
83
 
                ms_error("Could not get text message from SIP body");
84
 
                return;
85
 
        }
86
 
        msg=body->body;
87
 
        from_2char_without_params(from_url,&cleanfrom);
 
84
        addr=linphone_address_new(from);
 
85
        linphone_address_clean(addr);
88
86
        for(elem=lc->chatrooms;elem!=NULL;elem=ms_list_next(elem)){
89
87
                cr=(LinphoneChatRoom*)elem->data;
90
 
                if (linphone_chat_room_matches(cr,from_url)){
 
88
                if (linphone_chat_room_matches(cr,addr)){
91
89
                        break;
92
90
                }
93
91
                cr=NULL;
94
92
        }
 
93
        cleanfrom=linphone_address_as_string(addr);
95
94
        if (cr==NULL){
96
95
                /* create a new chat room */
97
96
                cr=linphone_core_create_chat_room(lc,cleanfrom);
98
97
        }
 
98
        linphone_address_destroy(addr);
99
99
        linphone_chat_room_text_received(cr,lc,cleanfrom,msg);
100
 
        osip_free(cleanfrom);
 
100
        ms_free(cleanfrom);
101
101
}
102
102
 
103
103