Compare commits
9 Commits
dcc-fastse
...
wip/file-h
Author | SHA1 | Date | |
---|---|---|---|
eafc1e2b70 | |||
06d323025d | |||
c0c2668c10 | |||
7cf631f93c | |||
f5142c6724 | |||
3ba5581c6b | |||
d825b3514b | |||
650bddcfd1 | |||
089fe95a42 |
@ -29,7 +29,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;PERL520_EXPORTS;$(OwnFlags);%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;PERL520_EXPORTS;HAS_BOOL;$(OwnFlags);%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(IntDir);..\..\src\common;$(HexChatLib);$(PerlPath)\lib\CORE;$(Glib);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
@ -49,7 +49,7 @@ move hexchat.pm.h "$(IntDir)"</Command>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;_WIN64;_AMD64_;NDEBUG;_WINDOWS;_USRDLL;PERL520_EXPORTS;$(OwnFlags);%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WIN64;_AMD64_;NDEBUG;_WINDOWS;_USRDLL;PERL520_EXPORTS;HAS_BOOL;$(OwnFlags);%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(IntDir);..\..\src\common;$(HexChatLib);$(PerlPath)\lib\CORE;$(Glib);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
|
@ -77,7 +77,7 @@ list_addentry (GSList ** list, char *cmd, char *name)
|
||||
/* read it in from a buffer to our linked list */
|
||||
|
||||
static void
|
||||
list_load_from_data (GSList ** list, char *ibuf, int size)
|
||||
list_load_from_data (GSList ** list, char *ibuf, gsize size)
|
||||
{
|
||||
char cmd[384];
|
||||
char name[128];
|
||||
@ -110,36 +110,28 @@ list_load_from_data (GSList ** list, char *ibuf, int size)
|
||||
}
|
||||
|
||||
void
|
||||
list_loadconf (char *file, GSList ** list, char *defaultconf)
|
||||
list_loadconf (char *filename, GSList ** list, char *defaultconf)
|
||||
{
|
||||
char *filebuf;
|
||||
char *ibuf;
|
||||
int fd;
|
||||
struct stat st;
|
||||
GFile *file;
|
||||
char *data;
|
||||
gsize len;
|
||||
|
||||
filebuf = g_build_filename (get_xdir (), file, NULL);
|
||||
fd = g_open (filebuf, O_RDONLY | OFLAGS, 0);
|
||||
g_free (filebuf);
|
||||
file = hexchat_open_gfile (filename);
|
||||
|
||||
if (fd == -1)
|
||||
if (!g_file_query_exists (file, NULL))
|
||||
{
|
||||
if (defaultconf)
|
||||
list_load_from_data (list, defaultconf, strlen (defaultconf));
|
||||
return;
|
||||
}
|
||||
if (fstat (fd, &st) != 0)
|
||||
|
||||
if (g_file_load_contents (file, NULL, &data, &len, NULL, NULL))
|
||||
{
|
||||
perror ("fstat");
|
||||
abort ();
|
||||
list_load_from_data (list, data, len);
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
ibuf = g_malloc (st.st_size);
|
||||
read (fd, ibuf, st.st_size);
|
||||
close (fd);
|
||||
|
||||
list_load_from_data (list, ibuf, st.st_size);
|
||||
|
||||
g_free (ibuf);
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
void
|
||||
@ -214,40 +206,25 @@ cfg_get_str (char *cfg, const char *var, char *dest, int dest_len)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
cfg_put_str (int fh, char *var, char *value)
|
||||
int
|
||||
cfg_put_str (GOutputStream *ostream, const char *var, const char *value)
|
||||
{
|
||||
char buf[512];
|
||||
int len;
|
||||
|
||||
g_snprintf (buf, sizeof buf, "%s = %s\n", var, value);
|
||||
len = strlen (buf);
|
||||
return (write (fh, buf, len) == len);
|
||||
return (stream_writef (ostream, "%s = %s\n", var, value) != 0);
|
||||
}
|
||||
|
||||
int
|
||||
cfg_put_color (int fh, guint16 r, guint16 g, guint16 b, char *var)
|
||||
cfg_put_color (GOutputStream *ostream, guint16 r, guint16 g, guint16 b, char *var)
|
||||
{
|
||||
char buf[400];
|
||||
int len;
|
||||
|
||||
g_snprintf (buf, sizeof buf, "%s = %04hx %04hx %04hx\n", var, r, g, b);
|
||||
len = strlen (buf);
|
||||
return (write (fh, buf, len) == len);
|
||||
return (stream_writef (ostream, "%s = %04x %04x %04x\n", var, r, g, b) != 0);
|
||||
}
|
||||
|
||||
int
|
||||
cfg_put_int (int fh, int value, char *var)
|
||||
cfg_put_int (GOutputStream *ostream, int value, char *var)
|
||||
{
|
||||
char buf[400];
|
||||
int len;
|
||||
|
||||
if (value == -1)
|
||||
value = 1;
|
||||
|
||||
g_snprintf (buf, sizeof buf, "%s = %d\n", var, value);
|
||||
len = strlen (buf);
|
||||
return (write (fh, buf, len) == len);
|
||||
return (stream_writef (ostream, "%s = %d\n", var, value) != 0);
|
||||
}
|
||||
|
||||
int
|
||||
@ -338,18 +315,6 @@ check_config_dir (void)
|
||||
return g_access (get_xdir (), F_OK);
|
||||
}
|
||||
|
||||
static char *
|
||||
default_file (void)
|
||||
{
|
||||
static char *dfile = NULL;
|
||||
|
||||
if (!dfile)
|
||||
{
|
||||
dfile = g_build_filename (get_xdir (), "hexchat.conf", NULL);
|
||||
}
|
||||
return dfile;
|
||||
}
|
||||
|
||||
/* Keep these sorted!! */
|
||||
|
||||
const struct prefs vars[] =
|
||||
@ -373,7 +338,9 @@ const struct prefs vars[] =
|
||||
{"dcc_blocksize", P_OFFINT (hex_dcc_blocksize), TYPE_INT},
|
||||
{"dcc_completed_dir", P_OFFSET (hex_dcc_completed_dir), TYPE_STR},
|
||||
{"dcc_dir", P_OFFSET (hex_dcc_dir), TYPE_STR},
|
||||
#ifndef WIN32
|
||||
{"dcc_fast_send", P_OFFINT (hex_dcc_fast_send), TYPE_BOOL},
|
||||
#endif
|
||||
{"dcc_global_max_get_cps", P_OFFINT (hex_dcc_global_max_get_cps), TYPE_INT},
|
||||
{"dcc_global_max_send_cps", P_OFFINT (hex_dcc_global_max_send_cps), TYPE_INT},
|
||||
{"dcc_ip", P_OFFSET (hex_dcc_ip), TYPE_STR},
|
||||
@ -739,7 +706,9 @@ load_default_config(void)
|
||||
prefs.hex_away_show_once = 1;
|
||||
prefs.hex_away_track = 1;
|
||||
prefs.hex_dcc_auto_resume = 1;
|
||||
#ifndef WIN32
|
||||
prefs.hex_dcc_fast_send = 1;
|
||||
#endif
|
||||
prefs.hex_gui_autoopen_chat = 1;
|
||||
prefs.hex_gui_autoopen_dialog = 1;
|
||||
prefs.hex_gui_autoopen_recv = 1;
|
||||
@ -949,13 +918,21 @@ make_dcc_dirs (void)
|
||||
int
|
||||
load_config (void)
|
||||
{
|
||||
GFile *file;
|
||||
char *cfg, *sp;
|
||||
int res, val, i;
|
||||
|
||||
g_assert(check_config_dir () == 0);
|
||||
|
||||
file = hexchat_open_gfile ("hexchat.conf");
|
||||
|
||||
if (!g_file_get_contents (default_file (), &cfg, NULL, NULL))
|
||||
if (!g_file_load_contents (file, NULL, &cfg, NULL, NULL, NULL))
|
||||
{
|
||||
g_object_unref (file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_object_unref (file);
|
||||
|
||||
/* If the config is incomplete we have the default values loaded */
|
||||
load_default_config();
|
||||
@ -997,26 +974,26 @@ load_config (void)
|
||||
int
|
||||
save_config (void)
|
||||
{
|
||||
int fh, i;
|
||||
char *config, *new_config;
|
||||
GFile *file, *tmpfile;
|
||||
GOutputStream *ostream;
|
||||
GFileIOStream *tmpstream;
|
||||
gboolean ret;
|
||||
int i;
|
||||
|
||||
if (check_config_dir () != 0)
|
||||
make_config_dirs ();
|
||||
|
||||
config = default_file ();
|
||||
new_config = g_strconcat (config, ".new", NULL);
|
||||
|
||||
fh = g_open (new_config, OFLAGS | O_TRUNC | O_WRONLY | O_CREAT, 0600);
|
||||
if (fh == -1)
|
||||
tmpfile = g_file_new_tmp (NULL, &tmpstream, NULL);
|
||||
if (!tmpfile)
|
||||
{
|
||||
g_free (new_config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ostream = g_io_stream_get_output_stream (G_IO_STREAM(tmpstream));
|
||||
|
||||
if (!cfg_put_str (fh, "version", PACKAGE_VERSION))
|
||||
if (!cfg_put_str (ostream, "version", PACKAGE_VERSION))
|
||||
{
|
||||
close (fh);
|
||||
g_free (new_config);
|
||||
g_object_unref (tmpfile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1026,19 +1003,17 @@ save_config (void)
|
||||
switch (vars[i].type)
|
||||
{
|
||||
case TYPE_STR:
|
||||
if (!cfg_put_str (fh, vars[i].name, (char *) &prefs + vars[i].offset))
|
||||
if (!cfg_put_str (ostream, vars[i].name, (char *) &prefs + vars[i].offset))
|
||||
{
|
||||
close (fh);
|
||||
g_free (new_config);
|
||||
g_object_unref (tmpfile);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case TYPE_INT:
|
||||
case TYPE_BOOL:
|
||||
if (!cfg_put_int (fh, *((int *) &prefs + vars[i].offset), vars[i].name))
|
||||
if (!cfg_put_int (ostream, *((int *) &prefs + vars[i].offset), vars[i].name))
|
||||
{
|
||||
close (fh);
|
||||
g_free (new_config);
|
||||
g_object_unref (tmpfile);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -1046,23 +1021,15 @@ save_config (void)
|
||||
}
|
||||
while (vars[i].name);
|
||||
|
||||
if (close (fh) == -1)
|
||||
{
|
||||
g_free (new_config);
|
||||
return 0;
|
||||
}
|
||||
g_object_unref (ostream);
|
||||
|
||||
#ifdef WIN32
|
||||
g_unlink (config); /* win32 can't rename to an existing file */
|
||||
#endif
|
||||
if (g_rename (new_config, config) == -1)
|
||||
{
|
||||
g_free (new_config);
|
||||
return 0;
|
||||
}
|
||||
g_free (new_config);
|
||||
file = hexchat_open_gfile ("hexchat.conf");
|
||||
ret = g_file_move (tmpfile, file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL);
|
||||
|
||||
return 1;
|
||||
g_object_unref (tmpfile);
|
||||
g_object_unref (file);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1353,3 +1320,69 @@ hexchat_fopen_file (const char *file, const char *mode, int xof_flags)
|
||||
|
||||
return fh;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a #GFile* to a file in HexChat's config dir.
|
||||
* Must be g_object_unref()'d when done.
|
||||
* @filename must be in utf8 encoding.
|
||||
*/
|
||||
GFile *
|
||||
hexchat_open_gfile (const char *filename)
|
||||
{
|
||||
GFile *file;
|
||||
gchar *full_path, *full_path_fs;
|
||||
|
||||
if (g_path_is_absolute (filename))
|
||||
full_path = g_strdup (filename);
|
||||
else
|
||||
full_path = g_build_filename (get_xdir(), filename, NULL);
|
||||
full_path_fs = g_filename_from_utf8 (full_path, -1, NULL, NULL, NULL);
|
||||
|
||||
file = g_file_new_for_path (full_path_fs);
|
||||
|
||||
g_free (full_path);
|
||||
g_free (full_path_fs);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
G_GNUC_PRINTF (2, 3)
|
||||
gsize
|
||||
stream_writef (GOutputStream *ostream, const char *fmt, ...)
|
||||
{
|
||||
char *tmp;
|
||||
va_list args;
|
||||
gint len;
|
||||
gsize ret;
|
||||
|
||||
va_start (args, fmt);
|
||||
len = g_vasprintf (&tmp, fmt, args);
|
||||
va_end (args);
|
||||
|
||||
ret = g_output_stream_write (ostream, tmp, len, NULL, NULL);
|
||||
g_free (tmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
GDataInputStream *
|
||||
file_get_datainputstream (GFile *file)
|
||||
{
|
||||
GInputStream *stream;
|
||||
GDataInputStream *datastream;
|
||||
|
||||
stream = G_INPUT_STREAM(g_file_read (file, NULL, NULL));
|
||||
if (!stream)
|
||||
return NULL;
|
||||
|
||||
datastream = g_data_input_stream_new (stream);
|
||||
/*
|
||||
* This is to avoid any issues moving between windows/unix
|
||||
* but the docs mention an invalid \r without a following \n
|
||||
* can lock up the program
|
||||
*/
|
||||
g_data_input_stream_set_newline_type (datastream, G_DATA_STREAM_NEWLINE_TYPE_ANY);
|
||||
g_object_unref (stream);
|
||||
|
||||
return datastream;
|
||||
}
|
||||
|
@ -30,12 +30,13 @@ extern char *xdir;
|
||||
extern const char * const languages[LANGUAGES_LENGTH];
|
||||
|
||||
char *cfg_get_str (char *cfg, const char *var, char *dest, int dest_len);
|
||||
int cfg_put_str (GOutputStream *ostream, const char *var, const char *value);
|
||||
int cfg_get_bool (char *var);
|
||||
int cfg_get_int_with_result (char *cfg, char *var, int *result);
|
||||
int cfg_get_int (char *cfg, char *var);
|
||||
int cfg_put_int (int fh, int value, char *var);
|
||||
int cfg_put_int (GOutputStream *ostream, int value, char *var);
|
||||
int cfg_get_color (char *cfg, char *var, guint16 *r, guint16 *g, guint16 *b);
|
||||
int cfg_put_color (int fh, guint16 r, guint16 g, guint16 b, char *var);
|
||||
int cfg_put_color (GOutputStream *ostream, guint16 r, guint16 g, guint16 b, char *var);
|
||||
char *get_xdir (void);
|
||||
int check_config_dir (void);
|
||||
void load_default_config (void);
|
||||
@ -44,12 +45,15 @@ int make_dcc_dirs (void);
|
||||
int load_config (void);
|
||||
int save_config (void);
|
||||
void list_free (GSList ** list);
|
||||
void list_loadconf (char *file, GSList ** list, char *defaultconf);
|
||||
void list_loadconf (char *filename, GSList ** list, char *defaultconf);
|
||||
int list_delentry (GSList ** list, char *name);
|
||||
void list_addentry (GSList ** list, char *cmd, char *name);
|
||||
int cmd_set (session *sess, char *tbuf, char *word[], char *word_eol[]);
|
||||
int hexchat_open_file (const char *file, int flags, int mode, int xof_flags);
|
||||
FILE *hexchat_fopen_file (const char *file, const char *mode, int xof_flags);
|
||||
GFile *hexchat_open_gfile (const char *filename);
|
||||
gsize stream_writef (GOutputStream *ostream, const char *fmt, ...) G_GNUC_PRINTF (2, 3);
|
||||
GDataInputStream *file_get_datainputstream (GFile *file);
|
||||
|
||||
#define XOF_DOMODE 1
|
||||
#define XOF_FULLPATH 2
|
||||
|
166
src/common/dcc.c
166
src/common/dcc.c
@ -328,16 +328,15 @@ dcc_lookup_proxy (char *host, struct sockaddr_in *addr)
|
||||
|
||||
#define DCC_USE_PROXY() (prefs.hex_net_proxy_host[0] && prefs.hex_net_proxy_type>0 && prefs.hex_net_proxy_type<5 && prefs.hex_net_proxy_use!=1)
|
||||
|
||||
static void
|
||||
static int
|
||||
dcc_connect_sok (struct DCC *dcc)
|
||||
{
|
||||
int sok;
|
||||
struct sockaddr_in addr;
|
||||
|
||||
dcc->sok = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (dcc->sok == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
sok = socket (AF_INET, SOCK_STREAM, 0);
|
||||
if (sok == -1)
|
||||
return -1;
|
||||
|
||||
memset (&addr, 0, sizeof (addr));
|
||||
addr.sin_family = AF_INET;
|
||||
@ -345,9 +344,8 @@ dcc_connect_sok (struct DCC *dcc)
|
||||
{
|
||||
if (!dcc_lookup_proxy (prefs.hex_net_proxy_host, &addr))
|
||||
{
|
||||
closesocket (dcc->sok);
|
||||
dcc->sok = - 1;
|
||||
return;
|
||||
closesocket (sok);
|
||||
return -1;
|
||||
}
|
||||
addr.sin_port = htons (prefs.hex_net_proxy_port);
|
||||
}
|
||||
@ -357,14 +355,10 @@ dcc_connect_sok (struct DCC *dcc)
|
||||
addr.sin_addr.s_addr = htonl (dcc->addr);
|
||||
}
|
||||
|
||||
set_nonblocking (dcc->sok);
|
||||
connect (dcc->sok, (struct sockaddr *) &addr, sizeof (addr));
|
||||
set_nonblocking (sok);
|
||||
connect (sok, (struct sockaddr *) &addr, sizeof (addr));
|
||||
|
||||
#ifdef WIN32
|
||||
dcc->channel = g_io_channel_win32_new_socket (dcc->sok);
|
||||
#else
|
||||
dcc->channel = g_io_channel_unix_new (dcc->sok);
|
||||
#endif
|
||||
return sok;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -372,22 +366,16 @@ dcc_close (struct DCC *dcc, int dccstat, int destroy)
|
||||
{
|
||||
if (dcc->wiotag)
|
||||
{
|
||||
g_source_remove (dcc->wiotag);
|
||||
fe_input_remove (dcc->wiotag);
|
||||
dcc->wiotag = 0;
|
||||
}
|
||||
|
||||
if (dcc->iotag)
|
||||
{
|
||||
g_source_remove (dcc->iotag);
|
||||
fe_input_remove (dcc->iotag);
|
||||
dcc->iotag = 0;
|
||||
}
|
||||
|
||||
if (dcc->channel != NULL)
|
||||
{
|
||||
g_io_channel_unref (dcc->channel);
|
||||
dcc->channel = NULL;
|
||||
}
|
||||
|
||||
if (dcc->sok != -1)
|
||||
{
|
||||
closesocket (dcc->sok);
|
||||
@ -581,15 +569,13 @@ dcc_read_chat (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
|
||||
{
|
||||
if (dcc->throttled)
|
||||
{
|
||||
g_source_remove (dcc->iotag);
|
||||
fe_input_remove (dcc->iotag);
|
||||
dcc->iotag = 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!dcc->iotag)
|
||||
{
|
||||
dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_read_chat, dcc);
|
||||
}
|
||||
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read_chat, dcc);
|
||||
|
||||
len = recv (dcc->sok, lbuf, sizeof (lbuf) - 2, 0);
|
||||
if (len < 1)
|
||||
@ -722,15 +708,13 @@ dcc_read (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
|
||||
if (need_ack)
|
||||
dcc_send_ack (dcc);
|
||||
|
||||
g_source_remove (dcc->iotag);
|
||||
fe_input_remove (dcc->iotag);
|
||||
dcc->iotag = 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!dcc->iotag)
|
||||
{
|
||||
dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_read, dcc);
|
||||
}
|
||||
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read, dcc);
|
||||
|
||||
n = recv (dcc->sok, buf, sizeof (buf), 0);
|
||||
if (n < 1)
|
||||
@ -844,7 +828,7 @@ dcc_connect_finished (GIOChannel *source, GIOCondition condition, struct DCC *dc
|
||||
|
||||
if (dcc->iotag)
|
||||
{
|
||||
g_source_remove (dcc->iotag);
|
||||
fe_input_remove (dcc->iotag);
|
||||
dcc->iotag = 0;
|
||||
}
|
||||
|
||||
@ -857,22 +841,24 @@ dcc_connect_finished (GIOChannel *source, GIOCondition condition, struct DCC *dc
|
||||
switch (dcc->type)
|
||||
{
|
||||
case TYPE_RECV:
|
||||
dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_read, dcc);
|
||||
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read, dcc);
|
||||
EMIT_SIGNAL (XP_TE_DCCCONRECV, dcc->serv->front_session,
|
||||
dcc->nick, host, dcc->file, NULL, 0);
|
||||
break;
|
||||
case TYPE_SEND:
|
||||
/* passive send */
|
||||
dcc->fastsend = prefs.hex_dcc_fast_send;
|
||||
dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_read_ack, dcc);
|
||||
dcc_send_data (NULL, 0, (gpointer) dcc);
|
||||
if (dcc->fastsend)
|
||||
dcc->wiotag = fe_input_add (dcc->sok, FIA_WRITE, dcc_send_data, dcc);
|
||||
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read_ack, dcc);
|
||||
dcc_send_data (NULL, 0, (gpointer)dcc);
|
||||
EMIT_SIGNAL (XP_TE_DCCCONSEND, dcc->serv->front_session,
|
||||
dcc->nick, host, dcc->file, NULL, 0);
|
||||
break;
|
||||
case TYPE_CHATSEND: /* pchat */
|
||||
dcc_open_query (dcc->serv, dcc->nick);
|
||||
case TYPE_CHATRECV: /* normal chat */
|
||||
dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_read_chat, dcc);
|
||||
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read_chat, dcc);
|
||||
dcc->dccchat = g_new0 (struct dcc_chat, 1);
|
||||
EMIT_SIGNAL (XP_TE_DCCCONCHAT, dcc->serv->front_session,
|
||||
dcc->nick, host, NULL, NULL, 0);
|
||||
@ -905,7 +891,7 @@ read_proxy (struct DCC *dcc)
|
||||
fe_dcc_update (dcc);
|
||||
if (dcc->iotag)
|
||||
{
|
||||
g_source_remove (dcc->iotag);
|
||||
fe_input_remove (dcc->iotag);
|
||||
dcc->iotag = 0;
|
||||
}
|
||||
return FALSE;
|
||||
@ -935,7 +921,7 @@ write_proxy (struct DCC *dcc)
|
||||
fe_dcc_update (dcc);
|
||||
if (dcc->wiotag)
|
||||
{
|
||||
g_source_remove (dcc->wiotag);
|
||||
fe_input_remove (dcc->wiotag);
|
||||
dcc->wiotag = 0;
|
||||
}
|
||||
return FALSE;
|
||||
@ -973,14 +959,15 @@ dcc_wingate_proxy_traverse (GIOChannel *source, GIOCondition condition, struct D
|
||||
"%s %d\r\n", net_ip(dcc->addr),
|
||||
dcc->port);
|
||||
proxy->bufferused = 0;
|
||||
dcc->wiotag = g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR | G_IO_PRI, dcc_wingate_proxy_traverse, dcc);
|
||||
dcc->wiotag = fe_input_add (dcc->sok, FIA_WRITE|FIA_EX,
|
||||
dcc_wingate_proxy_traverse, dcc);
|
||||
++proxy->phase;
|
||||
}
|
||||
if (proxy->phase == 1)
|
||||
{
|
||||
if (!read_proxy (dcc))
|
||||
return TRUE;
|
||||
g_source_remove (dcc->wiotag);
|
||||
fe_input_remove (dcc->wiotag);
|
||||
dcc->wiotag = 0;
|
||||
dcc_connect_finished (source, 0, dcc);
|
||||
}
|
||||
@ -1011,7 +998,8 @@ dcc_socks_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
|
||||
memcpy (proxy->buffer, &sc, sizeof (sc));
|
||||
proxy->buffersize = 8 + strlen (sc.username) + 1;
|
||||
proxy->bufferused = 0;
|
||||
dcc->wiotag = g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR | G_IO_PRI, dcc_socks_proxy_traverse, dcc);
|
||||
dcc->wiotag = fe_input_add (dcc->sok, FIA_WRITE|FIA_EX,
|
||||
dcc_socks_proxy_traverse, dcc);
|
||||
++proxy->phase;
|
||||
}
|
||||
|
||||
@ -1019,11 +1007,12 @@ dcc_socks_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
|
||||
{
|
||||
if (!write_proxy (dcc))
|
||||
return TRUE;
|
||||
g_source_remove (dcc->wiotag);
|
||||
fe_input_remove (dcc->wiotag);
|
||||
dcc->wiotag = 0;
|
||||
proxy->bufferused = 0;
|
||||
proxy->buffersize = 8;
|
||||
dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_socks_proxy_traverse, dcc);
|
||||
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX,
|
||||
dcc_socks_proxy_traverse, dcc);
|
||||
++proxy->phase;
|
||||
}
|
||||
|
||||
@ -1031,7 +1020,7 @@ dcc_socks_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
|
||||
{
|
||||
if (!read_proxy (dcc))
|
||||
return TRUE;
|
||||
g_source_remove (dcc->iotag);
|
||||
fe_input_remove (dcc->iotag);
|
||||
dcc->iotag = 0;
|
||||
if (proxy->buffer[1] == 90)
|
||||
dcc_connect_finished (source, 0, dcc);
|
||||
@ -1069,7 +1058,8 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
|
||||
memcpy (proxy->buffer, &sc1, 3);
|
||||
proxy->buffersize = 3;
|
||||
proxy->bufferused = 0;
|
||||
dcc->wiotag = g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR | G_IO_PRI, dcc_socks5_proxy_traverse, dcc);
|
||||
dcc->wiotag = fe_input_add (dcc->sok, FIA_WRITE|FIA_EX,
|
||||
dcc_socks5_proxy_traverse, dcc);
|
||||
++proxy->phase;
|
||||
}
|
||||
|
||||
@ -1077,11 +1067,12 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
|
||||
{
|
||||
if (!write_proxy (dcc))
|
||||
return TRUE;
|
||||
g_source_remove (dcc->wiotag);
|
||||
fe_input_remove (dcc->wiotag);
|
||||
dcc->wiotag = 0;
|
||||
proxy->bufferused = 0;
|
||||
proxy->buffersize = 2;
|
||||
dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_socks5_proxy_traverse, dcc);
|
||||
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX,
|
||||
dcc_socks5_proxy_traverse, dcc);
|
||||
++proxy->phase;
|
||||
}
|
||||
|
||||
@ -1089,7 +1080,7 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
|
||||
{
|
||||
if (!read_proxy (dcc))
|
||||
return TRUE;
|
||||
g_source_remove (dcc->iotag);
|
||||
fe_input_remove (dcc->iotag);
|
||||
dcc->iotag = 0;
|
||||
|
||||
/* did the server say no auth required? */
|
||||
@ -1123,7 +1114,8 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
|
||||
|
||||
proxy->buffersize = 3 + len_u + len_p;
|
||||
proxy->bufferused = 0;
|
||||
dcc->wiotag = g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR | G_IO_PRI, dcc_socks5_proxy_traverse, dcc);
|
||||
dcc->wiotag = fe_input_add (dcc->sok, FIA_WRITE|FIA_EX,
|
||||
dcc_socks5_proxy_traverse, dcc);
|
||||
++proxy->phase;
|
||||
}
|
||||
else
|
||||
@ -1143,11 +1135,12 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
|
||||
{
|
||||
if (!write_proxy (dcc))
|
||||
return TRUE;
|
||||
g_source_remove (dcc->wiotag);
|
||||
fe_input_remove (dcc->wiotag);
|
||||
dcc->wiotag = 0;
|
||||
proxy->buffersize = 2;
|
||||
proxy->bufferused = 0;
|
||||
dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_socks5_proxy_traverse, dcc);
|
||||
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX,
|
||||
dcc_socks5_proxy_traverse, dcc);
|
||||
++proxy->phase;
|
||||
}
|
||||
|
||||
@ -1157,7 +1150,7 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
|
||||
return TRUE;
|
||||
if (dcc->iotag)
|
||||
{
|
||||
g_source_remove (dcc->iotag);
|
||||
fe_input_remove (dcc->iotag);
|
||||
dcc->iotag = 0;
|
||||
}
|
||||
if (proxy->buffer[1] != 0)
|
||||
@ -1185,7 +1178,8 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
|
||||
proxy->buffer[9] = (dcc->port & 0xFF);
|
||||
proxy->buffersize = 10;
|
||||
proxy->bufferused = 0;
|
||||
dcc->wiotag = g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR | G_IO_PRI, dcc_socks5_proxy_traverse, dcc);
|
||||
dcc->wiotag = fe_input_add (dcc->sok, FIA_WRITE|FIA_EX,
|
||||
dcc_socks5_proxy_traverse, dcc);
|
||||
++proxy->phase;
|
||||
}
|
||||
|
||||
@ -1193,11 +1187,12 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
|
||||
{
|
||||
if (!write_proxy (dcc))
|
||||
return TRUE;
|
||||
g_source_remove (dcc->wiotag);
|
||||
fe_input_remove (dcc->wiotag);
|
||||
dcc->wiotag = 0;
|
||||
proxy->buffersize = 4;
|
||||
proxy->bufferused = 0;
|
||||
dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_socks5_proxy_traverse, dcc);
|
||||
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX,
|
||||
dcc_socks5_proxy_traverse, dcc);
|
||||
++proxy->phase;
|
||||
}
|
||||
|
||||
@ -1207,7 +1202,7 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
|
||||
return TRUE;
|
||||
if (proxy->buffer[0] != 5 || proxy->buffer[1] != 0)
|
||||
{
|
||||
g_source_remove (dcc->iotag);
|
||||
fe_input_remove (dcc->iotag);
|
||||
dcc->iotag = 0;
|
||||
if (proxy->buffer[1] == 2)
|
||||
PrintText (dcc->serv->front_session, "SOCKS\tProxy refused to connect to host (not allowed).\n");
|
||||
@ -1238,7 +1233,7 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
|
||||
/* everything done? */
|
||||
if (proxy->bufferused == proxy->buffersize)
|
||||
{
|
||||
g_source_remove (dcc->iotag);
|
||||
fe_input_remove (dcc->iotag);
|
||||
dcc->iotag = 0;
|
||||
dcc_connect_finished (source, 0, dcc);
|
||||
}
|
||||
@ -1271,7 +1266,8 @@ dcc_http_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
|
||||
proxy->buffersize = n;
|
||||
proxy->bufferused = 0;
|
||||
memcpy (proxy->buffer, buf, proxy->buffersize);
|
||||
dcc->wiotag = g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR | G_IO_PRI, dcc_http_proxy_traverse, dcc);
|
||||
dcc->wiotag = fe_input_add (dcc->sok, FIA_WRITE|FIA_EX,
|
||||
dcc_http_proxy_traverse, dcc);
|
||||
++proxy->phase;
|
||||
}
|
||||
|
||||
@ -1279,10 +1275,11 @@ dcc_http_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
|
||||
{
|
||||
if (!write_proxy (dcc))
|
||||
return TRUE;
|
||||
g_source_remove (dcc->wiotag);
|
||||
fe_input_remove (dcc->wiotag);
|
||||
dcc->wiotag = 0;
|
||||
proxy->bufferused = 0;
|
||||
dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_http_proxy_traverse, dcc);
|
||||
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX,
|
||||
dcc_http_proxy_traverse, dcc);
|
||||
++proxy->phase;
|
||||
}
|
||||
|
||||
@ -1294,7 +1291,7 @@ dcc_http_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
|
||||
if (proxy->bufferused < 12 ||
|
||||
memcmp (proxy->buffer, "HTTP/", 5) || memcmp (proxy->buffer + 9, "200", 3))
|
||||
{
|
||||
g_source_remove (dcc->iotag);
|
||||
fe_input_remove (dcc->iotag);
|
||||
dcc->iotag = 0;
|
||||
PrintText (dcc->serv->front_session, proxy->buffer);
|
||||
dcc->dccstat = STAT_FAILED;
|
||||
@ -1324,7 +1321,7 @@ dcc_http_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
g_source_remove (dcc->iotag);
|
||||
fe_input_remove (dcc->iotag);
|
||||
dcc->iotag = 0;
|
||||
dcc_connect_finished (source, 0, dcc);
|
||||
}
|
||||
@ -1335,7 +1332,7 @@ dcc_http_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
|
||||
static gboolean
|
||||
dcc_proxy_connect (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
|
||||
{
|
||||
g_source_remove (dcc->iotag);
|
||||
fe_input_remove (dcc->iotag);
|
||||
dcc->iotag = 0;
|
||||
|
||||
if (!dcc_did_connect (source, condition, dcc))
|
||||
@ -1387,7 +1384,7 @@ dcc_connect (struct DCC *dcc)
|
||||
}
|
||||
else
|
||||
{
|
||||
dcc_connect_sok (dcc);
|
||||
dcc->sok = dcc_connect_sok (dcc);
|
||||
if (dcc->sok == -1)
|
||||
{
|
||||
dcc->dccstat = STAT_FAILED;
|
||||
@ -1395,13 +1392,9 @@ dcc_connect (struct DCC *dcc)
|
||||
return;
|
||||
}
|
||||
if (DCC_USE_PROXY ())
|
||||
{
|
||||
g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR | G_IO_PRI, dcc_proxy_connect, dcc);
|
||||
}
|
||||
dcc->iotag = fe_input_add (dcc->sok, FIA_WRITE|FIA_EX, dcc_proxy_connect, dcc);
|
||||
else
|
||||
{
|
||||
g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR | G_IO_PRI, dcc_connect_finished, dcc);
|
||||
}
|
||||
dcc->iotag = fe_input_add (dcc->sok, FIA_WRITE|FIA_EX, dcc_connect_finished, dcc);
|
||||
}
|
||||
|
||||
fe_dcc_update (dcc);
|
||||
@ -1421,7 +1414,7 @@ dcc_send_data (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
|
||||
|
||||
if (dcc->throttled)
|
||||
{
|
||||
g_source_remove (dcc->wiotag);
|
||||
fe_input_remove (dcc->wiotag);
|
||||
dcc->wiotag = 0;
|
||||
return FALSE;
|
||||
}
|
||||
@ -1431,6 +1424,8 @@ dcc_send_data (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
|
||||
if (dcc->ack < (dcc->pos & 0xFFFFFFFF))
|
||||
return TRUE;
|
||||
}
|
||||
else if (!dcc->wiotag)
|
||||
dcc->wiotag = fe_input_add (sok, FIA_WRITE, dcc_send_data, dcc);
|
||||
|
||||
buf = g_malloc (prefs.hex_dcc_blocksize);
|
||||
|
||||
@ -1456,18 +1451,13 @@ abortit:
|
||||
dcc->lasttime = time (0);
|
||||
}
|
||||
|
||||
if (dcc->pos < dcc->size)
|
||||
{
|
||||
if (!dcc->wiotag)
|
||||
{
|
||||
dcc->wiotag = g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_HUP | G_IO_ERR, dcc_send_data, dcc);
|
||||
}
|
||||
}
|
||||
else
|
||||
/* have we sent it all yet? */
|
||||
if (dcc->pos >= dcc->size)
|
||||
{
|
||||
/* it's all sent now, so remove the WRITE/SEND handler */
|
||||
if (dcc->wiotag)
|
||||
{
|
||||
g_source_remove (dcc->wiotag);
|
||||
fe_input_remove (dcc->wiotag);
|
||||
dcc->wiotag = 0;
|
||||
}
|
||||
}
|
||||
@ -1566,7 +1556,7 @@ dcc_accept (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
|
||||
|
||||
len = sizeof (CAddr);
|
||||
sok = accept (dcc->sok, (struct sockaddr *) &CAddr, &len);
|
||||
g_source_remove (dcc->iotag);
|
||||
fe_input_remove (dcc->iotag);
|
||||
dcc->iotag = 0;
|
||||
closesocket (dcc->sok);
|
||||
if (sok < 0)
|
||||
@ -1592,18 +1582,16 @@ dcc_accept (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
|
||||
{
|
||||
case TYPE_SEND:
|
||||
if (dcc->fastsend)
|
||||
{
|
||||
dcc->wiotag = g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR, dcc_send_data, dcc);
|
||||
}
|
||||
dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_read_ack, dcc);
|
||||
dcc_send_data (NULL, 0, (gpointer) dcc);
|
||||
dcc->wiotag = fe_input_add (sok, FIA_WRITE, dcc_send_data, dcc);
|
||||
dcc->iotag = fe_input_add (sok, FIA_READ|FIA_EX, dcc_read_ack, dcc);
|
||||
dcc_send_data (NULL, 0, (gpointer)dcc);
|
||||
EMIT_SIGNAL (XP_TE_DCCCONSEND, dcc->serv->front_session,
|
||||
dcc->nick, host, dcc->file, NULL, 0);
|
||||
break;
|
||||
|
||||
case TYPE_CHATSEND:
|
||||
dcc_open_query (dcc->serv, dcc->nick);
|
||||
dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_read_chat, dcc);
|
||||
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read_chat, dcc);
|
||||
dcc->dccchat = g_new0 (struct dcc_chat, 1);
|
||||
EMIT_SIGNAL (XP_TE_DCCCONCHAT, dcc->serv->front_session,
|
||||
dcc->nick, host, NULL, NULL, 0);
|
||||
@ -1720,7 +1708,7 @@ dcc_listen_init (struct DCC *dcc, session *sess)
|
||||
listen (dcc->sok, 1);
|
||||
set_blocking (dcc->sok);
|
||||
|
||||
dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_accept, dcc);
|
||||
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_accept, dcc);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -47,7 +47,6 @@ struct DCC
|
||||
guint32 addr; /* the 32bit IP number, host byte order */
|
||||
int fp; /* file pointer */
|
||||
int sok;
|
||||
GIOChannel* channel;
|
||||
int iotag; /* reading io tag */
|
||||
int wiotag; /* writing/sending io tag */
|
||||
int port;
|
||||
|
@ -64,7 +64,7 @@ void fe_message (char *msg, int flags);
|
||||
#define FIA_WRITE 2
|
||||
#define FIA_EX 4
|
||||
#define FIA_FD 8
|
||||
int fe_input_add (int sok, int flags, GIOFunc func, void *data);
|
||||
int fe_input_add (int sok, int flags, void *func, void *data);
|
||||
void fe_input_remove (int tag);
|
||||
void fe_idle_add (void *func, void *data);
|
||||
void fe_set_topic (struct session *sess, char *topic, char *stripped_topic);
|
||||
|
@ -447,7 +447,6 @@ session_new (server *serv, char *from, int type, int focus)
|
||||
|
||||
sess->server = serv;
|
||||
sess->logfd = -1;
|
||||
sess->scrollfd = -1;
|
||||
sess->type = type;
|
||||
|
||||
sess->alert_beep = SET_DEFAULT;
|
||||
|
@ -377,7 +377,8 @@ typedef struct session
|
||||
char channelkey[64]; /* XXX correct max length? */
|
||||
int limit; /* channel user limit */
|
||||
int logfd;
|
||||
int scrollfd; /* scrollback filedes */
|
||||
|
||||
GFile *scrollfile; /* scrollback file */
|
||||
int scrollwritten; /* number of lines written */
|
||||
|
||||
char lastnick[NICKLEN]; /* last nick you /msg'ed */
|
||||
|
@ -78,40 +78,72 @@ notc_msg (struct session *sess)
|
||||
static char *
|
||||
random_line (char *file_name)
|
||||
{
|
||||
FILE *fh;
|
||||
char buf[512];
|
||||
int lines, ran;
|
||||
GFile *file;
|
||||
char *data, *p, *ret = NULL;
|
||||
int lines = 0, ran;
|
||||
gsize len;
|
||||
|
||||
if (!file_name[0])
|
||||
goto nofile;
|
||||
return g_strdup ("");
|
||||
|
||||
fh = hexchat_fopen_file (file_name, "r", 0);
|
||||
if (!fh)
|
||||
file = hexchat_open_gfile (file_name);
|
||||
|
||||
if (!g_file_query_exists (file, NULL))
|
||||
{
|
||||
nofile:
|
||||
/* reason is not a file, an actual reason! */
|
||||
return g_strdup (file_name);
|
||||
}
|
||||
|
||||
/* count number of lines in file */
|
||||
lines = 0;
|
||||
while (fgets (buf, sizeof (buf), fh))
|
||||
lines++;
|
||||
|
||||
if (lines < 1)
|
||||
goto nofile;
|
||||
|
||||
/* go down a random number */
|
||||
rewind (fh);
|
||||
ran = RAND_INT (lines);
|
||||
do
|
||||
if (!g_file_load_contents (file, NULL, &data, &len, NULL, NULL))
|
||||
{
|
||||
fgets (buf, sizeof (buf), fh);
|
||||
lines--;
|
||||
g_object_unref (file);
|
||||
return g_strdup (file_name);
|
||||
}
|
||||
while (lines > ran);
|
||||
fclose (fh);
|
||||
return g_strdup (buf);
|
||||
|
||||
g_object_unref (file);
|
||||
|
||||
/* count number of lines in file */
|
||||
p = data;
|
||||
while (p != data + len)
|
||||
{
|
||||
if (*p == '\n')
|
||||
lines++;
|
||||
p++;
|
||||
}
|
||||
|
||||
if (!lines)
|
||||
{
|
||||
g_free (data);
|
||||
return g_strdup (file_name);
|
||||
}
|
||||
|
||||
/* create random number */
|
||||
ran = RAND_INT (lines);
|
||||
|
||||
/* get that random line */
|
||||
p = data;
|
||||
while (p != data + len)
|
||||
{
|
||||
if (*p == '\n')
|
||||
{
|
||||
if (!--ran)
|
||||
{
|
||||
char *end;
|
||||
end = strchr (++p, '\n');
|
||||
*end = '\0';
|
||||
ret = g_strdup (p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
g_free (data);
|
||||
if (ret)
|
||||
return ret;
|
||||
else
|
||||
return g_strdup (file_name);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
@ -2487,30 +2519,32 @@ cmd_list (struct session *sess, char *tbuf, char *word[], char *word_eol[])
|
||||
}
|
||||
|
||||
gboolean
|
||||
load_perform_file (session *sess, char *file)
|
||||
load_perform_file (session *sess, char *filename)
|
||||
{
|
||||
char tbuf[1024 + 4];
|
||||
char *nl;
|
||||
FILE *fp;
|
||||
GFile *file;
|
||||
GDataInputStream *istream;
|
||||
gchar *buf;
|
||||
|
||||
fp = hexchat_fopen_file (file, "r", 0); /* load files from config dir */
|
||||
if (!fp)
|
||||
return FALSE;
|
||||
file = hexchat_open_gfile (filename);
|
||||
|
||||
tbuf[1024] = 0;
|
||||
while (fgets (tbuf, 1024, fp))
|
||||
istream = file_get_datainputstream (file);
|
||||
if (!istream)
|
||||
{
|
||||
nl = strchr (tbuf, '\n');
|
||||
if (nl == tbuf) /* skip empty commands */
|
||||
continue;
|
||||
if (nl)
|
||||
*nl = 0;
|
||||
if (tbuf[0] == prefs.hex_input_command_char[0])
|
||||
handle_command (sess, tbuf + 1, TRUE);
|
||||
else
|
||||
handle_command (sess, tbuf, TRUE);
|
||||
g_object_unref (file);
|
||||
return FALSE;
|
||||
}
|
||||
fclose (fp);
|
||||
|
||||
while ((buf = g_data_input_stream_read_line_utf8 (istream, NULL, NULL, NULL)))
|
||||
{
|
||||
if (g_str_has_prefix (buf, prefs.hex_input_command_char))
|
||||
handle_command (sess, buf + 1, TRUE);
|
||||
else
|
||||
handle_command (sess, buf, TRUE);
|
||||
g_free (buf);
|
||||
}
|
||||
|
||||
g_object_unref (file);
|
||||
g_object_unref (istream);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -998,9 +998,9 @@ servlist_load_defaults (void)
|
||||
static int
|
||||
servlist_load (void)
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[2048];
|
||||
int len;
|
||||
GFile *file;
|
||||
GDataInputStream *istream;
|
||||
gchar *buf;
|
||||
ircnet *net = NULL;
|
||||
|
||||
/* simple migration we will keep for a short while */
|
||||
@ -1015,15 +1015,16 @@ servlist_load (void)
|
||||
g_free (oldfile);
|
||||
g_free (newfile);
|
||||
|
||||
fp = hexchat_fopen_file ("servlist.conf", "r", 0);
|
||||
if (!fp)
|
||||
|
||||
file = hexchat_open_gfile ("servlist.conf");
|
||||
|
||||
istream = file_get_datainputstream (file);
|
||||
if (!istream)
|
||||
return FALSE;
|
||||
|
||||
while (fgets (buf, sizeof (buf) - 2, fp))
|
||||
|
||||
while ((buf = g_data_input_stream_read_line_utf8 (istream, NULL, NULL, NULL)))
|
||||
{
|
||||
len = strlen (buf);
|
||||
buf[len] = 0;
|
||||
buf[len-1] = 0; /* remove the trailing \n */
|
||||
if (net)
|
||||
{
|
||||
switch (buf[0])
|
||||
@ -1096,8 +1097,12 @@ servlist_load (void)
|
||||
}
|
||||
if (buf[0] == 'N')
|
||||
net = servlist_net_add (buf + 2, /* comment */ NULL, FALSE);
|
||||
|
||||
g_free (buf);
|
||||
}
|
||||
fclose (fp);
|
||||
|
||||
g_object_unref (file);
|
||||
g_object_unref (istream);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -1138,8 +1143,9 @@ servlist_check_encoding (char *charset)
|
||||
int
|
||||
servlist_save (void)
|
||||
{
|
||||
FILE *fp;
|
||||
char *buf;
|
||||
GFile *file;
|
||||
GOutputStream *ostream;
|
||||
gchar *buf;
|
||||
ircnet *net;
|
||||
ircserver *serv;
|
||||
commandentry *cmd;
|
||||
@ -1148,52 +1154,37 @@ servlist_save (void)
|
||||
GSList *netlist;
|
||||
GSList *cmdlist;
|
||||
GSList *favlist;
|
||||
#ifndef WIN32
|
||||
int first = FALSE;
|
||||
|
||||
buf = g_build_filename (get_xdir (), "servlist.conf", NULL);
|
||||
if (g_access (buf, F_OK) != 0)
|
||||
first = TRUE;
|
||||
#endif
|
||||
file = hexchat_open_gfile ("servlist.conf");
|
||||
|
||||
fp = hexchat_fopen_file ("servlist.conf", "w", 0);
|
||||
if (!fp)
|
||||
{
|
||||
#ifndef WIN32
|
||||
g_free (buf);
|
||||
#endif
|
||||
ostream = G_OUTPUT_STREAM(g_file_replace (file, NULL, TRUE,
|
||||
G_FILE_CREATE_PRIVATE, NULL, NULL));
|
||||
if (!ostream)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
if (first)
|
||||
g_chmod (buf, 0600);
|
||||
|
||||
g_free (buf);
|
||||
#endif
|
||||
fprintf (fp, "v=" PACKAGE_VERSION "\n\n");
|
||||
stream_writef (ostream, "v=%s\n\n", PACKAGE_VERSION);
|
||||
|
||||
list = network_list;
|
||||
while (list)
|
||||
{
|
||||
net = list->data;
|
||||
|
||||
fprintf (fp, "N=%s\n", net->name);
|
||||
stream_writef (ostream, "N=%s\n", net->name);
|
||||
if (net->nick)
|
||||
fprintf (fp, "I=%s\n", net->nick);
|
||||
stream_writef (ostream, "I=%s\n", net->nick);
|
||||
if (net->nick2)
|
||||
fprintf (fp, "i=%s\n", net->nick2);
|
||||
stream_writef (ostream, "i=%s\n", net->nick2);
|
||||
if (net->user)
|
||||
fprintf (fp, "U=%s\n", net->user);
|
||||
stream_writef (ostream, "U=%s\n", net->user);
|
||||
if (net->real)
|
||||
fprintf (fp, "R=%s\n", net->real);
|
||||
stream_writef (ostream, "R=%s\n", net->real);
|
||||
if (net->pass)
|
||||
fprintf (fp, "P=%s\n", net->pass);
|
||||
stream_writef (ostream, "P=%s\n", net->pass);
|
||||
if (net->logintype)
|
||||
fprintf (fp, "L=%d\n", net->logintype);
|
||||
stream_writef (ostream, "L=%d\n", net->logintype);
|
||||
if (net->encoding)
|
||||
{
|
||||
fprintf (fp, "E=%s\n", net->encoding);
|
||||
stream_writef (ostream, "E=%s\n", net->encoding);
|
||||
if (!servlist_check_encoding (net->encoding))
|
||||
{
|
||||
buf = g_strdup_printf (_("Warning: \"%s\" character set is unknown. No conversion will be applied for network %s."),
|
||||
@ -1203,13 +1194,13 @@ servlist_save (void)
|
||||
}
|
||||
}
|
||||
|
||||
fprintf (fp, "F=%d\nD=%d\n", net->flags, net->selected);
|
||||
stream_writef (ostream, "F=%d\nD=%d\n", net->flags, net->selected);
|
||||
|
||||
netlist = net->servlist;
|
||||
while (netlist)
|
||||
{
|
||||
serv = netlist->data;
|
||||
fprintf (fp, "S=%s\n", serv->hostname);
|
||||
stream_writef (ostream, "S=%s\n", serv->hostname);
|
||||
netlist = netlist->next;
|
||||
}
|
||||
|
||||
@ -1217,7 +1208,7 @@ servlist_save (void)
|
||||
while (cmdlist)
|
||||
{
|
||||
cmd = cmdlist->data;
|
||||
fprintf (fp, "C=%s\n", cmd->command);
|
||||
stream_writef (ostream, "C=%s\n", cmd->command);
|
||||
cmdlist = cmdlist->next;
|
||||
}
|
||||
|
||||
@ -1228,26 +1219,24 @@ servlist_save (void)
|
||||
|
||||
if (favchan->key)
|
||||
{
|
||||
fprintf (fp, "J=%s,%s\n", favchan->name, favchan->key);
|
||||
stream_writef (ostream, "J=%s,%s\n", favchan->name, favchan->key);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (fp, "J=%s\n", favchan->name);
|
||||
stream_writef (ostream, "J=%s\n", favchan->name);
|
||||
}
|
||||
|
||||
favlist = favlist->next;
|
||||
}
|
||||
|
||||
if (fprintf (fp, "\n") < 1)
|
||||
{
|
||||
fclose (fp);
|
||||
if (!stream_writef (ostream, "\n"))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
fclose (fp);
|
||||
g_object_unref (file);
|
||||
g_object_unref (ostream);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -65,13 +65,15 @@ struct pevt_stage1
|
||||
static ca_context *ca_con;
|
||||
#endif
|
||||
|
||||
#define SCROLLBACK_MAX 32000
|
||||
|
||||
static void mkdir_p (char *filename);
|
||||
static char *log_create_filename (char *channame);
|
||||
|
||||
static char *
|
||||
scrollback_get_filename (session *sess)
|
||||
{
|
||||
char *net, *chan, *buf;
|
||||
char *net, *chan, *buf, *ret = NULL;
|
||||
|
||||
net = server_get_network (sess->server, FALSE);
|
||||
if (!net)
|
||||
@ -88,54 +90,19 @@ scrollback_get_filename (session *sess)
|
||||
buf = NULL;
|
||||
g_free (chan);
|
||||
|
||||
return buf;
|
||||
if (buf)
|
||||
{
|
||||
ret = g_filename_from_utf8 (buf, -1, NULL, NULL, NULL);
|
||||
g_free (buf);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
static void
|
||||
scrollback_unlock (session *sess)
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
if (scrollback_get_filename (sess, buf, sizeof (buf) - 6) == NULL)
|
||||
return;
|
||||
|
||||
strcat (buf, ".lock");
|
||||
unlink (buf);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
scrollback_lock (session *sess)
|
||||
{
|
||||
char buf[1024];
|
||||
int fh;
|
||||
|
||||
if (scrollback_get_filename (sess, buf, sizeof (buf) - 6) == NULL)
|
||||
return FALSE;
|
||||
|
||||
strcat (buf, ".lock");
|
||||
|
||||
if (access (buf, F_OK) == 0)
|
||||
return FALSE; /* can't get lock */
|
||||
|
||||
fh = open (buf, O_CREAT | O_TRUNC | O_APPEND | O_WRONLY, 0644);
|
||||
if (fh == -1)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void
|
||||
scrollback_close (session *sess)
|
||||
{
|
||||
if (sess->scrollfd != -1)
|
||||
{
|
||||
close (sess->scrollfd);
|
||||
sess->scrollfd = -1;
|
||||
}
|
||||
g_clear_object (&sess->scrollfile);
|
||||
}
|
||||
|
||||
/* shrink the file to roughly prefs.hex_text_max_lines */
|
||||
@ -143,29 +110,13 @@ scrollback_close (session *sess)
|
||||
static void
|
||||
scrollback_shrink (session *sess)
|
||||
{
|
||||
char *file;
|
||||
char *buf;
|
||||
int fh;
|
||||
int lines;
|
||||
int line;
|
||||
char *buf, *p;
|
||||
gsize len;
|
||||
char *p;
|
||||
gint offset, lines = 0;
|
||||
const gint max_lines = MIN(prefs.hex_text_max_lines, SCROLLBACK_MAX);
|
||||
|
||||
scrollback_close (sess);
|
||||
sess->scrollwritten = 0;
|
||||
lines = 0;
|
||||
|
||||
if ((file = scrollback_get_filename (sess)) == NULL)
|
||||
{
|
||||
g_free (file);
|
||||
if (!g_file_load_contents (sess->scrollfile, NULL, &buf, &len, NULL, NULL))
|
||||
return;
|
||||
}
|
||||
|
||||
if (!g_file_get_contents (file, &buf, &len, NULL))
|
||||
{
|
||||
g_free (file);
|
||||
return;
|
||||
}
|
||||
|
||||
/* count all lines */
|
||||
p = buf;
|
||||
@ -176,41 +127,37 @@ scrollback_shrink (session *sess)
|
||||
p++;
|
||||
}
|
||||
|
||||
fh = g_open (file, O_CREAT | O_TRUNC | O_APPEND | O_WRONLY | OFLAGS, 0644);
|
||||
g_free (file);
|
||||
if (fh == -1)
|
||||
{
|
||||
g_free (buf);
|
||||
return;
|
||||
}
|
||||
offset = lines - max_lines;
|
||||
|
||||
line = 0;
|
||||
/* now just go back to where we want to start the file */
|
||||
p = buf;
|
||||
lines = 0;
|
||||
while (p != buf + len)
|
||||
{
|
||||
if (*p == '\n')
|
||||
{
|
||||
line++;
|
||||
if (line >= lines - prefs.hex_text_max_lines &&
|
||||
p + 1 != buf + len)
|
||||
lines++;
|
||||
if (lines == offset)
|
||||
{
|
||||
p++;
|
||||
write (fh, p, len - (p - buf));
|
||||
break;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
close (fh);
|
||||
if (g_file_replace_contents (sess->scrollfile, p, strlen(p), NULL, FALSE,
|
||||
G_FILE_CREATE_PRIVATE, NULL, NULL, NULL))
|
||||
sess->scrollwritten = lines;
|
||||
|
||||
g_free (buf);
|
||||
}
|
||||
|
||||
static void
|
||||
scrollback_save (session *sess, char *text, time_t stamp)
|
||||
{
|
||||
GOutputStream *ostream;
|
||||
char *buf;
|
||||
int len;
|
||||
|
||||
if (sess->type == SESS_SERVER && prefs.hex_gui_tab_server == 1)
|
||||
return;
|
||||
@ -226,16 +173,25 @@ scrollback_save (session *sess, char *text, time_t stamp)
|
||||
return;
|
||||
}
|
||||
|
||||
if (sess->scrollfd == -1)
|
||||
if (!sess->scrollfile)
|
||||
{
|
||||
if ((buf = scrollback_get_filename (sess)) == NULL)
|
||||
return;
|
||||
|
||||
sess->scrollfd = g_open (buf, O_CREAT | O_APPEND | O_WRONLY | OFLAGS, 0644);
|
||||
sess->scrollfile = g_file_new_for_path (buf);
|
||||
g_free (buf);
|
||||
if (sess->scrollfd == -1)
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Users can delete the folder after it's created... */
|
||||
GFile *parent = g_file_get_parent (sess->scrollfile);
|
||||
g_file_make_directory_with_parents (parent, NULL, NULL);
|
||||
g_object_unref (parent);
|
||||
}
|
||||
|
||||
ostream = G_OUTPUT_STREAM(g_file_append_to (sess->scrollfile, G_FILE_CREATE_PRIVATE, NULL, NULL));
|
||||
if (!ostream)
|
||||
return;
|
||||
|
||||
if (!stamp)
|
||||
stamp = time(0);
|
||||
@ -243,31 +199,29 @@ scrollback_save (session *sess, char *text, time_t stamp)
|
||||
buf = g_strdup_printf ("T %d ", (int) stamp);
|
||||
else
|
||||
buf = g_strdup_printf ("T %" G_GINT64_FORMAT " ", (gint64)stamp);
|
||||
write (sess->scrollfd, buf, strlen (buf));
|
||||
g_free (buf);
|
||||
|
||||
len = strlen (text);
|
||||
write (sess->scrollfd, text, len);
|
||||
if (len && text[len - 1] != '\n')
|
||||
write (sess->scrollfd, "\n", 1);
|
||||
g_output_stream_write (ostream, buf, strlen (buf), NULL, NULL);
|
||||
g_output_stream_write (ostream, text, strlen (text), NULL, NULL);
|
||||
if (!g_str_has_suffix (text, "\n"))
|
||||
g_output_stream_write (ostream, "\n", 1, NULL, NULL);
|
||||
|
||||
g_free (buf);
|
||||
g_object_unref (ostream);
|
||||
|
||||
sess->scrollwritten++;
|
||||
|
||||
if ((sess->scrollwritten * 2 > prefs.hex_text_max_lines && prefs.hex_text_max_lines > 0) ||
|
||||
sess->scrollwritten > 32000)
|
||||
if ((sess->scrollwritten > prefs.hex_text_max_lines && prefs.hex_text_max_lines > 0) ||
|
||||
sess->scrollwritten > SCROLLBACK_MAX)
|
||||
scrollback_shrink (sess);
|
||||
}
|
||||
|
||||
void
|
||||
scrollback_load (session *sess)
|
||||
{
|
||||
char *buf;
|
||||
char *text;
|
||||
GDataInputStream *istream;
|
||||
gchar *buf, *text;
|
||||
gint lines = 0;
|
||||
time_t stamp;
|
||||
int lines;
|
||||
GIOChannel *io;
|
||||
GError *file_error = NULL;
|
||||
GError *io_err = NULL;
|
||||
|
||||
if (sess->text_scrollback == SET_DEFAULT)
|
||||
{
|
||||
@ -280,32 +234,28 @@ scrollback_load (session *sess)
|
||||
return;
|
||||
}
|
||||
|
||||
if ((buf = scrollback_get_filename (sess)) == NULL)
|
||||
return;
|
||||
if (!sess->scrollfile)
|
||||
{
|
||||
if ((buf = scrollback_get_filename (sess)) == NULL)
|
||||
return;
|
||||
|
||||
io = g_io_channel_new_file (buf, "r", &file_error);
|
||||
g_free (buf);
|
||||
if (!io)
|
||||
return;
|
||||
sess->scrollfile = g_file_new_for_path (buf);
|
||||
g_free (buf);
|
||||
}
|
||||
|
||||
lines = 0;
|
||||
istream = file_get_datainputstream (sess->scrollfile);
|
||||
if (!istream)
|
||||
return;
|
||||
|
||||
while (1)
|
||||
{
|
||||
GError *err = NULL;
|
||||
gsize n_bytes;
|
||||
GIOStatus io_status;
|
||||
|
||||
io_status = g_io_channel_read_line (io, &buf, &n_bytes, NULL, &io_err);
|
||||
|
||||
if (io_status == G_IO_STATUS_NORMAL)
|
||||
buf = g_data_input_stream_read_line_utf8 (istream, &n_bytes, NULL, &err);
|
||||
|
||||
if (!err && buf)
|
||||
{
|
||||
char *buf_tmp;
|
||||
|
||||
n_bytes--;
|
||||
buf_tmp = buf;
|
||||
buf = g_strndup (buf_tmp, n_bytes);
|
||||
g_free (buf_tmp);
|
||||
|
||||
/*
|
||||
* Some scrollback lines have three blanks after the timestamp and a newline
|
||||
* Some have only one blank and a newline
|
||||
@ -349,12 +299,27 @@ scrollback_load (session *sess)
|
||||
|
||||
g_free (buf);
|
||||
}
|
||||
else if (err)
|
||||
{
|
||||
/* If its only an encoding error it may be specific to the line */
|
||||
if (g_error_matches (err, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE))
|
||||
{
|
||||
g_warning ("Invalid utf8 in scrollback file\n");
|
||||
g_clear_error (&err);
|
||||
continue;
|
||||
}
|
||||
|
||||
else
|
||||
/* For general errors just give up */
|
||||
g_clear_error (&err);
|
||||
break;
|
||||
}
|
||||
else /* No new line */
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_io_channel_unref (io);
|
||||
g_object_unref (istream);
|
||||
|
||||
sess->scrollwritten = lines;
|
||||
|
||||
@ -386,14 +351,30 @@ log_close (session *sess)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* filename should be in utf8 encoding and will be
|
||||
* converted to filesystem encoding automatically.
|
||||
*/
|
||||
static void
|
||||
mkdir_p (char *filename)
|
||||
{
|
||||
char *dirname = g_path_get_dirname (filename);
|
||||
char *dirname, *dirname_fs;
|
||||
GError *err = NULL;
|
||||
|
||||
dirname = g_path_get_dirname (filename);
|
||||
dirname_fs = g_filename_from_utf8 (dirname, -1, NULL, NULL, &err);
|
||||
if (!dirname_fs)
|
||||
{
|
||||
g_warning ("%s", err->message);
|
||||
g_error_free (err);
|
||||
g_free (dirname);
|
||||
return;
|
||||
}
|
||||
|
||||
g_mkdir_with_parents (dirname, 0700);
|
||||
g_mkdir_with_parents (dirname_fs, 0700);
|
||||
|
||||
g_free (dirname);
|
||||
g_free (dirname_fs);
|
||||
}
|
||||
|
||||
static char *
|
||||
|
@ -68,42 +68,47 @@ url_clear (void)
|
||||
}
|
||||
|
||||
static int
|
||||
url_save_cb (char *url, FILE *fd)
|
||||
url_save_cb (char *url, GOutputStream *ostream)
|
||||
{
|
||||
fprintf (fd, "%s\n", url);
|
||||
stream_writef (ostream, "%s\n", url);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
url_save_tree (const char *fname, const char *mode, gboolean fullpath)
|
||||
url_save_tree (const char *fname)
|
||||
{
|
||||
FILE *fd;
|
||||
GFile *file;
|
||||
GOutputStream *ostream;
|
||||
|
||||
if (fullpath)
|
||||
fd = hexchat_fopen_file (fname, mode, XOF_FULLPATH);
|
||||
else
|
||||
fd = hexchat_fopen_file (fname, mode, 0);
|
||||
if (fd == NULL)
|
||||
return;
|
||||
file = hexchat_open_gfile (fname);
|
||||
|
||||
tree_foreach (url_tree, (tree_traverse_func *)url_save_cb, fd);
|
||||
fclose (fd);
|
||||
ostream = G_OUTPUT_STREAM(g_file_append_to (file, G_FILE_CREATE_NONE, NULL, NULL));
|
||||
if (ostream)
|
||||
{
|
||||
tree_foreach (url_tree, (tree_traverse_func *)url_save_cb, ostream);
|
||||
g_object_unref (ostream);
|
||||
}
|
||||
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
static void
|
||||
url_save_node (char* url)
|
||||
{
|
||||
FILE *fd;
|
||||
GFile *file;
|
||||
GOutputStream *ostream;
|
||||
|
||||
/* open <config>/url.log in append mode */
|
||||
fd = hexchat_fopen_file ("url.log", "a", 0);
|
||||
if (fd == NULL)
|
||||
file = hexchat_open_gfile ("url.log");
|
||||
|
||||
ostream = G_OUTPUT_STREAM(g_file_append_to (file, G_FILE_CREATE_NONE, NULL, NULL));
|
||||
if (ostream)
|
||||
{
|
||||
return;
|
||||
stream_writef (ostream, "%s\n", url);
|
||||
g_object_unref (ostream);
|
||||
}
|
||||
|
||||
fprintf (fd, "%s\n", url);
|
||||
fclose (fd);
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -33,7 +33,7 @@ extern void *url_tree;
|
||||
#define WORD_PATH -2
|
||||
|
||||
void url_clear (void);
|
||||
void url_save_tree (const char *fname, const char *mode, gboolean fullpath);
|
||||
void url_save_tree (const char *fname);
|
||||
int url_last (int *, int *);
|
||||
int url_check_word (const char *word);
|
||||
void url_check_line (char *buf);
|
||||
|
@ -530,7 +530,7 @@ get_sys_str (int with_cpu)
|
||||
#endif
|
||||
|
||||
int
|
||||
buf_get_line (char *ibuf, char **buf, int *position, int len)
|
||||
buf_get_line (char *ibuf, char **buf, int *position, gsize len)
|
||||
{
|
||||
int pos = *position, spos = pos;
|
||||
|
||||
|
@ -44,7 +44,7 @@ char *file_part (char *file);
|
||||
void for_files (char *dirname, char *mask, void callback (char *file));
|
||||
int rfc_casecmp (const char *, const char *);
|
||||
int rfc_ncasecmp (char *, char *, int);
|
||||
int buf_get_line (char *, char **, int *, int len);
|
||||
int buf_get_line (char *, char **, int *, gsize len);
|
||||
char *nocasestrstr (const char *text, const char *tofind);
|
||||
char *country (char *);
|
||||
void country_search (char *pattern, void *ud, void (*print)(void *, char *, ...));
|
||||
|
@ -468,7 +468,7 @@ fe_input_remove (int tag)
|
||||
}
|
||||
|
||||
int
|
||||
fe_input_add (int sok, int flags, GIOFunc func, void *data)
|
||||
fe_input_add (int sok, int flags, void *func, void *data)
|
||||
{
|
||||
int tag, type = 0;
|
||||
GIOChannel *channel;
|
||||
@ -489,7 +489,7 @@ fe_input_add (int sok, int flags, GIOFunc func, void *data)
|
||||
if (flags & FIA_EX)
|
||||
type |= G_IO_PRI;
|
||||
|
||||
tag = g_io_add_watch (channel, type, func, data);
|
||||
tag = g_io_add_watch (channel, type, (GIOFunc) func, data);
|
||||
g_io_channel_unref (channel);
|
||||
|
||||
return tag;
|
||||
|
@ -146,26 +146,33 @@ palette_load (void)
|
||||
void
|
||||
palette_save (void)
|
||||
{
|
||||
int i, j, fh;
|
||||
GFile *file;
|
||||
GOutputStream *ostream;
|
||||
int i, j;
|
||||
char prefname[256];
|
||||
|
||||
fh = hexchat_open_file ("colors.conf", O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE);
|
||||
if (fh != -1)
|
||||
file = hexchat_open_gfile ("colors.conf");
|
||||
|
||||
ostream = G_OUTPUT_STREAM(g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL));
|
||||
|
||||
if (ostream)
|
||||
{
|
||||
/* mIRC colors 0-31 are here */
|
||||
for (i = 0; i < 32; i++)
|
||||
{
|
||||
g_snprintf (prefname, sizeof prefname, "color_%d", i);
|
||||
cfg_put_color (fh, colors[i].red, colors[i].green, colors[i].blue, prefname);
|
||||
cfg_put_color (ostream, colors[i].red, colors[i].green, colors[i].blue, prefname);
|
||||
}
|
||||
|
||||
/* our special colors are mapped at 256+ */
|
||||
for (i = 256, j = 32; j < MAX_COL+1; i++, j++)
|
||||
{
|
||||
g_snprintf (prefname, sizeof prefname, "color_%d", i);
|
||||
cfg_put_color (fh, colors[j].red, colors[j].green, colors[j].blue, prefname);
|
||||
cfg_put_color (ostream, colors[j].red, colors[j].green, colors[j].blue, prefname);
|
||||
}
|
||||
|
||||
close (fh);
|
||||
|
||||
g_object_unref (ostream);
|
||||
}
|
||||
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ url_save_callback (void *arg1, char *file)
|
||||
{
|
||||
if (file)
|
||||
{
|
||||
url_save_tree (file, "w", TRUE);
|
||||
url_save_tree (file);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -422,7 +422,7 @@ fe_input_remove (int tag)
|
||||
}
|
||||
|
||||
int
|
||||
fe_input_add (int sok, int flags, GIOFunc func, void *data)
|
||||
fe_input_add (int sok, int flags, void *func, void *data)
|
||||
{
|
||||
int tag, type = 0;
|
||||
GIOChannel *channel;
|
||||
@ -443,7 +443,7 @@ fe_input_add (int sok, int flags, GIOFunc func, void *data)
|
||||
if (flags & FIA_EX)
|
||||
type |= G_IO_PRI;
|
||||
|
||||
tag = g_io_add_watch (channel, type, func, data);
|
||||
tag = g_io_add_watch (channel, type, (GIOFunc) func, data);
|
||||
g_io_channel_unref (channel);
|
||||
|
||||
return tag;
|
||||
|
Reference in New Issue
Block a user