Beispiel #1
0
void linphone_core_message_received(LinphoneCore *lc, const char *from, const char *raw_msg,const char* external_url) {
    MSList *elem;
    LinphoneChatRoom *cr=NULL;
    LinphoneAddress *addr;
    char *cleanfrom;
    LinphoneChatMessage* msg;
    addr=linphone_address_new(from);
    linphone_address_clean(addr);
    for(elem=lc->chatrooms; elem!=NULL; elem=ms_list_next(elem)) {
        cr=(LinphoneChatRoom*)elem->data;
        if (linphone_chat_room_matches(cr,addr)) {
            break;
        }
        cr=NULL;
    }
    cleanfrom=linphone_address_as_string(addr);
    if (cr==NULL) {
        /* create a new chat room */
        cr=linphone_core_create_chat_room(lc,cleanfrom);
    }
    msg = linphone_chat_room_create_message(cr, raw_msg);
    linphone_chat_message_set_from(msg, cr->peer_url);
    if (external_url) {
        linphone_chat_message_set_external_body_url(msg, external_url);
    }
    linphone_address_destroy(addr);
    linphone_chat_room_message_received(cr,lc,msg);
    ms_free(cleanfrom);
}
Beispiel #2
0
/**
 * Create a message attached to a dedicated chat room;
 * @param cr the chat room.
 * @param message text message, NULL if absent.
 * @param external_body_url the URL given in external body or NULL.
 * @param state the LinphoneChatMessage.State of the message.
 * @param time the time_t at which the message has been received/sent.
 * @param is_read TRUE if the message should be flagged as read, FALSE otherwise.
 * @param is_incoming TRUE if the message has been received, FALSE otherwise.
 * @return a new #LinphoneChatMessage
 */
LinphoneChatMessage* linphone_chat_room_create_message_2(
        LinphoneChatRoom *cr, const char* message, const char* external_body_url,
        LinphoneChatMessageState state, time_t time, bool_t is_read, bool_t is_incoming) {
	LinphoneCore *lc=linphone_chat_room_get_lc(cr);

	LinphoneChatMessage* msg = ms_new0(LinphoneChatMessage,1);
	msg->chat_room=(LinphoneChatRoom*)cr;
	msg->message=message?ms_strdup(message):NULL;
	msg->external_body_url=external_body_url?ms_strdup(external_body_url):NULL;
	msg->time=time;
	msg->state=state;
	msg->is_read=is_read;
	if (is_incoming) {
		msg->dir=LinphoneChatMessageIncoming;
		linphone_chat_message_set_from(msg, linphone_chat_room_get_peer_address(cr));
		linphone_chat_message_set_to(msg, linphone_address_new(linphone_core_get_identity(lc)));
	} else {
		msg->dir=LinphoneChatMessageOutgoing;
		linphone_chat_message_set_to(msg, linphone_chat_room_get_peer_address(cr));
		linphone_chat_message_set_from(msg, linphone_address_new(linphone_core_get_identity(lc)));
	}
	return msg;
}
Beispiel #3
0
/* DB layout:
 * | 0  | storage_id
 * | 1  | localContact
 * | 2  | remoteContact
 * | 3  | direction flag
 * | 4  | message
 * | 5  | time (unused now, used to be string-based timestamp)
 * | 6  | read flag
 * | 7  | status
 * | 8  | external body url
 * | 9  | utc timestamp
 * | 10 | app data text
 * | 11 | linphone content
 */
