Пример #1
0
char*
message_send_chat_pgp(const char *const barejid, const char *const msg)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();

    char *state = _session_state(barejid);
    char *jid = _session_jid(barejid);
    char *id = create_unique_id("msg");

    xmpp_stanza_t *message = NULL;
#ifdef HAVE_LIBGPGME
    char *account_name = jabber_get_account_name();
    ProfAccount *account = accounts_get_account(account_name);
    if (account->pgp_keyid) {
        Jid *jidp = jid_create(jid);
        char *encrypted = p_gpg_encrypt(jidp->barejid, msg);
        if (encrypted) {
            message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, "This message is encrypted.");
            xmpp_stanza_t *x = xmpp_stanza_new(ctx);
            xmpp_stanza_set_name(x, STANZA_NAME_X);
            xmpp_stanza_set_ns(x, STANZA_NS_ENCRYPTED);
            xmpp_stanza_t *enc_st = xmpp_stanza_new(ctx);
            xmpp_stanza_set_text(enc_st, encrypted);
            xmpp_stanza_add_child(x, enc_st);
            xmpp_stanza_release(enc_st);
            xmpp_stanza_add_child(message, x);
            xmpp_stanza_release(x);
            free(encrypted);
        } else {
            message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg);
        }
        jid_destroy(jidp);
    } else {
        message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg);
    }
    account_free(account);
#else
    message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg);
