Ejemplo n.º 1
0
void
tag (char *name, ...)
{
	iks *x;
	va_list ap;

	x = my_x;
	va_start (ap, name);
	while (1) {
		char *name = iks_name (x);
		char *tmp = va_arg (ap, char*);
		if (NULL == tmp) break;
		x = iks_find (x, tmp);
		if (!x) {
			PR_TEST;
			printf ("Tag <%s> is not a child of tag <%s>\n", tmp, name);
			exit (1);
		}
	}
	if (!x || NULL == iks_find (x, name)) {
		PR_TEST;
		printf ("Tag <%s> is not a child of tag <%s>\n", name, iks_name (x));
		exit (1);
	}
	va_end (ap);
}
Ejemplo n.º 2
0
int
_imp_oasis_load(ImpDoc *doc)
{
	ImpPage *page;
	iks *x, *pres;
	int i;

	pres = iks_find(iks_find(doc->content, "office:body"), "office:presentation");
	if (!pres) return IMP_NOTIMP;

	x = iks_find(pres, "draw:page");
	if (!x) return IMP_NOTIMP;
	i = 0;
	for (; x; x = iks_next_tag(x)) {
		if (strcmp(iks_name(x), "draw:page") == 0) {
			page = iks_stack_alloc(doc->stack, sizeof(ImpPage));
			if (!page) return IMP_NOMEM;
			memset(page, 0, sizeof(ImpPage));
			page->page = x;
			page->nr = ++i;
			page->name = iks_find_attrib(x, "draw:name");
			page->doc = doc;
			if (!doc->pages) doc->pages = page;
			page->prev = doc->last_page;
			if (doc->last_page) doc->last_page->next = page;
			doc->last_page = page;
		}
	}
	doc->nr_pages = i;
	doc->get_geometry = get_geometry;
	doc->render_page = render_page;

	return 0;
}
Ejemplo n.º 3
0
void
acl_init(void)
{
    iks *policy;
    iks *model;
    int class_no;
    int e;

    // parse security policy file
    e = iks_load("/etc/comar/security-policy.xml", &policy);
    if (e) {
        log_error("Cannot process security policy file '%s', error %d\n",
                  "/etc/comar/security-policy.xml", e);
        return;
    }
    if (iks_strcmp(iks_name(policy), "comarSecurityPolicy") != 0) {
        log_error("Not a security policy file '%s'\n",
                  "/etc/comar/security-policy.xml");
        return;
    }

    // call permissions on the model
    model = iks_find(policy, "model");
    if (model) {
        class_no = -1;
        while (model_next_class(&class_no)) {
            set_class(model, class_no);
        }
    }
}
Ejemplo n.º 4
0
void
cdata (char *data, ...)
{
	iks *x;
	va_list ap;

	x = my_x;
	va_start (ap, data);
	while (1) {
		char *name = iks_name (x);
		char *tmp = va_arg (ap, char*);
		if (NULL == tmp) break;
		x = iks_find (x, tmp);
		if (!x) {
			PR_TEST;
			printf ("Tag <%s> is not a child of tag <%s>\n", tmp, name);
			exit (1);
		}
	}
	if (iks_strcmp ( iks_cdata (iks_child (x)), data) != 0) {
		PR_TEST;
		printf ("CDATA [%s] not found.\n", data);
		exit (1);
	}
	va_end (ap);
}
Ejemplo n.º 5
0
void
attrib (char *att, char *val, ...)
{
	iks *x;
	va_list ap;

	x = my_x;
	va_start (ap, val);
	while (1) {
		char *name = iks_name (x);
		char *tmp = va_arg (ap, char*);
		if (NULL == tmp) break;
		x = iks_find (x, tmp);
		if (!x) {
			PR_TEST;
			printf ("Tag <%s> is not a child of tag <%s>\n", tmp, name);
			exit (1);
		}
	}
	if (iks_strcmp (val, iks_find_attrib (x, att)) != 0) {
		PR_TEST;
		printf ("Attribute '%s' not found.\n", att);
		exit (1);
	}
	va_end (ap);
}
Ejemplo n.º 6
0
static void
add_groups(iks *tag, int class_no, int level, struct acl_class *ac)
{
    iks *x;
    // global permissions
    for (x = iks_find(tag, "group"); x; x = iks_next_tag(x)) {
        if (iks_strcmp(iks_name(x), "group") == 0)
            add_group(x, level, ac);
    }
    // class permissions
    x = iks_find_with_attrib(tag, "class", "name", model_get_path(class_no));
    for (x = iks_find(x, "group"); x; x = iks_next_tag(x)) {
        if (iks_strcmp(iks_name(x), "group") == 0)
            add_group(x, level, ac);
    }
}
Ejemplo n.º 7
0
static int
count_groups(iks *tag, int class_no)
{
    iks *x;
    unsigned int nr = 0;
    // global permissions
    for (x = iks_find(tag, "group"); x; x = iks_next_tag(x)) {
        if (iks_strcmp(iks_name(x), "group") == 0)
            ++nr;
    }
    // class permissions
    x = iks_find_with_attrib(tag, "class", "name", model_get_path(class_no));
    for (x = iks_find(x, "group"); x; x = iks_next_tag(x)) {
        if (iks_strcmp(iks_name(x), "group") == 0)
            ++nr;
    }
    return nr;
}
Ejemplo n.º 8
0
int
iks_stream_features (iks *x)
{
	int features = 0;

	if (iks_strcmp(iks_name(x), "stream:features"))
		return 0;
	for (x = iks_child(x); x; x = iks_next_tag(x))
		if (!iks_strcmp(iks_name(x), "starttls"))
			features |= IKS_STREAM_STARTTLS;
		else if (!iks_strcmp(iks_name(x), "bind"))
			features |= IKS_STREAM_BIND;
		else if (!iks_strcmp(iks_name(x), "session"))
			features |= IKS_STREAM_SESSION;
		else if (!iks_strcmp(iks_name(x), "mechanisms"))
			features |= iks_sasl_mechanisms(iks_child(x));
	return features;
}
Ejemplo n.º 9
0
/**
 * Create new output component
 */
static struct rayo_component *create_output_component(struct rayo_actor *actor, const char *type, iks *output, const char *client_jid)
{
	switch_memory_pool_t *pool;
	struct output_component *output_component = NULL;

