Beispiel #1
0
void do_register_exp(struct fetion_account_data *sip, gint expire)
{
    gchar *body = NULL;
    gchar *hdr = NULL;

    sip->reregister = time(NULL) + expire - 100;
    body =
        g_strdup_printf
        (" <args><device type=\"PC\" version=\"0\" client-version=\"3.3.0370\" /><caps value=\"fetion-im;im-session;temp-group\" /><events value=\"contact;permission;system-message\" /><user-info attributes=\"all\" /><presence><basic value=\"400\" desc=\"\" /></presence></args>");

    if (sip->registerstatus == FETION_REGISTER_COMPLETE) {
        if (expire == 0)
            hdr = g_strdup_printf("X: 0\r\n");
        g_free(body);
        body = NULL;
    } else if (sip->registerstatus == FETION_REGISTER_RETRY
               && (sip->registrar.digest_session_key)) {
        hdr =
            g_strdup_printf
            ("A: Digest response=\"%s\",cnonce=\"%s\"\r\n",
             sip->registrar.digest_session_key, sip->registrar.cnonce);
    } else {
        sip->registerstatus = FETION_REGISTER_SENT;
        hdr = NULL;
    }

    send_sip_request(sip->gc, "R", "", "", hdr, body, NULL,
                     process_register_response);
    if (body != NULL)
        g_free(body);
    if (hdr != NULL)
        g_free(hdr);
}
Beispiel #2
0
void SendInvite(struct fetion_account_data *sip,const gchar *who)
{
	gchar *body,*hdr,*fullto;
	const gchar *my_ip;
	gint my_port;
	struct fetion_buddy * buddy = NULL;
	if(strncmp("sip:", who, 4)==0)
		fullto = g_strdup_printf("T: %s\r\n", who);
	else 
		return;
	buddy = g_hash_table_lookup(sip->buddies,who);
	g_return_if_fail(buddy!=NULL);
	my_ip = purple_network_get_my_ip(sip->fd);
	my_port = purple_network_get_port_from_fd(sip->fd);
	purple_debug_info("fetion:","SendInvite:[%s:%d]\n",my_ip,my_port);
	hdr = g_strdup_printf("K: text/html-fragment\r\n"
			"K: multiparty\r\n"
			"K: nudge\r\n");	
	body = g_strdup_printf("v=0\r\n"
			"o=-0 0 IN %s:%d\r\n"
			"s=session\r\n"
			"c=IN IP4 %s:%d\r\n"
			"t=0 0\r\n"
			"m=message %d sip %s\r\n",
			my_ip,my_port,my_ip,my_port,my_port,sip->uri);

	purple_debug_info("fetion:","SendInvite:[%s]\n",body);
	send_sip_request(sip->gc,"I","",fullto,hdr,body,buddy->dialog,(TransCallback) SendInvite_cb);

	g_free(fullto);
	g_free(hdr);
	g_free(body);
}
Beispiel #3
0
void GetBuddyInfo(struct fetion_account_data *sip, const char *who)
{
	gint xml_len;
	xmlnode *root, *son, *item;
	gchar *body;

	root = xmlnode_new("args");
	g_return_if_fail(root != NULL);
	son = xmlnode_new_child(root, "contacts");
	xmlnode_set_attrib(son, "attributes", "all");
	//xmlnode_set_attrib(son,"extended-attributes","score-level");
	g_return_if_fail(son != NULL);
	item = xmlnode_new_child(son, "contact");
	g_return_if_fail(item != NULL);

	xmlnode_set_attrib(item, "uri", who);

	body = g_strdup_printf("%s",xmlnode_to_str(root, &xml_len));
	purple_debug_info("fetion:", "GetBuddyInfo:body=[%s]", body);

	send_sip_request(sip->gc, "S", "", "", "N: GetContactsInfo\r\n", body,
			 NULL, (TransCallback) GetBuddyInfo_cb);

	xmlnode_free(root);
	g_free(body);

}
Beispiel #4
0
void CreateTempGroup(PurpleConnection * gc, PurpleBuddy * buddy)
{
	gchar *body, *hdr;
	gint xml_len;
	xmlnode *root, *son, *item;
	struct fetion_account_data *sip = gc->proto_data;

	root = xmlnode_new("args");
	g_return_if_fail(root != NULL);
	son = xmlnode_new_child(root, "participants");
	g_return_if_fail(son != NULL);
	son = xmlnode_new_child(son, "participant");
	g_return_if_fail(son != NULL);

	xmlnode_set_attrib(son, "uri", buddy->name);

	hdr = g_strdup("N: CreateTemporaryGroup\r\nK: text/html-fragment\r\n");
	body = g_strdup_printf(xmlnode_to_str(root, &xml_len));
	purple_debug(PURPLE_DEBUG_MISC, "fetion", "in CreateTempGroup[%s]\n",
		     body);
	send_sip_request(sip->gc, "S", "", "", hdr, body, NULL,
			 CreateTempGroup_cb);

	g_free(body);
	g_free(hdr);
	xmlnode_free(root);

}
Beispiel #5
0
void GetAllBuddyInfo(struct fetion_account_data *sip)
{
	gchar body[10240];
	GSList *buddy_list;
	memset(body, 0, sizeof(body));
	g_strlcat(body, "<args><contacts attributes=\"provisioning;impresa;mobile-no;nickname;name;gender;portrait-crc;ivr-enabled\" extended-attributes=\"score-level\">", 10240);

	buddy_list = purple_find_buddies(sip->account, NULL);
	for (; buddy_list; buddy_list = g_slist_next(buddy_list)) {
		if ((strncmp (((PurpleBuddy *) buddy_list->data)->name, "sip", 3) == 0) &&
				(strcmp (((PurpleBuddy *) buddy_list->data)->name, sip->uri) != 0))
		{
			g_strlcat(body, "<contact uri=\"", 10240);
			g_strlcat(body, ((PurpleBuddy *) buddy_list-> data)->name, 10240);
			g_strlcat(body, "\" />", 10240);
		} else
			continue;
	}


	g_strlcat(body, "</contacts></args>", 10240);

	send_sip_request(sip->gc, "S", "", "", "N: GetContactsInfo\r\n", body,
			 NULL, NULL);

}
Beispiel #6
0
void
fetion_subscribe_exp(struct fetion_account_data *sip,
                     struct fetion_buddy *buddy)
{
    GSList *buddy_list;
    gchar body[10240], *hdr;

