예제 #1
0
파일: group.c 프로젝트: Matsu616/uTox
void e_group_msg_onenter(EDIT *edit) {
    char *text = edit->data;
    uint16_t length = edit->length;

    if (length <= 0) {
        return;
    }

    uint16_t command_length = 0; //, argument_length = 0;
    char *command = NULL;
    char *argument = NULL;

    command_length = utox_run_command(text, length, &command, &argument, 1);

    // TODO: Magic number
    if (command_length == UINT16_MAX) {
        edit->length = 0;
        return;
    }

    // LOG_NOTE("Group", "cmd %u\n", command_length);

    bool action = false;
    if (command_length) {
        length = length - command_length - 2; /* first / and then the SPACE */
        text   = argument;
        if ((command_length == 2) && (!memcmp(command, "me", 2))) {
            if (argument) {
                action = true;
            } else {
                return;
            }
        }
    }

    if (!text) {
        return;
    }

    GROUPCHAT *g = flist_get_groupchat();
    if (g) {
        void *d = malloc(length);
        if (!d) {
            LOG_ERR("Layout Group", "edit_msg_onenter:\t Ran out of memory.");
            return;
        }
        memcpy(d, text, length);
        postmessage_toxcore((action ? TOX_GROUP_SEND_ACTION : TOX_GROUP_SEND_MESSAGE), g->number, length, d);
    } else {
        LOG_ERR("Groups", "No Group selected!");
    }

    completion.active = 0;
    edit->length      = 0;
}
예제 #2
0
void edit_msg_onenter(EDIT *edit) {
    char_t *text = edit->data;
    STRING_IDX length = edit->length;

    if(length <= 0) {
        return;
    }

    STRING_IDX command_length = 0;//, argument_length = 0;
    char_t *command = NULL, *argument = NULL;


    command_length = utox_run_command(text, length, &command, &argument, 1);

    if(command_length == 65535){
        edit->length = 0;
        return;
    }

    debug("cmd %u\n", command_length);

    _Bool action = 0, topic = 0;
    if(command_length){
        length = length - command_length - 2; /* first / and then the SPACE */
        text = argument;
        if((command_length == 2) && (!memcmp(command, "me", 2))) {
            if(argument) {
                action = 1;
            } else {
                return;
            }
        } else if(command_length == 5){
            if(memcmp(command, "topic", 5) == 0){
               topic = 1;
            } /* Separated as a guide for commands that don't need a separate function */
        }
    }


    if(!text){
        return;
    }

    if(selected_item->item == ITEM_FRIEND) {
        FRIEND *f = selected_item->data;

        if(!f->online) {
            return;
        }

        MESSAGE *msg = malloc(length + sizeof(MESSAGE));
        msg->author = 1;
        msg->msg_type = action ? MSG_TYPE_ACTION_TEXT : MSG_TYPE_TEXT;
        msg->length = length;
        memcpy(msg->msg, text, length);

        friend_addmessage(f, msg);

        void *d = malloc(length);
        memcpy(d, text, length);

        postmessage_toxcore((action ? TOX_SEND_ACTION : TOX_SEND_MESSAGE), (f - friend), length, d);
    } else if(selected_item->item == ITEM_GROUP) {