Beispiel #1
0
static int
_iq_handle_discoinfo_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
    void * const userdata)
{
    xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
    const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);

    xmpp_stanza_t *incoming_query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
    const char *node_str = xmpp_stanza_get_attribute(incoming_query, STANZA_ATTR_NODE);

    if (from != NULL) {
        xmpp_stanza_t *response = xmpp_stanza_new(ctx);
        xmpp_stanza_set_name(response, STANZA_NAME_IQ);
        xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza));
        xmpp_stanza_set_attribute(response, STANZA_ATTR_TO, from);
        xmpp_stanza_set_type(response, STANZA_TYPE_RESULT);
        xmpp_stanza_t *query = caps_create_query_response_stanza(ctx);
        if (node_str != NULL) {
            xmpp_stanza_set_attribute(query, STANZA_ATTR_NODE, node_str);
        }
        xmpp_stanza_add_child(response, query);
        xmpp_send(conn, response);

        xmpp_stanza_release(query);
        xmpp_stanza_release(response);
    }

    return 1;
}
Beispiel #2
0
static int
_disco_items_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
    void * const userdata)
{
    xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
    const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
    const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);

    if (id != NULL) {
        log_debug("IQ disco items get handler fired, id: %s.", id);
    } else {
        log_debug("IQ disco items get handler fired.");
    }

    if (from != NULL) {
        xmpp_stanza_t *response = xmpp_stanza_new(ctx);
        xmpp_stanza_set_name(response, STANZA_NAME_IQ);
        xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza));
        xmpp_stanza_set_attribute(response, STANZA_ATTR_TO, from);
        xmpp_stanza_set_type(response, STANZA_TYPE_RESULT);
        xmpp_stanza_t *query = xmpp_stanza_new(ctx);
        xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
        xmpp_stanza_set_ns(query, XMPP_NS_DISCO_ITEMS);
        xmpp_stanza_add_child(response, query);
        xmpp_send(conn, response);

        xmpp_stanza_release(response);
    }

    return 1;
}
Beispiel #3
0
/**
 * This connection handler is called after connection has been etablized.
 * All initial messages can therefore be put here.
 */
static void sdvp_HandleConnection(xmpp_conn_t * const conn,
		const xmpp_conn_event_t status, const int error,
		xmpp_stream_error_t * const stream_error, void * const userdata) {
	xmpp_ctx_t *ctx = (xmpp_ctx_t *) userdata;
	xmpp_stanza_t* pres;
	char packetId[PACKET_ID_LENGTH_INC_TERM];
	if (status == XMPP_CONN_CONNECT) {
		syslog(LOG_DEBUG, "Connected\n");
		xmpp_handler_add(conn, HandleRpcCall, "jabber:iq:rpc", "iq", "get",
				ctx);
		xmpp_handler_add(conn, PresenceHandler, NULL, "presence", NULL, ctx);
		xmpp_handler_add(conn, HandlePing, "urn:xmpp:ping", "iq", "get", ctx);
		xmpp_id_handler_add(conn, HandlePingResult, "ping", ctx);

		// Send initial <presence/> so that we appear online to contacts
		// This is very important as the server don't route messages/iq's if not online!
		//
		pres = xmpp_stanza_new(ctx);
		xmpp_stanza_set_name(pres, "presence");
		_GeneratePacketId(packetId, PACKET_ID_LENGTH_INC_TERM);
		xmpp_stanza_set_id(pres, packetId);
		xmpp_send(conn, pres);
		xmpp_stanza_release(pres);

		// Send request for roaster
		_SendRosterRequest(conn, ctx);
		if (callbackOnConnectionChange != NULL ) {
			callbackOnConnectionChange(SDVP_CONN_CONNECT);
		}
	} else {
		syslog(LOG_WARNING, "conn_handler disconnected\n");
		sdvpIsRunning = false;
		xmpp_stop(ctx);
	}
}
Beispiel #4
0
static void _zkmuc_destroy_room(char *room_jid, xmpp_ua_t *ua)
{
	xmpp_stanza_t *iq = xmpp_stanza_new(_xmpp_ctx);
	
	char id[128];
	xmpp_ua_get_unique_string(ua, id);

	xmpp_stanza_set_name(iq, "iq");
	xmpp_stanza_set_id(iq, id);
	xmpp_stanza_set_type(iq, "set");
	xmpp_stanza_set_attribute(iq, "to", room_jid);
	xmpp_stanza_t *query = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(query, "query");
	xmpp_stanza_set_ns(query, XMPP_NS_MUC_OWNER);

	xmpp_stanza_t *destroy = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(destroy, "destroy");
	xmpp_stanza_set_attribute(destroy, "jid", room_jid);

	xmpp_stanza_add_child(query, destroy);
	xmpp_stanza_release(destroy);
	xmpp_stanza_add_child(iq, query);
	xmpp_stanza_release(query);
	xmpp_ua_id_handler_add(ua, zkmuc_destroy_room_result, id, NULL);
	xmpp_ua_send(ua, iq);
	xmpp_stanza_release(iq);
}
Beispiel #5
0
void
blocking_request(void)
{
    char *id = create_unique_id("blocked_list_request");
    xmpp_ctx_t *ctx = connection_get_ctx();
    xmpp_stanza_t *iq;

    if (blocked) {
        g_list_free_full(blocked, free);
        blocked = NULL;
    }

    if (blocked_ac) {
        autocomplete_free(blocked_ac);
    }
    blocked_ac = autocomplete_new();

    iq_id_handler_add(id, _blocklist_result_handler, NULL, NULL);

    iq = stanza_create_blocked_list_request(ctx);
    xmpp_stanza_set_id(iq, id);
    iq_send_stanza(iq);
    xmpp_stanza_release(iq);
    free(id);
}
Beispiel #6
0
void
bookmark_request(void)
{
    char *id;
    xmpp_conn_t *conn = connection_get_conn();
    xmpp_ctx_t *ctx = connection_get_ctx();
    xmpp_stanza_t *iq;

    id = strdup("bookmark_init_request");

    autojoin_count = 0;
    if (bookmark_ac != NULL) {
        autocomplete_free(bookmark_ac);
    }
    bookmark_ac = autocomplete_new();
    if (bookmark_list != NULL) {
        g_list_free_full(bookmark_list, _bookmark_item_destroy);
        bookmark_list = NULL;
    }

    xmpp_timed_handler_add(conn, _bookmark_handle_delete, BOOKMARK_TIMEOUT, id);
    xmpp_id_handler_add(conn, _bookmark_handle_result, id, id);

    iq = stanza_create_storage_bookmarks(ctx);
    xmpp_stanza_set_id(iq, id);
    xmpp_send(conn, iq);
    xmpp_stanza_release(iq);
}
Beispiel #7
0
/**
 * This is called when someone sends a RPC method call
 * Checks for XML-RPC format validation and sends error if so otherwise it calls the
 * HandleServiceCall for finding the right service and creating the right structures
 * @return KEEP_THIS_HANDLER_ACTIVE
 */
