Пример #1
0
void debug_info(const char* format , ...)
{
        char t_str[32] = { 0 };
        char fmt[4096] = { 0 };
        va_list ap;
        struct tm* t = get_currenttime();
        strftime(t_str , sizeof(t_str) , "%T" , t );
        sprintf(fmt , "[\033[32m\033[1m%s\033[0m]  %s\n" , t_str , format);
        va_start(ap, format);
        vfprintf(stdout , fmt , ap);
        va_end(ap);
}
Пример #2
0
int fetion_conversation_send_sms_with_reply(Conversation *conv, const char *msg)
{
	char       rep[1024];

	FetionSip* sip = conv->currentSip == NULL ?
		   	conv->currentUser->sip : conv->currentSip;
	SipHeader *toheader , *cheader , *kheader , *nheader;
	Message *message;
	char* res;
	struct tm *now;
	struct tm now_copy;

	fetion_sip_set_type(sip , SIP_MESSAGE);
	nheader  = fetion_sip_event_header_new(SIP_EVENT_CATMESSAGE);
	toheader = fetion_sip_header_new("T" , conv->currentContact->sipuri);
	cheader  = fetion_sip_header_new("C" , "text/plain");
	kheader  = fetion_sip_header_new("K" , "SaveHistory");
	fetion_sip_add_header(sip , toheader);
	fetion_sip_add_header(sip , cheader);
	fetion_sip_add_header(sip , kheader);
	fetion_sip_add_header(sip , nheader);
	/* add message to list */
	now = get_currenttime();
	now_copy = *now;
	message = fetion_message_new();
	fetion_message_set_sipuri(message , conv->currentContact->sipuri);
	fetion_message_set_time(message , now_copy);
	fetion_message_set_message(message , msg);
	fetion_message_set_callid(message , sip->callid);

	res = fetion_sip_to_string(sip , msg);
	debug_info("Sent a message to %s" , conv->currentContact->sipuri);
	tcp_connection_send(sip->tcp , res , strlen(res));
	sal_free(res);

	memset(rep , 0 , sizeof(rep));
	tcp_connection_recv(sip->tcp , rep , sizeof(rep));

	if(fetion_sip_get_code(rep) == 280 || fetion_sip_get_code(rep) == 200){
		return 1;
	}else{
		return -1;
	}
}
Пример #3
0
int fetion_conversation_send_sms(Conversation* conversation , const char* msg)
{
	FetionSip* sip = conversation->currentSip == NULL ?
		   	conversation->currentUser->sip : conversation->currentSip;
	SipHeader *toheader , *cheader , *kheader , *nheader;
	Message *message;
	struct unacked_list *unacked;
	char* res;
	struct tm *now;
	struct tm now_copy;

	fetion_sip_set_type(sip , SIP_MESSAGE);
	nheader  = fetion_sip_event_header_new(SIP_EVENT_CATMESSAGE);
	toheader = fetion_sip_header_new("T" , conversation->currentContact->sipuri);
	cheader  = fetion_sip_header_new("C" , "text/plain");
	kheader  = fetion_sip_header_new("K" , "SaveHistory");
	fetion_sip_add_header(sip , toheader);
	fetion_sip_add_header(sip , cheader);
	fetion_sip_add_header(sip , kheader);
	fetion_sip_add_header(sip , nheader);
	/* add message to list */
	now = get_currenttime();
	now_copy = *now;
	message = fetion_message_new();
	fetion_message_set_sipuri(message , conversation->currentContact->sipuri);
	fetion_message_set_time(message , now_copy);
	fetion_message_set_message(message , msg);
	fetion_message_set_callid(message , sip->callid);
	unacked = unacked_list_new(message);
	unacked_list_append(unackedlist , unacked);

	res = fetion_sip_to_string(sip , msg);
	debug_info("Sent a message to %s" , conversation->currentContact->sipuri);
	if(tcp_connection_send(sip->tcp , res , strlen(res)) == -1){
		sal_free(res);
		return -1;
	}
	sal_free(res);
	return 1;
}