Exemplo n.º 1
0
static void cmd_whois_cb(const char *info, void *args)
{
    struct cb_args *a = (struct cb_args *) args;

    if (info == NULL)
    {
        if (a->nick_to == NULL || a->jid_to == NULL)
            printf("No such user connected\n");
        else
            xmpp_send_message(a->nick_to, a->jid_to,
                              "I don't know that guy...");
        free(a->nick_to);
        free(a->jid_to);
        free(a);
    }
    else
    {
        a->status = get_info_int(info, "status='", "'", NULL);
        a->ip = get_info(info, "ip_address='", "'", NULL);

        pthread_t thread_gl;

        if (pthread_create(&thread_gl, NULL, thread_get_geoloc, args) == -1)
            perror("pthread_create");

        pthread_detach(thread_gl);
    }
}
Exemplo n.º 2
0
static void *thread_get_geoloc(void *vargs)
{
    struct cb_args *a = (struct cb_args *) vargs;
    struct geoip *g = geoip_get_info(a->ip, 0);

    enum e_status i_status = a->status;
    const char *s_status = a->status & STATUS_AFK ? "AFK" :
        i_status & STATUS_PLAYING ? "playing" :
        i_status & STATUS_SHOP ? "in shop" :
        i_status & STATUS_INVENTORY ? "in inventory" :
        i_status & STATUS_ROOM ? "in a room" :
        i_status & STATUS_LOBBY ? "in lobby" :
        i_status & STATUS_ONLINE ? "connecting" :
        "offline"; /* wut ? impossible !§§!§ */

    if (a->nick_to == NULL || a->jid_to == NULL)
    {
        if (g == NULL)
            printf("ip:%s is %s\n", a->ip, s_status);
        else
        {
            printf("ip:%s (%s) is %s\n", a->ip, g->country_name, s_status);
            geoip_free(g);
        }
    }
    else
    {
        int r = time(NULL) % 3;
        const char *format = r == 0 ? "He's from %s... currently %s" :
            r == 1 ? "That's a guy from %s. He is %s" :
            "I met him in %s but now he's %s";

        char *message;

        if (g == NULL)
            FORMAT(message, "He's %s", s_status);
        else
        {
            FORMAT(message, format, g->country_name, s_status);
            geoip_free(g);
        }

        xmpp_send_message(a->nick_to, a->jid_to, message);

        free(message);
    }

    free(a->ip);
    free(a->nick_to);
    free(a->jid_to);
    free(a);

    pthread_exit(NULL);
}
static void xmpp_iq_profile_info_get_status_cb(const char *msg, void *args)
{
    /* Answer:
       <iq from='k01.warface' type='result'>
        <query xmlns='urn:cryonline:k01'>
         <profile_info_get_status nickname='xxxx'>
          <profile_info>
           <info nickname='xxxx' online_id='xxxx@warface/GameClient'
                 status='33' profile_id='xxx' user_id='xxxxx'
                 rank='xx' tags='' ip_address='xxx.xxx.xxx.xxx'
                 login_time='xxxxxxxxxxx'/>
          </profile_info>
         </profile_info_get_status>
        </query>
       </iq>
     */

    struct cb_args *a = (struct cb_args *) args;

    if (strstr(msg, "type='result'") == NULL
        || a->nick_to == NULL
        || a->jid_to == NULL)
    {
        free(a->nick_to);
        free(a->jid_to);
        free(a);
    }

    char *info = get_info(msg, "<info", "/>", NULL);

    if (info == NULL)
    {
        xmpp_send_message(session.wfs, session.nickname, session.jid,
                          a->nick_to, a->jid_to,
                          "I don&apos;t know that guy...", NULL);
    }
    else
    {
        a->status = get_info_int(info, "status='", "'", NULL);
        a->ip = get_info(info, "ip_address='", "'", NULL);

        pthread_t thread_gl;

        if (pthread_create(&thread_gl, NULL, thread_get_geoloc, args) == -1)
            perror("pthread_create");

        pthread_detach(thread_gl);
    }

    free(info);
}
Exemplo n.º 4
0
Arquivo: xmpp.c Projeto: grouzen/xinb
void xmpp_send_stream(Xinb *x, FILE *stream)
{
    gchar *in_buf = NULL;
    size_t in_buf_len = 0;

    while(!feof(stream)) {
        gchar buf[256];
        size_t buf_len;
        gint i;
        
        buf_len = fread(buf, sizeof(gchar), 255, stream);
        if(!buf_len) {
            if(ferror(stream)) {
                log_record(x, LOGS_ERR,
                           "Error has been occured during reading stream");
            }
            break;
        }
        buf[buf_len] = '\0';
        
        in_buf = g_realloc(in_buf, in_buf_len + buf_len);
        for(i = 0; buf[i] != '\0'; i++) {
            in_buf[in_buf_len++] = buf[i];
        }
    }

    in_buf = g_realloc(in_buf, in_buf_len + 1);
    in_buf[in_buf_len] = '\0';
    
    if(!in_buf)
        return;
    
    x->to = g_strdup(g_hash_table_lookup(x->config, "owner"));
    x->message = g_strdup(in_buf);
    xmpp_send_message(x, LM_MESSAGE_SUB_TYPE_CHAT);

    g_free(x->to);
    g_free(x->message);
    g_free(in_buf);

    return;
}
Exemplo n.º 5
0
int32_t CASendRAUnicastData(const CAEndpoint_t *remoteEndpoint, const void *data,
                                  uint32_t dataLength)
{
    if (!remoteEndpoint || !data)
    {
        OIC_LOG(ERROR, RA_ADAPTER_TAG, "Invalid parameter!");
        return -1;
    }

    if (0 == dataLength)
    {
        OIC_LOG(ERROR, RA_ADAPTER_TAG, "Data length is 0!");
        return 0;
    }

    OIC_LOG_V(ERROR, RA_ADAPTER_TAG, "Sending unicast data to %s", remoteEndpoint->addr);
    ca_mutex_lock (g_raadapterMutex);

    if (CA_INTERFACE_UP != g_xmppData.connection_status)
    {
        OIC_LOG(ERROR, RA_ADAPTER_TAG, "Unable to send XMPP message, RA not connected");
        ca_mutex_unlock (g_raadapterMutex);
        return -1;
    }

    xmpp_error_code_t res = xmpp_send_message(g_xmppData.message_context,
            remoteEndpoint->addr, data, dataLength,
            XMPP_MESSAGE_TRANSMIT_DEFAULT);
    if (XMPP_ERR_OK != res)
    {
        OIC_LOG_V(ERROR, RA_ADAPTER_TAG, "Unable to send XMPP message, status: %d", res);
        ca_mutex_unlock (g_raadapterMutex);
        return -1;
    }
    ca_mutex_unlock (g_raadapterMutex);

    OIC_LOG_V(INFO, RA_ADAPTER_TAG, "Successfully dispatched bytes[%d] to addr[%s]",
            dataLength, remoteEndpoint->addr);

    return dataLength;
}
Exemplo n.º 6
0
static void cmd_whisper_cb(const char *info, void *args)
{
    struct cb_args *a = (struct cb_args *) args;

    if (info != NULL)
    {
        char *online_id = get_info(info, "online_id='", "'", NULL);
        char *nickname = get_info(info, "nickname='", "'", NULL);

        if (online_id != NULL && nickname != NULL)
            xmpp_send_message(nickname, online_id, a->message);

        free(nickname);
        free(online_id);
    }
    else
        fprintf(stderr, "No such connected user\n");

    free(a->message);
    free(a);
}
Exemplo n.º 7
0
Arquivo: xmpp.c Projeto: grouzen/xinb
LmHandlerResult xmpp_receive_command(LmMessageHandler *handler,
                        LmConnection *conn, LmMessage *m, gpointer udata)
{
    Xinb *x = udata;
    LmMessageNode *body;
    gchar *jid;
    const gchar *from;
    
    if(x->state != LM_CONNECTION_STATE_AUTHENTICATED) {
        log_record(x, LOGS_ERR,
                   "Unable to receive message: not authenticated");
        goto out;
    }
    
    from = lm_message_node_get_attribute(m->node, "from");
    jid = xmpp_get_jid(from);
    if(g_strcmp0(jid, g_hash_table_lookup(x->config, "owner"))) {
        log_record(x, LOGS_ERR, "To command may only owner: '%s'", from);
        x->to = jid;
        x->message = g_strdup("You don't have permission to command me");
        xmpp_send_message(x, LM_MESSAGE_SUB_TYPE_CHAT);
        g_free(x->message);
        goto out;
    }
    
    body = lm_message_node_find_child(m->node, "body");
    if(lm_message_get_sub_type(m) != LM_MESSAGE_SUB_TYPE_CHAT) {
        log_record(x, LOGS_ERR, "Invalid subtype of the command");
        goto out;
    }
    
    if(command_run(x, body->value)) {
        log_record(x, LOGS_INFO, "The command was successfully executed");
    }

    out:
    g_free(jid);
    lm_message_unref(m);
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
Exemplo n.º 8
0
static void handle_private_message_(const char *msg_id, const char *msg)
{

    /* Answer #2:
       <iq from='xxxxx@warface/GameClient' type='get'>
        <query xmlns='urn:cryonline:k01'>
         <message from='xxxx' nick='xxxx' message='xxxx'/>
        </query>
       </iq>
     */

    char *message = get_info(msg, "message='", "'", NULL);
    char *nick_from = get_info(msg, "<message from='", "'", NULL);
    char *jid_from = get_info(msg, "<iq from='", "'", NULL);

    /* Deserialize message */

    xml_deserialize_inplace(&message);

    /* Feedback the user what was sent */

    xmpp_ack_message(nick_from, jid_from, message, msg_id);

    /* Determine the correct command */

    if (strstr(message, "leave"))
    {
        cmd_leave();

        xmpp_send_message(nick_from, jid_from, "but whyy :(");
    }

    else if (strstr(message, "ready") || strstr(message, "take"))
    {
        cmd_ready(strstr(message, " "));

        xmpp_send_message(nick_from, jid_from, "go");
    }

    else if (strstr(message, "invite"))
    {
        cmd_invite(nick_from, 0);
    }

    else if (strstr(message, "master"))
    {
        cmd_master(nick_from);

        xmpp_send_message(nick_from, jid_from, "Yep, just a sec.");

    }

    else if (strstr(message, "whois"))
    {
        char *nickname = strchr(message, ' ');

        if (nickname == NULL)
            nickname = nick_from;
        else
            nickname++;

        cmd_whois(nickname, nick_from, jid_from);
    }

    else if (strstr(message, "missions"))
    {
        cmd_missions(nick_from, jid_from);
    }

    else if (strstr(message, "say"))
    {
        cmd_say(strchr(message, ' '));
    }

    else
    {
        int r = rand() % 4;
        const char *answer =
            r == 0 ? "I'm sorry Dave. I'm afraid I can't do that." :
            r == 1 ? "It can only be attributable to human error." :
            r == 2 ? "Just what do you think you're doing, Dave ?" :
            "Dave, stop. Stop, will you ?";

        /* Command not found */
        xmpp_send_message(nick_from, jid_from, answer);
    }

    free(jid_from);
    free(nick_from);
    free(message);
}