int HandleRpcCall(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
		void * const userdata) {
	xmpp_stanza_t *reply;
	xmpp_stanza_t *xmlRpcReply;
	xmpp_ctx_t *ctx = (xmpp_ctx_t*) userdata;
	sdvp_from_t* from;
	sdvp_reply_params_t* replyParams = NULL;
	int formatInvalid;

	sdvpIdleCounter = 0;
	sdvpPingsSent = 0;

	reply = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(reply, "iq");

	// TODO: Get the Group and get the jid
	from = _CreateFrom(xmpp_stanza_get_attribute(stanza, "from"), "TODO",
			"TODO");

	syslog(LOG_DEBUG, "Received a RPC Method call from %s\n", from->name);

	formatInvalid = _CheckRpcFormat(stanza);
	if (formatInvalid) {
	    // FIXME: Something here fails!
		syslog(LOG_WARNING, "Error in XML-RPC format\n");
		sdvp_InitiateReplyParameters(&replyParams, 1);
		replyParams->params[0].strValue = strdup("Error in XML-RPC format\n");
		replyParams->params[0].type = IEC_VISIBLE_STRING;
		xmpp_stanza_set_type(reply, "error");
		// TODO: Create a type

		//HJP var her!
		xmlRpcReply = _CreateReply(ctx, SDVP_METHOD_UNDEFINED ,replyParams);
		xmpp_stanza_add_child(reply, xmlRpcReply);
		//HJP: stanza_add_child laver en kopi, så der skal releases
		xmpp_stanza_release(xmlRpcReply);
		sdvp_FreeReplyParameters(replyParams);
	} else {
		// The reply from this function should be ready to send
		xmlRpcReply = _HandleServiceRequest(conn, stanza, userdata);
		xmpp_stanza_add_child(reply, xmlRpcReply);
		//HJP: stanza_add_child laver en kopi, så der skal releases
		xmpp_stanza_release(xmlRpcReply);
	}

	xmpp_stanza_set_id(reply, xmpp_stanza_get_id(stanza));
	xmpp_stanza_set_attribute(reply, "to",
			xmpp_stanza_get_attribute(stanza, "from"));
	xmpp_stanza_set_type(reply, "result");

	xmpp_send(conn, reply);
	xmpp_stanza_release(reply); // Frees the stanza and all of its children

	_FreeFrom(from);

	return KEEP_THIS_HANDLER_ACTIVE;
}
Beispiel #8
0
void
mood_publish(mood_callback_t callback, const char * const usermood,
    const char * const usertext)
{
	xmpp_stanza_t *iq, *pubsub, *publish, *item, *mood, *stanza, *text;

	iq = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(iq, "iq");
	xmpp_stanza_set_type(iq, "set");
	xmpp_stanza_set_id(iq, "mood1");	/* FIXME */

	pubsub = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(pubsub, "pubsub");
	xmpp_stanza_set_ns(pubsub, NS_PUBSUB);
	xmpp_stanza_add_child(iq, pubsub);
	xmpp_stanza_release(pubsub);

	publish = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(publish, "publish");
	xmpp_stanza_set_attribute(publish, "node", NS_MOOD);
	xmpp_stanza_add_child(pubsub, publish);
	xmpp_stanza_release(publish);

	item = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(item, "item");
	xmpp_stanza_add_child(publish, item);
	xmpp_stanza_release(item);

	mood = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(mood, "mood");
	xmpp_stanza_set_ns(mood, NS_MOOD);
	xmpp_stanza_add_child(item, mood);
	xmpp_stanza_release(mood);

	if (usermood != NULL) {
		stanza = xmpp_stanza_new(ctx);
		xmpp_stanza_set_name(stanza, usermood);
		xmpp_stanza_add_child(mood, stanza);
		xmpp_stanza_release(stanza);
	}

	if (usertext != NULL) {
		text = xmpp_stanza_new(ctx);
		xmpp_stanza_set_name(text, "text");
		xmpp_stanza_set_text(text, usertext);
		xmpp_stanza_add_child(mood, text);
		xmpp_stanza_release(text);
	}

	xmpp_id_handler_add(conn, mood_result_handler,
	    xmpp_stanza_get_id(iq), callback);

	xmpp_send(conn, iq);
	xmpp_stanza_release(iq);
}
Beispiel #9
0
static int alarmqueue_handler(xmpp_conn_t * const conn, void * const userdata)
{
    conflate_handle_t *handle = (conflate_handle_t*) userdata;
    alarm_t alarm;
    const char* myjid = xmpp_conn_get_bound_jid(conn);
    char id[262];
    char open[2] = { 0, 0 };
    char amsg[256];
    char body[1500];
    char num[255];
    while (handle->alarms->size > 0)
        {
            alarm = get_alarm(handle->alarms);
            open[0] = alarm.open ? '1' : '2';
            snprintf(amsg, sizeof(amsg), "%s", alarm.msg);
            /* if we got a legitimate alarm, send off alert */
            if(alarm.open == 1)
                {
                    snprintf(id, sizeof(id), "_alarm%d", alarm.num);
                    //handler_add_id(conn, alarm_response_handler, id, handle);
                    //handler_add_timed(conn, alarm_missing_handler, 120000, handle);
                    xmpp_stanza_t* msg = xmpp_stanza_new(handle->ctx);
                    assert(msg);
                    xmpp_stanza_set_name(msg, "message");
                    //xmpp_stanza_set_type(iq, "set");
                    xmpp_stanza_set_id(msg, id);
                    //xmpp_stanza_set_attribute(iq, "to", xmpp_stanza_get_attribute(stanza, "from"));
                    /* TODO: This needs to have a config on where to report to */
                    xmpp_stanza_set_attribute(msg, "to", "*****@*****.**");
                    xmpp_stanza_set_attribute(msg, "from", myjid);

                    xmpp_stanza_t* mbody = xmpp_stanza_new(handle->ctx);
                    assert(mbody);
                    xmpp_stanza_set_name(mbody, "body");
                    snprintf(body, sizeof(body), "Alert\n%s", amsg);
                    snprintf(num, sizeof(num), "%d", alarm.num);
                    xmpp_stanza_set_text(mbody, body);
                    add_and_release(msg, mbody);

                    xmpp_stanza_t* alert = xmpp_stanza_new(handle->ctx);
                    assert(alert);
                    xmpp_stanza_set_name(alert, "alert");
                    xmpp_stanza_set_attribute(alert, "xmlns", "http://northscale.net/protocol/alerts");
                    xmpp_stanza_set_attribute(alert, "open", open);
                    xmpp_stanza_set_attribute(alert, "msg", amsg);
                    xmpp_stanza_set_attribute(alert, "num", num);
                    xmpp_stanza_set_attribute(alert, "name", alarm.name);
                    add_and_release(msg, alert);

                    xmpp_send(conn, msg);
                    xmpp_stanza_release(msg);
                }
        }
    return 1;
}
Beispiel #10
0
void XMPP_IBB_SendPayload(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, 
void * const userdata, char* resp )
{

    static int seq = 0;
    int data_seq = 0;
    char Data_Seq_Buf[32];
    char ID_Buf[32];
    char* encoded_data;
    xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
    xmpp_stanza_t *iq, *data,  *text;

    iq  = xmpp_stanza_new(ctx);
    data = xmpp_stanza_new(ctx);
    text = xmpp_stanza_new(ctx);

    xmpp_stanza_set_name(iq, "iq");
    xmpp_stanza_set_type(iq, "set");

    sprintf(ID_Buf, "ID-seq-%d", seq);
    seq++;
    xmpp_stanza_set_id(iq, ID_Buf);
    xmpp_stanza_set_attribute(iq, "to", xmpp_stanza_get_attribute(stanza, "from"));
    xmpp_stanza_set_attribute(iq, "from", xmpp_stanza_get_attribute(stanza, "to"));

    xmpp_stanza_set_name(data, "data");

    xmpp_stanza_set_ns(data, XMLNS_IBB);

    xmpp_stanza_set_attribute(data, "sid",   \
    xmpp_stanza_get_attribute(xmpp_stanza_get_child_by_name(stanza, "data"), "sid"));
  
    sprintf(Data_Seq_Buf , "%d", data_seq);
    xmpp_stanza_set_attribute(data, "seq", Data_Seq_Buf);
       
    printf("\n[Response =%s]\n", resp);
    encoded_data = base64_encode(ctx, (unsigned char*)resp, strlen(resp));

    xmpp_stanza_set_text_with_size(text, encoded_data, strlen(encoded_data));
    xmpp_stanza_add_child(data, text);
    xmpp_stanza_add_child(iq, data);
    xmpp_send(conn, iq);
    seq++;

    free(resp);
    xmpp_free(ctx, encoded_data);

    xmpp_stanza_release(data);
    xmpp_stanza_release(iq);
    xmpp_stanza_release(text);

    xmpp_stanza_release(stanza);  //copied by IBB IQ receiver handler

}
Beispiel #11
0
static int _zkmuc_source_query(xmpp_ua_t *ua, xmpp_stanza_t *stanza, void *userdata)
{
	zkmuc_ctx_t *ctx = (zkmuc_ctx_t *)userdata;
	char *from = xmpp_stanza_get_attribute(stanza, "from");
	char *id = xmpp_stanza_get_id(stanza);
	if (id == NULL)
	{
		return 0;
	}
	xmpp_stanza_t *x = xmpp_stanza_get_child_by_name(stanza, "x");
	if(x && xmpp_stanza_get_ns(x) && !strcmp(XMPP_NS_SOURCE, xmpp_stanza_get_ns(x)))
	{
		char *action = xmpp_stanza_get_attribute(x, "action");
		if (!strcmp("query", action))	
		{
			xmpp_stanza_t *message = xmpp_stanza_new(_xmpp_ctx);
			xmpp_stanza_set_name(message, "message");
			xmpp_stanza_set_attribute(message, "to", from);
			xmpp_stanza_set_id(message, id);

			xmpp_stanza_t *result_x = xmpp_stanza_new(_xmpp_ctx);
			xmpp_stanza_set_name(result_x, "x");
			xmpp_stanza_set_ns(result_x, XMPP_NS_SOURCE);
			xmpp_stanza_set_attribute(result_x, "action", "result");

			WaitForSingleObject(ctx->_mutex_4_source, INFINITE);
			zkmuc_source_t *item = ctx->head;
			while (item)
			{
				xmpp_stanza_t *stanza_item = xmpp_stanza_new(_xmpp_ctx);
				xmpp_stanza_set_name(stanza_item, "item");
				char buf[32];
				xmpp_stanza_set_attribute(stanza_item, "cid", itoa(item->cid, buf, 10));
				xmpp_stanza_set_attribute(stanza_item, "sid", itoa(item->sid, buf, 10));
				xmpp_stanza_set_attribute(stanza_item, "desc", item->description);
				xmpp_stanza_set_attribute(stanza_item, "mcu", item->mcu);
				xmpp_stanza_add_child(result_x, stanza_item);
				xmpp_stanza_release(stanza_item);

				item = item->next;
			}
			ReleaseMutex(ctx->_mutex_4_source);
			xmpp_stanza_add_child(message, result_x);
			xmpp_stanza_release(result_x);
			xmpp_ua_send(ctx->ua, message);
			xmpp_stanza_release(message);

			return 1;
		}
	}
	return 0;
}
Beispiel #12
0
void XMPP_IBB_Ack_Send(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata)
{
    xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
    xmpp_stanza_t *iq;

    iq  = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(iq, "iq");
    xmpp_stanza_set_type(iq, "result");

    xmpp_stanza_set_id(iq, xmpp_stanza_get_attribute(stanza, "id"));
    xmpp_stanza_set_attribute(iq, "to", xmpp_stanza_get_attribute(stanza, "from"));
    xmpp_stanza_set_attribute(iq, "from", xmpp_stanza_get_attribute(stanza, "to"));
    xmpp_send(conn, iq);
    xmpp_stanza_release(iq);
}
Beispiel #13
0
/* Create an IQ response */
static xmpp_stanza_t* create_reply(xmpp_ctx_t* ctx, xmpp_stanza_t* stanza)
{
    xmpp_stanza_t* reply = xmpp_stanza_new(ctx);

    assert(reply);

    xmpp_stanza_set_name(reply, "iq");
    xmpp_stanza_set_type(reply, "result");
    if (xmpp_stanza_get_id(stanza)) {
        xmpp_stanza_set_id(reply, xmpp_stanza_get_id(stanza));
    }
    xmpp_stanza_set_attribute(reply, "to",
                              xmpp_stanza_get_attribute(stanza, "from"));

    return reply;
}
Beispiel #14
0
static void zkmuc_unlock_room(zkmuc_ctx_t *ctx)
{
	xmpp_stanza_t *iq = xmpp_stanza_new(_xmpp_ctx);
	char id[128];
	xmpp_ua_get_unique_string(ctx->ua, id);

	xmpp_stanza_set_name(iq, "iq");
	xmpp_stanza_set_id(iq, id);
	xmpp_stanza_set_type(iq, "set");
	xmpp_stanza_set_attribute(iq, "to", ctx->room_id);

	xmpp_stanza_t *query = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(query, "query");
	xmpp_stanza_set_ns(query, XMPP_NS_MUC_OWNER);

	xmpp_stanza_t *x = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(x, "x");
	xmpp_stanza_set_ns(x, XMPP_NS_X);
	xmpp_stanza_set_type(x, "submit");

	xmpp_stanza_t *field = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(field, "field");
	xmpp_stanza_set_attribute(field, "var", "muc#roomconfig_roomname");

	xmpp_stanza_t *stanza_value = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(stanza_value, "value");

	xmpp_stanza_t *stanza_text = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_text(stanza_text, ctx->room_desc);
	xmpp_stanza_add_child(stanza_value, stanza_text);
	xmpp_stanza_release(stanza_text);

	xmpp_stanza_add_child(field, stanza_value);
	xmpp_stanza_release(stanza_value);

	xmpp_stanza_add_child(x, field);
	xmpp_stanza_release(field);

	xmpp_stanza_add_child(query, x);
	xmpp_stanza_release(x);
	xmpp_stanza_add_child(iq, query);
	xmpp_stanza_release(query);

	xmpp_ua_id_handler_add(ctx->ua, zkmuc_unlock_room_result, id, ctx);
	xmpp_ua_send(ctx->ua, iq);
	xmpp_stanza_release(iq);
}
Beispiel #15
0
static void
_presence_update(const resource_presence_t presence_type, const char * const msg,
    const int idle)
{
    if (jabber_get_connection_status() != JABBER_CONNECTED) {
        log_warning("Error setting presence, not connected.");
        return;
    }

    if (msg != NULL) {
        log_debug("Updating presence: %s, \"%s\"",
            string_from_resource_presence(presence_type), msg);
    } else {
        log_debug("Updating presence: %s",
            string_from_resource_presence(presence_type));
    }

    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_conn_t * const conn = connection_get_conn();
    const int pri =
        accounts_get_priority_for_presence_type(jabber_get_account_name(),
                                                presence_type);
    const char *show = stanza_get_presence_string_from_type(presence_type);

    connection_set_presence_message(msg);
    connection_set_priority(pri);

    xmpp_stanza_t *presence = stanza_create_presence(ctx);
    char *id = create_unique_id("presence");
    xmpp_stanza_set_id(presence, id);
    stanza_attach_show(ctx, presence, show);
    stanza_attach_status(ctx, presence, msg);
    stanza_attach_priority(ctx, presence, pri);
    stanza_attach_last_activity(ctx, presence, idle);
    stanza_attach_caps(ctx, presence);
    xmpp_send(conn, presence);
    _send_room_presence(conn, presence);
    xmpp_stanza_release(presence);

    // set last presence for account
    const char *last = show;
    if (last == NULL) {
        last = STANZA_TEXT_ONLINE;
    }
    accounts_set_last_presence(jabber_get_account_name(), last);
    free(id);
}
Beispiel #16
0
xmpp_ibb_session_t *xmpp_ibb_open(xmpp_conn_t * const conn, char * const peer, char * const sid)
{
    xmpp_ibb_session_t *sess;
    xmpp_stanza_t *iq, *open;
    xmpp_ctx_t *ctx;
    const char *jid = xmpp_conn_get_bound_jid(conn);
    char sizetemp[6] = "";
    int size;

    if (peer == NULL || strlen(peer) == 0) {
        return NULL;
    }
    sess = _ibb_session_init(conn, peer, sid);
    if (sess == NULL) {
        return NULL;
    }
    size = snprintf(sizetemp, sizeof(sizetemp), "%d", sess->block_size);
    if (size < sizeof(sizetemp)) {
        sizetemp[size] = '\0';
    }
    nmtoken_generate(sess->id, 8);

    ctx = xmpp_conn_get_context(conn);
    iq = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(iq, "iq");
    xmpp_stanza_set_type(iq, "set");
    xmpp_stanza_set_id(iq, sess->id);
    xmpp_stanza_set_attribute(iq, "from", jid);
    xmpp_stanza_set_attribute(iq, "to", sess->peer);

    open = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(open, "open");
    xmpp_stanza_set_ns(open, XMLNS_IBB);
    xmpp_stanza_set_attribute(open, "block-size", sizetemp);
    xmpp_stanza_set_attribute(open, "sid", sess->sid);
    xmpp_stanza_set_attribute(open, "stanza", "iq");

    xmpp_stanza_add_child(iq, open);
    xmpp_send(conn, iq);
    xmpp_stanza_release(open);
    xmpp_stanza_release(iq);

    ilist_add(g_list, sess);

    return sess;
}
Beispiel #17
0
xmpp_stanza_t *
stanza_create_roster_iq(xmpp_ctx_t *ctx)
{
    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
    xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
    xmpp_stanza_set_id(iq, "roster");

    xmpp_stanza_t *query = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
    xmpp_stanza_set_ns(query, XMPP_NS_ROSTER);

    xmpp_stanza_add_child(iq, query);
    xmpp_stanza_release(query);

    return iq;
}
Beispiel #18
0
void
presence_subscription(const char *const jid, const jabber_subscr_t action)
{
    assert(jid != NULL);

    Jid *jidp = jid_create(jid);
    autocomplete_remove(sub_requests_ac, jidp->barejid);

    const char *type = NULL;
    switch (action)
    {
        case PRESENCE_SUBSCRIBE:
            log_debug("Sending presence subscribe: %s", jid);
            type = STANZA_TYPE_SUBSCRIBE;
            break;
        case PRESENCE_SUBSCRIBED:
            log_debug("Sending presence subscribed: %s", jid);
            type = STANZA_TYPE_SUBSCRIBED;
            break;
        case PRESENCE_UNSUBSCRIBED:
            log_debug("Sending presence usubscribed: %s", jid);
            type = STANZA_TYPE_UNSUBSCRIBED;
            break;
        default:
            break;
    }
    if (!type) {
        log_error("Attempt to send unknown subscription action: %s", jid);
        return;
    }

    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *presence = xmpp_presence_new(ctx);

    char *id = create_unique_id("sub");
    xmpp_stanza_set_id(presence, id);
    free(id);

    xmpp_stanza_set_type(presence, type);
    xmpp_stanza_set_to(presence, jidp->barejid);
    jid_destroy(jidp);

    _send_presence_stanza(presence);

    xmpp_stanza_release(presence);
}
Beispiel #19
0
xmpp_stanza_t *
stanza_create_ping_iq(xmpp_ctx_t *ctx)
{
    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
    xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
    xmpp_stanza_set_id(iq, "c2s1");

    xmpp_stanza_t *ping = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(ping, STANZA_NAME_PING);

    xmpp_stanza_set_ns(ping, STANZA_NS_PING);

    xmpp_stanza_add_child(iq, ping);
    xmpp_stanza_release(ping);

    return iq;
}
Beispiel #20
0
static void
_presence_subscription(const char * const jid, const jabber_subscr_t action)
{
    assert(jid != NULL);

    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_conn_t * const conn = connection_get_conn();
    const char *type = NULL;

    Jid *jidp = jid_create(jid);

    autocomplete_remove(sub_requests_ac, jidp->barejid);

    switch (action)
    {
        case PRESENCE_SUBSCRIBE:
            log_debug("Sending presence subscribe: %s", jid);
            type = STANZA_TYPE_SUBSCRIBE;
            break;
        case PRESENCE_SUBSCRIBED:
            log_debug("Sending presence subscribed: %s", jid);
            type = STANZA_TYPE_SUBSCRIBED;
            break;
        case PRESENCE_UNSUBSCRIBED:
            log_debug("Sending presence usubscribed: %s", jid);
            type = STANZA_TYPE_UNSUBSCRIBED;
            break;
        default:
            log_warning("Attempt to send unknown subscription action: %s", jid);
            break;
    }

    xmpp_stanza_t *presence = xmpp_stanza_new(ctx);
    char *id = create_unique_id("sub");
    xmpp_stanza_set_id(presence, id);
    xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE);
    xmpp_stanza_set_type(presence, type);
    xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, jidp->barejid);
    xmpp_send(conn, presence);
    xmpp_stanza_release(presence);

    jid_destroy(jidp);
    free(id);
}
Beispiel #21
0
int version_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata)
{
    xmpp_stanza_t *reply, *query, *name, *version, *text;
    char *ns;
    xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata;
    printf("Received version request from %s\n", xmpp_stanza_get_attribute(stanza, "from"));

    reply = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(reply, "iq");
    xmpp_stanza_set_type(reply, "result");
    xmpp_stanza_set_id(reply, xmpp_stanza_get_id(stanza));
    xmpp_stanza_set_attribute(reply, "to", xmpp_stanza_get_attribute(stanza, "from"));

    query = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(query, "query");
    ns = xmpp_stanza_get_ns(xmpp_stanza_get_children(stanza));
    if (ns) {
        xmpp_stanza_set_ns(query, ns);
    }

    name = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(name, "name");
    xmpp_stanza_add_child(query, name);

    text = xmpp_stanza_new(ctx);
    xmpp_stanza_set_text(text, "libstrophe example bot");
    xmpp_stanza_add_child(name, text);

    version = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(version, "version");
    xmpp_stanza_add_child(query, version);

    text = xmpp_stanza_new(ctx);
    xmpp_stanza_set_text(text, "1.0");
    xmpp_stanza_add_child(version, text);

    xmpp_stanza_add_child(reply, query);

    xmpp_send(conn, reply);
    xmpp_stanza_release(reply);
    return 1;
}
Beispiel #22
0
void
bookmark_request(void)
{
    if (bookmarks) {
        g_hash_table_destroy(bookmarks);
    }
    bookmarks = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_bookmark_destroy);

    autocomplete_free(bookmark_ac);
    bookmark_ac = autocomplete_new();

    char *id = "bookmark_init_request";
    iq_id_handler_add(id, _bookmark_result_id_handler, free, NULL);

    xmpp_ctx_t *ctx = connection_get_ctx();
    xmpp_stanza_t *iq = stanza_create_bookmarks_storage_request(ctx);
    xmpp_stanza_set_id(iq, id);

    iq_send_stanza(iq);
    xmpp_stanza_release(iq);
}
Beispiel #23
0
void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status, 
		  const int error, xmpp_stream_error_t * const stream_error,
		  void * const userdata)
{
    xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
    xmpp_stanza_t *iq, *query;

    if (status == XMPP_CONN_CONNECT) {
	fprintf(stderr, "DEBUG: connected\n");
	
	/* create iq stanza for request */
	iq = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(iq, "iq");
	xmpp_stanza_set_type(iq, "get");
	xmpp_stanza_set_id(iq, "active1");
	xmpp_stanza_set_attribute(iq, "to", "xxxxxxxxx.com");

	query = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(query, "query");
	xmpp_stanza_set_ns(query, XMPP_NS_DISCO_ITEMS);
	xmpp_stanza_set_attribute(query, "node", "sessions");

	xmpp_stanza_add_child(iq, query);

	/* we can release the stanza since it belongs to iq now */
	xmpp_stanza_release(query);

	/* set up reply handler */
	xmpp_id_handler_add(conn, handle_reply, "active1", ctx);

	/* send out the stanza */
	xmpp_send(conn, iq);

	/* release the stanza */
	xmpp_stanza_release(iq);
    } else {
	fprintf(stderr, "DEBUG: disconnected\n");
	xmpp_stop(ctx);
    }
}
Beispiel #24
0
int xmpp_ibb_close(xmpp_ibb_session_t *sess)
{
    xmpp_stanza_t *iq, *close;
    xmpp_ctx_t *ctx;
    const char *jid;

    if (sess == NULL) { return -1; }

    if (!ilist_foundinlist(g_list, sess)) {
        fprintf(stderr, "session is not in handle, may be closed.\n");
        return -1;
    }

    jid = xmpp_conn_get_bound_jid(sess->conn);
    ctx = xmpp_conn_get_context(sess->conn);

    iq = xmpp_stanza_new(ctx);
    close = xmpp_stanza_new(ctx);
    nmtoken_generate(sess->id, 8);

    xmpp_stanza_set_name(iq, "iq");
    xmpp_stanza_set_type(iq, "set");
    xmpp_stanza_set_id(iq, sess->id);
    xmpp_stanza_set_attribute(iq, "to", sess->peer);
    xmpp_stanza_set_attribute(iq, "from", jid);

    xmpp_stanza_set_name(close, "close");
    xmpp_stanza_set_ns(close, XMLNS_IBB);
    xmpp_stanza_set_attribute(close, "sid", sess->sid);

    xmpp_stanza_add_child(iq, close);
    xmpp_send(sess->conn, iq);
    xmpp_stanza_release(close);
    xmpp_stanza_release(iq);

    sess->state = STATE_CLOSING;

    return 0;
}
Beispiel #25
0
static int _SendRosterRequest(xmpp_conn_t * const conn, xmpp_ctx_t *ctx) {
	xmpp_stanza_t *roaster, *roaster_qry;
	char packetId[PACKET_ID_LENGTH_INC_TERM];
	_GeneratePacketId(packetId, PACKET_ID_LENGTH_INC_TERM);
	roaster = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(roaster, "iq");
	xmpp_stanza_set_type(roaster, "get");
	xmpp_stanza_set_id(roaster, packetId);
	roaster_qry = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(roaster_qry, "query");
	xmpp_stanza_set_ns(roaster_qry, XMPP_NS_ROSTER);
	xmpp_stanza_add_child(roaster, roaster_qry);
// we can release the stanza since it belongs to sr_iq now
	xmpp_stanza_release(roaster_qry);
// set up reply handler
	xmpp_handler_add(conn, _HandleRosterReply, "jabber:iq:roster", NULL, NULL,
			ctx);
	xmpp_send(conn, roaster);
	xmpp_stanza_release(roaster);

	return 0;
}
Beispiel #26
0
static void sdvpSendPing( xmpp_conn_t * const conn, xmpp_ctx_t * const ctx) {

	xmpp_stanza_t *iq,*ping;
	
	iq = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(iq, "iq");
	xmpp_stanza_set_type(iq, "get");
	xmpp_stanza_set_id(iq, "ping");

	ping = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(ping, "ping");
	xmpp_stanza_set_ns(ping, "urn:xmpp:ping");
	xmpp_stanza_add_child(iq,ping);
	xmpp_stanza_release(ping);

	xmpp_send(conn,iq);
	xmpp_stanza_release(iq);

	sdvpIdleCounter = 0;
	sdvpPingsSent++;

}
Beispiel #27
0
gboolean
blocked_remove(char *jid)
{
    GList *found = g_list_find_custom(blocked, jid, (GCompareFunc)g_strcmp0);
    if (!found) {
        return FALSE;
    }

    xmpp_ctx_t *ctx = connection_get_ctx();

    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
    xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
    char *id = create_unique_id("unblock");
    xmpp_stanza_set_id(iq, id);

    xmpp_stanza_t *block = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(block, STANZA_NAME_UNBLOCK);
    xmpp_stanza_set_ns(block, STANZA_NS_BLOCKING);

    xmpp_stanza_t *item = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(item, STANZA_NAME_ITEM);
    xmpp_stanza_set_attribute(item, STANZA_ATTR_JID, jid);

    xmpp_stanza_add_child(block, item);
    xmpp_stanza_release(item);

    xmpp_stanza_add_child(iq, block);
    xmpp_stanza_release(block);

    iq_id_handler_add(id, _block_remove_result_handler, free, strdup(jid));

    iq_send_stanza(iq);
    xmpp_stanza_release(iq);
    free(id);

    return TRUE;
}
Beispiel #28
0
static int disco_items_handler(xmpp_conn_t * const conn,
                               xmpp_stanza_t * const stanza,
                               void * const userdata)
{
    xmpp_stanza_t *reply, *query;
    const char* myjid = xmpp_conn_get_bound_jid(conn);
    conflate_handle_t *handle = (conflate_handle_t*) userdata;

    assert(conn);
    assert(myjid);
    assert(stanza);
    assert(userdata);

    reply = xmpp_stanza_new(handle->ctx);
    assert(reply);
    xmpp_stanza_set_name(reply, "iq");
    xmpp_stanza_set_type(reply, "result");
    xmpp_stanza_set_id(reply, xmpp_stanza_get_id(stanza));
    xmpp_stanza_set_attribute(reply, "to",
                              xmpp_stanza_get_attribute(stanza, "from"));
    xmpp_stanza_set_attribute(reply, "from", myjid);

    query = xmpp_stanza_new(handle->ctx);
    assert(query);
    xmpp_stanza_set_name(query, "query");
    xmpp_stanza_set_attribute(query, "xmlns", XMPP_NS_DISCO_ITEMS);
    xmpp_stanza_set_attribute(query, "node", "http://jabber.org/protocol/commands");
    add_and_release(reply, query);

    for (struct command_def *p = commands; p; p = p->next) {
        add_disco_item(handle->ctx, query, myjid, p->name, p->description);
    }

    xmpp_send(conn, reply);
    xmpp_stanza_release(reply);

    return 1;
}
Beispiel #29
0
static xmpp_stanza_t *
_stanza_new_with_attrs(xmpp_ctx_t *ctx, const char * const name,
                       const char * const type, const char * const id,
                       const char * const to)
{
    xmpp_stanza_t *stanza = xmpp_stanza_new(ctx);
    int ret;

    if (stanza) {
        ret = xmpp_stanza_set_name(stanza, name);
        if (ret == XMPP_EOK && type)
            ret = xmpp_stanza_set_type(stanza, type);
        if (ret == XMPP_EOK && id)
            ret = xmpp_stanza_set_id(stanza, id);
        if (ret == XMPP_EOK && to)
            ret = xmpp_stanza_set_to(stanza, to);
        if (ret != XMPP_EOK) {
            xmpp_stanza_release(stanza);
            stanza = NULL;
        }
    }
    return stanza;
}
Beispiel #30
0
void
_message_send_receipt(const char *const fulljid, const char *const message_id)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *message = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(message, STANZA_NAME_MESSAGE);
    char *id = create_unique_id("receipt");
    xmpp_stanza_set_id(message, id);
    free(id);
    xmpp_stanza_set_attribute(message, STANZA_ATTR_TO, fulljid);

    xmpp_stanza_t *receipt = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(receipt, "received");
    xmpp_stanza_set_ns(receipt, STANZA_NS_RECEIPTS);
    xmpp_stanza_set_attribute(receipt, STANZA_ATTR_ID, message_id);

    xmpp_stanza_add_child(message, receipt);
    xmpp_stanza_release(receipt);

    xmpp_send(conn, message);
    xmpp_stanza_release(message);
}