static void create_chat_message(char **argv, void *data){
	LinphoneChatRoom *cr = (LinphoneChatRoom *)data;
	LinphoneAddress *from;
	LinphoneAddress *to;

	unsigned int storage_id = atoi(argv[0]);

	// check if the message exists in the transient list, in which case we should return that one.
	LinphoneChatMessage* new_message = get_transient_message(cr, storage_id);
	if( new_message == NULL ){
		new_message = linphone_chat_room_create_message(cr, argv[4]);

		if(atoi(argv[3])==LinphoneChatMessageIncoming){
			new_message->dir=LinphoneChatMessageIncoming;
			from=linphone_address_new(argv[2]);
			to=linphone_address_new(argv[1]);
		} else {
			new_message->dir=LinphoneChatMessageOutgoing;
			from=linphone_address_new(argv[1]);
			to=linphone_address_new(argv[2]);
		}
		linphone_chat_message_set_from(new_message,from);
		linphone_address_destroy(from);
		if (to){
			linphone_chat_message_set_to(new_message,to);
			linphone_address_destroy(to);
		}

		if( argv[9] != NULL ){
			new_message->time = (time_t)atol(argv[9]);
		} else {
			new_message->time = time(NULL);
		}

		new_message->is_read=atoi(argv[6]);
		new_message->state=atoi(argv[7]);
		new_message->storage_id=storage_id;
		new_message->external_body_url= argv[8] ? ms_strdup(argv[8])  : NULL;
		new_message->appdata          = argv[10]? ms_strdup(argv[10]) : NULL;

		if (argv[11] != NULL) {
			int id = atoi(argv[11]);
			if (id >= 0) {
				fetch_content_from_database(cr->lc->db, new_message, id);
			}
		}
	}
	cr->messages_hist=ms_list_prepend(cr->messages_hist,new_message);
}
Beispiel #4
0
void linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessage *sal_msg){
	
	LinphoneChatRoom *cr=NULL;
	LinphoneAddress *addr;
	char *cleanfrom;
	char *from;
	LinphoneChatMessage* msg;
	const SalCustomHeader *ch;
	
	addr=linphone_address_new(sal_msg->from);
	linphone_address_clean(addr);
	cr=linphone_core_get_chat_room(lc,addr);
	cleanfrom=linphone_address_as_string(addr);
	from=linphone_address_as_string_uri_only(addr);
	if (cr==NULL){
		/* create a new chat room */
		cr=linphone_core_create_chat_room(lc,cleanfrom);
	}
	msg = linphone_chat_room_create_message(cr, sal_msg->text);
	linphone_chat_message_set_from(msg, cr->peer_url);
	
	{
		LinphoneAddress *to;
		to=sal_op_get_to(op) ? linphone_address_new(sal_op_get_to(op)) : linphone_address_new(linphone_core_get_identity(lc));
		msg->to=to;
	}
	
	msg->time=sal_msg->time;
	msg->state=LinphoneChatMessageStateDelivered;
	msg->is_read=FALSE;
	msg->dir=LinphoneChatMessageIncoming;
	ch=sal_op_get_recv_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);
	}
	linphone_address_destroy(addr);
	msg->storage_id=linphone_chat_message_store(msg);
	linphone_chat_room_message_received(cr,lc,msg);
	ms_free(cleanfrom);
	ms_free(from);
}
Beispiel #5
0
/* DB layout:
 * | 0  | storage_id
 * | 1  | localContact
 * | 2  | remoteContact
 * | 3  | direction flag
 * | 4  | message
 * | 5  | time (unused now, used to be string-based timestamp)
 * | 6  | read flag
 * | 7  | status
 * | 8  | external body url
 * | 9  | utc timestamp
 * | 10 | app data text
 * | 11 | linphone content id
 */
static int create_chat_message(void *data, int argc, char **argv, char **colName){
	LinphoneChatRoom *cr = (LinphoneChatRoom *)data;
	unsigned int storage_id = atoi(argv[0]);

	// check if the message exists in the transient list, in which case we should return that one.
	LinphoneChatMessage* new_message = get_transient_message(cr, storage_id);
	if( new_message == NULL ){
		LinphoneAddress *local_addr=linphone_address_new(argv[1]);
		new_message = linphone_chat_room_create_message(cr, argv[4]);

		if(atoi(argv[3])==LinphoneChatMessageIncoming){
			new_message->dir=LinphoneChatMessageIncoming;
			linphone_chat_message_set_from(new_message,linphone_chat_room_get_peer_address(cr));
			new_message->to = local_addr; /*direct assignation to avoid a copy*/
		} else {
			new_message->dir=LinphoneChatMessageOutgoing;
			new_message->from = local_addr; /*direct assignation to avoid a copy*/
			linphone_chat_message_set_to(new_message,linphone_chat_room_get_peer_address(cr));
		}

		new_message->time = (time_t)atol(argv[9]);
		new_message->is_read=atoi(argv[6]);
		new_message->state=atoi(argv[7]);
		new_message->storage_id=storage_id;
		new_message->external_body_url= ms_strdup(argv[8]);
		new_message->appdata = ms_strdup(argv[10]);

		if (argv[11] != NULL) {
			int id = atoi(argv[11]);
			if (id >= 0) {
				fetch_content_from_database(cr->lc->db, new_message, id);
			}
		}
	}
	cr->messages_hist=ms_list_prepend(cr->messages_hist,new_message);

	return 0;
}