static void
shinima_message_links_foreach(gchar **message,
							  void(*foreach_func)(xmlnode*,
												  const gchar*,
												  gchar**,
												  gboolean*,
												  gpointer),
							  gboolean *_changed,
							  gpointer *user_data)
{
	xmlnode *root, *a;
	gboolean *changed =
		(_changed != NULL) ? changed : g_malloc(sizeof(gboolean));

	g_return_if_fail(foreach_func != NULL);

	root = xmlnode_from_str(*message, -1);

	for(a=xmlnode_get_child(root, "a"); a; a=xmlnode_get_next_twin(a))
	{
		const gchar *href = xmlnode_get_attrib(a, "href");
		if(href) foreach_func(a, href, message, changed, user_data);
	}

	if(changed)
	{
		g_free(*message);
		*message = xmlnode_to_str(root, NULL);
	}

	if(_changed == NULL) g_free(changed);

	xmlnode_free(root);
}
Example #2
0
static void
purple_smileys_load(void)
{
	xmlnode *root_node, *profile_node;
	xmlnode *smileyset_node = NULL;
	xmlnode *smiley_node;

	smileys_loaded = TRUE;

	root_node = purple_util_read_xml_from_file(XML_FILE_NAME,
			_(SMILEYS_LOG_ID));

	if (root_node == NULL)
		return;

	/* See the top comments above to understand why initial tag elements
	 * are not being considered by now. */
	profile_node = xmlnode_get_child(root_node, XML_PROFILE_TAG);
	if (profile_node)
		smileyset_node = xmlnode_get_child(profile_node, XML_SMILEY_SET_TAG);

	if (smileyset_node) {
		smiley_node = xmlnode_get_child(smileyset_node, XML_SMILEY_TAG);
		for (; smiley_node != NULL;
				smiley_node = xmlnode_get_next_twin(smiley_node)) {
			PurpleSmiley *smiley;

			smiley = parse_smiley(smiley_node);
		}
	}

	xmlnode_free(root_node);
}
Example #3
0
void
campfire_xaction_free(CampfireSslTransaction *xaction)
{
	if (xaction) {
		if (xaction->http_request) {
			g_string_free(xaction->http_request, TRUE);
		}
		if (xaction->http_response.response) {
			g_string_free(xaction->http_response.response,
				      TRUE);
		}
		if (xaction->http_response.header) {
			g_string_free(xaction->http_response.header,
				      TRUE);
		}
		if (xaction->http_response.content) {
			g_string_free(xaction->http_response.content,
				      TRUE);
		}
		if (xaction->xml_response) {
			xmlnode_free(xaction->xml_response);
		}
		if (xaction->room_id) {
			g_free(xaction->room_id);
		}
		g_list_free_full(xaction->messages, &campfire_message_free);
		xaction->campfire->num_xaction_free++; /* valgrind investigation */
		purple_debug_info("campfire", "xaction: %p, num_xaction_malloc:%d: num_xaction_free:%d\n",
		                  xaction,
		                  xaction->campfire->num_xaction_malloc,
		                  xaction->campfire->num_xaction_free);
		g_free(xaction);
	}

}
Example #4
0
/* destroys Session object */
static int session_destroy(Session *s){
GList *it;

	g_message(L_("Deleting session for '%s'"),s->jid);
	if (s->ping_timeout_func) g_source_remove(s->ping_timeout_func);
	if (s->timeout_func) g_source_remove(s->timeout_func);
	if (s->ping_timer) g_timer_destroy(s->ping_timer);
	session_remove_g_source(s);
	while(s->resources) resource_remove((Resource *)s->resources->data,0);
	if (s->ggs){
		if (s->connected){
			debug("gg_logoff(%p)",s->ggs);
			gg_logoff(s->ggs);
		}
		gg_free_session(s->ggs);
		s->ggs=NULL;
	}
	if (s->connected && s->s && s->jid){
		for(it=g_list_first(s->user->contacts);it;it=g_list_next(it)){
			Contact *c=(Contact *)it->data;

			if (!GG_S_NA(c->status) && c->status!=-1){
				char *ujid;
				ujid=jid_build_full(c->uin);
				presence_send(s->s,ujid,s->user->jid,0,NULL,NULL,0);
				g_free(ujid);
			}
		}
	}
	if (s->query) xmlnode_free(s->query);
	if (s->user) user_unref(s->user);
	g_free(s->gg_status_descr);
	g_free(s);
	return 0;
}
Example #5
0
void jabber_chat_change_nick(JabberChat *chat, const char *nick)
{
	xmlnode *presence;
	char *full_jid;
	PurplePresence *gpresence;
	PurpleStatus *status;
	JabberBuddyState state;
	char *msg;
	int priority;

	if(!chat->muc) {
		purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "",
				_("Nick changing not supported in non-MUC chatrooms"),
				PURPLE_MESSAGE_SYSTEM, time(NULL));
		return;
	}

	gpresence = purple_account_get_presence(chat->js->gc->account);
	status = purple_presence_get_active_status(gpresence);

	purple_status_to_jabber(status, &state, &msg, &priority);

	presence = jabber_presence_create(state, msg, priority);
	full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, nick);
	xmlnode_set_attrib(presence, "to", full_jid);
	g_free(full_jid);
	g_free(msg);

	jabber_send(chat->js, presence);
	xmlnode_free(presence);
}
Example #6
0
/* thread safe with sem */
mreturn mod_presence_deliver(mapi m, void *arg)
{
	session cur;

	if (m->packet->type != JPACKET_PRESENCE)
		return M_IGNORE;

	log_debug("deliver phase");

	/* only if we HAVE a user, and it was sent to ONLY the user@server, and there is at least one session available */
	if (m->user != NULL && m->packet->to->resource == NULL && js_session_primary_all_sem(m->user) != NULL) {
		log_debug("broadcasting to %s", m->user->user);

		/* broadcast */
		for (cur = m->user->sessions; cur != NULL; cur = cur->next) {
			if (cur->priority < -128)
				continue;
			js_session_to(cur, jpacket_new(xmlnode_dup(m->packet->x)));
		}
		SEM_UNLOCK(m->user->sem);

		if (jpacket_subtype(m->packet) != JPACKET__PROBE) {
			/* probes get handled by the offline thread as well? */
			xmlnode_free(m->packet->x);
			return M_HANDLED;
		}
	}

	return M_PASS;
}
Example #7
0
/* bounces packet for unknown users with the appropriate error */
void mt_unknown_bounce(void *arg)
{
    jpacket jp = (jpacket) arg;
    mti ti = (mti) jp->aux1;
    xmlnode reg;

    lowercase(jp->from->user);
    lowercase(jp->from->server);

    if ((reg = xdb_get(ti->xc,mt_xdb_id(jp->p,jp->from,jp->to->server),NS_REGISTER)) != NULL)
    {
        xmlnode p = xmlnode_new_tag("presence");
        xmlnode_put_attrib(p,"to",jid_full(jp->from));
        xmlnode_put_attrib(p,"from",jp->to->server);
        xmlnode_put_attrib(p,"type","probe");

        mt_deliver(ti,p);

        jutil_error(jp->x,TERROR_NOTFOUND);
        xmlnode_free(reg);
    }
    else
        jutil_error(jp->x,TERROR_REGISTER);

    mt_deliver(ti,jp->x);
}
static char*
format_message(char *sender,
               char *message)
{
    GString* format_message = g_string_new("");
    xmlnode* message_node = xmlnode_from_str(message, -1);

    /* raw */
    if ( !message_node ||
            !( strcmp(message_node->name, "html")==0 ||
               strcmp(message_node->name, "body")==0 )) {
        g_string_printf(format_message, "%s: %s", sender, message);
        return g_string_free(format_message, FALSE);
    }

    xmlnode* body_node =
        (strcmp(message_node->name, "body")) ?
        xmlnode_get_child(message_node, "body") :
        message_node;

    char* message_content = xmlnode_get_content(body_node);
    g_string_printf(format_message, "%s: %s", sender, message_content);
    g_free(message_content);

    xmlnode_free(message_node);

    return g_string_free(format_message, FALSE);
}
Example #9
0
xmlnode xmlnode_str(char *str, int len)
{
    XML_Parser p;
    xmlnode *x, node; /* pointer to an xmlnode */

    if(NULL == str)
        return NULL;

    x = malloc(sizeof(void *));

    *x = NULL; /* pointer to NULL */
    p = XML_ParserCreate(NULL);
    XML_SetUserData(p, x);
    XML_SetElementHandler(p, expat_startElement, expat_endElement);
    XML_SetCharacterDataHandler(p, expat_charData);
    if(!XML_Parse(p, str, len, 1))
    {
        /*        jdebug(ZONE,"xmlnode_str_error: %s",(char *)XML_ErrorString(XML_GetErrorCode(p)));*/
        xmlnode_free(*x);
        *x = NULL;
    }
    node = *x;
    free(x);
    XML_ParserFree(p);
    return node; /* return the xmlnode x points to */
}
void jabber_presence_send(GaimConnection *gc, const char *state,
		const char *msg)
{
	JabberStream *js = gc->proto_data;
	xmlnode *presence;
	char *stripped = NULL;

	if(msg) {
		gaim_markup_html_to_xhtml(msg, NULL, &stripped);
	} else if(!state || strcmp(state, GAIM_AWAY_CUSTOM)) {
		/* i can't wait until someone re-writes the status/away stuff */
		stripped = g_strdup("");
	}

	if(gc->away)
		g_free(gc->away);
	gc->away = stripped;

	presence = jabber_presence_create(state, stripped);
	jabber_send(js, presence);
	g_hash_table_foreach(js->chats, chats_send_presence_foreach, presence);
	xmlnode_free(presence);

	jabber_presence_fake_to_self(js, state, stripped);
}
Example #11
0
int presence_send_error(struct stream_s *stream,const char *from,const char *to,
				int code,const char *string){
xmlnode pres;
xmlnode error;
char *jid;
char *str;

	pres=xmlnode_new_tag("presence");
	jid=jid_my_registered();
	if (from!=NULL)
		xmlnode_put_attrib(pres,"from",from);
	else{
		char *jid;
		jid=jid_my_registered();
		xmlnode_put_attrib(pres,"from",jid);
		g_free(jid);
	}
	g_free(jid);
	xmlnode_put_attrib(pres,"to",to);
	xmlnode_put_attrib(pres,"type","error");
	error=xmlnode_insert_tag(pres,"error");
	if (code>0){
		str=g_strdup_printf("%03u",(unsigned)code);
		xmlnode_put_attrib(error,"code",str);
		g_free(str);
	}
	xmlnode_insert_cdata(error,string,-1);

	stream_write(stream,pres);
	xmlnode_free(pres);
	return 0;
}
Example #12
0
gint
xmpp_message_send(XmppStream *stream, const gchar *text, const gchar *to)
{
    xmlnode *root;
    xmlnode *node;
    gchar   *xml_string;

    g_return_val_if_fail(stream != NULL, HYBRID_ERROR);
    g_return_val_if_fail(text != NULL, HYBRID_ERROR);
    g_return_val_if_fail(to != NULL, HYBRID_ERROR);

    root = xmlnode_create("message");
    xmlnode_new_prop(root, "from", stream->jid);
    xmlnode_new_prop(root, "to", to);
    xmlnode_new_prop(root, "type", "chat");
    node = xmlnode_new_child(root, "body");
    xmlnode_set_content(node, text);

    xml_string = xmlnode_to_string(root);
    xmlnode_free(root);

    hybrid_debug_info("xmpp", "send message to %s:\n%s", to, xml_string);

    if (hybrid_ssl_write(stream->ssl, xml_string, strlen(xml_string)) == -1) {

        hybrid_debug_error("xmpp", "send message to %s failed\n", to);
        g_free(xml_string);

        return HYBRID_ERROR;
    }

    g_free(xml_string);

    return HYBRID_OK;
}
Example #13
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);

}
Example #14
0
/* Coprocess functionality */
void dnsrv_child_process_xstream_io(int type, xmlnode x, void* args)
{
     dns_io di = (dns_io)args;
     char*  hostname;
     char*  str = NULL;
     dns_resend_list iternode = NULL;

     if (type == XSTREAM_NODE)
     {
          /* Get the hostname out... */
          hostname = xmlnode_get_data(x);
          log_debug(ZONE, "dnsrv: Recv'd lookup request for %s", hostname);
          if (hostname != NULL)
          {
               /* For each entry in the svclist, try and resolve using
                  the specified service and resend it to the specified host */
               iternode = di->svclist;
               while (iternode != NULL)
               {
                    str = srv_lookup(x->p, iternode->service, hostname);
                    if (str != NULL)
                    {
                         log_debug(ZONE, "Resolved %s(%s): %s\tresend to:%s", hostname, iternode->service, str, iternode->host);
                         xmlnode_put_attrib(x, "ip", str);
                         xmlnode_put_attrib(x, "to", iternode->host);
                         break;
                    }
                    iternode = iternode->next;
               }
               str = xmlnode2str(x);
               write(di->out, str, strlen(str));
          }
     }
     xmlnode_free(x);
}
Example #15
0
static gchar*
generate_handle_request_body(const gchar *sipuri, const gchar *userid,
		const gchar *alias, const gchar *groupid, gboolean accept)
{
	xmlnode *root;
	xmlnode *node;
	gchar *res;

	root = xmlnode_create("args");
	node = xmlnode_new_child(root, "contacts");
	node = xmlnode_new_child(node, "buddies");
	node = xmlnode_new_child(node, "buddy");

	xmlnode_new_prop(node, "user-id", userid);
	xmlnode_new_prop(node, "uri", sipuri);
	xmlnode_new_prop(node, "result", accept ? "1": "0");
	xmlnode_new_prop(node, "buddy-lists", groupid);
	xmlnode_new_prop(node, "expose-mobile-no", "1");
	xmlnode_new_prop(node, "expose-name", "1");
	xmlnode_new_prop(node, "local-name", alias);

	res = xmlnode_to_string(root);

	xmlnode_free(root);

	return res;
}
Example #16
0
void xmlnode_handle_end(void *data, const char *name)
{
	session_t *s = (session_t *) data;
	xmlnode_t *n;
	jabber_private_t *j;

	if (!s || !(j = s->priv) || !name) {
		debug_error("[jabber] xmlnode_handle_end() invalid parameters\n");
		return;
	}

	if (!(n = j->node)) {
			/* XXX: dj, maybe we set some sessionvar here,
			 * and then take a look at it before submitting PROTOCOL_DISCONNECTED
			 * with some weird error? */
		debug("[jabber] end tag within <stream>, ignoring\n");
		return;
	}

	if (!n->parent) {
		jabber_handle(data, n);
		xmlnode_free(n);
		j->node = NULL;
		return;
	} else {
		j->node = n->parent;
	}
}
Example #17
0
/** Convert XML to something based on MSIM_XMLNODE_CONVERT. */
static gchar *
msim_convert_xml(MsimSession *session, const gchar *raw, MSIM_XMLNODE_CONVERT f)
{
	xmlnode *root;
	GString *str;
	gchar *enclosed_raw;

	g_return_val_if_fail(raw != NULL, NULL);

	/* Enclose text in one root tag, to try to make it valid XML for parsing. */
	enclosed_raw = g_strconcat("<root>", raw, "</root>", NULL);

	root = xmlnode_from_str(enclosed_raw, -1);

	if (!root) {
		purple_debug_warning("msim", "msim_markup_to_html: couldn't parse "
				"%s as XML, returning raw: %s\n", enclosed_raw, raw);
		/* TODO: msim_unrecognized */
		g_free(enclosed_raw);
		return g_strdup(raw);
	}

	g_free(enclosed_raw);

	str = g_string_new(NULL);
	msim_convert_xmlnode(session, str, root, f, 0);
	xmlnode_free(root);

	purple_debug_info("msim", "msim_markup_to_html: returning %s\n", str->str);

	return g_string_free(str, FALSE);
}
Example #18
0
static void
msn_oim_request_helper(MsnOimRequestData *data)
{
	MsnSession *session = data->oim->session;

	if (data->send) {
		/* The Sending of OIM's uses a different token for some reason. */
		xmlnode *ticket;
		ticket = xmlnode_get_child(data->body, "Header/Ticket");
		xmlnode_set_attrib(ticket, "passport",
			msn_nexus_get_token_str(session->nexus, MSN_AUTH_LIVE_SECURE));
	}
	else
	{
		xmlnode *passport;
		xmlnode *xml_t;
		xmlnode *xml_p;
		GHashTable *token;
		const char *msn_t;
		const char *msn_p;

		token = msn_nexus_get_token(session->nexus, MSN_AUTH_MESSENGER_WEB);
		g_return_if_fail(token != NULL);

		msn_t = g_hash_table_lookup(token, "t");
		msn_p = g_hash_table_lookup(token, "p");

		g_return_if_fail(msn_t != NULL);
		g_return_if_fail(msn_p != NULL);

		passport = xmlnode_get_child(data->body, "Header/PassportCookie");
		xml_t = xmlnode_get_child(passport, "t");
		xml_p = xmlnode_get_child(passport, "p");

		/* frees old token text, or the 'EMPTY' text if first time */
		xmlnode_free(xml_t->child);
		xmlnode_free(xml_p->child);

		xmlnode_insert_data(xml_t, msn_t, -1);
		xmlnode_insert_data(xml_p, msn_p, -1);
	}

	msn_soap_message_send(session,
		msn_soap_message_new(data->action, xmlnode_copy(data->body)),
		data->host, data->url, FALSE,
		msn_oim_request_cb, data);
}
Example #19
0
result dnsrv_deliver(instance i, dpacket p, void* args)
{
     dns_io di = (dns_io)args;
     xmlnode c;
     int timeout = di->cache_timeout;
     char *ip;
     jid to;

     /* if we get a route packet, it has to be to *us* and have the child as the real packet */
     if(p->type == p_ROUTE)
     {
        if(j_strcmp(p->host,i->id) != 0 || (to = jid_new(p->p,xmlnode_get_attrib(xmlnode_get_firstchild(p->x),"to"))) == NULL)
            return r_ERR;
        p->x=xmlnode_get_firstchild(p->x);
        p->id = to;
        p->host = to->server;
     }

     /* Ensure this packet doesn't already have an IP */
     if(xmlnode_get_attrib(p->x, "ip") || xmlnode_get_attrib(p->x, "iperror"))
     {
        log_notice(p->host, "dropping looping dns lookup request: %s", xmlnode2str(p->x));
        xmlnode_free(p->x);
        return r_DONE;
     }

     /* try the cache first */
     if((c = xhash_get(di->cache_table, p->host)) != NULL)
     {
         /* if there's no IP, cached failed lookup, time those out 10 times faster! (weird, I know, *shrug*) */
         if((ip = xmlnode_get_attrib(c,"ip")) == NULL)
            timeout = timeout / 10;
         if((time(NULL) - (int)xmlnode_get_vattrib(c,"t")) > timeout)
         { /* timed out of the cache, lookup again */
             xmlnode_free(c);
             xhash_zap(di->cache_table,p->host);
         }else{
             /* yay, send back right from the cache */
             dnsrv_resend(p->x, ip, xmlnode_get_attrib(c,"to"));
             return r_DONE;
         }
     }

    dnsrv_lookup(di, p);
    return r_DONE;
}
Example #20
0
File: iq.c Project: bf4/pidgin-mac
void jabber_iq_free(JabberIq *iq)
{
	g_return_if_fail(iq != NULL);

	g_free(iq->id);
	xmlnode_free(iq->node);
	g_free(iq);
}
Example #21
0
gchar*
get_province_name(const gchar *province)
{
    xmlnode *root;
    xmlnode *node;
    gchar   *name;
    gchar   *value;

    g_return_val_if_fail(province != NULL, NULL);

    if (!(root = xmlnode_root_from_file(FETION_RES_DIR"province.xml"))) {
        return NULL;
    }

    if (!(node = xmlnode_child(root)) || g_strcmp0(node->name, "Province")) {
        hybrid_debug_error("fetion",
                "get full province name");
        return NULL;
    }

    for (; node; node = xmlnode_next(node)) {

        if (!xmlnode_has_prop(node, "id")) {
            continue;
        }

        value = xmlnode_prop(node, "id");

        if (g_strcmp0(value, province) == 0) {
            name = xmlnode_content(node);

            /* found, do cleanup. */
            g_free(value);
            xmlnode_free(root);

            return name;
        }

        g_free(value);
    }

    xmlnode_free(root);

    return NULL;
}
Example #22
0
/* match will find a child in the parent, and either replace (if it's an insert) or remove (if data is NULL) */
int xdb_act(xdbcache xc, jid owner, char *ns, char *act, char *match,
	    xmlnode data)
{
	xdbrequest_p cur;
	struct timeval tv;

	if (xc->shutdown)
		return 1;

	if (xc == NULL || owner == NULL || ns == NULL) {
		log_alert("xdb_set",
			  "Programming Error: xdb_set() called with NULL\n");
		return 1;
	}

	log_debug("XDB SET");


	cur = malloc(sizeof(xdbrequest_t));
	memset(cur, 0, sizeof(xdbrequest_t));

	cur->set = 1;
	cur->data = data;
	cur->ns = ns;
	cur->owner = owner;
	cur->act = act;
	cur->match = match;
	gettimeofday(&tv, NULL);
	cur->sent = tv.tv_sec;

	SEM_LOCK(xc->sem);
	cur->id = xc->id++;

	cur->next = xc->first;
	xc->first = cur;

	SEM_UNLOCK(xc->sem);

	/* send it on it's way */
	xdb_deliver(xc->i, cur, 0);
	cur->external = 1;

	/* if it hasn't already returned, we should block here until it returns */
	while (cur->preblock != 1)
		usleep(10);

	/* if it didn't actually get set, flag that */
	if (cur->data == NULL) {
		free(cur);
		return 1;
	}

	xmlnode_free(cur->data);

	free(cur);
	return 0;
}
Example #23
0
static void twitter_multipage_all_request_data_free(TwitterMultiPageAllRequestData * request_data_all)
{
    GList          *l = request_data_all->nodes;
    for (l = request_data_all->nodes; l; l = l->next) {
        xmlnode_free(l->data);
    }
    g_list_free(request_data_all->nodes);
    g_free(request_data_all);
}
Example #24
0
mreturn mod_roster_auto_in_s10n(mapi m, void *arg)
{
	xmlnode reply, x;

	log_debug("AUTO ROSTER");

	//in not s10n
	if (m->packet->type != JPACKET_S10N)
		return M_IGNORE;
	//if no to
	if (m->packet->to == NULL)
		return M_PASS;
	//if from me
	if (jid_cmpx(m->s->uid, m->packet->from, JID_USER | JID_SERVER) ==
	    0)
		return M_PASS;

	log_debug("handling incoming s10n");

	switch (jpacket_subtype(m->packet)) {
	case JPACKET__SUBSCRIBE:
		log_debug("SUBSCRIBE");
		reply =
		    jutil_presnew(JPACKET__SUBSCRIBED,
				  jid_full(m->packet->from), NULL);
		js_session_from(m->s, jpacket_new(reply));
		reply =
		    jutil_presnew(JPACKET__SUBSCRIBE,
				  jid_full(m->packet->from), NULL);
		js_session_from(m->s, jpacket_new(reply));
		break;
	case JPACKET__SUBSCRIBED:
		break;
	case JPACKET__UNSUBSCRIBE:
		log_debug("UNSUBSCRIBE");
		//reply = jutil_presnew(JPACKET__UNSUBSCRIBED, jid_full(m->packet->from),NULL);
		//js_session_from(m->s, jpacket_new(reply));
		//remove account.
		reply = jutil_iqnew(JPACKET__SET, NS_ROSTER);
		x = xmlnode_get_tag(reply, "query");
		x = xmlnode_insert_tag(x, "item");
		xmlnode_put_attrib(x, "jid",
				   jid_full(jid_user(m->packet->from)));
		xmlnode_put_attrib(x, "subscription", "remove");
		js_session_from(m->s, jpacket_new(reply));

		// reply = jutil_iqnewpresnew(JPACKET__UNSUBSCRIBE, jid_full(m->packet->from),NULL);
		// js_session_from(m->s, jpacket_new(reply));
		break;
	case JPACKET__UNSUBSCRIBED:
		break;
	}

	xmlnode_free(m->packet->x);
	return M_HANDLED;
}
Example #25
0
/* child that handles packets from the user */
void _js_session_from(void *arg)
{
	jpacket p = (jpacket) arg;
	session s = (session) (p->aux1);

	/* if this session is dead */
	if (s->exit_flag) {
		/* send the packet into oblivion */
		xmlnode_free(p->x);
		return;
	}

	/* at least we must have a valid packet */
	if (p->type == JPACKET_UNKNOWN) {
		/* send an error back */
		jutil_error(p->x, TERROR_BAD);
		jpacket_reset(p);
		js_session_to(s, p);
		return;
	}

	/* debug message */
	log_debug("THREAD:SESSION:FROM received a packet!");

	/* increment packet out count */
	s->si->stats->packets_out++;
	s->c_out++;

	/* make sure we have our from set correctly for outgoing packets */
	if (jid_cmpx(p->from, s->id, JID_USER | JID_SERVER) != 0) {
		/* nope, fix it */
		xmlnode_put_attrib(p->x, "from", jid_full(s->id));
		p->from = jid_new(p->p, jid_full(s->id));
	}

	/* if you use to="yourself@yourhost" it's the same as not having a to, the modules use the NULL as a self-flag */
	if (jid_cmp(p->to, s->uid) == 0) {
		/* xmlnode_hide_attrib(p->x,"to"); */
		p->to = NULL;
	}

	/* let the modules have their heyday */
	if (js_mapi_call(NULL, es_OUT, p, s->u, s))
		return;

	/* no module handled it, so restore the to attrib to us */
	if (p->to == NULL) {
		xmlnode_put_attrib(p->x, "to", jid_full(s->uid));
		p->to = jid_new(p->p, jid_full(s->uid));
	}

	js_post_out_main(s, p);

	/* pass these to the general delivery function */
	//    js_deliver(s->si, p);
}
Example #26
0
static gchar   *twitter_xml_text_parse_error(const gchar * response)
{
    xmlnode        *response_node;
    if (response && (response_node = xmlnode_from_str(response, strlen(response)))) {
        gchar          *message = twitter_xml_node_parse_error(response_node);
        xmlnode_free(response_node);
        return message;
    }
    return NULL;
}
Example #27
0
/**
 * Frees the whole tree of an xml node
 *
 * First determines the root of the xml tree and then frees the whole tree
 * from there.
 *
 * @param node	The node to free the tree from
 */