	switch_core_new_memory_pool(&pool);
	output_component = switch_core_alloc(pool, sizeof(*output_component));
	output_component = OUTPUT_COMPONENT(rayo_component_init((struct rayo_component *)output_component, pool, type, "output", NULL, actor, client_jid));
	if (output_component) {
		output_component->document = iks_copy(output);
		output_component->start_offset_ms = iks_find_int_attrib(output, "start-offset");
		output_component->repeat_interval_ms = iks_find_int_attrib(output, "repeat-interval");
		output_component->repeat_times = iks_find_int_attrib(output, "repeat-times");
		output_component->max_time_ms = iks_find_int_attrib(output, "max-time");
		output_component->start_paused = iks_find_bool_attrib(output, "start-paused");
		output_component->renderer = switch_core_strdup(RAYO_POOL(output_component), iks_find_attrib_soft(output, "renderer"));
		/* get custom headers */
		{
			switch_stream_handle_t headers = { 0 };
			iks *header = NULL;
			int first = 1;
			SWITCH_STANDARD_STREAM(headers);
			for (header = iks_find(output, "header"); header; header = iks_next_tag(header)) {
				if (!strcmp("header", iks_name(header))) {
					const char *name = iks_find_attrib_soft(header, "name");
					const char *value = iks_find_attrib_soft(header, "value");
					if (!zstr(name) && !zstr(value)) {
						headers.write_function(&headers, "%s%s=%s", first ? "{" : ",", name, value);
						first = 0;
					}
				}
			}
			if (headers.data) {
				headers.write_function(&headers, "}");
				output_component->headers = switch_core_strdup(RAYO_POOL(output_component), (char *)headers.data);
				free(headers.data);
			}
		}
	} else {
		switch_core_destroy_memory_pool(&pool);
	}

	return RAYO_COMPONENT(output_component);
}
Ejemplo n.º 10
0
void
prefs_setup (void)
{
	iks *x;

	memset (&prefs, 0, sizeof (struct prefs_struct));

	prefs_chdir (".ulubot");

	if (iks_load ("ayarlar.xml", &x) == IKS_OK) {
		if (iks_strcmp (iks_name (x), "ulubot") == 0) {
			prefs.jid = iks_strdup (iks_find_cdata (x, "id"));
			prefs.pass = iks_strdup (iks_find_cdata (x, "password"));
			prefs.admin_jid = iks_strdup (iks_find_cdata (x, "admin_id"));
			iks_delete (x);
			if (prefs.jid && prefs.pass && prefs.admin_jid) return;
		}
	}

	puts (PACKAGE" v"VERSION" sözlük sunucusuna hoşgeldiniz!");
	puts ("Hemen bir kaç ayar yapalım:");

	prefs.jid = iks_strdup (input ("Botun Jabber hesabı"));
	prefs.pass = iks_strdup (input ("Botun Jabber şifresi"));
	prefs.admin_jid = iks_strdup (input ("Yöneticinin Jabber hesabı"));

	x = iks_new ("ulubot");
	iks_insert_cdata (iks_insert (x, "id"), prefs.jid, 0);
	iks_insert_cdata (iks_insert (x, "password"), prefs.pass, 0);
	iks_insert_cdata (iks_insert (x, "admin_id"), prefs.admin_jid, 0);
	if (iks_save ("ayarlar.xml", x) != IKS_OK) {
		puts ("Hata: ayarları kaydedemedim!");
	}
	iks_delete (x);

	puts ("Ayarlar tamam.");
}
Ejemplo n.º 11
0
static void _StouXmppGwConnParseStouSvrConnXml(CFStouXmppGwConn* gwConn, iks* node)
{
    const char *tag;
    CFStouXmppGw *gw;
    
    LCF_DBG_IN_FUNC();
    gw = gwConn->gw;
    tag = iks_name(node);
    if (!tag) {
        LCF_ERR_OUT(ERR_OUT, "tag == NULL, bug!!\n");
    }
    
    if (!strcmp(tag, "iq")) {
        if (gwConn->stat != CF_STOU_XMPP_GW_CONN_ST_TUNNEL_CREATED) {
            CFStouXmppGwDestroyConn(gw, gwConn);
            LCF_ERR_OUT(ERR_OUT, "Tunnel not created yet!!\n");
        }
        //if (!(iks_find_with_attrib(node, "ctl", "xmlns", XMLNS_CTL))) {
        //    LCF_ERR_OUT(ERR_OUT, "iq with no xmlns named "XMLNS_CTL"\n");
        //} else {
            if (XCSendStanza(&gwConn->xc, node)) {
                LCF_ERR_OUT(ERR_OUT, "XCSendStanza(iq) failed, maybe out of memory\n");
            }
        //}
    } else if (!strcmp(tag, "STOU_XMPP_AUTH")) {
        const char *rsid;
        if (gwConn->stat != CF_STOU_XMPP_GW_CONN_ST_AUTHING) {
            CFStouXmppGwDestroyConn(gw, gwConn);
            LCF_ERR_OUT(ERR_OUT, "Tunnel not created yet!!\n");
        }
        if (!(rsid = iks_find_attrib(node, "rsid"))) {
            CFStouXmppGwDestroyConn(gw, gwConn);
            LCF_ERR_OUT(ERR_OUT, "auth failed, no rsid\n");
        }
        
        if (!CFStouXmppGwConnAuth(gwConn, rsid)) {
            CFStouXmppGwDestroyConn(gw, gwConn);
            LCF_ERR_OUT(ERR_OUT, "Auth failed\n");
        }
        
        if (XCStart(&gwConn->xc)) {
            CFStouXmppGwDestroyConn(gw, gwConn);
            LCF_ERR_OUT(ERR_OUT, "XCStart() failed\n");            
        }
        
        gwConn->stat = CF_STOU_XMPP_GW_CONN_ST_XC_STARTING;
    } else if (!strcmp(tag, "message")) {
        if (gwConn->stat != CF_STOU_XMPP_GW_CONN_ST_TUNNEL_CREATED) {
            CFStouXmppGwDestroyConn(gw, gwConn);
            LCF_ERR_OUT(ERR_OUT, "Tunnel not created yet!!\n");
        }
        if (XCSendStanza(&gwConn->xc, node)) {
            LCF_ERR_OUT(ERR_OUT, "XCSendStanza(iq) failed, maybe out of memory\n");
        }
    } else {
        LCF_ERR("recieved unknown xml stanza\n");
    }
    
    return;
ERR_OUT:
    return;
}
Ejemplo n.º 12
0
/**
 * Start CPA
 */
