示例#1
0
文件: xmlnode.c 项目: bcy/muc
int xmlnode_get_datasz(xmlnode node)
{
    if(xmlnode_get_type(node) != NTYPE_CDATA) return 0;

    /* check for a dirty node w/ unassembled cdata chunks */
    if(xmlnode_get_type(node->next) == NTYPE_CDATA)
        _xmlnode_merge(node);
    return node->data_sz;
}
示例#2
0
int
main(){

xmlnode point;
xmlnode conf;

    conf=xmlnode_file("./test.xml");
    point=conf;

    printf("\n");
    printf("Tagname is %s.\n", xmlnode_get_name(point));
    printf("Data is \"%s\"\n", xmlnode_get_data(point));
    printf("Type is %d.\n", xmlnode_get_type(point));

    point = xmlnode_get_firstchild(point);

    printf("\n");
    printf("Tagname is %s.\n", xmlnode_get_name(point));
    printf("Data is \"%s\"\n", xmlnode_get_data(point));
    printf("Type is %d.\n", xmlnode_get_type(point));

    point = xmlnode_get_nextsibling(point);

    printf("\n");
    printf("Tagname is %s.\n", xmlnode_get_name(point));
    printf("Data is %s.\n", xmlnode_get_data(point));
    printf("Type is %d.\n", xmlnode_get_type(point));

    point = xmlnode_get_nextsibling(point);

    printf("\n");
    printf("Tagname is %s.\n", xmlnode_get_name(point));
    printf("Data is %s.\n", xmlnode_get_data(point));
    printf("Type is %d.\n", xmlnode_get_type(point));

    point = xmlnode_get_nextsibling(point);

    printf("\n");
    printf("Tagname is %s.\n", xmlnode_get_name(point));
    printf("Data is %s.\n", xmlnode_get_data(point));
    printf("Type is %d.\n", xmlnode_get_type(point));

    point = xmlnode_get_nextsibling(point);


/*
    point = xmlnode_get_nextsibling(point);
    point = xmlnode_get_firstchild(point);
    point = xmlnode_get_nextsibling(xmlnode_get_parent(point));
*/

   xmlnode_free(conf);

} /* END MAIN */
示例#3
0
文件: xmlnode.c 项目: bcy/muc
char* xmlnode_get_data(xmlnode node)
{
    if(xmlnode_get_type(node) == NTYPE_TAG) /* loop till we find a CDATA in the children */
        for(node = xmlnode_get_firstchild(node); node != NULL; node = xmlnode_get_nextsibling(node))
            if(xmlnode_get_type(node) == NTYPE_CDATA) break;

    if(node == NULL) return NULL;

    /* check for a dirty node w/ unassembled cdata chunks */
    if(xmlnode_get_type(node->next) == NTYPE_CDATA)
        _xmlnode_merge(node);

    return node->data;
}
示例#4
0
文件: xmlnode.c 项目: bcy/muc
static spool _xmlnode2spool(xmlnode node)
{
    spool s;
    int level=0,dir=0;
    xmlnode tmp;

    if(!node || xmlnode_get_type(node)!=NTYPE_TAG)
        return NULL;

    s = spool_new(xmlnode_pool(node));
    if(!s) return(NULL);

    while(1)
    {
        if(dir==0)
        {
    	    if(xmlnode_get_type(node) == NTYPE_TAG)
            {
                if(xmlnode_has_children(node))
                {
                    _xmlnode_tag2str(s,node,1);
                    node = xmlnode_get_firstchild(node);
                    level++;
                    continue;
                }else{
                    _xmlnode_tag2str(s,node,0);
                }
            }else{
                spool_add(s,strescape(xmlnode_pool(node),xmlnode_get_data(node)));
            }
        }

    	tmp = xmlnode_get_nextsibling(node);
        if(!tmp)
        {
            node = xmlnode_get_parent(node);
            level--;
            if(level>=0) _xmlnode_tag2str(s,node,2);
            if(level<1) break;
            dir = 1;
        }else{
            node = tmp;
            dir = 0;
        }
    }

    return s;
}
示例#5
0
/**
 * init the module, register callbacks
 *
 * builds a list of JabberIDs where presences should be blind carbon copied to.
 * (Enclosing each in a <bcc/> element, which are contained in one <presence/>
 * element in the session manager configuration.)
 *
 * registers mod_presence_session() as a callback, that gets notified on new sessions
 * and mod_presence_deliver() as a callback to deliver presence stanzas locally.
 *
 * @param si the session manager instance
 */
