Ejemplo n.º 1
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);

}
Ejemplo n.º 2
0
static xmlnode *gfire_game_configuration_to_xmlnode(const gfire_game_configuration *p_gconf)
{
	xmlnode *ret = xmlnode_new("game");
	gchar *id_str = g_strdup_printf("%u", p_gconf->game_id);
	xmlnode_set_attrib(ret, "id", id_str);
	g_free(id_str);

	xmlnode *command_node = xmlnode_new_child(ret, "command");

	if(p_gconf->detect_file)
	{
		xmlnode *detect_node = xmlnode_new_child(command_node, "detect");
		xmlnode_insert_data(detect_node, p_gconf->detect_file, -1);
	}

	if(p_gconf->launch_file)
	{
		xmlnode *launch_node = xmlnode_new_child(command_node, "launch");
		xmlnode_insert_data(launch_node, p_gconf->launch_file, -1);
	}

	if(p_gconf->launch_prefix)
	{
		xmlnode *prefix_node = xmlnode_new_child(command_node, "prefix");
		xmlnode_insert_data(prefix_node, p_gconf->launch_prefix, -1);
	}

	return ret;
}
Ejemplo n.º 3
0
void
jabber_data_parse(JabberStream *js, const char *who, JabberIqType type,
                  const char *id, xmlnode *data_node)
{
    JabberIq *result = NULL;
    const char *cid = xmlnode_get_attrib(data_node, "cid");
    const JabberData *data = cid ? jabber_data_find_local_by_cid(cid) : NULL;

    if (!data) {
        xmlnode *item_not_found = xmlnode_new("item-not-found");

        result = jabber_iq_new(js, JABBER_IQ_ERROR);
        if (who)
            xmlnode_set_attrib(result->node, "to", who);
        xmlnode_set_attrib(result->node, "id", id);
        xmlnode_insert_child(result->node, item_not_found);
    } else {
        result = jabber_iq_new(js, JABBER_IQ_RESULT);
        if (who)
            xmlnode_set_attrib(result->node, "to", who);
        xmlnode_set_attrib(result->node, "id", id);
        xmlnode_insert_child(result->node,
                             jabber_data_get_xml_definition(data));
    }
    jabber_iq_send(result);
}
Ejemplo n.º 4
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);

}
Ejemplo n.º 5
0
static JabberSaslState
fb_start(JabberStream *js, xmlnode *packet, xmlnode **response, char **error)
{
	PurpleAccount *account;
	const char *username;
	gchar **parts;

	account = purple_connection_get_account(js->gc);
	username = purple_account_get_username(account);

	purple_debug_error("auth_fb", "account name is %s", username);

	parts = g_strsplit(username, "@", 0);
	if (parts[0] && strlen(parts[0]) && g_str_has_prefix(parts[0], "-")) {
		/* When connecting with X-FACEBOOK-PLATFORM, the password field must be set to the
		 * OAUTH 2.0 session key.
		 *
		 * X-FACEBOOK-PLATFORM is only valid for a facebook userID, which is prefixed with '-'
		 */
		xmlnode *auth = xmlnode_new("auth");
		xmlnode_set_namespace(auth, "urn:ietf:params:xml:ns:xmpp-sasl");
		xmlnode_set_attrib(auth, "mechanism", "X-FACEBOOK-PLATFORM");
		
		*response = auth;
		
		g_strfreev(parts);
		return JABBER_SASL_STATE_CONTINUE;		
	} else {
		g_strfreev(parts);
		return JABBER_SASL_STATE_FAIL;		
	}
}
Ejemplo n.º 6
0
int main(int argc, char *argv[])
{
	int	i;

	list_init();

	for(i = 1; i < argc; i++)
	{
		DynStr	*ds;

		if((ds = dynstr_new_from_file(argv[i])) != NULL)
		{
			XmlNode	*xn;

			if((xn = xmlnode_new(dynstr_string(ds))) != NULL)
			{
				xmlnode_print_outline(xn);
				xmlnode_destroy(xn);
			}
		}
		else
			printf("read error\n");
	}
	return 0;
}
Ejemplo n.º 7
0
void
jabber_data_parse(JabberStream *js, xmlnode *packet)
{
    JabberIq *result = NULL;
    const char *who = xmlnode_get_attrib(packet, "from");
    xmlnode *data_node = xmlnode_get_child(packet, "data");
    const JabberData *data =
        jabber_data_find_local_by_cid(xmlnode_get_attrib(data_node, "cid"));

    if (!data) {
        xmlnode *item_not_found = xmlnode_new("item-not-found");

        result = jabber_iq_new(js, JABBER_IQ_ERROR);
        xmlnode_set_attrib(result->node, "to", who);
        xmlnode_set_attrib(result->node, "id", xmlnode_get_attrib(packet, "id"));
        xmlnode_insert_child(result->node, item_not_found);
    } else {
        result = jabber_iq_new(js, JABBER_IQ_RESULT);
        xmlnode_set_attrib(result->node, "to", who);
        xmlnode_set_attrib(result->node, "id", xmlnode_get_attrib(packet, "id"));
        xmlnode_insert_child(result->node,
                             jabber_data_get_xml_definition(data));
    }
    jabber_iq_send(result);
}
Ejemplo n.º 8
0
int main(void)
{
	test_package_begin("xmlnode", "XML parser");

	test_begin("Non-creation");
	{
		XmlNode	*root;

		root = xmlnode_new(NULL);
		test_result(root == NULL);
	}
	test_end();

	test_begin("Single node creation");
	{
		XmlNode	*root;

		root = xmlnode_new("<test/>");
		test_result(root != NULL && strcmp(xmlnode_get_name(root), "test") == 0);
		xmlnode_destroy(root);
	}
	test_end();

	test_begin("Attribute access");
	{
		XmlNode	*root;

		root = xmlnode_new("<test foo='bar'/>");
		test_result(strcmp(xmlnode_attrib_get_value(root, "foo"), "bar") == 0);
		xmlnode_destroy(root);
	}
	test_end();

	test_begin("Path evaluation");
	{
		XmlNode	*root;

		root = xmlnode_new("<parent><child name='foo'/><child name='bar'/><child name='baz'/></parent>");
		test_result(strcmp(xmlnode_eval_single(root, "parent/child[@NAME]"), "baz") == 0);
		xmlnode_destroy(root);
	}
	test_end();
	
	return test_package_end();
}
Ejemplo n.º 9
0
static xmlnode *
google_session_create_xmlnode(GoogleSession *session, const char *type)
{
	xmlnode *node = xmlnode_new("session");
	xmlnode_set_namespace(node, NS_GOOGLE_SESSION);
	xmlnode_set_attrib(node, "id", session->id.id);
	xmlnode_set_attrib(node, "initiator", session->id.initiator);
	xmlnode_set_attrib(node, "type", type);
	return node;
}
Ejemplo n.º 10
0
xmlnode *
jabber_data_get_xml_request(const gchar *cid)
{
    xmlnode *tag = xmlnode_new("data");

    xmlnode_set_namespace(tag, NS_BOB);
    xmlnode_set_attrib(tag, "cid", cid);

    return tag;
}
Ejemplo n.º 11
0
static void
xmlnode_parser_element_start_libxml(void *user_data,
				   const xmlChar *element_name, const xmlChar *prefix, const xmlChar *xmlns,
				   int nb_namespaces, const xmlChar **namespaces,
				   int nb_attributes, int nb_defaulted, const xmlChar **attributes)
{
	struct _xmlnode_parser_data *xpd = user_data;
	xmlnode *node;
	int i, j;

	if(!element_name || xpd->error) {
		return;
	} else {
		if(xpd->current)
			node = xmlnode_new_child(xpd->current, (const char*) element_name);
		else
			node = xmlnode_new((const char *) element_name);

		xmlnode_set_namespace(node, (const char *) xmlns);
		xmlnode_set_prefix(node, (const char *)prefix);

		if (nb_namespaces != 0) {
			node->namespace_map = g_hash_table_new_full(
				g_str_hash, g_str_equal, g_free, g_free);

			for (i = 0, j = 0; i < nb_namespaces; i++, j += 2) {
				const char *key = (const char *)namespaces[j];
				const char *val = (const char *)namespaces[j + 1];
				g_hash_table_insert(node->namespace_map,
					g_strdup(key ? key : ""), g_strdup(val ? val : ""));
			}
		}

		for(i=0; i < nb_attributes * 5; i+=5) {
			const char *prefix = (const char *)attributes[i + 1];
			char *txt;
			int attrib_len = attributes[i+4] - attributes[i+3];
			char *attrib = g_malloc(attrib_len + 1);
			memcpy(attrib, attributes[i+3], attrib_len);
			attrib[attrib_len] = '\0';
			txt = attrib;
			attrib = purple_unescape_html(txt);
			g_free(txt);
			if (prefix && *prefix) {
				xmlnode_set_attrib_with_prefix(node, (const char*) attributes[i], prefix, attrib);
			} else {
				xmlnode_set_attrib(node, (const char*) attributes[i], attrib);
			}
			g_free(attrib);
		}

		xpd->current = node;
	}
}
Ejemplo n.º 12
0
static JabberSaslState
digest_md5_start(JabberStream *js, xmlnode *packet, xmlnode **response,
                 char **error)
{
	xmlnode *auth = xmlnode_new("auth");
	xmlnode_set_namespace(auth, NS_XMPP_SASL);
	xmlnode_set_attrib(auth, "mechanism", "DIGEST-MD5");

	*response = auth;
	return JABBER_SASL_STATE_CONTINUE;
}
Ejemplo n.º 13
0
static JabberSaslState
jabber_cyrus_handle_challenge(JabberStream *js, xmlnode *packet,
                              xmlnode **reply, char **error)
{
	char *enc_in = xmlnode_get_data(packet);
	unsigned char *dec_in;
	char *enc_out;
	const char *c_out;
	unsigned int clen;
	gsize declen;

	dec_in = purple_base64_decode(enc_in, &declen);

	js->sasl_state = sasl_client_step(js->sasl, (char*)dec_in, declen,
					  NULL, &c_out, &clen);
	g_free(enc_in);
	g_free(dec_in);
	if (js->sasl_state != SASL_CONTINUE && js->sasl_state != SASL_OK) {
		gchar *tmp = g_strdup_printf(_("SASL error: %s"),
				sasl_errdetail(js->sasl));
		purple_debug_error("jabber", "Error is %d : %s\n",
				js->sasl_state, sasl_errdetail(js->sasl));
		*error = tmp;
		return JABBER_SASL_STATE_FAIL;
	} else {
		xmlnode *response = xmlnode_new("response");
		xmlnode_set_namespace(response, NS_XMPP_SASL);
		if (clen > 0) {
			/* Cyrus SASL 2.1.22 appears to contain code to add the charset
			 * to the response for DIGEST-MD5 but there is no possibility
			 * it will be executed.
			 *
			 * My reading of the digestmd5 plugin indicates the username and
			 * realm are always encoded in UTF-8 (they seem to be the values
			 * we pass in), so we need to ensure charset=utf-8 is set.
			 */
			if (!purple_strequal(js->current_mech, "DIGEST-MD5") ||
					strstr(c_out, ",charset="))
				/* If we're not using DIGEST-MD5 or Cyrus SASL is fixed */
				enc_out = purple_base64_encode((unsigned char*)c_out, clen);
			else {
				char *tmp = g_strdup_printf("%s,charset=utf-8", c_out);
				enc_out = purple_base64_encode((unsigned char*)tmp, clen + 14);
				g_free(tmp);
			}

			xmlnode_insert_data(response, enc_out, -1);
			g_free(enc_out);
		}

		*reply = response;
		return JABBER_SASL_STATE_CONTINUE;
	}
}
Ejemplo n.º 14
0
void jabber_chat_invite(PurpleConnection *gc, int id, const char *msg,
		const char *name)
{
	JabberStream *js = gc->proto_data;
	JabberChat *chat;
	xmlnode *message, *body, *x, *invite;
	char *room_jid;

	chat = jabber_chat_find_by_id(js, id);
	if(!chat)
		return;

	message = xmlnode_new("message");

	room_jid = g_strdup_printf("%s@%s", chat->room, chat->server);

	if(chat->muc) {
		xmlnode_set_attrib(message, "to", room_jid);
		x = xmlnode_new_child(message, "x");
		xmlnode_set_namespace(x, "http://jabber.org/protocol/muc#user");
		invite = xmlnode_new_child(x, "invite");
		xmlnode_set_attrib(invite, "to", name);
		if (msg) {
			body = xmlnode_new_child(invite, "reason");
			xmlnode_insert_data(body, msg, -1);
		}
	} else {
		xmlnode_set_attrib(message, "to", name);
		/*
		 * Putting the reason into the body was an 'undocumented protocol,
		 * ...not part of "groupchat 1.0"'.
		 * http://xmpp.org/extensions/attic/jep-0045-1.16.html#invite
		 *
		 * Left here for compatibility.
		 */
		if (msg) {
			body = xmlnode_new_child(message, "body");
			xmlnode_insert_data(body, msg, -1);
		}

		x = xmlnode_new_child(message, "x");
		xmlnode_set_attrib(x, "jid", room_jid);

		/* The better place for it! XEP-0249 style. */
		if (msg)
			xmlnode_set_attrib(x, "reason", msg);
		xmlnode_set_namespace(x, "jabber:x:conference");
	}

	jabber_send(js, message);
	xmlnode_free(message);
	g_free(room_jid);
}
Ejemplo n.º 15
0
xmlnode *
jabber_data_get_xhtml_im(const JabberData *data, const gchar *alt)
{
    xmlnode *img = xmlnode_new("img");
    char src[128];

    xmlnode_set_attrib(img, "alt", alt);
    g_snprintf(src, sizeof(src), "cid:%s", data->cid);
    xmlnode_set_attrib(img, "src", src);

    return img;
}
Ejemplo n.º 16
0
/*
 * WLM media PSM info build prcedure
 *
 * Result can like:
 *	<CurrentMedia>\0Music\01\0{0} - {1}\0Song Title\0Song Artist\0Song Album\0\0</CurrentMedia>\
 *	<CurrentMedia>\0Games\01\0Playing {0}\0Game Name\0</CurrentMedia>\
 *	<CurrentMedia>\0Office\01\0Office Message\0Office App Name\0</CurrentMedia>"
 */