iks *rayo_cpa_component_start(struct rayo_actor *call, struct rayo_message *msg, void *session_data)
{
    iks *iq = msg->payload;
    switch_core_session_t *session = (switch_core_session_t *)session_data;
    iks *input = iks_find(iq, "input");
    switch_memory_pool_t *pool = NULL;
    struct cpa_component *component = NULL;
    int have_grammar = 0;
    iks *grammar = NULL;

    /* create CPA component */
    switch_core_new_memory_pool(&pool);
    component = switch_core_alloc(pool, sizeof(*component));
    component = CPA_COMPONENT(rayo_component_init((struct rayo_component *)component, pool, RAT_CALL_COMPONENT, "cpa", NULL, call, iks_find_attrib(iq, "from")));
    if (!component) {
        switch_core_destroy_memory_pool(&pool);
        return iks_new_error_detailed(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "Failed to create CPA entity");
    }

    switch_core_hash_init(&component->signals);

    /* start CPA detectors */
    for (grammar = iks_find(input, "grammar"); grammar; grammar = iks_next_tag(grammar)) {
        if (!strcmp("grammar", iks_name(grammar))) {
            const char *error_str = "";
            const char *url = iks_find_attrib_soft(grammar, "url");
            char *url_dup;
            char *url_params;

            if (zstr(url)) {
                stop_cpa_detectors(component);
                RAYO_UNLOCK(component);
                RAYO_DESTROY(component);
                return iks_new_error_detailed(iq, STANZA_ERROR_BAD_REQUEST, "Missing grammar URL");
            }
            have_grammar = 1;

            url_dup = strdup(url);
            if ((url_params = strchr(url_dup, '?'))) {
                *url_params = '\0';
                url_params++;
            }

            if (switch_core_hash_find(component->signals, url)) {
                free(url_dup);
                stop_cpa_detectors(component);
                RAYO_UNLOCK(component);
                RAYO_DESTROY(component);
                return iks_new_error_detailed(iq, STANZA_ERROR_BAD_REQUEST, "Duplicate URL");
            }

            /* start detector */
            /* TODO return better reasons... */
            if (rayo_cpa_detector_start(switch_core_session_get_uuid(session), url_dup, &error_str)) {
                struct cpa_signal *cpa_signal = switch_core_alloc(pool, sizeof(*cpa_signal));
                cpa_signal->terminate = !zstr(url_params) && strstr(url_params, "terminate=true");
                cpa_signal->name = switch_core_strdup(pool, url_dup);
                switch_core_hash_insert(component->signals, cpa_signal->name, cpa_signal);
                subscribe(switch_core_session_get_uuid(session), cpa_signal->name, RAYO_JID(component));
            } else {
                free(url_dup);
                stop_cpa_detectors(component);
                RAYO_UNLOCK(component);
                RAYO_DESTROY(component);
                return iks_new_error_detailed(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, error_str);
            }

            free(url_dup);
        }
    }

    if (!have_grammar) {
        stop_cpa_detectors(component);
        RAYO_UNLOCK(component);
        RAYO_DESTROY(component);
        return iks_new_error_detailed(iq, STANZA_ERROR_BAD_REQUEST, "No grammar defined");
    }

    /* acknowledge command */
    rayo_component_send_start(RAYO_COMPONENT(component), iq);

    /* TODO hangup race condition */
    subscribe(switch_core_session_get_uuid(session), "hangup", RAYO_JID(component));

    /* ready to forward detector events */
    component->ready = 1;

    return NULL;
}
Ejemplo n.º 13
0
/**
 * Pass output component command
 */