JSM_FUNC void mod_presence(jsmi si)
{
	xmlnode cfg = js_config(si, "presence");
	modpres_conf conf =
	    (modpres_conf) pmalloco(si->p, sizeof(_modpres_conf));

	log_debug("init");

	for (cfg = xmlnode_get_firstchild(cfg); cfg != NULL;
	     cfg = xmlnode_get_nextsibling(cfg)) {
		char *element_name = NULL;

		if (xmlnode_get_type(cfg) != NTYPE_TAG)
			continue;

		element_name = xmlnode_get_name(cfg);
		if (j_strcmp(element_name, "bcc") == 0) {
			if (conf->bcc == NULL)
				conf->bcc =
				    jid_new(si->p, xmlnode_get_data(cfg));
			else
				jid_append(conf->bcc,
					   jid_new(si->p,
						   xmlnode_get_data(cfg)));
		} else if (j_strcmp(element_name, "presence2xdb") == 0) {
			conf->pres_to_xdb++;
		}
	}

	js_mapi_register(si, e_DELIVER, mod_presence_deliver, NULL);
	js_mapi_register(si, e_SESSION, mod_presence_session,
			 (void *) conf);
}
示例#6
0
文件: xmlnode.c 项目: bcy/muc
/* loop through both a and b comparing everything, attribs, cdata, children, etc */
int xmlnode_cmp(xmlnode a, xmlnode b)
{
    int ret = 0;

    while(1)
    {
        if(a == NULL && b == NULL)
            return 0;

        if(a == NULL || b == NULL)
            return -1;

        if(xmlnode_get_type(a) != xmlnode_get_type(b))
            return -1;

        switch(xmlnode_get_type(a))
        {
        case NTYPE_ATTRIB:
            ret = j_strcmp(xmlnode_get_name(a), xmlnode_get_name(b));
            if(ret != 0)
                return -1;
            ret = j_strcmp(xmlnode_get_data(a), xmlnode_get_data(b));
            if(ret != 0)
                return -1;
            break;
        case NTYPE_TAG:
            ret = j_strcmp(xmlnode_get_name(a), xmlnode_get_name(b));
            if(ret != 0)
                return -1;
            ret = xmlnode_cmp(xmlnode_get_firstattrib(a), xmlnode_get_firstattrib(b));
            if(ret != 0)
                return -1;
            ret = xmlnode_cmp(xmlnode_get_firstchild(a), xmlnode_get_firstchild(b));
            if(ret != 0)
                return -1;
            break;
        case NTYPE_CDATA:
            ret = j_strcmp(xmlnode_get_data(a), xmlnode_get_data(b));
            if(ret != 0)
                return -1;
        }
        a = xmlnode_get_nextsibling(a);
        b = xmlnode_get_nextsibling(b);
    }
}
示例#7
0
文件: xdb.c 项目: Doap/transports
/* blocks until namespace is retrieved, host must map back to this service! */
xmlnode xdb_get(xdbcache xc, jid owner, char *ns)
{
    xdbcache newx;
    xmlnode x;
	pool p;

    if(xc == NULL || owner == NULL || ns == NULL)
    {
        fprintf(stderr,"Programming Error: xdb_get() called with NULL\n");
        return NULL;
    }

    log_debug(ZONE,"XDB GET");

    /* init this newx */
	p = pool_new();
	newx = pmalloco(p, sizeof(_xdbcache));
    newx->i = xc->i;
    newx->set = 0;
    newx->data = NULL;
    newx->ns = ns;
    newx->owner = owner;
    newx->sent = time(NULL);
    newx->preblock = 0; /* flag */


    pthread_mutex_lock(&(xc->sem));
    newx->id = xc->id++;
    newx->next = xc->next;
    newx->prev = xc;
    newx->next->prev = newx;
    xc->next = newx;
    pthread_mutex_unlock(&(xc->sem));

    /* send it on it's way */
    xdb_deliver(xc->i, newx,0);

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

    /* newx.data is now the returned xml packet */

    /* return the xmlnode inside <xdb>...</xdb> */
    for(x = xmlnode_get_firstchild(newx->data); x != NULL && xmlnode_get_type(x) != NTYPE_TAG; x = xmlnode_get_nextsibling(x));

    /* there were no children (results) to the xdb request, free the packet */
    if(x == NULL)
        xmlnode_free(newx->data);

	pool_free(p);

    return x;
}
示例#8
0
文件: xmlnode.c 项目: bcy/muc
/* places copy of node and node's siblings in parent */
void xmlnode_insert_node(xmlnode parent, xmlnode node)
{
    if(node == NULL || parent == NULL)
        return;

    while(node != NULL)
    {
        switch(xmlnode_get_type(node))
        {
        case NTYPE_ATTRIB:
            xmlnode_put_attrib(parent, xmlnode_get_name(node), xmlnode_get_data(node));
            break;
        case NTYPE_TAG:
            xmlnode_insert_tag_node(parent, node);
            break;
        case NTYPE_CDATA:
            xmlnode_insert_cdata(parent, xmlnode_get_data(node), xmlnode_get_datasz(node));
        }
        node = xmlnode_get_nextsibling(node);
    }
}
示例#9
0
文件: mod_log.c 项目: smokku/wpjabber
/* we should be last in the list of modules */
JSM_FUNC void mod_log(jsmi si)
{
	xmlnode cfg = js_config(si, "archive");
	jid svcs = NULL;

	log_debug("mod_log init");

	/* look for archiving service too */
	for (cfg = xmlnode_get_firstchild(cfg); cfg != NULL;
	     cfg = xmlnode_get_nextsibling(cfg)) {
		if (xmlnode_get_type(cfg) != NTYPE_TAG
		    || j_strcmp(xmlnode_get_name(cfg), "service") != 0)
			continue;
		if (svcs == NULL)
			svcs = jid_new(si->p, xmlnode_get_data(cfg));
		else
			jid_append(svcs,
				   jid_new(si->p, xmlnode_get_data(cfg)));
	}

	js_mapi_register(si, e_SESSION, mod_log_session, (void *) svcs);
}
示例#10
0
/** Start up transport. Read configuration, register callbacks. */
void icqtrans(instance i, xmlnode x)
{
    iti ti;
    pool p = i->p;
    xmlnode config;
    xmlnode cur;
	int check;

    log_debug(ZONE,"ICQ Transport, initializing for section '%s'",i->id);

    /* create new transport instance */
    ti = pmalloco(p,sizeof(_iti));
    ti->i = i;
    ti->xc = xdb_cache(i);

    config = xdb_get(ti->xc,jid_new(xmlnode_pool(x),"config@-internal"),"jabber:config:icqtrans");
    if (config == NULL)
    {
        log_error(i->id,"Configuration not found!");
        return;
    }

    ti->registration_instructions = pstrdup(p,xmlnode_get_tag_data(config,"instructions"));
    if (ti->registration_instructions == NULL)
    { 
        log_debug(i->id,"Registration instructions not found");
    }

    ti->search_instructions = pstrdup(p,xmlnode_get_tag_data(config,"search"));
    if (ti->search_instructions == NULL)
    {
        log_debug(i->id,"Search instructions not found");
    }

    ti->charset = pstrdup(p,xmlnode_get_tag_data(config,"charset"));
    if (ti->charset == NULL)
    {
	  log_debug(i->id,"Charset not specified, set default to %s ",DEFAULT_CHARSET);
	  ti->charset = pstrdup(p,DEFAULT_CHARSET);
    }

    _ucs2utf = iconv_open("UTF-8","UCS-2BE");

    _win2utf = iconv_open("UTF-8",ti->charset);
    if (_win2utf==(iconv_t)-1) {
      ti->charset = pstrdup(p,DEFAULT_CHARSET);
      _win2utf = iconv_open("UTF-8",ti->charset);
      if (_win2utf==(iconv_t)-1) {
        log_error(i->id,"Charset error!");
        return;
      }
    }

    _utf2win = iconv_open(ti->charset,"UTF-8");
    if (_utf2win ==(iconv_t)-1) {
      ti->charset = pstrdup(p,DEFAULT_CHARSET);
      _utf2win = iconv_open(ti->charset,"UTF-8");
      if (_utf2win ==(iconv_t)-1) {
        log_error(i->id,"Charset error!");
        return;
      }
    }

	log_notice("config","charset %s",ti->charset);
	
    ti->msg_chat = xmlnode_get_tag(config,"chat") ? 1 : 0;
	if (ti->msg_chat) {
	  log_notice("config","chat messages enabled");
	}
    ti->web_aware = xmlnode_get_tag(config,"web") ? 1 : 0;
	if (ti->web_aware) {
	  log_notice("config","web presence enabled");
	}
    ti->own_roster = xmlnode_get_tag(config,"own_roster") ? 1 : 0;
	if (ti->own_roster) {
	  log_notice("config","JIT will use own roster");
	}
    ti->no_jabber_roster = xmlnode_get_tag(config,"no_jabber_roster") ? 1 : 0;
	if (ti->no_jabber_roster) {
	  log_notice("config","JIT willn't get users from jabber roster");
	}
	ti->no_x_data = xmlnode_get_tag(config,"no_xdata") ? 1 : 0;
	if (ti->no_x_data) {
	  log_notice("config","JIT will not use xdata");
	}

    cur = xmlnode_get_tag(config,"sms");

    if (cur) {
      ti->sms_id = pstrdup(p,xmlnode_get_tag_data(cur,"host"));
      if (ti->sms_id) {
        ti->sms_show = jit_show2status(xmlnode_get_tag_data(cur,"show"));

        if (ti->sms_show==ICQ_STATUS_NOT_IN_LIST) {
          ti->sms_show = ICQ_STATUS_ONLINE;
        }
        
        log_notice("config","sms host %s show: %d",ti->sms_id,ti->sms_show);

        ti->sms_status = pstrdup(p,xmlnode_get_tag_data(cur,"status"));

        if (ti->sms_status) {
          log_debug(ZONE,"sms st %s ",ti->sms_status);
        }

        ti->sms_name = pstrdup(p,xmlnode_get_tag_data(cur,"name"));

	if (ti->sms_name) {
	  log_debug(ZONE,"sms name %s",ti->sms_name);
	}
      }
    }

    ti->count_file = pstrdup(p,xmlnode_get_tag_data(config,"user_count_file"));
    if (ti->count_file == NULL)  {
      ti->count_file = "icqcount";
    }

	log_notice("config","Using %s as count log file",ti->count_file);

    for (cur = xmlnode_get_firstchild(xmlnode_get_tag(config,"server"));
     cur != NULL;
     cur = xmlnode_get_nextsibling(cur)) {

      char * port;
      char * host;

      if (xmlnode_get_type(cur) != NTYPE_TAG) continue;

      if ((port = xmlnode_get_attrib(cur,"port")) == NULL) continue;
   
      if ((host = xmlnode_get_data(cur)) == NULL) continue;

      ti->auth_hosts[ti->auth_hosts_count] = pstrdup(p,host);
      ti->auth_ports[ti->auth_hosts_count] = j_atoi(port,5190);
      log_debug(ZONE,"Host %s port %d at pos %d",
				ti->auth_hosts[ti->auth_hosts_count],
				ti->auth_ports[ti->auth_hosts_count],
				ti->auth_hosts_count);
      ti->auth_hosts_count++;

      if (ti->auth_hosts_count >= MAX_AUTH_HOSTS) break;
    }

    if (ti->auth_hosts_count == 0) {
      log_alert("err","No hosts to auth icq client !. Using default");
      ti->auth_hosts[ti->auth_hosts_count] = pstrdup(p,"205.188.179.233");
      ti->auth_ports[ti->auth_hosts_count] = 5190;
      ti->auth_hosts_count++;
    }

	/* add queue for unknown packets */
	ti->q = mtq_new(i->p);

    ti->sessions = wpxhash_new(j_atoi(xmlnode_get_tag_data(config,"prime"),509));
    ti->sessions_alt = wpxhash_new(j_atoi(xmlnode_get_tag_data(config,"prime"),509));
    SEM_INIT(ti->sessions_sem);
    ti->vcard = xmlnode_new_tag_pool(p,"vCard");

    xmlnode_put_attrib(ti->vcard,"xmlns",NS_VCARD);
    xmlnode_insert_node(ti->vcard,xmlnode_get_firstchild(xmlnode_get_tag(config,"vCard")));

    /* default 5 hours */
    ti->session_timeout = j_atoi(xmlnode_get_tag_data(config,"session_timeout"),18000);
	log_notice("config","session_timeout in sec : %d",ti->session_timeout);

    ti->reconnect = j_atoi(xmlnode_get_tag_data(config,"reconnects"),0);
    log_notice("config","Number of reconnects for session %d",ti->reconnect);

	check = j_atoi(xmlnode_get_tag_data(config,"session_check"),10);
    log_notice("config","JIT will check session every %d sec",check);
      
	//    ti->admin = xmlnode_dup(xmlnode_get_tag(config,"admin"));
    ti->start = time(NULL);

    /* Register callbacks */
    register_phandler(i,o_DELIVER,it_receive,(void *) ti);
    register_shutdown(it_shutdown,(void *) ti);

    /* Start up heartbeat thread */
    register_beat(check,it_sessions_check,(void *) ti);

    xmlnode_free(config);
}
示例#11
0
mreturn mod_agents_agents(mapi m)
{
	xmlnode ret, retq, agents, cur, a, cur2;

	/* get data from the config file */
	agents = js_config(m->si, "browse");

	/* if we don't have anything to say, bounce */
	if (agents == NULL)
		return M_PASS;

	log_debug("handling agents query");

	/* build the result IQ */
	ret = jutil_iqresult(m->packet->x);
	retq = xmlnode_insert_tag(ret, "query");
	xmlnode_put_attrib(retq, "xmlns", NS_AGENTS);

	/* parse the new browse data into old agents format */
	for (cur = xmlnode_get_firstchild(agents); cur != NULL;
	     cur = xmlnode_get_nextsibling(cur)) {
		if (xmlnode_get_type(cur) != NTYPE_TAG)
			continue;

		/* generic <agent> part */
		a = xmlnode_insert_tag(retq, "agent");
		xmlnode_put_attrib(a, "jid",
				   xmlnode_get_attrib(cur, "jid"));
		xmlnode_insert_cdata(xmlnode_insert_tag(a, "name"),
				     xmlnode_get_attrib(cur, "name"), -1);
		xmlnode_insert_cdata(xmlnode_insert_tag(a, "service"),
				     xmlnode_get_attrib(cur, "type"), -1);

		if (j_strcmp(xmlnode_get_name(cur), "conference") == 0)
			xmlnode_insert_tag(a, "groupchat");

		/* map the included <ns>'s in browse to the old agent flags */
		for (cur2 = xmlnode_get_firstchild(cur); cur2 != NULL;
		     cur2 = xmlnode_get_nextsibling(cur2)) {
			if (j_strcmp(xmlnode_get_name(cur2), "ns") != 0)
				continue;
			if (j_strcmp
			    (xmlnode_get_data(cur2),
			     "jabber:iq:register") == 0)
				xmlnode_insert_tag(a, "register");
			if (j_strcmp
			    (xmlnode_get_data(cur2),
			     "jabber:iq:search") == 0)
				xmlnode_insert_tag(a, "search");
			if (j_strcmp
			    (xmlnode_get_data(cur2),
			     "jabber:iq:gateway") == 0)
				xmlnode_insert_cdata(xmlnode_insert_tag
						     (a, "transport"),
						     "Enter ID", -1);
		}
	}

	jpacket_reset(m->packet);
	if (m->s != NULL) {	/* XXX null session hack! */
		xmlnode_put_attrib(m->packet->x, "from",
				   m->packet->from->server);
		js_session_to(m->s, m->packet);
	} else {
		js_deliver(m->si, m->packet);
	}

	return M_HANDLED;
}
示例#12
0
文件: xmlnode.c 项目: bcy/muc
/*
 *  xmlnode_get_tag -- find given tag in an xmlnode tree
 *
 *  parameters
 *      parent -- pointer to the parent tag
 *      name -- "name" for the child tag of that name
 *              "name/name" for a sub child (recurses)
 *              "?attrib" to match the first tag with that attrib defined
 *              "?attrib=value" to match the first tag with that attrib and value
 *              "=cdata" to match the cdata contents of the child
 *              or any combination: "name/name/?attrib", "name=cdata", etc
 *
 *  results
 *      a pointer to the tag matching search criteria
 *      or NULL if search was unsuccessfull
 */
