struct sip_session * sipe_session_add_chat(struct sipe_account_data *sip) { struct sip_session *session = g_new0(struct sip_session, 1); session->callid = gencallid(); session->is_multiparty = TRUE; session->chat_id = rand(); session->unconfirmed_messages = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); session->conf_unconfirmed_messages = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); sip->sessions = g_slist_append(sip->sessions, session); return session; }
void send_sip_request(PurpleConnection * gc, const gchar * method, const gchar * url, const gchar * to, const gchar * addheaders, const gchar * body, struct sip_dialog *dialog, TransCallback tc) { struct fetion_account_data *sip = gc->proto_data; gchar *callid = dialog ? g_strdup(dialog->callid) : gencallid(); const gchar *addh = ""; GString *outstr = g_string_new(""); if (!strcmp(method, "R")) { if (sip->regcallid) { g_free(callid); callid = g_strdup(sip->regcallid); } else sip->regcallid = g_strdup(callid); } if (addheaders) addh = addheaders; g_string_append_printf(outstr, "%s fetion.com.cn SIP-C/2.0\r\n" "F: %s\r\n" "I: %s\r\n" "Q: %d %s\r\n" "%s%s", method, sip->username, callid, ++sip->cseq, method, to, addh); if (body) g_string_append_printf(outstr, "L: %d\r\n\r\n%s", (int)strlen(body), body); else g_string_append_printf(outstr, "\r\n\r\n"); g_free(callid); /* add to ongoing transactions */ transactions_add_buf(sip, outstr->str, tc); sendout_pkt(gc, outstr->str); g_string_free(outstr, TRUE); }
/** * Invites counterparty to join conference. */ void sipe_invite_conf(struct sipe_core_private *sipe_private, struct sip_session *session, const gchar* who) { gchar *hdr; gchar *contact; gchar *body; struct sip_dialog *dialog = NULL; /* It will be short lived special dialog. * Will not be stored in session. */ dialog = g_new0(struct sip_dialog, 1); dialog->callid = gencallid(); dialog->with = g_strdup(who); dialog->ourtag = gentag(); contact = get_contact(sipe_private); hdr = g_strdup_printf( "Supported: ms-sender\r\n" "Contact: %s\r\n" "Content-Type: application/ms-conf-invite+xml\r\n", contact); g_free(contact); body = g_strdup_printf( SIPE_SEND_CONF_INVITE, session->chat_session->id, session->subject ? session->subject : "" ); sip_transport_invite(sipe_private, hdr, body, dialog, process_invite_conf_response); sipe_dialog_free(dialog); g_free(body); g_free(hdr); }
/** Invite us to the focus */ void sipe_invite_conf_focus(struct sipe_core_private *sipe_private, struct sip_session *session) { gchar *hdr; gchar *contact; gchar *body; gchar *self; if (session->focus_dialog && session->focus_dialog->is_established) { SIPE_DEBUG_INFO("session with %s already has a dialog open", session->focus_uri); return; } if(!session->focus_dialog) { session->focus_dialog = g_new0(struct sip_dialog, 1); session->focus_dialog->callid = gencallid(); session->focus_dialog->with = g_strdup(session->focus_uri); session->focus_dialog->endpoint_GUID = rand_guid(); }
/** Create new session with Focus URI */ struct sip_session * sipe_conf_create(struct sipe_core_private *sipe_private, struct sipe_chat_session *chat_session, const gchar *focus_uri) { gchar *hdr; gchar *contact; gchar *body; gchar *self; struct sip_session *session = sipe_session_add_chat(sipe_private, chat_session, FALSE, focus_uri); session->focus_dialog = g_new0(struct sip_dialog, 1); session->focus_dialog->callid = gencallid(); session->focus_dialog->with = g_strdup(session->chat_session->id); session->focus_dialog->endpoint_GUID = rand_guid(); session->focus_dialog->ourtag = gentag(); contact = get_contact(sipe_private); hdr = g_strdup_printf( "Supported: ms-sender\r\n" "Contact: %s\r\n" "Content-Type: application/cccp+xml\r\n", contact); g_free(contact); /* @TODO put request_id to queue to further compare with incoming one */ /* focus_URI, from, request_id, focus_URI, from, endpoint_GUID */ self = sip_uri_self(sipe_private); body = g_strdup_printf( SIPE_SEND_CONF_ADD_USER, session->focus_dialog->with, self, session->request_id++, session->focus_dialog->with, self, session->focus_dialog->endpoint_GUID); session->focus_dialog->outgoing_invite = sip_transport_invite(sipe_private, hdr, body, session->focus_dialog, process_invite_conf_focus_response); g_free(body); g_free(hdr); /* Rejoin existing session? */ if (chat_session) { SIPE_DEBUG_INFO("sipe_conf_create: rejoin '%s' (%s)", chat_session->title, chat_session->id); sipe_backend_chat_rejoin(SIPE_CORE_PUBLIC, chat_session->backend, self, chat_session->title); } g_free(self); return(session); }