#endif
    free(jid);

    if (state) {
        stanza_attach_state(ctx, message, state);
    }

    stanza_attach_carbons_private(ctx, message);

    if (prefs_get_boolean(PREF_RECEIPTS_REQUEST)) {
        stanza_attach_receipt_request(ctx, message);
    }

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

    return id;
}
Пример #2
0
static void
_iq_disco_items_request(gchar *jid)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *iq = stanza_create_disco_items_iq(ctx, "discoitemsreq", jid);
    xmpp_send(conn, iq);
    xmpp_stanza_release(iq);
}
Пример #3
0
void
message_send_gone(const char *const jid)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, jid, STANZA_NAME_GONE);
    xmpp_send(conn, stanza);
    xmpp_stanza_release(stanza);
}
Пример #4
0
static void
_iq_send_software_version(const char * const fulljid)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *iq = stanza_create_software_version_iq(ctx, fulljid);
    xmpp_send(conn, iq);
    xmpp_stanza_release(iq);
}
Пример #5
0
static void
_iq_room_config_cancel(const char * const room_jid)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *iq = stanza_create_room_config_cancel_iq(ctx, room_jid);
    xmpp_send(conn, iq);
    xmpp_stanza_release(iq);
}
Пример #6
0
static void
_roster_send_add_new(const char * const barejid, const char * const name)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *iq = stanza_create_roster_set(ctx, NULL, barejid, name, NULL);
    xmpp_send(conn, iq);
    xmpp_stanza_release(iq);
}
Пример #7
0
void
roster_request(void)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *iq = stanza_create_roster_iq(ctx);
    xmpp_send(conn, iq);
    xmpp_stanza_release(iq);
}
Пример #8
0
static void
_iq_confirm_instant_room(const char * const room_jid)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *iq = stanza_create_instant_room_request_iq(ctx, room_jid);
    xmpp_send(conn, iq);
    xmpp_stanza_release(iq);
}
Пример #9
0
void
roster_send_remove(const char * const barejid)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *iq = stanza_create_roster_remove_set(ctx, barejid);
    xmpp_send(conn, iq);
    xmpp_stanza_release(iq);
}
Пример #10
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;
}
Пример #11
0
static void
_iq_room_list_request(gchar *conferencejid)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *iq = stanza_create_disco_items_iq(ctx, "confreq", conferencejid);
    xmpp_send(conn, iq);
    xmpp_stanza_release(iq);
}
Пример #12
0
void
roster_send_name_change(const char * const barejid, const char * const new_name, GSList *groups)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *iq = stanza_create_roster_set(ctx, NULL, barejid, new_name,
        groups);
    xmpp_send(conn, iq);
    xmpp_stanza_release(iq);
}
Пример #13
0
void
message_send_groupchat_subject(const char *const roomjid, const char *const subject)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *message = stanza_create_room_subject_message(ctx, roomjid, subject);

    xmpp_send(conn, message);
    xmpp_stanza_release(message);
}
Пример #14
0
/* handle the challenge phase of digest auth */
static int _handle_digestmd5_challenge(xmpp_conn_t * const conn,
			      xmpp_stanza_t * const stanza,
			      void * const userdata)
{
    char *text;
    char *response;
    xmpp_stanza_t *auth, *authdata;
    char *name;

    name = xmpp_stanza_get_name(stanza);
    xmpp_debug(conn->ctx, "xmpp",\
	"handle digest-md5 (challenge) called for %s", name);

    if (strcmp(name, "challenge") == 0) {
	text = xmpp_stanza_get_text(stanza);
	response = sasl_digest_md5(conn->ctx, text, conn->jid, conn->pass);
	if (!response) {
	    disconnect_mem_error(conn);
	    return 0;
	}
	xmpp_free(conn->ctx, text);

	auth = xmpp_stanza_new(conn->ctx);
	if (!auth) {
	    disconnect_mem_error(conn);
	    return 0;
	}
	xmpp_stanza_set_name(auth, "response");
	xmpp_stanza_set_ns(auth, XMPP_NS_SASL);

	authdata = xmpp_stanza_new(conn->ctx);
	if (!authdata) {
	    disconnect_mem_error(conn);
	    return 0;
	}

	xmpp_stanza_set_text(authdata, response);
	xmpp_free(conn->ctx, response);

	xmpp_stanza_add_child(auth, authdata);
	xmpp_stanza_release(authdata);

	handler_add(conn, _handle_digestmd5_rspauth,
		    XMPP_NS_SASL, NULL, NULL, NULL);

	xmpp_send(conn, auth);
	xmpp_stanza_release(auth);

    } else {
	return _handle_sasl_result(conn, stanza, "DIGEST-MD5");
    }

    /* remove ourselves */
    return 0;
}
Пример #15
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);
}
Пример #16
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;
}
Пример #17
0
void
message_send_groupchat(const char * const msg, const char * const recipient)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *message = stanza_create_message(ctx, recipient,
        STANZA_TYPE_GROUPCHAT, msg, NULL, NULL);

    xmpp_send(conn, message);
    xmpp_stanza_release(message);
}
Пример #18
0
void
message_send_duck(const char * const query)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *message = stanza_create_message(ctx, "*****@*****.**",
        STANZA_TYPE_CHAT, query, NULL, NULL);

    xmpp_send(conn, message);
    xmpp_stanza_release(message);
}
Пример #19
0
void
message_send_invite(const char * const room, const char * const contact,
    const char * const reason)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *stanza = stanza_create_invite(ctx, room, contact, reason);

    xmpp_send(conn, stanza);
    xmpp_stanza_release(stanza);
}
Пример #20
0
void
roster_send_add_new(const char * const barejid, const char * const name)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    char *id = create_unique_id("roster");
    xmpp_stanza_t *iq = stanza_create_roster_set(ctx, id, barejid, name, NULL);
    free(id);
    xmpp_send(conn, iq);
    xmpp_stanza_release(iq);
}
Пример #21
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

}
Пример #22
0
static void
_message_send_composing(const char * const recipient)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, recipient,
        STANZA_NAME_COMPOSING);

    xmpp_send(conn, stanza);
    xmpp_stanza_release(stanza);
    chat_session_set_sent(recipient);
}
Пример #23
0
void
message_send_gone(const char * const recipient)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, recipient,
        STANZA_NAME_GONE);

    xmpp_send(conn, stanza);
    xmpp_stanza_release(stanza);
    chat_session_set_sent(recipient);
}
Пример #24
0
void
message_send_groupchat(const char *const roomjid, const char *const msg)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    char *id = create_unique_id("muc");
    xmpp_stanza_t *message = stanza_create_message(ctx, id, roomjid, STANZA_TYPE_GROUPCHAT, msg);
    free(id);

    xmpp_send(conn, message);
    xmpp_stanza_release(message);
}
Пример #25
0
void
message_send_private(const char *const fulljid, const char *const msg)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    char *id = create_unique_id("prv");
    xmpp_stanza_t *message = stanza_create_message(ctx, id, fulljid, STANZA_TYPE_CHAT, msg);
    free(id);

    xmpp_send(conn, message);
    xmpp_stanza_release(message);
}
Пример #26
0
static void
_iq_disco_info_request(gchar *jid)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    char *id = create_unique_id("disco_info");
    xmpp_stanza_t *iq = stanza_create_disco_info_iq(ctx, id, jid, NULL);

    xmpp_id_handler_add(conn, _disco_info_response_handler, id, NULL);

    xmpp_send(conn, iq);
    xmpp_stanza_release(iq);
}
Пример #27
0
static void
_iq_destroy_instant_room(const char * const room_jid)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *iq = stanza_create_instant_room_destroy_iq(ctx, room_jid);

    char *id = xmpp_stanza_get_id(iq);
    xmpp_id_handler_add(conn, _destroy_room_result_handler, id, NULL);

    xmpp_send(conn, iq);
    xmpp_stanza_release(iq);
}
Пример #28
0
static void
_iq_request_room_config_form(const char * const room_jid)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *iq = stanza_create_room_config_request_iq(ctx, room_jid);

    char *id = xmpp_stanza_get_id(iq);
    xmpp_id_handler_add(conn, _room_config_handler, id, NULL);

    xmpp_send(conn, iq);
    xmpp_stanza_release(iq);
}
Пример #29
0
static void
_iq_submit_room_config(const char * const room, DataForm *form)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();
    xmpp_stanza_t *iq = stanza_create_room_config_submit_iq(ctx, room, form);

    char *id = xmpp_stanza_get_id(iq);
    xmpp_id_handler_add(conn, _room_config_submit_handler, id, NULL);

    xmpp_send(conn, iq);
    xmpp_stanza_release(iq);
}
Пример #30
0
int xmpp_ua_send(xmpp_ua_t *ua, xmpp_stanza_t *stanza)
{
	WaitForSingleObject(ua->mutex_4_ua, INFINITE);
	if (ua->conn == NULL)
	{
		ReleaseMutex(ua->mutex_4_ua);
		return -1;
	}

	xmpp_send(ua->conn, stanza);
	ReleaseMutex(ua->mutex_4_ua);
	return 0;
}