    memset(body, 0, sizeof(body));
    g_strlcat(body, "<args><subscription><contacts>", 10240);
    hdr = g_strdup_printf("N: presence\r\n");
    if (buddy == NULL) {
        buddy_list = purple_find_buddies(sip->account, NULL);
        for (; buddy_list; buddy_list = g_slist_next(buddy_list)) {
            if ((strncmp
                    (((PurpleBuddy *) buddy_list->data)->name, "sip",
                     3) == 0)
                    &&
                    (strcmp
                     (((PurpleBuddy *) buddy_list->data)->name,
                      sip->uri)
                     != 0)) {
                g_strlcat(body, "<contact uri=\"", 10240);
                purple_debug_info("fetion:sub", "name=[%s]\n",
                                  ((PurpleBuddy *)
                                   buddy_list->data)->name);
                g_strlcat(body,
                          ((PurpleBuddy *) buddy_list->
                           data)->name, 10240);
                g_strlcat(body, "\" />", 10240);
            } else
                continue;
        }

    } else {
        g_strlcat(body, "<contact uri=\"", 10240);
        g_strlcat(body, buddy->name, 10240);
        g_strlcat(body, "\" />", 10240);
    }
    g_strlcat(body, "</contacts>", 10240);
    g_strlcat(body,
              "<presence><basic attributes=\"all\" /><personal attributes=\"all\" /><extended types=\"sms;location;listening;ring-back-tone\" /></presence></subscription><subscription><contacts><contact uri=\"",
              10240);
    g_strlcat(body, sip->uri, 10240);
    g_strlcat(body,
              "\" /></contacts><presence><extended types=\"sms;location;listening;ring-back-tone\" /></presence></subscription></args>",
              10240);

    purple_debug_info("fetion:sub", "name=[%s]\n", body);

    send_sip_request(sip->gc, "SUB", "", "", hdr, body, NULL,
                     process_subscribe_response);

}
Beispiel #7
0
void SendInvite_cb(struct fetion_account_data *sip, struct sipmsg *msg, struct transaction *tc)
{
	const gchar *to;
	gchar *fullto;

	to = sipmsg_find_header(msg,"T");	
	fullto = g_strdup_printf("T: %s\r\n",to);

	purple_debug_info("fetion:","SendACK:\n");
	send_sip_request(sip->gc,"A","",fullto,NULL,NULL,NULL,NULL);

	g_free(fullto);
}
Beispiel #8
0
static void fetion_set_status(PurpleAccount * account, PurpleStatus * status)
{
	/*
	   Away = 100,
	   BeRightBack = 300,
	   Busy = 600,
	   DoNotDisturb = 800,
	   InTheMeeting = 850,
	   Invisible = 0x383,
	   Offline = 0,
	   Online = 400,
	   OnThePhone = 500,
	   OutToLunch = 150,
	   SmsOnline = 1,
	   Unknown = -1
	 */
	const char *status_id;
	char *body;
	int status_code;

	status_id = purple_status_get_id(status);

	if (!strcmp(status_id, "away"))
		status_code = 100;
	else if (!strcmp(status_id, "brb"))
		status_code = 300;
	else if (!strcmp(status_id, "busy"))
		status_code = 600;
	else if (!strcmp(status_id, "phone"))
		status_code = 500;
	else if (!strcmp(status_id, "lunch"))
		status_code = 150;
	else if (!strcmp(status_id, "invisible"))
		status_code = 0x383;
	else
		status_code = 400;

	body =
	    g_strdup_printf
	    ("<args><presence><basic value=\"%d\" /></presence></args>",
	     status_code);
	send_sip_request(account->gc, "S", "", "", "N: SetPresence\r\n", body,
			 NULL, NULL);
	g_free(body);
	//<args><presence><basic value="400" /></presence></args>
}
Beispiel #9
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);
		}
