Exemplo n.º 1
0
void
fifo_remove_old_pipes ()
{
    char *buf;
    int buf_len, prefix_len;
    const char *dogechat_home, *dir_separator;
    DIR *dp;
    struct dirent *entry;
    struct stat statbuf;

    buf_len = PATH_MAX;
    buf = malloc (buf_len);
    if (!buf)
        return;

    dogechat_home = dogechat_info_get ("dogechat_dir", "");
    dir_separator = dogechat_info_get ("dir_separator", "");

    prefix_len = strlen (FIFO_FILENAME_PREFIX);

    dp = opendir (dogechat_home);
    if (dp != NULL)
    {
        while ((entry = readdir (dp)) != NULL)
        {
            if (strcmp (entry->d_name, ".") == 0 || strcmp (entry->d_name, "..") == 0)
                continue;

            if (strncmp (entry->d_name, FIFO_FILENAME_PREFIX, prefix_len) == 0)
            {
                snprintf (buf, buf_len, "%s%s%s",
                          dogechat_home, dir_separator, entry->d_name);
                if (stat (buf, &statbuf) != -1)
                {
                    dogechat_printf (NULL,
                                    _("%s: removing old fifo pipe \"%s\""),
                                    FIFO_PLUGIN_NAME, buf);
                    unlink (buf);
                }
            }
        }
        closedir (dp);
    }

    free (buf);
}
Exemplo n.º 2
0
int
script_completion_scripts_files_cb (void *data, const char *completion_item,
                                    struct t_gui_buffer *buffer,
                                    struct t_gui_completion *completion)
{
    const char *dogechat_home;
    char *directory;
    int length, i;
    void *pointers[2];

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

    dogechat_home = dogechat_info_get ("dogechat_dir", NULL);

    length = strlen (dogechat_home) + 128 + 1;
    directory = malloc (length);
    if (directory)
    {
        for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
        {
            pointers[0] = completion;
            pointers[1] = script_extension[i];

            /* look for files in "~/.dogechat/<language>/" */
            snprintf (directory, length,
                      "%s/%s", dogechat_home, script_language[i]);
            dogechat_exec_on_files (directory, 0,
                                   pointers, &script_completion_exec_file_cb);

            /* look for files in "~/.dogechat/<language>/autoload/" */
            snprintf (directory, length,
                      "%s/%s/autoload", dogechat_home, script_language[i]);
            dogechat_exec_on_files (directory, 0,
                                   pointers, &script_completion_exec_file_cb);
        }
        free (directory);
    }

    return DOGECHAT_RC_OK;
}
Exemplo n.º 3
0
char *
irc_sasl_get_key_content (struct t_irc_server *server, const char *sasl_key)
{
    const char *dogechat_dir;
    char *key_path1, *key_path2, *content;

    if (!sasl_key)
        return NULL;

    content = NULL;

    dogechat_dir = dogechat_info_get ("dogechat_dir", "");
    key_path1 = dogechat_string_replace (sasl_key, "%h", dogechat_dir);
    key_path2 = (key_path1) ?
        dogechat_string_expand_home (key_path1) : NULL;

    if (key_path2)
        content = dogechat_file_get_content (key_path2);

    if (!content)
    {
        dogechat_printf (
            server->buffer,
            _("%s%s: unable to read private key in file \"%s\""),
            dogechat_prefix ("error"),
            IRC_PLUGIN_NAME,
            (key_path2) ? key_path2 : ((key_path1) ? key_path1 : sasl_key));
    }

    if (key_path1)
        free (key_path1);
    if (key_path2)
        free (key_path2);

    return content;
}
Exemplo n.º 4
0
void
fifo_create ()
{
    int filename_length;
    const char *fifo_option, *dogechat_home;

    fifo_option = dogechat_config_get_plugin ("fifo");
    if (!fifo_option)
    {
        dogechat_config_set_plugin ("fifo", "on");
        fifo_option = dogechat_config_get_plugin ("fifo");
    }

    dogechat_home = dogechat_info_get ("dogechat_dir", "");

    if (fifo_option && dogechat_home)
    {
        fifo_remove_old_pipes ();

        if (dogechat_strcasecmp (fifo_option, "on") == 0)
        {
            /*
             * build FIFO filename:
             *   "<dogechat_home>/dogechat_fifo_" + process PID
             */
            if (!fifo_filename)
            {
                filename_length = strlen (dogechat_home) + 64;
                fifo_filename = malloc (filename_length);
                snprintf (fifo_filename, filename_length,
                          "%s/%s%d",
                          dogechat_home, FIFO_FILENAME_PREFIX, (int) getpid());
            }

            fifo_fd = -1;

            /* create FIFO pipe, writable for user only */
            if (mkfifo (fifo_filename, 0600) == 0)
            {
                /* open FIFO pipe in read-only, non-blocking mode */
                if ((fifo_fd = open (fifo_filename,
                                     O_RDONLY | O_NONBLOCK)) != -1)
                {
                    if ((dogechat_fifo_plugin->debug >= 1) || !fifo_quiet)
                    {
                        dogechat_printf (NULL,
                                        _("%s: pipe opened (file: %s)"),
                                        FIFO_PLUGIN_NAME,
                                        fifo_filename);
                    }
                    fifo_fd_hook = dogechat_hook_fd (fifo_fd, 1, 0, 0,
                                                    &fifo_read, NULL);
                }
                else
                    dogechat_printf (NULL,
                                    _("%s%s: unable to open pipe (%s) for "
                                      "reading"),
                                    dogechat_prefix ("error"), FIFO_PLUGIN_NAME,
                                    fifo_filename);
            }
            else
            {
                dogechat_printf (NULL,
                                _("%s%s: unable to create pipe for remote "
                                  "control (%s): error %d %s"),
                                dogechat_prefix ("error"), FIFO_PLUGIN_NAME,
                                fifo_filename, errno, strerror (errno));
            }
        }
    }
}