static char *
msn_build_psm(const char *psmstr,const char *mediastr, const char *guidstr, guint protocol_ver)
{
	xmlnode *dataNode,*psmNode,*mediaNode,*guidNode;
	char *result;
	int length;

	dataNode = xmlnode_new("Data");

	psmNode = xmlnode_new("PSM");
	if(psmstr != NULL){
		xmlnode_insert_data(psmNode, psmstr, -1);
	}
	xmlnode_insert_child(dataNode, psmNode);

	mediaNode = xmlnode_new("CurrentMedia");
	if(mediastr != NULL){
		xmlnode_insert_data(mediaNode, mediastr, -1);
	}
	xmlnode_insert_child(dataNode, mediaNode);

	guidNode = xmlnode_new("MachineGuid");
	if(guidstr != NULL){
		xmlnode_insert_data(guidNode, guidstr, -1);
	}
	xmlnode_insert_child(dataNode, guidNode);

	if (protocol_ver >= 16) {
		/* TODO: What is this for? */
		xmlnode *ddpNode = xmlnode_new("DDP");
		xmlnode_insert_child(dataNode, ddpNode);
	}

	result = xmlnode_to_str(dataNode, &length);
	xmlnode_free(dataNode);
	return result;
}
Ejemplo n.º 17
0
static xmlnode *
smileys_to_xmlnode(void)
{
	xmlnode *root_node, *profile_node, *smileyset_node;

	root_node = xmlnode_new(XML_ROOT_TAG);
	xmlnode_set_attrib(root_node, "version", "1.0");

	/* See the top comments above to understand why initial tag elements
	 * are not being considered by now. */
	profile_node = xmlnode_new(XML_PROFILE_TAG);
	if (profile_node) {
		xmlnode_set_attrib(profile_node, XML_PROFILE_NAME_ATTRIB_TAG, "Default");
		xmlnode_insert_child(root_node, profile_node);

		smileyset_node = xmlnode_new(XML_SMILEY_SET_TAG);
		if (smileyset_node) {
			xmlnode_insert_child(profile_node, smileyset_node);
			g_hash_table_foreach(smiley_shortcut_index, add_smiley_to_main_node, smileyset_node);
		}
	}

	return root_node;
}
Ejemplo n.º 18
0
static void do_nick_set(JabberStream *js, const char *nick) {
	xmlnode *publish, *nicknode;

	publish = xmlnode_new("publish");
	xmlnode_set_attrib(publish,"node","http://jabber.org/protocol/nick");
	nicknode = xmlnode_new_child(xmlnode_new_child(publish, "item"), "nick");
	xmlnode_set_namespace(nicknode, "http://jabber.org/protocol/nick");

	if(nick && nick[0] != '\0')
		xmlnode_insert_data(nicknode, nick, -1);

	jabber_pep_publish(js, publish);
	/* publish is freed by jabber_pep_publish -> jabber_iq_send -> jabber_iq_free
		(yay for well-defined memory management rules) */
}
Ejemplo n.º 19
0
xmlnode *
jabber_data_get_xml_definition(const JabberData *data)
{
    xmlnode *tag = xmlnode_new("data");
    char *base64data = purple_base64_encode(data->data, data->size);

    xmlnode_set_namespace(tag, NS_BOB);
    xmlnode_set_attrib(tag, "cid", data->cid);
    xmlnode_set_attrib(tag, "type", data->type);

    xmlnode_insert_data(tag, base64data, -1);

    g_free(base64data);

    return tag;
}
Ejemplo n.º 20
0
Archivo: xdata.c Proyecto: VoxOx/VoxOx
static void jabber_x_data_cancel_cb(struct jabber_x_data_data *data, GaimRequestFields *fields) {
	xmlnode *result = xmlnode_new("x");
	jabber_x_data_cb cb = data->cb;
	gpointer user_data = data->user_data;
	JabberStream *js = data->js;
	g_hash_table_destroy(data->fields);
	while(data->values) {
		g_free(data->values->data);
		data->values = g_slist_delete_link(data->values, data->values);
	}
	g_free(data);

	xmlnode_set_namespace(result, "jabber:x:data");
	xmlnode_set_attrib(result, "type", "cancel");

	cb(js, result, user_data);
}
Ejemplo n.º 21
0
void jabber_chat_part(JabberChat *chat, const char *msg)
{
	char *room_jid;
	xmlnode *presence;

	room_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server,
			chat->handle);
	presence = xmlnode_new("presence");
	xmlnode_set_attrib(presence, "to", room_jid);
	xmlnode_set_attrib(presence, "type", "unavailable");
	if(msg) {
		xmlnode *status = xmlnode_new_child(presence, "status");
		xmlnode_insert_data(status, msg, -1);
	}
	jabber_send(chat->js, presence);
	xmlnode_free(presence);
	g_free(room_jid);
}
Ejemplo n.º 22
0
static xmlnode *
prefs_to_xmlnode(void)
{
	xmlnode *node;
	struct purple_pref *pref, *child;

	pref = &prefs;

	/* Create the root preference node */
	node = xmlnode_new("pref");
	xmlnode_set_attrib(node, "version", "1");
	xmlnode_set_attrib(node, "name", "/");

	/* All My Children */
	for (child = pref->first_child; child != NULL; child = child->sibling)
		pref_to_xmlnode(node, child);

	return node;
}
Ejemplo n.º 23
0
static void
shinima_message_link_to_img(xmlnode *a,
							const gchar *href,
							gchar **message,
							gboolean *changed,
							gpointer user_data)
{
	ShinimaLink *link = NULL;

	purple_debug_info(PLUGIN_ID, "Found link %s\n", href);

	link = shinima_link_get(href);
	if(link && link->load_success)
	{
		// Here's useless check for I want to replace
		// non-image links with html title tag contents on the
		// future...
		if(link->is_image && link->data != NULL)
		{
			gint id = -1;
			id = shinima_link_store_image(link);
			if(id > 0)
			{
				gchar *idstr = g_strdup_printf("%d", id);
				xmlnode *img = xmlnode_new("img");

				img->next = a->next;
				img->parent = a->parent;
				a->next = img;

				xmlnode_set_attrib(img, "id", idstr);
				g_free(idstr);
				*changed = TRUE;
			}
		}
		shinima_link_debug_describe(link);
	}

	shinima_link_free(link);

	return;
}
Ejemplo n.º 24
0
static void gfire_game_save_config_xml()
{
	xmlnode *game_config = xmlnode_new("game_config");
	xmlnode_set_attrib(game_config, "version", "2");

	GList *cur = gfire_games_config;
	while(cur)
	{
		xmlnode_insert_child(game_config, gfire_game_configuration_to_xmlnode((gfire_game_configuration*)cur->data));

		cur = g_list_next(cur);
	}

	gchar *xml_str = xmlnode_to_formatted_str(game_config, NULL);

	purple_util_write_data_to_file("gfire_game_config.xml", xml_str, -1);
	g_free(xml_str);

	xmlnode_free(game_config);
}
Ejemplo n.º 25
0
static xmlnode *
smiley_to_xmlnode(PurpleSmiley *smiley)
{
	xmlnode *smiley_node = NULL;

	smiley_node = xmlnode_new(XML_SMILEY_TAG);

	if (!smiley_node)
		return NULL;

	xmlnode_set_attrib(smiley_node, XML_SHORTCUT_ATTRIB_TAG,
			smiley->shortcut);

	xmlnode_set_attrib(smiley_node, XML_CHECKSUM_ATRIB_TAG,
			smiley->checksum);

	xmlnode_set_attrib(smiley_node, XML_FILENAME_ATRIB_TAG,
			purple_imgstore_get_filename(smiley->img));

	return smiley_node;
}
Ejemplo n.º 26
0
static void
xmlnode_parser_element_start(GMarkupParseContext *context,
		const char *element_name, const char **attrib_names,
		const char **attrib_values, gpointer user_data, GError **error)
{
	struct _xmlnode_parser_data *xpd = user_data;
	xmlnode *node;
	int i;

	if(!element_name) {
		return;
	} else {
		if(xpd->current)
			node = xmlnode_new_child(xpd->current, element_name);
		else
			node = xmlnode_new(element_name);

		for(i=0; attrib_names[i]; i++)
			xmlnode_set_attrib(node, attrib_names[i], attrib_values[i]);

		xpd->current = node;
	}
}
Ejemplo n.º 27
0
void jabber_chat_invite(PurpleConnection *gc, int id, const char *msg,
		const char *name)
{
	JabberStream *js = gc->proto_data;
	JabberChat *chat;
	xmlnode *message, *body, *x, *invite;
	char *room_jid;

	chat = jabber_chat_find_by_id(js, id);
	if(!chat)
		return;

	message = xmlnode_new("message");

	room_jid = g_strdup_printf("%s@%s", chat->room, chat->server);

	if(chat->muc) {
		xmlnode_set_attrib(message, "to", room_jid);
		x = xmlnode_new_child(message, "x");
		xmlnode_set_namespace(x, "http://jabber.org/protocol/muc#user");
		invite = xmlnode_new_child(x, "invite");
		xmlnode_set_attrib(invite, "to", name);
		body = xmlnode_new_child(invite, "reason");
		xmlnode_insert_data(body, msg, -1);
	} else {
		xmlnode_set_attrib(message, "to", name);
		body = xmlnode_new_child(message, "body");
		xmlnode_insert_data(body, msg, -1);
		x = xmlnode_new_child(message, "x");
		xmlnode_set_attrib(x, "jid", room_jid);
		xmlnode_set_namespace(x, "jabber:x:conference");
	}

	jabber_send(js, message);
	xmlnode_free(message);
	g_free(room_jid);
}
Ejemplo n.º 28
0
xmlnode *jabber_presence_create(const char *state, const char *msg)
{
	xmlnode *show, *status, *presence;


	presence = xmlnode_new("presence");

	if(state) {
		const char *show_string = NULL;
		if(!strcmp(state, _("Chatty")))
			show_string = "chat";
		else if(!strcmp(state, _("Away")) ||
				(msg && !strcmp(state, GAIM_AWAY_CUSTOM)))
			show_string = "away";
		else if(!strcmp(state, _("Extended Away")))
			show_string = "xa";
		else if(!strcmp(state, _("Do Not Disturb")))
			show_string = "dnd";
		else if(!strcmp(state, _("Invisible")))
			xmlnode_set_attrib(presence, "type", "invisible");
		else if(!strcmp(state, "unavailable"))
			xmlnode_set_attrib(presence, "type", "unavailable");

		if(show_string) {
			show = xmlnode_new_child(presence, "show");
			xmlnode_insert_data(show, show_string, -1);
		}
	}

	if(msg && *msg) {
		status = xmlnode_new_child(presence, "status");
		xmlnode_insert_data(status, msg, -1);
	}

	return presence;
}
static void
notify_test_jabber_send_cb(PurplePluginAction *action)
{
       xmlnode* message;
       xmlnode* body;
       message = xmlnode_new("message");
       xmlnode_set_attrib(message, "from", "xuewen@localhost/develop");
       xmlnode_set_attrib(message, "to", "test@localhost");
       xmlnode_set_attrib(message, "type", "chat");

       body = xmlnode_new_child(message, "body");
       const char* body_data = "this is a test stanza";
       body->data = (char*)body_data;
       body->data_sz = strlen(body_data);

       // get a connection and emit it
       GList* connections = purple_connections_get_all();
       GList* connection = g_list_first(connections);
       PurpleConnection * gc_xuewen = 0;
       while(connection) {
               PurpleConnection * gc = (PurpleConnection*) connection->data;
               if (strcmp(gc->display_name, "test@localhost/QAS") == 0)
                       gc_xuewen = gc;
               connection = g_list_next(connection);
       }
/*
       const gchar* id = purple_plugin_get_id(gc_xuewen->prpl);
       if (strcmp(id, prpl-jabber) == 0) {

       }
*/
       PurplePlugin* plugin = purple_connection_get_prpl(gc_xuewen);
       PurplePluginProtocolInfo* info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);
       info->send_raw(gc_xuewen, msg, strlen(msg));
       //serv_send_im(gc_xuewen, "test@localhost", "this is a test", PURPLE_MESSAGE_SEND);
}
Ejemplo n.º 30
0
Archivo: iq.c Proyecto: bf4/pidgin-mac
JabberIq *jabber_iq_new(JabberStream *js, JabberIqType type)
{
	JabberIq *iq;

	iq = g_new0(JabberIq, 1);

	iq->type = type;

	iq->node = xmlnode_new("iq");
	switch(iq->type) {
		case JABBER_IQ_SET:
			xmlnode_set_attrib(iq->node, "type", "set");
			break;
		case JABBER_IQ_GET:
			xmlnode_set_attrib(iq->node, "type", "get");
			break;
		case JABBER_IQ_ERROR:
			xmlnode_set_attrib(iq->node, "type", "error");
			break;
		case JABBER_IQ_RESULT:
			xmlnode_set_attrib(iq->node, "type", "result");
			break;
		case JABBER_IQ_NONE:
			/* this shouldn't ever happen */
			break;
	}

	iq->js = js;

	if(type == JABBER_IQ_GET || type == JABBER_IQ_SET) {
		iq->id = jabber_get_next_id(js);
		xmlnode_set_attrib(iq->node, "id", iq->id);
	}

	return iq;
}