static void
xmlnode_free_tree(xmlnode *node)
{
	g_return_if_fail(node != NULL);

	while(xmlnode_get_parent(node))
		node = xmlnode_get_parent(node);

	xmlnode_free(node);
}
Example #28
0
File: logs.c Project: bigbo/hybrid
void
hybrid_logs_destroy(HybridLogs *log)
{
    if (log) {
        g_free(log->log_path);
        g_free(log->id);
        xmlnode_free(log->root);
        g_free(log);
    }
}
Example #29
0
static void
msn_soap_message_destroy(MsnSoapMessage *message)
{
	g_slist_foreach(message->headers, (GFunc)g_free, NULL);
	g_slist_free(message->headers);
	g_free(message->action);
	if (message->xml)
		xmlnode_free(message->xml);
	g_free(message);
}
Example #30
0
File: jcr_xdb.c Project: bcy/muc
/**
 * A replacement for xdb_set
 * returns 0 if the set succeeded, 1 if not
*/
int xdb_set(void *noop, jid fn, char *ns, xmlnode x) {
  extern jcr_instance jcr;
  char buf[512];
  xmlnode n, s, xdb;
  int rc;

  n = xdb_get(noop, fn, NULL);

  if (n == NULL) {
    memset(buf, 0, 512);
    snprintf(buf, 511, "%s/%s.xml", jcr->spool_dir, fn->user);
    xdb = xmlnode_new_tag("xdb");
    if (ns != NULL)
      xmlnode_put_attrib(x, "xdbns", ns);
//  log_debug(JDBG, "node not found, creating %s", xmlnode2str(x));
    xmlnode_insert_node(xdb, x);
//  log_debug(JDBG, "\nwriting '%s'\n\n", xmlnode2str(xdb));
    rc = xmlnode2file(buf, xdb);
    xmlnode_free(xdb);
    return rc;
  } else {
    s = NULL;
//  log_debug(JDBG, "node found '%s'", xmlnode2str(n));
    if (ns == NULL) {
      s = xmlnode_get_tag(n, xmlnode_get_name(x));
    } else {
      memset(buf, 0, 512);
      snprintf(buf, 511, "%s?xdbns=%s", xmlnode_get_name(x), ns);
//    log_debug(JDBG, "search for '%s'", buf);
      s = xmlnode_get_tag(n, buf);
    }
//  log_debug(JDBG, "removing '%s'", xmlnode2str(s));
    xmlnode_hide(s);
    if (ns != NULL)
      xmlnode_put_attrib(x, "xdbns", ns);
    xmlnode_insert_tag_node(n, x);
  }
  snprintf(buf, 511, "%s/%s.xml", jcr->spool_dir, fn->user);
  rc = xmlnode2file(buf, n);
  xmlnode_free(n);
  log_debug(JDBG, "xdb_set: rc == %d", rc);
  return 0;
}