示例#1
0
struct t_plugin_script *
script_buffer_get_script_pointer (struct t_script_repo *script,
                                  struct t_hdata *hdata_script)
{
    char *filename, *ptr_base_name;
    const char *ptr_filename;
    void *ptr_script;

    ptr_script = weechat_hdata_get_list (hdata_script, "scripts");
    while (ptr_script)
    {
        ptr_filename = weechat_hdata_string (hdata_script,
                                             ptr_script, "filename");
        if (ptr_filename)
        {
            filename = strdup (ptr_filename);
            if (filename)
            {
                ptr_base_name = basename (filename);
                if (strcmp (ptr_base_name, script->name_with_extension) == 0)
                {
                    free (filename);
                    return ptr_script;
                }
                free (filename);
            }
        }
        ptr_script = weechat_hdata_move (hdata_script, ptr_script, 1);
    }

    /* script not found */
    return NULL;
}
示例#2
0
void
relay_weechat_msg_add_nicklist (struct t_relay_weechat_msg *msg,
                                struct t_gui_buffer *buffer,
                                struct t_relay_weechat_nicklist *nicklist)
{
    char str_vars[512];
    struct t_hdata *ptr_hdata;
    struct t_gui_buffer *ptr_buffer;
    int pos_count, count;
    uint32_t count32;

    snprintf (str_vars, sizeof (str_vars),
              "%sgroup:chr,visible:chr,level:int,"
              "name:str,color:str,"
              "prefix:str,prefix_color:str",
              (nicklist) ? "_diff:chr," : "");

    relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_HDATA);
    relay_weechat_msg_add_string (msg, "buffer/nicklist_item");
    relay_weechat_msg_add_string (msg, str_vars);

    /* "count" will be set later, with number of objects in hdata */
    pos_count = msg->data_size;
    count = 0;
    relay_weechat_msg_add_int (msg, 0);

    if (buffer)
    {
        count += relay_weechat_msg_add_nicklist_buffer (msg, buffer, nicklist);
    }
    else
    {
        ptr_hdata = weechat_hdata_get ("buffer");
        ptr_buffer = weechat_hdata_get_list (ptr_hdata, "gui_buffers");
        while (ptr_buffer)
        {
            count += relay_weechat_msg_add_nicklist_buffer (msg, ptr_buffer, NULL);
            ptr_buffer = weechat_hdata_move (ptr_hdata, ptr_buffer, 1);
        }
    }

    count32 = htonl ((uint32_t)count);
    relay_weechat_msg_set_bytes (msg, pos_count, &count32, 4);
}
示例#3
0
struct t_weelist *
script_buffer_get_script_usage (struct t_script_repo *script)
{
    struct t_weelist *list;
    char hdata_name[128], str_option[256], str_info[1024];
    int config_files;
    const char *ptr_name_hdata_callback, *type;
    struct t_hdata *ptr_hdata_script, *ptr_hdata_callback;
    struct t_hdata *ptr_hdata_config_file, *ptr_hdata_bar_item;
    void *ptr_script, *ptr_callback;
    struct t_config_file *ptr_config_file;
    struct t_hook *ptr_hook;
    struct t_gui_bar_item *ptr_bar_item;
    struct t_infolist *infolist;

    config_files = 0;

    snprintf (hdata_name, sizeof (hdata_name),
              "%s_script", script_language[script->language]);
    ptr_hdata_script = weechat_hdata_get (hdata_name);
    if (!ptr_hdata_script)
        return NULL;

    ptr_script = script_buffer_get_script_pointer (script, ptr_hdata_script);
    if (!ptr_script)
        return NULL;

    ptr_name_hdata_callback = weechat_hdata_get_var_hdata (ptr_hdata_script,
                                                           "callbacks");
    if (!ptr_name_hdata_callback)
        return NULL;
    ptr_hdata_callback = weechat_hdata_get (ptr_name_hdata_callback);
    if (!ptr_hdata_callback)
        return NULL;

    list = weechat_list_new ();

    ptr_hdata_config_file = weechat_hdata_get ("config_file");
    ptr_hdata_bar_item = weechat_hdata_get ("bar_item");

    ptr_callback = weechat_hdata_pointer (ptr_hdata_script,
                                          ptr_script,
                                          "callbacks");
    while (ptr_callback)
    {
        str_info[0] = '\0';
        ptr_config_file = weechat_hdata_pointer (ptr_hdata_callback,
                                                 ptr_callback,
                                                 "config_file");
        ptr_hook = weechat_hdata_pointer (ptr_hdata_callback,
                                          ptr_callback,
                                          "hook");
        ptr_bar_item = weechat_hdata_pointer (ptr_hdata_callback,
                                              ptr_callback,
                                              "bar_item");
        if (ptr_config_file)
        {
            snprintf (str_info, sizeof (str_info),
                      _("configuration file \"%s\" (options %s.*)"),
                      weechat_hdata_string (ptr_hdata_config_file,
                                            ptr_config_file,
                                            "filename"),
                      weechat_hdata_string (ptr_hdata_config_file,
                                            ptr_config_file,
                                            "name"));
            config_files++;
        }
        else if (ptr_hook)
        {
            infolist = weechat_infolist_get ("hook", ptr_hook, NULL);
            if (infolist)
            {
                if (weechat_infolist_next (infolist))
                {
                    type = weechat_infolist_string (infolist, "type");
                    if (type)
                    {
                        if (strcmp (type, "command") == 0)
                        {
                            snprintf (str_info, sizeof (str_info),
                                      _("command /%s"),
                                      weechat_infolist_string (infolist,
                                                               "command"));
                        }
                        else if (strcmp (type, "completion") == 0)
                        {
                            snprintf (str_info, sizeof (str_info),
                                      _("completion %%(%s)"),
                                      weechat_infolist_string (infolist,
                                                               "completion_item"));
                        }
                        else if (strcmp (type, "info") == 0)
                        {
                            snprintf (str_info, sizeof (str_info),
                                      "info \"%s\"",
                                      weechat_infolist_string (infolist,
                                                               "info_name"));
                        }
                        else if (strcmp (type, "info_hashtable") == 0)
                        {
                            snprintf (str_info, sizeof (str_info),
                                      "info_hashtable \"%s\"",
                                      weechat_infolist_string (infolist,
                                                               "info_name"));
                        }
                        else if (strcmp (type, "infolist") == 0)
                        {
                            snprintf (str_info, sizeof (str_info),
                                      "infolist \"%s\"",
                                      weechat_infolist_string (infolist,
                                                               "infolist_name"));
                        }
                    }
                }
                weechat_infolist_free (infolist);
            }
        }
        else if (ptr_bar_item)
        {
            snprintf (str_info, sizeof (str_info),
                      _("bar item \"%s\""),
                      weechat_hdata_string (ptr_hdata_bar_item,
                                            ptr_bar_item,
                                            "name"));
        }
        if (str_info[0])
        {
            weechat_list_add (list, str_info,
                              WEECHAT_LIST_POS_END, NULL);
        }
        ptr_callback = weechat_hdata_move (ptr_hdata_callback,
                                           ptr_callback,
                                           1);
    }

    snprintf (str_option, sizeof (str_option),
              "plugins.var.%s.%s.*",
              script_language[script->language],
              weechat_hdata_string (ptr_hdata_script, ptr_script, "name"));
    infolist = weechat_infolist_get ("option", NULL, str_option);
    if (infolist)
    {
        if (weechat_infolist_next (infolist))
        {
            snprintf (str_info, sizeof (str_info),
                      _("options %s%s%s"),
                      str_option,
                      (config_files > 0) ? " " : "",
                      (config_files > 0) ? _("(old options?)") : "");
            weechat_list_add (list, str_info,
                              WEECHAT_LIST_POS_END, NULL);
        }
        weechat_infolist_free (infolist);
    }

    return list;
}
示例#4
0
int
relay_weechat_msg_add_hdata_path (struct t_relay_weechat_msg *msg,
                                  char **list_path,
                                  int index_path,
                                  void **path_pointers,
                                  struct t_hdata *hdata,
                                  void *pointer,
                                  char **list_keys)
{
    int num_added, i, j, count, count_all, var_type, array_size, max_array_size;
    int length;
    char *pos, *pos2, *str_count, *error, *name;
    void *sub_pointer;
    struct t_hdata *sub_hdata;
    const char *sub_hdata_name;

    num_added = 0;

    count_all = 0;
    count = 0;
    pos = strchr (list_path[index_path], '(');
    if (pos)
    {
        pos2 = strchr (pos + 1, ')');
        if (pos2 && (pos2 > pos + 1))
        {
            str_count = weechat_strndup (pos + 1, pos2 - (pos + 1));
            if (str_count)
            {
                if (strcmp (str_count, "*") == 0)
                    count_all = 1;
                else
                {
                    error = NULL;
                    count = (int)strtol (str_count, &error, 10);
                    if (error && !error[0])
                    {
                        if (count > 0)
                            count--;
                        else if (count < 0)
                            count++;
                    }
                    else
                        count = 0;
                }
                free (str_count);
            }
        }
    }

    while (pointer)
    {
        path_pointers[index_path] = pointer;

        if (list_path[index_path + 1])
        {
            /* recursive call with next path */
            pos = strchr (list_path[index_path + 1], '(');
            if (pos)
                pos[0] = '\0';
            sub_pointer = weechat_hdata_pointer (hdata, pointer, list_path[index_path + 1]);
            sub_hdata_name = weechat_hdata_get_var_hdata (hdata, list_path[index_path + 1]);
            if (pos)
                pos[0] = '(';
            if (sub_pointer && sub_hdata_name)
            {
                sub_hdata = weechat_hdata_get (sub_hdata_name);
                if (sub_hdata)
                {
                    num_added += relay_weechat_msg_add_hdata_path (msg,
                                                                   list_path,
                                                                   index_path + 1,
                                                                   path_pointers,
                                                                   sub_hdata,
                                                                   sub_pointer,
                                                                   list_keys);
                }
            }
        }
        else
        {
            /* last path? then get pointer + values and fill message with them */
            for (i = 0; list_path[i]; i++)
            {
                relay_weechat_msg_add_pointer (msg, path_pointers[i]);
            }
            for (i = 0; list_keys[i]; i++)
            {
                var_type = weechat_hdata_get_var_type (hdata, list_keys[i]);
                if ((var_type >= 0) && (var_type != WEECHAT_HDATA_OTHER))
                {
                    max_array_size = 1;
                    array_size = weechat_hdata_get_var_array_size (hdata,
                                                                   pointer,
                                                                   list_keys[i]);
                    if (array_size >= 0)
                    {
                        switch (var_type)
                        {
                            case WEECHAT_HDATA_CHAR:
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_CHAR);
                                break;
                            case WEECHAT_HDATA_INTEGER:
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_INT);
                                break;
                            case WEECHAT_HDATA_LONG:
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_LONG);
                                break;
                            case WEECHAT_HDATA_STRING:
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_STRING);
                                break;
                            case WEECHAT_HDATA_POINTER:
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_POINTER);
                                break;
                            case WEECHAT_HDATA_TIME:
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_TIME);
                                break;
                            case WEECHAT_HDATA_HASHTABLE:
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_HASHTABLE);
                                break;
                        }
                        relay_weechat_msg_add_int (msg, array_size);
                        max_array_size = array_size;
                    }
                    length = 16 + strlen (list_keys[i]) + 1;
                    name = malloc (length);
                    if (name)
                    {
                        for (j = 0; j < max_array_size; j++)
                        {
                            snprintf (name, length, "%d|%s", j, list_keys[i]);
                            switch (var_type)
                            {
                                case WEECHAT_HDATA_CHAR:
                                    relay_weechat_msg_add_char (msg,
                                                                weechat_hdata_char (hdata,
                                                                                    pointer,
                                                                                    name));
                                    break;
                                case WEECHAT_HDATA_INTEGER:
                                    relay_weechat_msg_add_int (msg,
                                                               weechat_hdata_integer (hdata,
                                                                                      pointer,
                                                                                      name));
                                    break;
                                case WEECHAT_HDATA_LONG:
                                    relay_weechat_msg_add_long (msg,
                                                                weechat_hdata_long (hdata,
                                                                                    pointer,
                                                                                    name));
                                    break;
                                case WEECHAT_HDATA_STRING:
                                    relay_weechat_msg_add_string (msg,
                                                                  weechat_hdata_string (hdata,
                                                                                        pointer,
                                                                                        name));
                                    break;
                                case WEECHAT_HDATA_POINTER:
                                    relay_weechat_msg_add_pointer (msg,
                                                                   weechat_hdata_pointer (hdata,
                                                                                          pointer,
                                                                                          name));
                                    break;
                                case WEECHAT_HDATA_TIME:
                                    relay_weechat_msg_add_time (msg,
                                                                weechat_hdata_time (hdata,
                                                                                    pointer,
                                                                                    name));
                                    break;
                                case WEECHAT_HDATA_HASHTABLE:
                                    relay_weechat_msg_add_hashtable (msg,
                                                                     weechat_hdata_hashtable (hdata,
                                                                                              pointer,
                                                                                              name));
                                    break;
                            }
                        }
                        free (name);
                    }
                }
            }
            num_added++;
        }
        if (count_all)
        {
            pointer = weechat_hdata_move (hdata, pointer, 1);
        }
        else if (count == 0)
            pointer = NULL;
        else if (count > 0)
        {
            pointer = weechat_hdata_move (hdata, pointer, 1);
            count--;
        }
        else
        {
            pointer = weechat_hdata_move (hdata, pointer, -1);
            count++;
        }
        if (!pointer)
            break;
    }

    return num_added;
}
示例#5
0
struct t_weelist *
script_buffer_get_script_usage (struct t_script_repo *script)
{
    struct t_weelist *list;
    char hdata_name[128], str_option[256], str_info[1024];
    int config_files;
    struct t_hdata *hdata_script, *hdata_config, *hdata_bar_item;
    void *ptr_script, *callback_pointer;
    struct t_config_file *ptr_config;
    struct t_gui_bar_item *ptr_bar_item;
    struct t_infolist *infolist;

    config_files = 0;

    snprintf (hdata_name, sizeof (hdata_name),
              "%s_script", script_language[script->language]);
    hdata_script = weechat_hdata_get (hdata_name);
    if (!hdata_script)
        return NULL;

    ptr_script = script_buffer_get_script_pointer (script, hdata_script);
    if (!ptr_script)
        return NULL;

    list = weechat_list_new ();

    /* get configuration files created by the script */
    hdata_config = weechat_hdata_get ("config_file");
    ptr_config = weechat_hdata_get_list (hdata_config, "config_files");
    while (ptr_config)
    {
        callback_pointer = weechat_hdata_pointer (
            hdata_config, ptr_config, "callback_reload_pointer");
        if (callback_pointer == ptr_script)
        {
            snprintf (str_info, sizeof (str_info),
                      _("configuration file \"%s\" (options %s.*)"),
                      weechat_hdata_string (hdata_config, ptr_config,
                                            "filename"),
                      weechat_hdata_string (hdata_config, ptr_config,
                                            "name"));
            weechat_list_add (list, str_info, WEECHAT_LIST_POS_END, NULL);
            config_files++;
        }
        ptr_config = weechat_hdata_move (hdata_config, ptr_config, 1);
    }

    /* get the commands created by the script */
    infolist = weechat_infolist_get ("hook", NULL, "command");
    if (infolist)
    {
        while (weechat_infolist_next (infolist))
        {
            callback_pointer = weechat_infolist_pointer (infolist,
                                                         "callback_pointer");
            if (callback_pointer == ptr_script)
            {
                snprintf (str_info, sizeof (str_info),
                          _("command /%s"),
                          weechat_infolist_string (infolist,
                                                   "command"));
                weechat_list_add (list, str_info, WEECHAT_LIST_POS_END, NULL);
            }
        }
        weechat_infolist_free (infolist);
    }

    /* get the completions created by the script */
    infolist = weechat_infolist_get ("hook", NULL, "completion");
    if (infolist)
    {
        while (weechat_infolist_next (infolist))
        {
            callback_pointer = weechat_infolist_pointer (infolist,
                                                         "callback_pointer");
            if (callback_pointer == ptr_script)
            {
                snprintf (str_info, sizeof (str_info),
                          _("completion %%(%s)"),
                          weechat_infolist_string (infolist,
                                                   "completion_item"));
                weechat_list_add (list, str_info, WEECHAT_LIST_POS_END, NULL);
            }
        }
        weechat_infolist_free (infolist);
    }

    /* get the infos created by the script */
    infolist = weechat_infolist_get ("hook", NULL, "info");
    if (infolist)
    {
        while (weechat_infolist_next (infolist))
        {
            callback_pointer = weechat_infolist_pointer (infolist,
                                                         "callback_pointer");
            if (callback_pointer == ptr_script)
            {
                snprintf (str_info, sizeof (str_info),
                          "info \"%s\"",
                          weechat_infolist_string (infolist,
                                                   "info_name"));
                weechat_list_add (list, str_info, WEECHAT_LIST_POS_END, NULL);
            }
        }
        weechat_infolist_free (infolist);
    }

    /* get the infos (hashtable) created by the script */
    infolist = weechat_infolist_get ("hook", NULL, "info_hashtable");
    if (infolist)
    {
        while (weechat_infolist_next (infolist))
        {
            callback_pointer = weechat_infolist_pointer (infolist,
                                                         "callback_pointer");
            if (callback_pointer == ptr_script)
            {
                snprintf (str_info, sizeof (str_info),
                          "info_hashtable \"%s\"",
                          weechat_infolist_string (infolist,
                                                   "info_name"));
                weechat_list_add (list, str_info, WEECHAT_LIST_POS_END, NULL);
            }
        }
        weechat_infolist_free (infolist);
    }

    /* get the infolists created by the script */
    infolist = weechat_infolist_get ("hook", NULL, "infolist");
    if (infolist)
    {
        while (weechat_infolist_next (infolist))
        {
            callback_pointer = weechat_infolist_pointer (infolist,
                                                         "callback_pointer");
            if (callback_pointer == ptr_script)
            {
                snprintf (str_info, sizeof (str_info),
                          "infolist \"%s\"",
                          weechat_infolist_string (infolist,
                                                   "infolist_name"));
                weechat_list_add (list, str_info, WEECHAT_LIST_POS_END, NULL);
            }
        }
        weechat_infolist_free (infolist);
    }

    /* get the bar items created by the script */
    hdata_bar_item = weechat_hdata_get ("bar_item");
    ptr_bar_item = weechat_hdata_get_list (hdata_bar_item, "gui_bar_items");
    while (ptr_bar_item)
    {
        callback_pointer = weechat_hdata_pointer (hdata_bar_item, ptr_bar_item,
                                                  "build_callback_pointer");
        if (callback_pointer == ptr_script)
        {
            snprintf (str_info, sizeof (str_info),
                      _("bar item \"%s\""),
                      weechat_hdata_string (hdata_bar_item,
                                            ptr_bar_item,
                                            "name"));
            weechat_list_add (list, str_info, WEECHAT_LIST_POS_END, NULL);
        }
        ptr_bar_item = weechat_hdata_move (hdata_bar_item, ptr_bar_item, 1);
    }

    /* get the script options (in plugins.var) */
    snprintf (str_option, sizeof (str_option),
              "plugins.var.%s.%s.*",
              script_language[script->language],
              weechat_hdata_string (hdata_script, ptr_script, "name"));
    infolist = weechat_infolist_get ("option", NULL, str_option);
    if (infolist)
    {
        if (weechat_infolist_next (infolist))
        {
            snprintf (str_info, sizeof (str_info),
                      _("options %s%s%s"),
                      str_option,
                      (config_files > 0) ? " " : "",
                      (config_files > 0) ? _("(old options?)") : "");
            weechat_list_add (list, str_info,
                              WEECHAT_LIST_POS_END, NULL);
        }
        weechat_infolist_free (infolist);
    }

    return list;
}
示例#6
0
int
fset_completion_option_cb (const void *pointer, void *data,
                           const char *completion_item,
                           struct t_gui_buffer *buffer,
                           struct t_gui_completion *completion)
{
    struct t_config_file *ptr_config;
    struct t_config_section *ptr_section;
    struct t_config_option *ptr_option;
    char **words;
    int config_section_added, num_words, i;