Beispiel #10
0
gboolean GetContactList(struct fetion_account_data *sip)
{
	gchar * body, *hdr;

	if(sip->GetContactFlag == 1)
	{
		purple_timeout_remove(sip->GetContactTimeOut);
		sip->GetContactTimeOut = NULL;
		return TRUE;
	}
	hdr = g_strdup("N: GetContactList\r\n");
	body = g_strdup("<args><contacts><buddy-lists /><buddies attributes=\"all\" /><mobile-buddies attributes=\"all\" /><chat-friends /><blacklist /></contacts></args>");
	send_sip_request(sip->gc,"S","","",hdr,body,NULL,GetContactList_cb);

	g_free(body);
	g_free(hdr);

	return TRUE;
}
Beispiel #11
0
void
SendInvite_cb(struct fetion_account_data *sip, struct sipmsg *msg,
	      struct transaction *tc)
{
	const gchar *to;
	gchar *fullto;
	struct fetion_buddy *buddy = NULL;

	to = sipmsg_find_header(msg, "T");
	if (strncmp("sip:", to, 4) == 0)
		fullto = g_strdup_printf("T: %s\r\n", to);
	else
		return;
	buddy = g_hash_table_lookup(sip->buddies, to);
	g_return_if_fail(buddy != NULL);

	purple_debug_info("fetion:", "SendACK:\n");
	sip->cseq=0;//make cseq=1
	send_sip_request(sip->gc, "A", "", fullto, NULL, NULL, buddy->dialog, NULL);

	g_free(fullto);
}
Beispiel #12
0
void
AddMobileBuddy(struct fetion_account_data *sip, struct sipmsg *msg,
	       struct transaction *tc)
{
	gint xml_len;
	xmlnode *root, *son, *item;
	gchar *body;
	const gchar *uri, *name, *group_id;
	struct group_attr *g_attr = NULL;
	gchar *buddy_name;
	PurpleBuddy *b;
	PurpleGroup *g = NULL;
	struct fetion_buddy *bs;
	struct sipmsg *old = NULL;
	const gchar *real_name;

	real_name =
	    purple_account_get_string(sip->account, "realname", sip->username);

	if (!real_name || strlen(real_name) < 1) {
		real_name = sip->username;
	}

	g_return_if_fail(tc->msg != NULL);
	old = tc->msg;
	g_return_if_fail(old != NULL);
	purple_debug_info("fetion:", "AddMobileBuddy:oldmsg[%s]", old->body);
	root = xmlnode_from_str(old->body, old->bodylen);
	item = xmlnode_get_child(root, "contacts/buddies/buddy");
	g_return_if_fail(item != NULL);

	uri = xmlnode_get_attrib(item, "uri");
	name = xmlnode_get_attrib(item, "local-name");
	group_id = xmlnode_get_attrib(item, "buddy-lists");
	buddy_name = g_strdup_printf("%s", uri);
	g_attr = g_hash_table_lookup(sip->group, group_id);
	g_return_if_fail(g_attr != NULL);
	g = purple_find_group(g_attr->name);
	if (!g)
		g = purple_group_new(g_attr->name);

	b = purple_find_buddy(sip->account, buddy_name);
	if (!b) {
		b = purple_buddy_new(sip->account, buddy_name, NULL);
	}

	purple_blist_add_buddy(b, NULL, g, NULL);
	if (name != NULL && *name != '\0')
		purple_blist_alias_buddy(b, name);
	bs = g_new0(struct fetion_buddy, 1);
	bs->name = g_strdup(b->name);
	g_hash_table_insert(sip->buddies, bs->name, bs);

	xmlnode_free(root);

	root = xmlnode_new("args");
	g_return_if_fail(root != NULL);
	son = xmlnode_new_child(root, "contacts");
	g_return_if_fail(son != NULL);
	son = xmlnode_new_child(son, "mobile-buddies");
	g_return_if_fail(son != NULL);
	item = xmlnode_new_child(son, "mobile-buddy");
	g_return_if_fail(item != NULL);

	xmlnode_set_attrib(item, "expose-mobile-no", "1");
	xmlnode_set_attrib(item, "expose-name", "1");
	xmlnode_set_attrib(item, "invite", "1");

	xmlnode_set_attrib(item, "uri", buddy_name);
	xmlnode_set_attrib(item, "buddy-lists", "1");
	//xmlnode_set_attrib(item,"desc",sip->mobileno);
	xmlnode_set_attrib(item, "desc", real_name);

	body = g_strdup_printf("%s",xmlnode_to_str(root, &xml_len));
	purple_debug_info("fetion:", "add_buddy:body=[%s]", body);

	send_sip_request(sip->gc, "S", "", "", "N: AddMobileBuddy\r\n", body,
			 NULL, (TransCallback) AddMobileBuddy_cb);

	g_free(buddy_name);
	xmlnode_free(root);
	g_free(body);

}