xmlnode xmlnode_get_tag(xmlnode parent, const char* name)
{
    char *str, *slash, *qmark, *equals;
    xmlnode step, ret;


    if(parent == NULL || parent->firstchild == NULL || name == NULL || name == '\0') return NULL;

    if(strstr(name, "/") == NULL && strstr(name,"?") == NULL && strstr(name, "=") == NULL)
        return _xmlnode_search(parent->firstchild, name, NTYPE_TAG);

    str = strdup(name);
    slash = strstr(str, "/");
    qmark = strstr(str, "?");
    equals = strstr(str, "=");

    if(equals != NULL && (slash == NULL || equals < slash) && (qmark == NULL || equals < qmark))
    { /* of type =cdata */

        *equals = '\0';
        equals++;

        for(step = parent->firstchild; step != NULL; step = xmlnode_get_nextsibling(step))
        {
            if(xmlnode_get_type(step) != NTYPE_TAG)
                continue;

            if(*str != '\0')
                if(j_strcmp(xmlnode_get_name(step),str) != 0)
                    continue;

            if(j_strcmp(xmlnode_get_data(step),equals) != 0)
                continue;

            break;
        }

        free(str);
        return step;
    }


    if(qmark != NULL && (slash == NULL || qmark < slash))
    { /* of type ?attrib */

        *qmark = '\0';
        qmark++;
        if(equals != NULL)
        {
            *equals = '\0';
            equals++;
        }

        for(step = parent->firstchild; step != NULL; step = xmlnode_get_nextsibling(step))
        {
            if(xmlnode_get_type(step) != NTYPE_TAG)
                continue;

            if(*str != '\0')
                if(j_strcmp(xmlnode_get_name(step),str) != 0)
                    continue;

            if(xmlnode_get_attrib(step,qmark) == NULL)
                continue;

            if(equals != NULL && j_strcmp(xmlnode_get_attrib(step,qmark),equals) != 0)
                continue;

            break;
        }

        free(str);
        return step;
    }


    *slash = '\0';
    ++slash;

    for(step = parent->firstchild; step != NULL; step = xmlnode_get_nextsibling(step))
    {
        if(xmlnode_get_type(step) != NTYPE_TAG) continue;

        if(j_strcmp(xmlnode_get_name(step),str) != 0)
            continue;

        ret = xmlnode_get_tag(step, slash);
        if(ret != NULL)
        {
            free(str);
            return ret;
        }
    }

    free(str);
    return NULL;
}
示例#13
0
int sessions_init(){
char *proxy_ip,*proxy_username,*proxy_password,*proxy_http_only;
char *p,*r;
int port;
int i;
xmlnode parent,tag;
GgServer *server;

	stream_add_destroy_handler(sessions_stream_destroyed);

	sessions_jid=g_hash_table_new(g_str_hash,g_str_equal);
	if (!sessions_jid) return -1;

	i=config_load_int("conn_timeout",0);
	if (i>0) conn_timeout=i;
	i=config_load_int("pong_timeout",0);
	if (i>0) pong_timeout=i;
	i=config_load_int("ping_interval",0);
	if (i>0) ping_interval=i;
	i=config_load_int("reconnect",0);
	if (i>0) reconnect=i;
	i=config_load_int("server_cutoff",0);
	if (i>0) cutoff=i;
	i=config_load_int("server_cutoff_timeout",0);
	if (i>0) cutoff_timeout=i;

	tag = xmlnode_get_tag(config, "ignore_system_messages");
	if (!tag) {
		ignore_system_messages = ISM_IGNORE_NONE;
	}
	else {
		r=xmlnode_get_attrib(tag, "which");
		if (r && !g_strcasecmp(r,"html")) {
			ignore_system_messages = ISM_IGNORE_HTML;
		}
		else {
			ignore_system_messages = ISM_IGNORE_ALL;
		}
	}

	parent=xmlnode_get_tag(config,"servers");
	if (parent && xmlnode_has_children(parent)){
		gg_servers=NULL;
		for(tag=xmlnode_get_firstchild(parent); tag!=NULL;
				tag=xmlnode_get_nextsibling(tag)){
			if(xmlnode_get_type(tag) != NTYPE_TAG) continue;
			p=xmlnode_get_name(tag);
			if (strcmp(p, "hub")==0){
				server=g_new(GgServer, 1);
				server->port=1;
				gg_servers=g_list_append(gg_servers, server);
			}
			else if (strcmp(p, "server")==0){
				server=g_new(GgServer, 1);
				server->error_count=0;
				r=xmlnode_get_attrib(tag, "port");
				if (r)
					server->port=atoi(r);
				else
					server->port=8074;
				r=xmlnode_get_data(tag);
				if(inet_aton(r, &server->addr))
					gg_servers=g_list_append(gg_servers, server);
			}
			else continue;

			r=xmlnode_get_attrib(tag, "tls");
			if (r && !g_strcasecmp(r,"no"))
				server->tls=0;
			else
				server->tls=1;
		}


	}
	else{
		server=g_new(GgServer, 1);
		server->port=1;
		server->tls=0;
		gg_servers=g_list_append(gg_servers, server);

		server=g_new(GgServer, 1);
		server->error_count=0;
		inet_aton("217.17.45.145", &server->addr);
		server->port=8074;
		server->tls=0;
		gg_servers=g_list_append(gg_servers, server);
	}

	proxy_ip=config_load_string("proxy/ip");
	if (!proxy_ip) return 0;
	port=config_load_int("proxy/port",0);
	if (port<=0) return 0;
	proxy_username=config_load_string("proxy/username");
	proxy_password=config_load_string("proxy/password");

	tag=xmlnode_get_tag(config,"proxy");
	proxy_http_only=xmlnode_get_attrib(tag,"http_only");

	g_message(L_("Using proxy: http://%s:%i"),proxy_ip,port);
	gg_proxy_enabled=1;
	gg_proxy_host=proxy_ip;
	gg_proxy_port=port;
	if (proxy_username && proxy_password){
		gg_proxy_username=proxy_username;
		gg_proxy_password=proxy_password;
	}
	if (proxy_http_only && strcmp(proxy_http_only,"no")){
		gg_proxy_http_only=1;
	}
	return 0;
}
示例#14
0
mreturn mod_stats_server(mapi m, void *arg)
{
	xmlnode cur;
	int i;

	if (m->packet->type != JPACKET_IQ)
		return M_IGNORE;
	if (jpacket_subtype(m->packet) != JPACKET__GET)
		return M_PASS;
	if (!NSCHECK(m->packet->iq, NS_STATS))
		return M_PASS;
	if (m->packet->to->resource)
		return M_PASS;

	/* get data from the config file */
	i = 0;
	if (xmlnode_get_tag(js_config(m->si, "stats"), "allow_all") !=
	    NULL)
		i = 1;

	log_debug("handling stats get %s", jid_full(m->packet->from));

	/* check if admin */
	if ((i == 0) &&
	    (!js_admin_jid(m->si, jid_user(m->packet->from), ADMIN_READ)))
	{
		jutil_error(m->packet->x, TERROR_AUTH);
		jpacket_reset(m->packet);
		js_deliver(m->si, m->packet);
		return M_HANDLED;
	}

	/* check if any stat have given iq query */
	cur = xmlnode_get_firstchild(m->packet->iq);
	for (; cur != NULL; cur = xmlnode_get_nextsibling(cur)) {
		if (xmlnode_get_type(cur) != NTYPE_TAG)
			continue;
		break;
	}
	if (cur != NULL)
		cur = xmlnode_get_firstchild(m->packet->iq);

	jutil_tofrom(m->packet->x);
	xmlnode_put_attrib(m->packet->x, "type", "result");

	/* return available stats */
	if (!cur) {
		for (i = 0; available_stats[i]; i++) {
			xmlnode_put_attrib(xmlnode_insert_tag
					   (m->packet->iq, "stat"), "name",
					   available_stats[i]);
		}
		jpacket_reset(m->packet);
		js_deliver(m->si, m->packet);
		return M_HANDLED;
	}

	/* return server stats */
	/* cur is already first stat */
	for (; cur != NULL; cur = xmlnode_get_nextsibling(cur)) {
		char *name;
		char buf[31];
		int found;

		if (xmlnode_get_type(cur) != NTYPE_TAG)
			continue;
		if (j_strcmp(xmlnode_get_name(cur), "stat") != 0)
			continue;

		name = xmlnode_get_attrib(cur, "name");

		if (!name)
			continue;

		log_debug("get stats for %s", name);

		found = 0;
		for (i = 0; available_stats[i]; i++) {

			if (j_strcmp(available_stats[i], name) != 0)
				continue;

			log_debug("stats for %s", name);
			/* give stats */

			found = 1;

			/* time/uptime */
			if (j_strcmp(name, "time/uptime") == 0) {
				snprintf(buf, 30, "%d",
					 time(NULL) -
					 m->si->stats->started);
				xmlnode_put_attrib(cur, "value", buf);
				xmlnode_put_attrib(cur, "units",
						   "seconds");
			}

			/* users/online */
			if (j_strcmp(name, "users/online") == 0) {
				snprintf(buf, 30, "%d",
					 m->si->stats->sessioncount);
				xmlnode_put_attrib(cur, "value", buf);
				xmlnode_put_attrib(cur, "units", "users");
			}

			if (j_strcmp(name, "users/max_online_today") == 0) {
				snprintf(buf, 30, "%d",
					 m->si->stats->session_max_today);
				xmlnode_put_attrib(cur, "value", buf);
				xmlnode_put_attrib(cur, "units", "users");
			}

			if (j_strcmp(name, "users/max_online_yesterday") ==
			    0) {
				snprintf(buf, 30, "%d",
					 m->si->stats->
					 session_max_yesterday);
				xmlnode_put_attrib(cur, "value", buf);
				xmlnode_put_attrib(cur, "units", "users");
			}

			if (j_strcmp(name, "users/registered_today") == 0) {
				snprintf(buf, 30, "%d",
					 m->si->stats->
					 users_registered_today);
				xmlnode_put_attrib(cur, "value", buf);
				xmlnode_put_attrib(cur, "units", "users");
			}

			if (j_strcmp(name, "users/registered_from_start")
			    == 0) {
				snprintf(buf, 30, "%d",
					 m->si->stats->
					 users_registered_from_start);
				xmlnode_put_attrib(cur, "value", buf);
				xmlnode_put_attrib(cur, "units", "users");
			}

			if (j_strcmp(name, "bandwidth/packets-in") == 0) {
				snprintf(buf, 30, "%lu",
					 m->si->stats->packets_in);
				xmlnode_put_attrib(cur, "value", buf);
				xmlnode_put_attrib(cur, "units",
						   "packets");
			}

			if (j_strcmp(name, "bandwidth/packets-out") == 0) {
				snprintf(buf, 30, "%lu",
					 m->si->stats->packets_out);
				xmlnode_put_attrib(cur, "value", buf);
				xmlnode_put_attrib(cur, "units",
						   "packets");
			}
#ifndef WIN32
			if (j_strcmp(name, "memory/usage") == 0) {
				long mem = get_memory_usage();
				if (mem > 0) {
					snprintf(buf, 30, "%lu", mem);
					xmlnode_put_attrib(cur, "value",
							   buf);
					xmlnode_put_attrib(cur, "units",
							   "bytes");
				} else
					found = 0;
			}
#endif
			break;
		}

		if (found <= 0) {
			xmlnode err;
			err = xmlnode_insert_tag(cur, "error");
			xmlnode_put_attrib(err, "code", "404");
			xmlnode_insert_cdata(err, "Not Found", -1);
		}
	}

	jpacket_reset(m->packet);
	js_deliver(m->si, m->packet);
	return M_HANDLED;
}
示例#15
0
文件: xdb.c 项目: smokku/wpjabber
/* blocks until namespace is retrieved, host must map back to this service! */
xmlnode xdb_get(xdbcache xc, jid owner, char *ns)
{
	xdbrequest_p cur;
	xmlnode x;
	struct timeval tv;

	if (xc->shutdown)
		return NULL;

	if (xc == NULL || owner == NULL || ns == NULL) {
		if (ns) {
			log_alert("xdb_get",
				  "Programming Error: xdb_get() called with NULL ns: %s\n",
				  ns);
		} else {
			log_alert("xdb_get",
				  "Programming Error: xdb_get() called with NULL ns: NULL\n");
		}

		if (owner) {
			log_alert("owner", "%s", jid_full(owner));
		}
		return NULL;
	}

	log_debug("XDB GET");

	/* init this newx */
	cur = malloc(sizeof(xdbrequest_t));
	memset(cur, 0, sizeof(xdbrequest_t));
	// cur->set = 0;
	// cur->data = NULL;
	cur->ns = ns;
	cur->owner = owner;
	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);

	/* newx.data is now the returned xml packet */

	/* return the xmlnode inside <xdb>...</xdb> */
	for (x = xmlnode_get_firstchild(cur->data);
	     x != NULL && xmlnode_get_type(x) != NTYPE_TAG;
	     x = xmlnode_get_nextsibling(x));

	/* there were no children (results) to the xdb request, free the packet */
	if (x == NULL)
		xmlnode_free(cur->data);

	free(cur);
	return x;
}