    /* make C compiler happy */
    (void) pointer;
    (void) data;
    (void) completion_item;
    (void) buffer;

    ptr_config = weechat_hdata_get_list (fset_hdata_config_file,
                                         "config_files");
    while (ptr_config)
    {
        ptr_section = weechat_hdata_pointer (fset_hdata_config_file,
                                             ptr_config, "sections");
        while (ptr_section)
        {
            config_section_added = 0;
            ptr_option = weechat_hdata_pointer (fset_hdata_config_section,
                                                ptr_section, "options");
            while (ptr_option)
            {
                if (!config_section_added)
                {
                    weechat_hook_completion_list_add (
                        completion,
                        weechat_config_option_get_string (ptr_option,
                                                          "config_name"),
                        0, WEECHAT_LIST_POS_SORT);
                    weechat_hook_completion_list_add (
                        completion,
                        weechat_config_option_get_string (ptr_option,
                                                          "section_name"),
                        0, WEECHAT_LIST_POS_SORT);
                    config_section_added = 1;
                }
                weechat_hook_completion_list_add (
                    completion,
                    weechat_config_option_get_string (ptr_option, "name"),
                    0,
                    WEECHAT_LIST_POS_SORT);
                words = weechat_string_split (
                    weechat_config_option_get_string (ptr_option, "name"),
                    "_",
                    WEECHAT_STRING_SPLIT_STRIP_LEFT
                    | WEECHAT_STRING_SPLIT_STRIP_RIGHT
                    | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
                    0,
                    &num_words);
                if (words && (num_words > 1))
                {
                    for (i = 0; i < num_words; i++)
                    {
                        weechat_hook_completion_list_add (
                            completion, words[i], 0, WEECHAT_LIST_POS_SORT);
                    }
                }
                if (words)
                    weechat_string_free_split (words);
                ptr_option = weechat_hdata_move (fset_hdata_config_option,
                                                 ptr_option, 1);
            }
            ptr_section = weechat_hdata_move (fset_hdata_config_section,
                                              ptr_section, 1);
        }
        ptr_config = weechat_hdata_move (fset_hdata_config_file,
                                         ptr_config, 1);
    }

    return WEECHAT_RC_OK;
}