int fetion_buddylist_delete(User* user , int id) { FetionSip* sip = user->sip; SipHeader* eheader; char *res , *body; int ret; fetion_sip_set_type(sip , SIP_SERVICE); eheader = fetion_sip_event_header_new(SIP_EVENT_DELETEBUDDYLIST); fetion_sip_add_header(sip , eheader); body = generate_delete_buddylist_body(id); res = fetion_sip_to_string(sip , body); free(body); tcp_connection_send(sip->tcp , res , strlen(res)); free(res); res = fetion_sip_get_response(sip); ret = fetion_sip_get_code(res); free(res); if(ret == 200) { fetion_group_remove(user->groupList , id); debug_info("Delete buddy list success"); return 1; } else { debug_error("Delete buddy list failed , errno:%d" , ret); return -1; } }
int fetion_buddylist_edit(User* user , int id , const char* name) { FetionSip* sip = user->sip; SipHeader* eheader; char *res , *body; int ret; fetion_sip_set_type(sip , SIP_SERVICE); eheader = fetion_sip_event_header_new(SIP_EVENT_SETBUDDYLISTINFO); fetion_sip_add_header(sip , eheader); body = generate_edit_buddylist_body(id , name); res = fetion_sip_to_string(sip , body); free(body); tcp_connection_send(sip->tcp , res , strlen(res)); free(res); res = fetion_sip_get_response(sip); ret = fetion_sip_get_code(res); free(res); if(ret == 200) { debug_info("Set buddy list name to %s success" , name); return 1; } else { debug_error("Set buddy list name to %s failed , errno:%d" , name , ret); return -1; } }
int fetion_conversation_send_sms_to_myself_with_reply(Conversation* conversation, const char* message) { SipHeader *toheader = NULL; SipHeader *eheader = NULL; char *res = NULL; char rep[1024]; int code; FetionSip *sip = conversation->currentUser->sip; fetion_sip_set_type(sip , SIP_MESSAGE); toheader = fetion_sip_header_new("T" , conversation->currentUser->sipuri); eheader = fetion_sip_event_header_new(SIP_EVENT_SENDCATMESSAGE); fetion_sip_add_header(sip , toheader); fetion_sip_add_header(sip , eheader); res = fetion_sip_to_string(sip , message); debug_info("Sent a message to myself" , conversation->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)); code = fetion_sip_get_code(rep); if(code == 200 || code == 280){ return 1; }else{ return -1; } }
int fetion_buddylist_create(User* user , const char* name) { FetionSip* sip = user->sip; SipHeader* eheader; char *res , *body; int ret; fetion_sip_set_type(sip , SIP_SERVICE); eheader = fetion_sip_event_header_new(SIP_EVENT_CREATEBUDDYLIST); fetion_sip_add_header(sip , eheader); body = generate_create_buddylist_body(name); res = fetion_sip_to_string(sip , body); free(body); tcp_connection_send(sip->tcp , res , strlen(res)); free(res) ; res = fetion_sip_get_response(sip); ret = fetion_sip_get_code(res); if(ret == 200) { ret = parse_create_buddylist_response(user , res); free(res); debug_info("Create buddy list success"); return ret; } else { free(res); debug_error("Create buddy list failed , errno :" , ret); return -1; } }
int pg_group_get_list(User *user) { FetionSip *sip; SipHeader *eheader; const char *body = "<args><group-list /></args>"; char *res; extern int callid; sip = user->sip; eheader = fetion_sip_event_header_new(SIP_EVENT_PGGETGROUPLIST); if(eheader == NULL){ return -1; } fetion_sip_set_type(sip , SIP_SERVICE); fetion_sip_add_header(sip , eheader); user->pgGroupCallId = callid; res = fetion_sip_to_string(sip , body); if(res == NULL){ return -1; } int ret = tcp_connection_send(sip->tcp , res , strlen(res)); free(res); return ret; }
gint fetion_buddylist_create(User *user, const gchar *name) { fetion_sip* sip = user->sip; SipHeader* eheader; gchar *res , *body; fetion_sip_set_type(sip , SIP_SERVICE); eheader = fetion_sip_event_header_new(SIP_EVENT_CREATEBUDDYLIST); fetion_sip_add_header(sip , eheader); body = generate_create_buddylist_body(name); res = fetion_sip_to_string(sip , body); g_free(body); g_free(res); return 0; }
gint fetion_buddylist_edit(fetion_account *ac, gint id, const gchar *name) { fetion_sip *sip = ac->user->sip; SipHeader *eheader; gchar *res, *body; fetion_sip_set_type(sip , SIP_SERVICE); eheader = fetion_sip_event_header_new(SIP_EVENT_SETBUDDYLISTINFO); fetion_sip_add_header(sip , eheader); body = generate_edit_buddylist_body(id , name); res = fetion_sip_to_string(sip , body); g_free(body); if(send(ac->sk, res, strlen(res), 0) == -1) { g_free(res); return -1; } g_free(res); return 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; } }
int fetion_conversation_send_sms_to_phone_with_reply(Conversation* conversation , const char* message , int* daycount , int* monthcount) { SipHeader *toheader , *eheader , *aheader; char* res; char* xml; User *user = conversation->currentUser; FetionSip* sip = user->sip; char astr[256] , rep[1024]; char* sipuri = conversation->currentContact->sipuri; fetion_sip_set_type(sip , SIP_MESSAGE); toheader = fetion_sip_header_new("T" , sipuri); eheader = fetion_sip_event_header_new(SIP_EVENT_SENDCATMESSAGE); fetion_sip_add_header(sip , toheader); if(user->verification != NULL){ sprintf(astr , "Verify algorithm=\"picc\",chid=\"%s\",response=\"%s\"" , user->verification->guid , user->verification->code); aheader = fetion_sip_header_new("A" , astr); fetion_sip_add_header(sip , aheader); } fetion_sip_add_header(sip , eheader); res = fetion_sip_to_string(sip , message); debug_info("Sent a message to (%s)`s mobile phone" , 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){ xml = strstr(rep , "\r\n\r\n") + 4; fetion_conversation_parse_send_sms(xml , daycount , monthcount); return 1; }else{ debug_error("Send a message to (%s)`s mobile phone failed", sipuri); return -1; } }
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; }
int fetion_conversation_send_sms_to_phone(Conversation* conversation, const char* message) { SipHeader *toheader = NULL; SipHeader *eheader = NULL; SipHeader *aheader = NULL; User *user = conversation->currentUser; char* res = NULL; FetionSip* sip = user->sip; char* sipuri = conversation->currentContact->sipuri; char astr[256] , rep[1024]; int code; fetion_sip_set_type(sip , SIP_MESSAGE); toheader = fetion_sip_header_new("T" , sipuri); eheader = fetion_sip_event_header_new(SIP_EVENT_SENDCATMESSAGE); fetion_sip_add_header(sip , toheader); if(user->verification != NULL){ memset(astr, 0, sizeof(astr)); sprintf(astr , "Verify algorithm=\"picc\",chid=\"%s\",response=\"%s\"" , user->verification->guid , user->verification->code); aheader = fetion_sip_header_new("A" , astr); fetion_sip_add_header(sip , aheader); } fetion_sip_add_header(sip , eheader); res = fetion_sip_to_string(sip , message); debug_info("Sent a message to (%s)`s mobile phone" , 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)); code = fetion_sip_get_code(rep); if(code == 420 || code == 421){ return -1; }else{ return 1; } }
int fetion_conversation_send_sms_to_myself(Conversation* conversation, const char* message) { SipHeader *toheader = NULL; SipHeader *eheader = NULL; char* res = NULL; FetionSip* sip = conversation->currentUser->sip; fetion_sip_set_type(sip , SIP_MESSAGE); toheader = fetion_sip_header_new("T" , conversation->currentUser->sipuri); eheader = fetion_sip_event_header_new(SIP_EVENT_SENDCATMESSAGE); fetion_sip_add_header(sip , toheader); fetion_sip_add_header(sip , eheader); res = fetion_sip_to_string(sip , message); debug_info("Sent a message to myself" , conversation->currentContact->sipuri); if(tcp_connection_send(sip->tcp , res , strlen(res)) == -1) { sal_free(res); return -1; } sal_free(res); res = fetion_sip_get_response(sip); sal_free(res); return 1; }
int fetion_conversation_invite_friend(Conversation* conversation) { FetionSip* sip = conversation->currentUser->sip; char *res , *ip , *credential , auth[256] , *body; int port , ret; FetionConnection* conn; Proxy *proxy = conversation->currentUser->config->proxy; SipHeader *eheader , *theader , *mheader , *nheader , *aheader; /*start chat*/ fetion_sip_set_type(sip , SIP_SERVICE); eheader = fetion_sip_event_header_new(SIP_EVENT_STARTCHAT); fetion_sip_add_header(sip , eheader); res = fetion_sip_to_string(sip , NULL); tcp_connection_send(sip->tcp , res , strlen(res)); sal_free(res); res = NULL; res = fetion_sip_get_response(sip); if(!res) return -1; memset(auth , 0 , sizeof(auth)); fetion_sip_get_attr(res , "A" , auth); if(auth==NULL) return -1; fetion_sip_get_auth_attr(auth , &ip , &port , &credential); sal_free(res); res = NULL; conn = tcp_connection_new(); if(proxy != NULL && proxy->proxyEnabled) ret = tcp_connection_connect_with_proxy(conn , ip , port , proxy); else ret = tcp_connection_connect(conn , ip , port); if(ret == -1) return -1; /*clone sip*/ conversation->currentSip = fetion_sip_clone(conversation->currentUser->sip); memset(conversation->currentSip->sipuri, 0 , sizeof(conversation->currentSip->sipuri)); strcpy(conversation->currentSip->sipuri , conversation->currentContact->sipuri); fetion_sip_set_connection(conversation->currentSip , conn); sal_free(ip); ip = NULL; /*register*/ sip = conversation->currentSip; fetion_sip_set_type(sip , SIP_REGISTER); aheader = fetion_sip_credential_header_new(credential); theader = fetion_sip_header_new("K" , "text/html-fragment"); mheader = fetion_sip_header_new("K" , "multiparty"); nheader = fetion_sip_header_new("K" , "nudge"); fetion_sip_add_header(sip , aheader); fetion_sip_add_header(sip , theader); fetion_sip_add_header(sip , mheader); fetion_sip_add_header(sip , nheader); res = fetion_sip_to_string(sip , NULL); tcp_connection_send(conn , res , strlen(res)); sal_free(res);res = NULL; sal_free(credential); credential = NULL; res = fetion_sip_get_response(sip); sal_free(res); res = NULL; /*invite buddy*/ fetion_sip_set_type(sip , SIP_SERVICE); eheader = fetion_sip_event_header_new(SIP_EVENT_INVITEBUDDY); fetion_sip_add_header(sip , eheader); body = generate_invite_friend_body(conversation->currentContact->sipuri); res = fetion_sip_to_string(sip , body); sal_free(body); body = NULL; tcp_connection_send(sip->tcp , res , strlen(res)); sal_free(res); res = NULL; res = fetion_sip_get_response(sip); if(fetion_sip_get_code(res) == 200) { sal_free(res); res = (char*)sal_malloc(2048); memset(res , 0 , 2048); tcp_connection_recv(sip->tcp , res , 2048); //res = fetion_sip_get_response(sip); sal_free(res); return 1; }else{ sal_free(res); return -1; } }