示例#1
0
static void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage* msg){
	SalOp *op=NULL;
	LinphoneCall *call;
	char* content_type;
	const char *identity=NULL;
	time_t t=time(NULL);
	
	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 ||
			call->state==LinphoneCallPaused ||
			call->state==LinphoneCallPausing ||
			call->state==LinphoneCallPausedByRemote){
				ms_message("send SIP message through the existing call.");
				op = call->op;
				call->pending_message=msg;
				identity=linphone_core_find_best_identity(cr->lc,linphone_call_get_remote_address(call));
			}
		}
	}
	msg->time=t;
	if (op==NULL){
		LinphoneProxyConfig *proxy=linphone_core_lookup_known_proxy(cr->lc,cr->peer_url);
		if (proxy){
			identity=linphone_proxy_config_get_identity(proxy);
		}else identity=linphone_core_get_primary_contact(cr->lc);
		/*sending out of calls*/
		op = sal_op_new(cr->lc->sal);
		linphone_configure_op(cr->lc,op,cr->peer_url,msg->custom_headers,lp_config_get_int(cr->lc->config,"sip","chat_msg_with_contact",0));
		sal_op_set_user_pointer(op, msg); /*if out of call, directly store msg*/
	}
	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);
		ms_free(content_type);
	} else {
		sal_text_send(op, identity, cr->peer,msg->message);
	}
	msg->dir=LinphoneChatMessageOutgoing;
	msg->from=linphone_address_new(identity);
	msg->storage_id=linphone_chat_message_store(msg);
}
示例#2
0
文件: chat.c 项目: crazyfree/linphone
static void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage* msg) {
    const char *route=NULL;
    const char *identity=linphone_core_find_best_identity(cr->lc,cr->peer_url,&route);
    SalOp *op=NULL;
    LinphoneCall *call;
    char* content_type;

    if (lp_config_get_int(cr->lc->config,"sip","chat_use_call_dialogs",1)) {
        if((call = linphone_core_get_call_by_remote_address(cr->lc,cr->peer))!=NULL) {
            if (call->state==LinphoneCallConnected ||
                    call->state==LinphoneCallStreamsRunning ||
                    call->state==LinphoneCallPaused ||
                    call->state==LinphoneCallPausing ||
                    call->state==LinphoneCallPausedByRemote) {
                ms_message("send SIP message through the existing call.");
                op = call->op;
                call->pending_message=msg;
            }
        }
    }
    if (op==NULL) {
        /*sending out of calls*/
        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->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);
        ms_free(content_type);
    } else {
        sal_text_send(op, identity, cr->peer, msg->message);
    }


}
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, NULL);
}