static iks *forward_output_component_request(struct rayo_actor *prompt, struct rayo_message *msg, void *data)
{
	iks *iq = msg->payload;
	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s (%s) %s prompt\n",
		RAYO_JID(prompt), prompt_component_state_to_string(PROMPT_COMPONENT(prompt)->state), iks_name(iks_first_tag(iq)));

	switch (PROMPT_COMPONENT(prompt)->state) {
		case PCS_OUTPUT:
		case PCS_START_INPUT_OUTPUT:
		case PCS_INPUT_OUTPUT: {
			/* forward request to output component */
			iks_insert_attrib(iq, "from", RAYO_JID(prompt));
			iks_insert_attrib(iq, "to", PROMPT_COMPONENT(prompt)->output_jid);
			RAYO_SEND_MESSAGE_DUP(prompt, PROMPT_COMPONENT(prompt)->output_jid, iq);
			return NULL;
		}
		case PCS_START_INPUT_TIMERS:
		case PCS_START_OUTPUT:
		case PCS_START_OUTPUT_BARGE:
			/* ref hasn't been sent yet */
			return iks_new_error_detailed(iq, STANZA_ERROR_UNEXPECTED_REQUEST, "too soon");
			break;
		case PCS_START_INPUT:
		case PCS_STOP_OUTPUT:
		case PCS_DONE_STOP_OUTPUT:
		case PCS_INPUT:
		case PCS_DONE:
			return iks_new_error_detailed(iq, STANZA_ERROR_UNEXPECTED_REQUEST, "output is finished");
	}
	return NULL;
}
Ejemplo n.º 14
0
//! Loads model to database
void
db_load_model(iks *xml, PyObject **py_models)
{
    /*!
     * Loads models to database
     *
     * @xml Iksemel document
     * @py_models Pointer to models dictionary
     *
     */

    iks *iface, *met, *arg;

    for (iface = iks_first_tag(xml); iface; iface = iks_next_tag(iface)) {
        PyObject *py_methods = PyDict_New();

        char *iface_name = iks_find_attrib(iface, "name");

        for (met = iks_first_tag(iface); met; met = iks_next_tag(met)) {
            PyObject *py_tuple = PyTuple_New(4);

            // First argument is type. 0 for methods, 1 for signals
            if (iks_strcmp(iks_name(met), "method") == 0) {
                PyTuple_SetItem(py_tuple, 0, PyInt_FromLong((long) 0));
            }
            else {
                PyTuple_SetItem(py_tuple, 0, PyInt_FromLong((long) 1));
            }

            // Second argument is PolicyKit action ID
            char *action_id = db_action_id(iface_name, met);
            PyTuple_SetItem(py_tuple, 1, PyString_FromString(action_id));

            // Build argument lists
            PyObject *py_args_in = PyList_New(0);
            PyObject *py_args_out = PyList_New(0);
            int noreply = 0;
            for (arg = iks_first_tag(met); arg; arg = iks_next_tag(arg)) {
                if (iks_strcmp(iks_name(arg), "attribute") == 0) {
                    if (iks_strcmp(iks_find_attrib(arg, "name"), "org.freedesktop.DBus.Method.NoReply") == 0) {
                        if (iks_strcmp(iks_find_attrib(arg, "value"), "true") == 0) {
                            noreply = 1;
                        }
                    }
                }
                else if (iks_strcmp(iks_name(arg), "arg") == 0) {
                    if (iks_strcmp(iks_name(met), "method") == 0) {
                        if (iks_strcmp(iks_find_attrib(arg, "direction"), "out") == 0) {
                            PyList_Append(py_args_out, PyString_FromString(iks_find_attrib(arg, "type")));
                        }
                        else {
                            PyList_Append(py_args_in, PyString_FromString(iks_find_attrib(arg, "type")));
                        }
                    }
                    else if (iks_strcmp(iks_name(met), "signal") == 0) {
                        PyList_Append(py_args_out, PyString_FromString(iks_find_attrib(arg, "type")));
                    }
                }
            }

            if (noreply) {
                py_args_out = PyList_New(0);
            }

            // Third argument is input arguments
            PyTuple_SetItem(py_tuple, 2, py_args_in);
            // Fourth argument is output arguments
            PyTuple_SetItem(py_tuple, 3, py_args_out);

            PyDict_SetItemString(py_methods, iks_find_attrib(met, "name"), py_tuple);
        }

        PyDict_SetItemString(*py_models, iface_name, py_methods);
    }
}
Ejemplo n.º 15
0
//! Imports model file
static int
model_import(const char *model_file)
{
    /*!
     * Imports model file to node table.
     *
     * @model_file File to import
     * @return 0 on success, -1 on error
     */

    iks *obj, *met;
    size_t size = 0;
    size_t obj_size, met_size;
    int obj_no;
    int count = 0;
    int e;

    e = iks_load(model_file, &model_xml);
    if (e != 0) {
        log_error("XML load error.\n");
        return -1;
    }

    if (iks_strcmp(iks_name(model_xml), "comarModel") != 0) {
        log_error("Bad XML: not a Comar model.\n");
        return -1;
    }

    // scan the model
    for (obj = iks_first_tag(model_xml); obj; obj = iks_next_tag(obj)) {
        if (iks_strcmp(iks_name(obj), "interface") == 0) {
            obj_size = iks_strlen(iks_find_attrib(obj, "name"));
            if (!obj_size) {
                log_error("Bad XML: interface has no name.\n");
                return -1;
            }

            size += obj_size + 1;
            ++count;

            for (met = iks_first_tag(obj); met; met = iks_next_tag(met)) {
                if (iks_strcmp(iks_name(met), "method") == 0 || iks_strcmp(iks_name(met), "signal") == 0) {
                    met_size = iks_strlen(iks_find_attrib(met, "name"));
                    if (!met_size) {
                        log_error("Bad XML: method/signal has no name.\n");
                        return -1;
                    }
                    size += obj_size + 1 + met_size + 1;
                    ++count;

                    iks *arg;
                    for (arg = iks_first_tag(met); arg; arg = iks_next_tag(arg)) {
                        if (iks_strcmp(iks_name(arg), "arg") != 0 && iks_strcmp(iks_name(arg), "annotation") != 0) {
                            log_error("Bad XML: method/signal may contain <arg> or <annotation> only\n");
                            return -1;
                        }
                    }
                }
                else {
                    log_error("Bad XML: interface may contain <method> or <signal> only\n");
                    return -1;
                }
            }
        }
        else {
            log_error("Bad XML: root node may contain <interface> only\n");
            return -1;
        }
    }

    // size is counted to alloc mem for paths
    // prepare data structures
    if (prepare_tables(count, size) != 0) return -1;

    // load model
    for (obj = iks_first_tag(model_xml); obj; obj = iks_next_tag(obj)) {
        if (iks_strcmp(iks_find_attrib(obj, "name"), "Comar") == 0) {
            continue;
        }
        obj_no = add_node(-1, build_path(obj, NULL), "", N_INTERFACE);
        for (met = iks_first_tag(obj); met; met = iks_next_tag(met)) {
            if (iks_strcmp(iks_name(met), "method") == 0) {
                char *label = iks_find_attrib(met, "access_label");
                if (label) {
                    iks_insert_attrib(met, "access_label", NULL);
                }
                else {
                    label = iks_find_attrib(met, "name");
                }
                add_node(obj_no, build_path(obj, met), label, N_METHOD);
            }
            else if (iks_strcmp(iks_name(met), "signal") == 0) {
                add_node(obj_no, build_path(obj, met), "", N_SIGNAL);
            }
        }
    }

    return 0;
}
Ejemplo n.º 16
0
static int
on_stream (void *ptr, int type, iks *node)
{
	iks *x;
	ikspak *pak;

	switch (type) {
		case IKS_NODE_START:
			/* x = iks_make_auth (j_user, prefs.pass, iks_find_attrib (node, "id"));
			iks_insert_attrib (x, "id", "auth");
			iks_send (j_parser, x);
			iks_delete (x); */
			break;

		case IKS_NODE_NORMAL:
			if (strcmp("stream:features", iks_name(node)) == 0) {
				if (authorized) {
					int features;
					features = iks_stream_features(node);
					if (features & IKS_STREAM_BIND) {
						x = iks_make_resource_bind(j_user);
						iks_send(j_parser, x);
						iks_delete(x);
					}
					if (features & IKS_STREAM_SESSION) {
						x = iks_make_session();
						iks_insert_attrib(x, "id", "auth");
						iks_send(j_parser, x);
						iks_delete(x);
					}
				} else {
					iks_start_sasl(j_parser, IKS_SASL_DIGEST_MD5, j_user->user, prefs.pass);
				}
				break;
			} else if (strcmp("failure", iks_name(node)) == 0) {
				log_event ("Hata: SASL başarısız!");
				return IKS_HOOK;
			} else if (strcmp("success", iks_name(node)) == 0) {
				authorized = 1;
				iks_send_header(j_parser, j_user->server);
				break;
			}
		
			pak = iks_packet (node);
			if (pak->type == IKS_PAK_MESSAGE) {
				// process incoming messages
				command_parse (pak->from->partial, iks_find_cdata (node, "body"));
			} else if (pak->type == IKS_PAK_S10N) {
				// always accept subscriptions
				if (pak->subtype == IKS_TYPE_SUBSCRIBE) {
					x = iks_make_s10n (IKS_TYPE_SUBSCRIBED, pak->from->full, NULL);
					iks_send (j_parser, x);
					iks_delete (x);
				}
			} else if (pak->type == IKS_PAK_IQ) {
				if (iks_strcmp (pak->id, "auth") == 0) {
					// auth response
					if (pak->subtype == IKS_TYPE_RESULT) {
						log_event ("Bağlandık.");
						x = iks_make_iq (IKS_TYPE_GET, IKS_NS_ROSTER);
						iks_send (j_parser, x);
						iks_delete (x);
						x = iks_make_pres (IKS_SHOW_AVAILABLE, NULL);
						iks_send (j_parser, x);
						iks_delete (x);
					} else {
						log_event ("Hata: kullanıcı doğrulama başarısız oldu!");
						return IKS_HOOK;
					}
				}
			}
			break;

		case IKS_NODE_STOP:
		case IKS_NODE_ERROR:
			log_event ("Hata: XMPP stream hatası!");
			return IKS_HOOK;
	}
	if (node) iks_delete (node);

	return IKS_OK;
}
Ejemplo n.º 17
0
//! Validates model file
int
db_validate_model(iks *xml, char *filename)
{
    /*!
     * Validates model file.
     *
     * @xml Iksemel document
     * @return 0 on success, -1 on error
     *
     */

    iks *iface, *met, *arg;

    DBusError bus_error;
    dbus_error_init(&bus_error);

    // Check root tag
    if (iks_strcmp(iks_name(xml), "comarModel") != 0) {
        log_error("Not a valid model XML: %s\n", filename);
        return -1;
    }

    for (iface = iks_first_tag(xml); iface; iface = iks_next_tag(iface)) {
        // Only "interface" tag is allowed
        if (iks_strcmp(iks_name(iface), "interface") != 0) {
            log_error("Unknown tag '%s' in XML: %s\n", iks_name(iface), filename);
            return -1;
        }
        // Interfaces must have a "name" attribute
        if (!iks_strlen(iks_find_attrib(iface, "name"))) {
            log_error("Model with no name in XML: %s\n", filename);
            return -1;
        }

        for (met = iks_first_tag(iface); met; met = iks_next_tag(met)) {
            // Only "method" and "signal" tags are allowed
            if (iks_strcmp(iks_name(met), "method") == 0 || iks_strcmp(iks_name(met), "signal") == 0) {
                // Tags must have a "name" attribute
                if (!iks_strlen(iks_find_attrib(met, "name"))) {
                    log_error("Method/Signal tag without name under '%s' in XML: %s\n", iks_find_attrib(iface, "name"), filename);
                    return -1;
                }
                for (arg = iks_first_tag(met); arg; arg = iks_next_tag(arg)) {
                    if (iks_strcmp(iks_name(arg), "arg") == 0) {
                        // Arguments must have a "name" attribute
                        if (!iks_strlen(iks_find_attrib(arg, "name"))) {
                            log_error("Argument tag with no name under '%s/%s' in XML: %s\n", iks_find_attrib(iface, "name"), iks_find_attrib(met, "name"), filename);
                            return -1;
                        }
                        // Arguments must have a "type" attribute
                        if (!iks_strlen(iks_find_attrib(arg, "type"))) {
                            log_error("Argument tag without type under '%s/%s' in XML: %s\n", iks_find_attrib(iface, "name"), iks_find_attrib(met, "name"), filename);
                            return -1;
                        }
                        // Types must be a valid DBus signature
                        if (!dbus_signature_validate(iks_find_attrib(arg, "type"), &bus_error)) {
                            dbus_error_free(&bus_error);
                            log_error("Argument tag with invalid type (%s/%s/%s) in XML: %s\n", iks_find_attrib(iface, "name"), iks_find_attrib(met, "name"), iks_find_attrib(arg, "name"), filename);
                            return -1;
                        }
                        // Types must be single type object
                        if (!dbus_signature_validate_single(iks_find_attrib(arg, "type"), &bus_error)) {
                            dbus_error_free(&bus_error);
                            log_error("Argument tag with a non-single element type (%s/%s/%s) in XML: %s\n", iks_find_attrib(iface, "name"), iks_find_attrib(met, "name"), iks_find_attrib(arg, "name"), filename);
                            return -1;
                        }
                    }
                    else if (iks_strcmp(iks_name(arg), "annotation") == 0) {
                        // Attributes must have a "name" attribute
                        if (!iks_strlen(iks_find_attrib(arg, "name"))) {
                            log_error("Annotation tag without name under '%s' in XML: %s\n", iks_find_attrib(iface, "name"), iks_find_attrib(met, "name"), filename);
                            return -1;
                        }
                    }
                    else {
                        log_error("Unknown tag '%s' under '%s/%s' in XML: %s\n", iks_name(arg), iks_find_attrib(iface, "name"), iks_find_attrib(met, "name"), filename);
                        return -1;
                    }
                }
            }
            else {
                log_error("Unknown tag '%s' under '%s' in XML: %s\n", iks_name(met), iks_find_attrib(iface, "name"), filename);
                return -1;
            }
        }
    }

    return 0;
}
Ejemplo n.º 18
0
int
model_init(void)
{
	iks *model;
	iks *grp, *obj, *met;
	int count = 0;
	size_t size = 0;
	size_t grp_size, obj_size, met_size;
	int grp_no, obj_no;
	int e;

	// parse model file
	e = iks_load(cfg_model_file, &model);
	if (e) {
		log_error("Cannot process model file '%s'\n", cfg_model_file);
		return -1;
	}

	if (iks_strcmp(iks_name(model), "comarModel") != 0) {
		log_error("Not a COMAR model file '%s'\n", cfg_model_file);
		return -1;
	}

	// FIXME: ugly code ahead, split into functions and simplify

	// scan the model
	for (grp = iks_first_tag(model); grp; grp = iks_next_tag(grp)) {
		if (iks_strcmp(iks_name(grp), "group") == 0) {
			grp_size = iks_strlen(iks_find_attrib(grp, "name"));
			if (!grp_size) {
				log_error("Broken COMAR model file '%s'\n", cfg_model_file);
				return -1;
			}
			size += grp_size + 1;
			++count;
			for (obj = iks_first_tag(grp); obj; obj = iks_next_tag(obj)) {
				if (iks_strcmp(iks_name(obj), "class") == 0) {
					obj_size = iks_strlen(iks_find_attrib(obj, "name"));
					if (!obj_size) {
						log_error("Broken COMAR model file '%s'\n", cfg_model_file);
						return -1;
					}
					size += grp_size + obj_size + 2;
					++count;
					for (met = iks_first_tag(obj); met; met = iks_next_tag(met)) {
						if (iks_strcmp(iks_name(met), "method") == 0
							|| iks_strcmp(iks_name(met), "notify") == 0) {
							met_size = iks_strlen(iks_find_attrib(met, "name"));
							if (!met_size) {
								log_error("Broken COMAR model file '%s'\n", cfg_model_file);
								return -1;
							}
							size += grp_size + obj_size + met_size + 3;
							++count;
						}
						if (iks_strcmp(iks_name(met), "method") == 0) {
							iks *arg;
							for (arg = iks_first_tag(met); arg; arg = iks_next_tag(arg)) {
								if (iks_strcmp(iks_name(arg), "argument") == 0
									|| iks_strcmp(iks_name(arg), "instance") == 0) {
									size += iks_cdata_size(iks_child(arg)) + 1;
								}
							}
						}
					}
				}
			}
		}
	}

	// prepare data structures
	if (prepare_tables(count, size)) return -1;

	// load the model
	for (grp = iks_first_tag(model); grp; grp = iks_next_tag(grp)) {
		if (iks_strcmp(iks_name(grp), "group") == 0) {
			grp_no = add_node(-1, build_path(grp, NULL, NULL), N_GROUP);
			for (obj = iks_first_tag(grp); obj; obj = iks_next_tag(obj)) {
				if (iks_strcmp(iks_name(obj), "class") == 0) {
					obj_no = add_node(grp_no, build_path(grp, obj, NULL), N_CLASS);
					for (met = iks_first_tag(obj); met; met = iks_next_tag(met)) {
						int no;
						if (iks_strcmp(iks_name(met), "method") == 0) {
							iks *arg;
							char *prof;
							no = add_node(obj_no, build_path(grp, obj, met), N_METHOD);
							prof = iks_find_attrib(met, "access");
							if (prof) {
								if (strcmp(prof, "user") == 0)
									nodes[no].level = ACL_USER;
								if (strcmp(prof, "guest") == 0)
									nodes[no].level = ACL_GUEST;
							}
							prof = iks_find_attrib(met, "profile");
							if (prof) {
								if (strcmp(prof, "global") == 0)
									nodes[no].flags |= P_GLOBAL;
								if (strcmp(prof, "package") == 0)
									nodes[no].flags |= P_PACKAGE;
							}
							prof = iks_find_attrib(met, "profileOp");
							if (prof) {
								if (strcmp(prof, "delete") == 0)
									nodes[no].flags |= P_DELETE;
								if (strcmp(prof, "startup") == 0)
									nodes[no].flags |= P_STARTUP;
							}
							for (arg = iks_first_tag(met); arg; arg = iks_next_tag(arg)) {
								if (iks_strcmp(iks_name(arg), "instance") == 0) {
									build_arg(no, 1, iks_cdata(iks_child(arg)));
								}
							}
							for (arg = iks_first_tag(met); arg; arg = iks_next_tag(arg)) {
								if (iks_strcmp(iks_name(arg), "argument") == 0) {
									char *argname;
									argname = iks_cdata(iks_child(arg));
									if (argname) {
										build_arg(no, 0, argname);
									} else {
										log_error("Argument name needed in <argument> tag of model.xml\n");
									}
								}
							}
						} else if (iks_strcmp(iks_name(met), "notify") == 0) {
							no = add_node(obj_no, build_path(grp, obj, met), N_NOTIFY);
							if (no >= model_max_notifications)
								model_max_notifications = no + 1;
						}
					}
				}
			}
		}
	}

	// no need to keep dom tree in memory
	iks_delete(model);

	return 0;
}
Ejemplo n.º 19
0
static void
render_object(ImpRenderCtx *ctx, void *drw_data, iks *node)
{
	char *tag, *t;
	ImpColor fg;

	tag = iks_name(node);
	if (strcmp(tag, "draw:g") == 0) {
		iks *x;
		for (x = iks_first_tag(node); x; x = iks_next_tag(x)) {
			render_object(ctx, drw_data, x);
		}
	} else if (strcmp(tag, "draw:frame") == 0) {
		iks *x;
		for (x = iks_first_tag(node); x; x = iks_next_tag(x)) {
			render_object(ctx, drw_data, x);
		}
	} else if (strcmp(tag, "draw:line") == 0) {
		r_get_color(ctx, node, "svg:stroke-color", &fg);
		ctx->drw->set_fg_color(drw_data, &fg);
		ctx->drw->draw_line(drw_data,
			r_get_x(ctx, node, "svg:x1"), r_get_y(ctx, node, "svg:y1"),
			r_get_x(ctx, node, "svg:x2"), r_get_y(ctx, node, "svg:y2")
		);
	} else if (strcmp(tag, "draw:rect") == 0) {
		int x, y, w, h, r = 0;
		char *t;
		x = r_get_x(ctx, node, "svg:x");
		y = r_get_y(ctx, node, "svg:y");
		w = r_get_x(ctx, node, "svg:width");
		h = r_get_y(ctx, node, "svg:height");
		t = r_get_style(ctx, node, "draw:corner-radius");
		if (t) r = atof(t) * ctx->fact_x;
		if (r_get_style(ctx, node, "draw:fill")) {
			r_get_color(ctx, node, "draw:fill-color", &fg);
			ctx->drw->set_fg_color(drw_data, &fg);
			_imp_draw_rect(ctx, drw_data, 1, x, y, w, h, r);
		}
		r_get_color(ctx, node, "svg:stroke-color", &fg);
		ctx->drw->set_fg_color(drw_data, &fg);
		_imp_draw_rect(ctx, drw_data, 0, x, y, w, h, r);
		r_text(ctx, drw_data, node);
	} else if (strcmp(tag, "draw:ellipse") == 0 || strcmp(tag, "draw:circle") == 0) {
		int sa, ea, fill = 0;
		r_get_color(ctx, node, "svg:stroke-color", &fg);
		sa = r_get_angle(node, "draw:start-angle", 0);
		ea = r_get_angle(node, "draw:end-angle", 360);
		if (ea > sa) ea = ea - sa; else ea = 360 + ea - sa;
		t = r_get_style(ctx, node, "draw:fill");
		if (t) fill = 1;
		ctx->drw->set_fg_color(drw_data, &fg);
		ctx->drw->draw_arc(drw_data,
			fill,
			r_get_x(ctx, node, "svg:x"), r_get_y(ctx, node, "svg:y"),
			r_get_x(ctx, node, "svg:width"), r_get_y(ctx, node, "svg:height"),
			sa, ea
		);
	} else if (strcmp(tag, "draw:polygon") == 0) {
		// FIXME:
		r_polygon(ctx, drw_data, node);
	} else if (strcmp(tag, "draw:text-box") == 0) {
		// FIXME:
		r_text(ctx, drw_data, node);
	} else if (strcmp(tag, "draw:image") == 0) {
		char *name;

		name = iks_find_attrib(node, "xlink:href");
		if (!name) return;
		if (name[0] == '#') ++name;

		_imp_draw_image(ctx, drw_data,
			name,
			r_get_x(ctx, node, "svg:x"),
			r_get_y(ctx, node, "svg:y"),
			r_get_x(ctx, node, "svg:width"),
			r_get_y(ctx, node, "svg:height")
		);
	} else {
		printf("Unknown element: %s\n", tag);
	}
}
Ejemplo n.º 20
0
int axis2_xmpp_client_on_normal_node(
    axis2_xmpp_session_data_t *session,
    iks* node)
{
    if(!strcmp("stream:features", iks_name(node)))
    {
        session->features = iks_stream_features(node);

        if(session->use_sasl)
        {
            if(session->use_tls && !iks_is_secure(session->parser))
            {
                if(!session->authorized)
                {
                    /* we might be in the process of establishing TLS. so should return OK */
                    return IKS_OK;
                }

                return IKS_HOOK;
            }

            if(session->authorized)
            {
                /* Bind a resource if required */
                xmpp_process_msg(session, node);
            }
            else
            {
                if(session->features & IKS_STREAM_SASL_MD5)
                {
                    iks_start_sasl(session->parser, IKS_SASL_DIGEST_MD5, session->jid->user,
                        session->password);
                }
                else if(session->features & IKS_STREAM_SASL_PLAIN)
                {
                    iks_start_sasl(session->parser, IKS_SASL_PLAIN, session->jid->user,
                        session->password);
                }
#ifdef AXIS2_XMPP_GSSAPI
                else if (session->features & IKS_STREAM_SASL_GSSAPI)
                {
                    iks_start_sasl (session->parser, IKS_SASL_GSSAPI,
                        session->jid->user, session->password);
                }
#endif  /* AXIS2_XMPP_GSSAPI */

            }
        }
        else
        {
            /* features node */
            if(!strcmp("stream:features", iks_name(node)))
            {
                if(session->authorized)
                    xmpp_process_msg(session, node);

            }
        }
    }
    else if(!strcmp("failure", iks_name(node)))
    {
        AXIS2_LOG_ERROR(session->env->log, AXIS2_LOG_SI, "[xmpp]Authentication failed.");
        return IKS_HOOK;
    }
    else if(!strcmp("success", iks_name(node)))
    {
        AXIS2_LOG_INFO(session->env->log, "[xmpp]Authentication successful.");
        session->authorized = 1;
        iks_send_header(session->parser, session->server);
    }
    else
    {
        ikspak *pak;
        pak = iks_packet(node);
        iks_filter_packet(session->filter, pak);
    }

    return IKS_OK;
}
Ejemplo n.º 21
0
// 客户端解析服务器响应的协商包,从协商包中解析出临时密钥,并使用自己的私钥进行解密
// 服务器端解析客户端发来的协商包,并填充服务器包解析器
int pkg_talk_parse(packet_parser_t *pkg, const char* xml)
{
	iks *x, *e, *c;
	int result=0;
	int dest_len;

	if(NULL==xml) return NULL_ERROR;

	x =	iks_tree (xml, 0, &result);
	if(!x) return NULL_ERROR;
	if(result != IKS_OK)
	{
		iks_delete(x);
		return IKS_BADXML;
	}

	if(0 == iks_strcmp("connection",iks_name(x)))
	{
		char* tmp = NULL;
		char *tempkey;
		char *output;

		tmp = iks_find_attrib(x, "type");
		if(NULL != tmp){
			if(strcmp(tmp, "create")==0)
				set_talk_type(1, pkg); //说明为服务端
			else
				set_talk_type(0, pkg); //说明为客户端
		}

		if(1 == pkg->talk_type)
		{
			//说明本端为服务端
			tmp = iks_find_cdata(x, "client-id");
			set_client_id(tmp, pkg);

			tmp = iks_find_cdata(x, "public-key");
			if(SUCCESS != set_talk_crt_public_key(tmp, pkg))
				return SET_TALK_CRT_KEY_ERROR;

			tmp = iks_find_attrib(iks_find(x,"public-key"), "type");
			if(SUCCESS != set_talk_crt_type(tmp, pkg))
				return SET_TALK_CRT_TYPE_ERROR;

			e = iks_find(x,"encryption");
			while( e ){
				tmp = iks_find_cdata(e, "allow");
				if(SUCCESS == set_transfer_crt_type(tmp, pkg)) break;
				e = iks_next(e);
			}
			// 服务器端设置传输数据使用的临时密钥
			set_transfer_crt_key(TRANSFERKEY, pkg);

			c = iks_find(x,"compression");
			while( c ){
				tmp = iks_find_cdata(c, "allow");
				if(SUCCESS == set_cps_type(tmp, pkg)) break;
				c = iks_next(c);
			}
		}
		else if(0 == pkg->talk_type)
		{
			// 说明本端为客户端
			tempkey = iks_find_cdata(x,"encryption");
			output = (char *)calloc(strlen(tempkey)/2+1, 1);
			hex2byte(tempkey, strlen(tempkey), (unsigned char *)output);
			if (pkg->asym_encrypt_hook == NULL)
			{
				tempkey = (char *)rsa_encrypt((unsigned char *)output, strlen(tempkey)/2, &dest_len, pkg->curr_ert.ert_keys[1], CRYPT_TYPE_DECRYPT);
			}
			else
			{
				tempkey = (char *)pkg->asym_encrypt_hook((unsigned char *)output, strlen(tempkey)/2, &dest_len, pkg->curr_ert.ert_keys[1], CRYPT_TYPE_DECRYPT);
			}
			free(output);
			// 比较服务器端响应的压缩加密方式与客户端请求的是否相同
			if( SUCCESS != set_transfer_crt_key(tempkey, pkg))
				return SET_TRANSFER_ERT_KEY_ERROR;
			free(tempkey);
			if( SUCCESS != cmp_transfer_crt_type(iks_find_attrib(iks_find(x, "encryption"), "type"), pkg) )
				return CMP_TRANSFER_CRT_TYPE_ERROR;
			if( SUCCESS != cmp_cps_type(iks_find_cdata(x, "compression"), pkg) )
				return CMP_CPS_TYPE_ERROR;
			set_heatbeat("client", iks_find_attrib(iks_find(x, "heartbeat"), "seconds"), pkg);
		}	
	} 
	
	//iks_parser_delete (p);
	iks_delete(x);
	return SUCCESS;
}
Ejemplo n.º 22
0
ikspak *
iks_packet (iks *x)
{
	ikspak *pak;
	ikstack *s;
	char *tmp;

	s = iks_stack (x);
	pak = iks_stack_alloc (s, sizeof (ikspak));
	if (!pak) return NULL;
	memset (pak, 0, sizeof (ikspak));
	pak->x = x;
	tmp = iks_find_attrib (x, "from");
	if (tmp) pak->from = iks_id_new (s, tmp);
	pak->id = iks_find_attrib (x, "id");

	tmp = iks_find_attrib (x, "type");
	if (strcmp (iks_name (x), "message") == 0) {
		pak->type = IKS_PAK_MESSAGE;
		if (tmp) {
			if (strcmp (tmp, "chat") == 0)
				pak->subtype = IKS_TYPE_CHAT;
			else if (strcmp (tmp, "groupchat") == 0)
				pak->subtype = IKS_TYPE_GROUPCHAT;
			else if (strcmp (tmp, "headline") == 0)
				pak->subtype = IKS_TYPE_HEADLINE;
			else if (strcmp (tmp, "error") == 0)
				pak->subtype = IKS_TYPE_ERROR;
		}
	} else if (strcmp (iks_name (x), "presence") == 0) {
		pak->type = IKS_PAK_S10N;
		if (tmp) {
			if (strcmp (tmp, "unavailable") == 0) {
				pak->type = IKS_PAK_PRESENCE;
				pak->subtype = IKS_TYPE_UNAVAILABLE;
				pak->show = IKS_SHOW_UNAVAILABLE;
			} else if (strcmp (tmp, "probe") == 0) {
				pak->type = IKS_PAK_PRESENCE;
				pak->subtype = IKS_TYPE_PROBE;
			} else if(strcmp(tmp, "subscribe") == 0)
				pak->subtype = IKS_TYPE_SUBSCRIBE;
			else if(strcmp(tmp, "subscribed") == 0)
				pak->subtype = IKS_TYPE_SUBSCRIBED;
			else if(strcmp(tmp, "unsubscribe") == 0)
				pak->subtype = IKS_TYPE_UNSUBSCRIBE;
			else if(strcmp(tmp, "unsubscribed") == 0)
				pak->subtype = IKS_TYPE_UNSUBSCRIBED;
			else if(strcmp(tmp, "error") == 0)
				pak->subtype = IKS_TYPE_ERROR;
		} else {
			pak->type = IKS_PAK_PRESENCE;
			pak->subtype = IKS_TYPE_AVAILABLE;
			tmp = iks_find_cdata (x, "show");
			pak->show = IKS_SHOW_AVAILABLE;
			if (tmp) {
				if (strcmp (tmp, "chat") == 0)
					pak->show = IKS_SHOW_CHAT;
				else if (strcmp (tmp, "away") == 0)
					pak->show = IKS_SHOW_AWAY;
				else if (strcmp (tmp, "xa") == 0)
					pak->show = IKS_SHOW_XA;
				else if (strcmp (tmp, "dnd") == 0)
					pak->show = IKS_SHOW_DND;
			}
		}
	} else if (strcmp (iks_name (x), "iq") == 0) {
		iks *q;
		pak->type = IKS_PAK_IQ;
		if (tmp) {
			if (strcmp (tmp, "get") == 0)
				pak->subtype = IKS_TYPE_GET;
			else if (strcmp (tmp, "set") == 0)
				pak->subtype = IKS_TYPE_SET;
			else if (strcmp (tmp, "result") == 0)
				pak->subtype = IKS_TYPE_RESULT;
			else if (strcmp (tmp, "error") == 0)
				pak->subtype = IKS_TYPE_ERROR;
		}
		for (q = iks_child (x); q; q = iks_next (q)) {
			if (IKS_TAG == iks_type (q)) {
				char *ns;
				ns = iks_find_attrib (q, "xmlns");
				if (ns) {
					pak->query = q;
					pak->ns = ns;
					break;
				}
			}
		}
	}
	return pak;
}