Example #1
0
int command_silc_join(void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) {
    SilcPluginServerList server;
    char *channelname;
    char *command;
    size_t command_length;

    if (argc < 3) {
        weechat_printf(buffer, "you need to specify a channel to join");
        return WEECHAT_RC_ERROR;
    }

    channelname = argv[2];
    command_length = strlen(channelname) + 6;
    command = malloc(command_length);
    memset(command, 0, command_length);
    snprintf(command, command_length, "JOIN %s", channelname);

    server = find_server_for_buffer(buffer);
    if (server == NULL) {
        weechat_printf(buffer, "%sCurrent buffer is not a SILC buffer", weechat_prefix("error"));
        return WEECHAT_RC_OK;
    }

    // Join here
    silc_client_command_call(silc_plugin->client, server->connection, command);
    return WEECHAT_RC_OK;
}
Example #2
0
void silc_plugin_connected(SilcClient client, SilcClientConnection conn, SilcClientConnectionStatus status,
        SilcStatus error, const char *message, void *context) {
    SilcConnectionContext connContext;
    SilcPluginServerList server;

    server = find_server_for_buffer(context);

    if (status == SILC_CLIENT_CONN_DISCONNECTED) {
        weechat_log_printf("Disconnected: %s", message ? message : "");
        weechat_buffer_close(context);
        remove_server(server);
        return;
    }

    if (status != SILC_CLIENT_CONN_SUCCESS && status != SILC_CLIENT_CONN_SUCCESS_RESUME) {
        weechat_log_printf("Error connecting to server: %d", status);
        return;
    }
    connContext = malloc(sizeof(SilcConnectionContext));
    connContext->server_buffer = context;

    conn->context = connContext;

    server->connection = conn;

    weechat_log_printf("connection successfull");
}
Example #3
0
int command_silc_disconnect(void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) {
    SilcPluginServerList server;

    server = find_server_for_buffer(buffer);
    if (server == NULL) {
        weechat_printf(buffer, "%sCurrent buffer is not a SILC buffer", weechat_prefix("error"));
        return WEECHAT_RC_OK;
    }

    silc_client_command_call(silc_plugin->client, server->connection, "QUIT");
    return WEECHAT_RC_OK;
}
Example #4
0
void silc_verify_public_key(SilcClient client, SilcClientConnection conn, SilcConnectionType conn_type, SilcPublicKey public_key, SilcVerifyPublicKey completion, void *context) {
    SilcPluginServerList server;

    weechat_log_printf("silc_verify_public_key was called");

    server = find_server_for_buffer(context);
    if (server != NULL) {
        server->server_key = public_key;
    }

    completion(TRUE, context);
}
Example #5
0
int command_silc_msg(void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) {
    char *nickname;
    char *msg;
    struct t_gui_buffer *query_buffer;
    struct SilcClientContext *clientCtx;
    SilcClientEntry client_entry;
    SilcDList list;
    SilcPluginServerList server = find_server_for_buffer(buffer);

    if (argc < 3) {
        weechat_printf(buffer, "you need to specify a recipient");
        return WEECHAT_RC_ERROR;
    }

    nickname = argv[2];
    list = silc_client_get_clients_local(silc_plugin->client, server->connection, nickname, FALSE);
    if (list == NULL) {
        weechat_printf(buffer, "no such nick: %s", nickname);
        return WEECHAT_RC_OK;
    }
    silc_dlist_start(list);
    client_entry = silc_dlist_get(list);
    silc_client_list_free(silc_plugin->client, server->connection, list);
    clientCtx = client_entry->context;
    if (clientCtx == NULL) {
        clientCtx = malloc(sizeof(struct SilcClientContext));
        query_buffer = weechat_buffer_new(client_entry->nickname, &silc_plugin_query_input, clientCtx, NULL, NULL);
        clientCtx->query_buffer = query_buffer;
        clientCtx->client_entry = client_entry;
        clientCtx->connection = server->connection;
    }

    if (argc > 3) {
        msg = argv_eol[3];
        silc_plugin_query_input(clientCtx, clientCtx->query_buffer, msg);
    }
    return WEECHAT_RC_OK;
}
Example #6
0
void silc_command_reply(SilcClient client, SilcClientConnection conn, SilcCommand command, SilcStatus status, SilcStatus error, va_list ap) {
    // "infrastructure"
    struct t_gui_buffer *channelbuffer, *serverbuffer;
    SilcConnectionContext ctx = conn->context;
    //SilcPluginChannelList channel;
    struct SilcChannelContext *chanCtx;

    // possible args
    char *str, *topic, *cipher, *hmac;
    SilcChannelEntry channel_entry;
    SilcUInt32 mode, userlimit;
    SilcHashTableList *userlist;
    SilcPublicKey key;
    SilcDList pubkeys;

    size_t strsize;

    // needed for the nicklist
    SilcClientEntry user_client;
    SilcChannelUser user;
    struct t_gui_nick *nick = NULL;

    switch (command) {
        case SILC_COMMAND_JOIN:
            str = va_arg(ap, char *);
            channel_entry = va_arg(ap, SilcChannelEntry);
            mode = va_arg(ap, SilcUInt32);
            userlist = va_arg(ap, SilcHashTableList *);
            topic = va_arg(ap, char *);
            cipher = va_arg(ap, char *);
            hmac = va_arg(ap, char *);
            key = va_arg(ap, SilcPublicKey);
            pubkeys = va_arg(ap, SilcDList);
            userlimit = va_arg(ap, SilcUInt32);

            chanCtx = malloc(sizeof(struct SilcChannelContext));
            chanCtx->channel_name = str;
            chanCtx->channel_entry = channel_entry;
            chanCtx->connection = conn;

            strsize = strlen(channel_entry->channel_name) + strlen(channel_entry->server) + 1;
            str = malloc(strsize+1);
            snprintf(str, strsize, "%s.%s", channel_entry->channel_name, channel_entry->server);

            // create a regular chat buffer and set some senible values
            channelbuffer = weechat_buffer_new(str, &silc_plugin_channel_input, chanCtx, NULL, NULL);
            weechat_buffer_set(channelbuffer, "name", str);
            weechat_buffer_set(channelbuffer, "short_name", channel_entry->channel_name);
            weechat_buffer_set(channelbuffer, "title", topic);
            weechat_buffer_set(channelbuffer, "hotlist", WEECHAT_HOTLIST_LOW);
            weechat_buffer_set(channelbuffer, "nicklist", "1");

            chanCtx->channel_buffer = channelbuffer;
            channel_entry->context = channelbuffer;

            serverbuffer = ctx->server_buffer;

            add_channel(channel_entry->channel_name, find_server_for_buffer(serverbuffer), channel_entry, NULL, channelbuffer);

            // fill the nicklist with users currently on the channel
            while (silc_hash_table_get(userlist, (void **)&user_client, (void **)&user)) {
                nick = silc_nicklist_add(user);
            }
            break;
        default:
            weechat_log_printf("unhandled command reply for %d", command);
            break;
    }
}