Example #1
0
/**
 * lm_message_new:
 * @to: receipient jid
 * @type: message type
 * 
 * Creates a new #LmMessage which can be sent with lm_connection_send() or 
 * lm_connection_send_with_reply(). If @to is %NULL the message is sent to the
 * server. The returned message should be unreferenced with lm_message_unref() 
 * when caller is finished with it.
 * 
 * Return value: a newly created #LmMessage
 **/
LmMessage *
lm_message_new (const gchar *to, LmMessageType type)
{
    LmMessage *m;
    gchar     *id;

    m       = g_new0 (LmMessage, 1);
    m->priv = g_new0 (LmMessagePriv, 1);

    PRIV(m)->ref_count = 1;
    PRIV(m)->type      = type;
    PRIV(m)->sub_type  = message_sub_type_when_unset (type);
    
    m->node = _lm_message_node_new (_lm_message_type_to_string (type));

    if (type != LM_MESSAGE_TYPE_STREAM) {
        id = _lm_utils_generate_id ();
        lm_message_node_set_attribute (m->node, "id", id);
        g_free (id);
    }

    if (to) {
        lm_message_node_set_attribute (m->node, "to", to);
    }

    if (type == LM_MESSAGE_TYPE_IQ) {
        lm_message_node_set_attribute (m->node, "type", "get");
    }
    
    return m;
}
Example #2
0
static void
parser_start_node_cb (GMarkupParseContext  *context,
                      const gchar          *node_name,
                      const gchar         **attribute_names,
                      const gchar         **attribute_values,
                      gpointer              user_data,
                      GError              **error)
{
    LmParser     *parser;
    gint          i;
    const gchar  *node_name_unq;
    const gchar  *xmlns = NULL;

    parser = LM_PARSER (user_data);;


/*  parser->cur_depth++; */

    //strip namespace prefix other than "stream:" from node_name
    node_name_unq = strrchr(node_name, ':');
    if (!node_name_unq || !strncmp(node_name, "stream:", 7))
        node_name_unq = node_name;
    else
        ++node_name_unq;

    if (!parser->cur_root) {
        /* New toplevel element */
        parser->cur_root = _lm_message_node_new (node_name_unq);
        parser->cur_node = parser->cur_root;
    } else {
        LmMessageNode *parent_node;

        parent_node = parser->cur_node;

        parser->cur_node = _lm_message_node_new (node_name_unq);
        _lm_message_node_add_child_node (parent_node,
                                         parser->cur_node);
    }

    for (i = 0; attribute_names[i]; ++i) {
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_PARSER,
               "ATTRIBUTE: %s = %s\n",
               attribute_names[i],
               attribute_values[i]);
        //FIXME: strip namespace suffix from xmlns: attribute if exists

        lm_message_node_set_attributes (parser->cur_node,
                                        attribute_names[i],
                                        attribute_values[i],
                                        NULL);
        if (!strncmp(attribute_names[i], "xmlns:", 6))
            xmlns = attribute_values[i];
    }
    if (xmlns && !lm_message_node_get_attribute(parser->cur_node, "xmlns")) {
        lm_message_node_set_attribute (parser->cur_node, "xmlns", xmlns);
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_PARSER,
               "ATTRIBUTE: %s = %s\n",
               "xmlns", xmlns);
    }

    if (strcmp ("stream:stream", node_name) == 0) {
        parser_end_node_cb (context,
                            "stream:stream",
                            user_data,
                            error);
    }
}