diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c index 6bdecc4b584885e271420efa581301a432a0c0ae..1c87f88ced3045ee03ef834de121badb75a71e37 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -845,7 +845,7 @@ static bool_t is_duplicate_msg(LinphoneCore *lc, const char *msg_id){ static void text_received(SalOp *op, const SalMessage *msg){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op)); if (is_duplicate_msg(lc,msg->message_id)==FALSE){ - linphone_core_message_received(lc,msg); + linphone_core_message_received(lc,op,msg); } } diff --git a/coreapi/chat.c b/coreapi/chat.c index 29af16eecd38b61b0db10e07cc05678cf33a387c..b9894ea8fabbf7750b23b14e7921ae238a771604 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -25,8 +25,19 @@ #include "linphonecore.h" #include "private.h" #include "lpconfig.h" - - LinphoneChatRoom * linphone_core_create_chat_room(LinphoneCore *lc, const char *to){ + +/** + * @addtogroup chatroom + * @{ + */ + +/** + * Create a new chat room for messaging from a sip uri like sip:joe@sip.linphone.org + * @param lc #LinphoneCore object + * @param to destination address for messages + * @return #LinphoneChatRoom where messaging can take place. + */ +LinphoneChatRoom * linphone_core_create_chat_room(LinphoneCore *lc, const char *to){ LinphoneAddress *parsed_url=NULL; if ((parsed_url=linphone_core_interpret_url(lc,to))!=NULL){ @@ -38,16 +49,18 @@ return cr; } return NULL; - } - +} - void linphone_chat_room_destroy(LinphoneChatRoom *cr){ +/** + * Destroy a LinphoneChatRoom. + * @param cr #LinphoneChatRoom object + */ +void linphone_chat_room_destroy(LinphoneChatRoom *cr){ LinphoneCore *lc=cr->lc; lc->chatrooms=ms_list_remove(lc->chatrooms,(void *) cr); linphone_address_destroy(cr->peer_url); ms_free(cr->peer); - } - +} static void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage* msg){ const char *route=NULL; @@ -56,7 +69,7 @@ static void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatM LinphoneCall *call; char* content_type; - if (lp_config_get_int(cr->lc->config,"sip","chat_use_call_dialogs",1)){ + if (lp_config_get_int(cr->lc->config,"sip","chat_use_call_dialogs",0)){ if((call = linphone_core_get_call_by_remote_address(cr->lc,cr->peer))!=NULL){ if (call->state==LinphoneCallConnected || call->state==LinphoneCallStreamsRunning || @@ -74,21 +87,30 @@ static void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatM op = sal_op_new(cr->lc->sal); sal_op_set_route(op,route); sal_op_set_user_pointer(op, msg); /*if out of call, directly store msg*/ + if (msg->custom_headers){ + sal_op_set_custom_header(op,msg->custom_headers); + msg->custom_headers=NULL; /*transfered to the SalOp*/ + } } if (msg->external_body_url) { content_type=ms_strdup_printf("message/external-body; access-type=URL; URL=\"%s\"",msg->external_body_url); - sal_message_send(op,identity,cr->peer,content_type,NULL); + sal_message_send(op,identity,cr->peer,content_type, NULL); ms_free(content_type); } else { - sal_text_send(op, identity, cr->peer, msg->message); + sal_text_send(op, identity, cr->peer,msg->message); } - - } +/** + * Send a message to peer member of this chat room. + * @deprecated linphone_chat_room_send_message2() gives more control on the message expedition. + * @param cr #LinphoneChatRoom object + * @param msg message to be sent + */ void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg) { _linphone_chat_room_send_message(cr,linphone_chat_room_create_message(cr,msg)); } + bool_t linphone_chat_room_matches(LinphoneChatRoom *cr, const LinphoneAddress *from){ if (linphone_address_get_username(cr->peer_url) && linphone_address_get_username(from) && strcmp(linphone_address_get_username(cr->peer_url),linphone_address_get_username(from))==0) return TRUE; @@ -103,12 +125,14 @@ void linphone_chat_room_message_received(LinphoneChatRoom *cr, LinphoneCore *lc, } -void linphone_core_message_received(LinphoneCore *lc, const SalMessage *sal_msg){ +void linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessage *sal_msg){ MSList *elem; LinphoneChatRoom *cr=NULL; LinphoneAddress *addr; char *cleanfrom; LinphoneChatMessage* msg; + const SalCustomHeader *ch; + addr=linphone_address_new(sal_msg->from); linphone_address_clean(addr); for(elem=lc->chatrooms;elem!=NULL;elem=ms_list_next(elem)){ @@ -126,6 +150,8 @@ void linphone_core_message_received(LinphoneCore *lc, const SalMessage *sal_msg) msg = linphone_chat_room_create_message(cr, sal_msg->text); linphone_chat_message_set_from(msg, cr->peer_url); msg->time=sal_msg->time; + ch=sal_op_get_custom_header(op); + if (ch) msg->custom_headers=sal_custom_header_clone(ch); if (sal_msg->url) { linphone_chat_message_set_external_body_url(msg, sal_msg->url); @@ -135,37 +161,66 @@ void linphone_core_message_received(LinphoneCore *lc, const SalMessage *sal_msg) ms_free(cleanfrom); } +/** + * Returns back pointer to LinphoneCore object. +**/ LinphoneCore* linphone_chat_room_get_lc(LinphoneChatRoom *cr){ return cr->lc; } -LinphoneChatRoom* linphone_chat_message_get_chat_room(LinphoneChatMessage *msg){ - return msg->chat_room; -} - +/** + * Assign a user pointer to the chat room. +**/ void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void * ud){ cr->user_data=ud; } + +/** + * Retrieve the user pointer associated with the chat room. +**/ void * linphone_chat_room_get_user_data(LinphoneChatRoom *cr){ return cr->user_data; } + +/** + * get peer address \link linphone_core_create_chat_room() associated to \endlink this #LinphoneChatRoom + * @param cr #LinphoneChatRoom object + * @return #LinphoneAddress peer address + */ const LinphoneAddress* linphone_chat_room_get_peer_address(LinphoneChatRoom *cr) { return cr->peer_url; } -LinphoneChatMessage* linphone_chat_room_create_message(const LinphoneChatRoom *cr,const char* message) { +/** + * Create a message attached to a dedicated chat room; + * @param cr the chat room. + * @param message text message, NULL if absent. + * @return a new #LinphoneChatMessage + */ +LinphoneChatMessage* linphone_chat_room_create_message(LinphoneChatRoom *cr, const char* message) { LinphoneChatMessage* msg = ms_new0(LinphoneChatMessage,1); msg->chat_room=(LinphoneChatRoom*)cr; msg->message=message?ms_strdup(message):NULL; return msg; } -void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangeCb status_cb,void* ud) { +/** + * Send a message to peer member of this chat room. + * @param cr #LinphoneChatRoom object + * @param msg #LinphoneChatMessage message to be sent + * @param status_cb LinphoneChatMessageStateChangeCb status callback invoked when message is delivered or could not be delivered. May be NULL + * @param ud user data for the status cb. + * @note The LinphoneChatMessage must not be destroyed until the the callback is called. + */ +void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangeCb status_cb, void* ud) { msg->cb=status_cb; msg->cb_ud=ud; _linphone_chat_room_send_message(cr, msg); } +/** + * Returns a #LinphoneChatMessageState as a string. + */ const char* linphone_chat_message_state_to_string(const LinphoneChatMessageState state) { switch (state) { case LinphoneChatMessageStateIdle:return "LinphoneChatMessageStateIdle"; @@ -177,62 +232,112 @@ const char* linphone_chat_message_state_to_string(const LinphoneChatMessageState } -char* linphone_chat_message_get_message(LinphoneChatMessage* msg) { - return msg->message; +/** + * Returns the chatroom this message belongs to. +**/ +LinphoneChatRoom* linphone_chat_message_get_chat_room(LinphoneChatMessage *msg){ + return msg->chat_room; } +/** + * Returns the peer (remote) address for the message. +**/ const LinphoneAddress* linphone_chat_message_get_peer_address(LinphoneChatMessage *msg) { return linphone_chat_room_get_peer_address(msg->chat_room); } /** - * user pointer set function + *User pointer set function */ void linphone_chat_message_set_user_data(LinphoneChatMessage* message,void* ud) { message->message_userdata=ud; } + /** - * user pointer get function + * User pointer get function */ void* linphone_chat_message_get_user_data(const LinphoneChatMessage* message) { return message->message_userdata; } +/** + * Linphone message can carry external body as defined by rfc2017 + * @param message #LinphoneChatMessage + * @return external body url or NULL if not present. + */ const char* linphone_chat_message_get_external_body_url(const LinphoneChatMessage* message) { return message->external_body_url; } +/** + * Linphone message can carry external body as defined by rfc2017 + * + * @param message a LinphoneChatMessage + * @param url ex: access-type=URL; URL="http://www.foo.com/file" + */ void linphone_chat_message_set_external_body_url(LinphoneChatMessage* message,const char* url) { if (message->external_body_url) { ms_free(message->external_body_url); } message->external_body_url=url?ms_strdup(url):NULL; } + +/** + * Set origin of the message + *@param message #LinphoneChatMessage obj + *@param from #LinphoneAddress origin of this message (copied) + */ void linphone_chat_message_set_from(LinphoneChatMessage* message, const LinphoneAddress* from) { if(message->from) linphone_address_destroy(message->from); message->from=linphone_address_clone(from); - } + +/** + * Get origin of the message + *@param message #LinphoneChatMessage obj + *@return #LinphoneAddress + */ LinphoneAddress* linphone_chat_message_get_from(const LinphoneChatMessage* message) { return message->from; } +/** + * Get the time the message was sent. + */ time_t linphone_chat_message_get_time(const LinphoneChatMessage* message) { return message->time; } +/** + * Get text part of this message + * @return text or NULL if no text. + */ const char * linphone_chat_message_get_text(const LinphoneChatMessage* message) { return message->message; } +/** + * Add custom headers to the message. + * @param message the message + * @param header_name name of the header_name + * @param header_value header value +**/ void linphone_chat_message_add_custom_header(LinphoneChatMessage* message, const char *header_name, const char *header_value){ message->custom_headers=sal_custom_header_append(message->custom_headers,header_name,header_value); } +/** + * Retrieve a custom header value given its name. + * @param message the message + * @param header_name header name searched +**/ const char * linphone_chat_message_get_custom_header(LinphoneChatMessage* message, const char *header_name){ return sal_custom_header_find(message->custom_headers,header_name); } +/** + * Duplicate a LinphoneChatMessage +**/ LinphoneChatMessage* linphone_chat_message_clone(const LinphoneChatMessage* msg) { /*struct _LinphoneChatMessage { char* message; @@ -253,6 +358,9 @@ LinphoneChatMessage* linphone_chat_message_clone(const LinphoneChatMessage* msg) return new_message; } +/** + * Destroys a LinphoneChatMessage. +**/ void linphone_chat_message_destroy(LinphoneChatMessage* msg) { if (msg->message) ms_free(msg->message); if (msg->external_body_url) ms_free(msg->external_body_url); @@ -262,3 +370,8 @@ void linphone_chat_message_destroy(LinphoneChatMessage* msg) { } +/** + * @} + */ + + diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 08c4f89ee26eb67aedabcb0fb3e432bde19c06fd..f0b6f3d56872081ac5aedb077a264e4053772bcf 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -644,37 +644,6 @@ typedef struct _LinphoneChatMessage LinphoneChatMessage; */ typedef struct _LinphoneChatRoom LinphoneChatRoom; -/** - * Create a new chat room for messaging from a sip uri like sip:joe@sip.linphone.org - * @param lc #LinphoneCore object - * @param to destination address for messages - * @return #LinphoneChatRoom where messaging can take place. - */ -LinphoneChatRoom * linphone_core_create_chat_room(LinphoneCore *lc, const char *to); -/** - * Destructor - * @param cr #LinphoneChatRoom object - */ -void linphone_chat_room_destroy(LinphoneChatRoom *cr); - -/** - * create a message attached to a dedicated chat room; - */ -LinphoneChatMessage* linphone_chat_room_create_message(const LinphoneChatRoom *cr,const char* message); - - -/** - * get peer address \link linphone_core_create_chat_room() associated to \endlink this #LinphoneChatRoom - * @param cr #LinphoneChatRoom object - * @return #LinphoneAddress peer address - */ -const LinphoneAddress* linphone_chat_room_get_peer_address(LinphoneChatRoom *cr); -/** - * send a message to peer member of this chat room. - * @param cr #LinphoneChatRoom object - * @param msg message to be sent - */ -void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg); /** *LinphoneChatMessageState is used to notify if messages have been succesfully delivered or not. */ @@ -685,90 +654,38 @@ typedef enum _LinphoneChatMessageStates { LinphoneChatMessageStateNotDelivered /**<message was not delivered*/ }LinphoneChatMessageState; - /** - * to string function + * Call back used to notify message delivery status + *@param msg #LinphoneChatMessage object + *@param status LinphoneChatMessageState + *@param ud application user data */ -const char* linphone_chat_message_state_to_string(const LinphoneChatMessageState state); +typedef void (*LinphoneChatMessageStateChangeCb)(LinphoneChatMessage* msg,LinphoneChatMessageState state,void* ud); -/** - * Clone a chat message - *@param message #LinphoneChatMessage obj - *@return #LinphoneChatMessage - */ +LinphoneChatRoom * linphone_core_create_chat_room(LinphoneCore *lc, const char *to); +void linphone_chat_room_destroy(LinphoneChatRoom *cr); +LinphoneChatMessage* linphone_chat_room_create_message(LinphoneChatRoom *cr,const char* message); +const LinphoneAddress* linphone_chat_room_get_peer_address(LinphoneChatRoom *cr); +void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg); +void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangeCb status_cb,void* ud); +LinphoneCore* linphone_chat_room_get_lc(LinphoneChatRoom *cr); +void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void * ud); +void * linphone_chat_room_get_user_data(LinphoneChatRoom *cr); + +const char* linphone_chat_message_state_to_string(const LinphoneChatMessageState state); LinphoneChatMessage* linphone_chat_message_clone(const LinphoneChatMessage* message); -/** - * Set origin of the message - *@param message #LinphoneChatMessage obj - *@param from #LinphoneAddress origin of this message (copied) - */ void linphone_chat_message_set_from(LinphoneChatMessage* message, const LinphoneAddress* from); - -/** - * Get origin of the message - *@param message #LinphoneChatMessage obj - *@return #LinphoneAddress - */ LinphoneAddress* linphone_chat_message_get_from(const LinphoneChatMessage* message); - -/** - * Linphone message can carry external body as defined by rfc2017 - * @param message #LinphoneChatMessage - * @return external body url or NULL if not present. - */ const char* linphone_chat_message_get_external_body_url(const LinphoneChatMessage* message); - -/** - * Linphone message can carry external body as defined by rfc2017 - * - * @param message a LinphoneChatMessage - * @param url ex: access-type=URL; URL="http://www.foo.com/file" - */ void linphone_chat_message_set_external_body_url(LinphoneChatMessage* message,const char* url); - -/** - * Get text part of this message - * @return text or NULL if no text. - */ const char * linphone_chat_message_get_text(const LinphoneChatMessage* message); - -/** - * Get the time the message was sent - * @return time_t or NULL if no time - */ time_t linphone_chat_message_get_time(const LinphoneChatMessage* message); - -/** - * user pointer get function - */ - void* linphone_chat_message_get_user_data(const LinphoneChatMessage* message); -/** - * user pointer set function - */ void linphone_chat_message_set_user_data(LinphoneChatMessage* message,void*); - -/** - * Call back used to notify message delivery status - *@param msg #LinphoneChatMessage object - *@param status LinphoneChatMessageState - *@param ud application user data - */ -typedef void (*LinphoneChatMessageStateChangeCb)(LinphoneChatMessage* msg,LinphoneChatMessageState state,void* ud); -/** - * send a message to peer member of this chat room. - * @param cr #LinphoneChatRoom object - * @param msg #LinphoneChatMessage message to be sent - * @param status_cb LinphoneChatMessageStateChangeCb status callback invoked when message is delivered or could not be delivered. May be NULL - * @param ud user data for the status cb. - */ -void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangeCb status_cb,void* ud); -LinphoneCore* linphone_chat_room_get_lc(LinphoneChatRoom *cr); LinphoneChatRoom* linphone_chat_message_get_chat_room(LinphoneChatMessage *msg); -char* linphone_chat_message_get_message(LinphoneChatMessage *msg); const LinphoneAddress* linphone_chat_message_get_peer_address(LinphoneChatMessage *msg); -void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void * ud); -void * linphone_chat_room_get_user_data(LinphoneChatRoom *cr); +void linphone_chat_message_add_custom_header(LinphoneChatMessage* message, const char *header_name, const char *header_value); +const char * linphone_chat_message_get_custom_header(LinphoneChatMessage* message, const char *header_name); /** * @} diff --git a/coreapi/private.h b/coreapi/private.h index b98995fa6cae873d32ced58ebdd00a01299e859f..1f3ed6abad1566f43f76f6392c5093169aee2947 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -302,7 +302,7 @@ void linphone_proxy_config_write_to_config_file(struct _LpConfig* config,Linphon int linphone_proxy_config_normalize_number(LinphoneProxyConfig *cfg, const char *username, char *result, size_t result_len); -void linphone_core_message_received(LinphoneCore *lc, const SalMessage *msg); +void linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessage *msg); void linphone_core_play_tone(LinphoneCore *lc); diff --git a/coreapi/sal.c b/coreapi/sal.c index e988a141bb9b5af1c79bdb8d5d819563679e9a6c..1411407a8350228f93d7ac3a324e6ef490c148c5 100644 --- a/coreapi/sal.c +++ b/coreapi/sal.c @@ -402,7 +402,7 @@ void sal_custom_header_free(SalCustomHeader *ch){ ms_list_free((MSList *)ch); } -SalCustomHeader *sal_custom_header_clone(SalCustomHeader *ch){ +SalCustomHeader *sal_custom_header_clone(const SalCustomHeader *ch){ const MSList *it; SalCustomHeader *ret=NULL; for (it=(const MSList*)ch;it!=NULL;it=it->next){ diff --git a/coreapi/sal.h b/coreapi/sal.h index 26efa81152850f22db507823233acfa435ef529c..25d8d20bcc38b2c58836a636a25d36d3c25d2443 100644 --- a/coreapi/sal.h +++ b/coreapi/sal.h @@ -465,7 +465,7 @@ struct SalCustomHeader{ SalCustomHeader *sal_custom_header_append(SalCustomHeader *ch, const char *name, const char *value); const char *sal_custom_header_find(const SalCustomHeader *ch, const char *name); void sal_custom_header_free(SalCustomHeader *ch); -SalCustomHeader *sal_custom_header_clone(SalCustomHeader *ch); +SalCustomHeader *sal_custom_header_clone(const SalCustomHeader *ch); const SalCustomHeader *sal_op_get_custom_header(SalOp *op); void sal_op_set_custom_header(SalOp *op, SalCustomHeader* ch); diff --git a/coreapi/sal_eXosip2_presence.c b/coreapi/sal_eXosip2_presence.c index 4e0a9338d3441b93716925e9238eaaaa3d8e0024..1e49970bfd4a3d05c4f177100b731d5d7b1447f0 100644 --- a/coreapi/sal_eXosip2_presence.c +++ b/coreapi/sal_eXosip2_presence.c @@ -140,6 +140,7 @@ int sal_message_send(SalOp *op, const char *from, const char *to, const char* co } return 0; } + int sal_text_send(SalOp *op, const char *from, const char *to, const char *msg) { return sal_message_send(op,from,to,"text/plain",msg); } diff --git a/gtk/calllogs.c b/gtk/calllogs.c index 7dc82920a1689d8a7ad87f7529fda65bc3deecdd..4a9330f4affb0e1913c9fa815cd62d79e1128496 100644 --- a/gtk/calllogs.c +++ b/gtk/calllogs.c @@ -58,8 +58,8 @@ void linphone_gtk_call_log_update(GtkWidget *w){ gchar quality[20]; const char *status=NULL; gchar *start_date=NULL; - time_t start_date_time=linphone_call_log_get_start_date(cl); int duration=linphone_call_log_get_duration(cl); + time_t start_date_time=linphone_call_log_get_start_date(cl); #if GLIB_CHECK_VERSION(2,26,0) if (start_date_time){ @@ -67,6 +67,8 @@ void linphone_gtk_call_log_update(GtkWidget *w){ start_date=g_date_time_format(dt,"%c"); g_date_time_unref(dt); } +#else + start_date=g_strdup(ctime(start_date_time)); #endif display=linphone_address_get_display_name (la);