Пример #1
0
void
send_sip_response(PurpleConnection * gc, struct sipmsg *msg, int code,
		  const char *text, const char *body)
{
	GSList *tmp = msg->headers;
	gchar *name;
	gchar *value;
	GString *outstr = g_string_new("");

	/* When sending the acknowlegements and errors, the content length from the original
	   message is still here, but there is no body; we need to make sure we're sending the
	   correct content length */
	sipmsg_remove_header(msg, "L");
	if (body) {
		gchar len[12];
		sprintf(len, "%d", (int)strlen(body));
		sipmsg_add_header(msg, "L", len);
	}

	g_string_append_printf(outstr, "SIP-C/2.0 %d %s\r\n", code, text);
	while (tmp) {
		name = ((struct siphdrelement *)(tmp->data))->name;
		value = ((struct siphdrelement *)(tmp->data))->value;

		g_string_append_printf(outstr, "%s: %s\r\n", name, value);
		tmp = g_slist_next(tmp);
	}
	g_string_append_printf(outstr, "\r\n%s", body ? body : "");
	sendout_pkt(gc, outstr->str);
	g_string_free(outstr, TRUE);
}
Пример #2
0
void
process_incoming_invite(struct fetion_account_data *sip, struct sipmsg *msg)
{
        /* Plato Wu,2010/09/29: update it for SIP/C 4.0 protocol*/
#if 1
        gchar *body, *hdr;
        const char *auth, *to, *callid;
        char* ipaddress = NULL;
	char* credential = NULL;
        int port;
	struct group_chat *g_chat;
	struct fetion_buddy *buddy = NULL;

        auth = g_strdup_printf(sipmsg_find_header(msg, "A"));
	callid = sipmsg_find_header(msg, "I");
	to = sipmsg_find_header(msg, "F");

        sipmsg_remove_header(msg, "K");
        sipmsg_remove_header(msg, "XI");
        sipmsg_remove_header(msg, "AL");
        sipmsg_remove_header(msg, "A");
        purple_debug_info("plato:", "Received a conversation invitation");
        send_sip_response(sip->gc, msg, 200, "OK", NULL);

        fetion_sip_get_auth_attr(auth , &ipaddress , &port , &credential);
        purple_debug_info("plato:", "ipaddress is %s, port is %d, credential is %s", ipaddress, port, credential);
        /* Plato Wu,2010/09/29: TODO Openfetion new a TCP connection here, but I don't
         * know how to do in pidgin.*/
        /* purple_proxy_connect(sip->gc, sip->account, ipaddress, port, invite_cb, sip->gc); */
        /* Plato Wu,2010/09/29: TODO, R command should be sent into new connection. */
       hdr = g_strdup_printf("A: TICKS auth=\"%s\"\r\n", credential);
//"       K: text/html-fragment\r\nK: multiparty\r\nK: nudge\r\n"

       send_sip_request(sip->gc, "R", "", "", hdr, NULL, NULL, NULL);

       purple_debug_info("plato:", "start free");
       
	if (strncmp(to, "sip:TG", 6) != 0) {
		buddy = g_hash_table_lookup(sip->buddies, to);
		if (buddy == NULL) {
			buddy = g_new0(struct fetion_buddy, 1);
			buddy->name = g_strdup(to);
			g_hash_table_insert(sip->buddies, buddy->name, buddy);
		}