Jabberd14-1.6.0/jabberd/base/base_accept.c/base_accept_config

Last-modified: 2007-04-14 (土) 22:14:40

このページを編集する際は,編集に関する方針に従ってください.

概要

引数

実装

- 設定ファイルの設定を元にlistenする。
static result base_accept_config(instance id, xmlnode x, void *arg) {
    char *secret = NULL;
    accept_instance inst;
    int port = 0;
    xht namespaces = NULL;
    char *ip = NULL;
    int restrict_var = 0;
    int offline = 0;
    int timeout = 0;
    namespaces = xhash_new(3);
    xhash_put(namespaces, "", NS_JABBERD_CONFIGFILE);
    secret = xmlnode_get_data(xmlnode_get_list_item(xmlnode_get_tags(x, "secret", namespaces), 0));
    ip = xmlnode_get_data(xmlnode_get_list_item(xmlnode_get_tags(x, "ip", namespaces), 0));
    port = j_atoi(xmlnode_get_data(xmlnode_get_list_item(xmlnode_get_tags(x, "port", namespaces), 0)), 0);
    restrict_var = xmlnode_get_data(xmlnode_get_list_item(xmlnode_get_tags(x, "restrict", namespaces), 0)) != NULL ? 1 : 0;
    offline = xmlnode_get_data(xmlnode_get_list_item(xmlnode_get_tags(x, "offline", namespaces), 0)) != NULL ? 1 : 0;
    timeout = j_atoi(xmlnode_get_data(xmlnode_get_list_item(xmlnode_get_tags(x, "timeout", namespaces), 0)), 10);
    xhash_free(namespaces);
    if(id == NULL) {
	 log_debug2(ZONE, LOGT_INIT|LOGT_CONFIG, "base_accept_config validating configuration...");
	 if (port == 0 || secret == NULL) {
	     xmlnode_put_attrib_ns(x, "error", NULL, NULL, "<accept> requires the following subtags: <port>, and <secret>");
	     return r_ERR;
	 }
	 return r_PASS;
    }
    log_debug2(ZONE, LOGT_INIT|LOGT_CONFIG, "base_accept_config performing configuration %s\n",xmlnode2str(x));
    /* Setup the default sink for this instance */
    inst              = pmalloco(id->p, sizeof(_accept_instance));
    inst->p           = id->p;
    inst->i           = id;
    inst->secret      = secret;
    inst->ip          = ip;
    inst->port        = port;
    inst->timeout     = timeout;
    if (restrict_var)
	 inst->restrict_var = 1;
    if (offline) {
	 inst->offline = xdb_cache(id);
	 inst->offjid = jid_new(id->p,id->id);
    }
    /* Start a new listening thread and associate this <listen> tag with it */
    if (mio_listen(inst->port, inst->ip, base_accept_process_xml, (void*)inst, mio_handlers_new(NULL, NULL, MIO_XML_PARSER)) == NULL) {
	 xmlnode_put_attrib_ns(x, "error", NULL, NULL, "<accept> unable to listen on the configured ip and port");
	 return r_ERR;
    }
    /* Register a packet handler and cleanup heartbeat for this instance */
    register_phandler(id, o_DELIVER, base_accept_deliver, (void *)inst);
    /* timeout check */
    register_beat(inst->timeout, base_accept_beat, (void *)inst);
    return r_DONE;
}

呼出元