Пример #1
0
bool process_cmd(const char *cmd, int argc, char **argv, void* userdata)
{
    xmpp_conn_t *conn = (xmpp_conn_t*)userdata;

    if (strncmp("quit", cmd, 4) == 0) {
        // # quit
        return false;

    } else if (strncmp("message", cmd, 7) == 0 && argc == 2) {
        // # message $who $message
        cmd_send_msg(conn, argv[0], argv[1]);

    } else if (strncmp("raw", cmd, 3) == 0 && argc == 1) {
        // # image $who $fullfilepath $imagetype
        xmpp_send_raw(conn, argv[0], strlen(argv[0]));

    } else if (strncmp("voice", cmd, 5) == 0 && argc == 4) {
        // # voice $who $fullfilepath $container $codec

    } else if (strncmp("call", cmd, 4) == 0 && argc == 1) {
        // # call $who $codec

    } else {
        printf("未知命令或者参数错误 \n");
    }

    return true;
}
Пример #2
0
/** Send an XML stanza to the XMPP server.
 *  This is the main way to send data to the XMPP server.  The function will
 *  terminate without action if the connection state is not CONNECTED.
 *
 *  @param conn a Strophe connection object
 *  @param stanza a Strophe stanza object
 *
 *  @ingroup Connections
 */
void xmpp_send(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza)
{
	char *buf;
	size_t len;

	if (conn->state == XMPP_STATE_CONNECTED &&
	    !xmpp_stanza_to_text(stanza, &buf, &len)) {
			xmpp_send_raw(conn, buf, len);
			xmpp_debug(conn->ctx, "conn", "SENT: %s", buf);
			xmpp_free(conn->ctx, buf);
	}
}
Пример #3
0
/** Send a raw string to the XMPP server.
 *  This function is a convenience function to send raw string data to the 
 *  XMPP server.  It is used by Strophe to send short messages instead of
 *  building up an XML stanza with DOM methods.  This should be used with care
 *  as it does not validate the data; invalid data may result in immediate
 *  stream termination by the XMPP server.
 *
 *  @param conn a Strophe connection object
 *  @param fmt a printf-style format string followed by a variable list of
 *      arguments to format
 */
void xmpp_send_raw_string(xmpp_conn_t * const conn, 
			  const char * const fmt, ...)
{
    va_list ap;
    size_t len;
    char buf[1024]; /* small buffer for common case */
    char *bigbuf;

    va_start(ap, fmt);
    len = xmpp_vsnprintf(buf, 1024, fmt, ap);
    va_end(ap);

    if (len >= 1024) {
	/* we need more space for this data, so we allocate a big 
	 * enough buffer and print to that */
	len++; /* account for trailing \0 */
	bigbuf = xmpp_alloc(conn->ctx, len);
	if (!bigbuf) {
	    xmpp_debug(conn->ctx, "xmpp", "Could not allocate memory for send_raw_string");
	    return;
	}
	va_start(ap, fmt);
	xmpp_vsnprintf(bigbuf, len, fmt, ap);
	va_end(ap);

	xmpp_debug(conn->ctx, "conn", "SENT: %s", bigbuf);

	/* len - 1 so we don't send trailing \0 */
	xmpp_send_raw(conn, bigbuf, len - 1);

	xmpp_free(conn->ctx, bigbuf);
    } else {
	xmpp_debug(conn->ctx, "conn", "SENT: %s", buf);

	xmpp_send_raw(conn, buf, len);
    }
}
Пример #4
0
/** Send a raw string to the XMPP server.
 *  This function is a convenience function to send raw string data to the 
 *  XMPP server.  It is used by Strophe to send short messages instead of
 *  building up an XML stanza with DOM methods.  This should be used with care
 *  as it does not validate the data; invalid data may result in immediate
 *  stream termination by the XMPP server.
 *
 *  @param conn a Strophe connection object
 *  @param fmt a printf-style format string followed by a variable list of
 *      arguments to format
 */
void xmpp_send_raw_string(xmpp_conn_t * const conn, 
			  const char * const fmt, ...)
{
    va_list ap;
    char buf[1024]; /* small buffer for common case */
    xmpp_sized_string_t str;

    va_start(ap, fmt);
    str = xmpp_vsnprintf_heap(conn->ctx, buf, 1024, fmt, ap);
    va_end(ap);

    xmpp_debug(conn->ctx, "conn", "SENT: %s", str.buf);

    /* len - 1 so we don't send trailing \0 */
    xmpp_send_raw(conn, str.buf, str.len - 1);

    if (str.buf != buf)
        xmpp_free(conn->ctx, str.buf);
}
Пример #5
0
static int keepalive_handler(xmpp_conn_t * const conn, void * const userdata)
{
    xmpp_send_raw(conn, " ", 1);
    return 1;
}