Compare commits

..

9 Commits

Author SHA1 Message Date
TingPing
eafc1e2b70 Use Gio for url logger 2016-01-31 16:20:10 -05:00
TingPing
06d323025d Use Gio for load_perform_file() 2016-01-31 16:20:10 -05:00
TingPing
c0c2668c10 Use Gio for random_line() 2016-01-31 16:20:10 -05:00
TingPing
7cf631f93c Create convenience function to get datastreams 2016-01-31 16:16:18 -05:00
TingPing
f5142c6724 Use Gio for cfgfiles 2016-01-31 16:15:14 -05:00
TingPing
3ba5581c6b Move writeline func to cfgfiles 2016-01-31 15:40:16 -05:00
TingPing
d825b3514b Use Gio for servlist.conf 2016-01-31 15:39:08 -05:00
Patrick Griffis
650bddcfd1 Improve scrollback file handling
- Properly use filesystem encoding
- Validate utf8 when loading (hopefully fixing crashes)
- Use Gio
- Handle Windows line endings
- Remove dead code
- Fix respecting max length of scrollback files
2016-01-31 15:31:15 -05:00
Arnavion
089fe95a42 perl: Fixed warning about duplicate definition of bool. 2016-01-30 19:57:12 -08:00
19 changed files with 469 additions and 429 deletions

View File

@@ -29,7 +29,7 @@
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile> <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> <AdditionalIncludeDirectories>$(IntDir);..\..\src\common;$(HexChatLib);$(PerlPath)\lib\CORE;$(Glib);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
@@ -49,7 +49,7 @@ move hexchat.pm.h "$(IntDir)"</Command>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile> <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> <AdditionalIncludeDirectories>$(IntDir);..\..\src\common;$(HexChatLib);$(PerlPath)\lib\CORE;$(Glib);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>

View File

@@ -77,7 +77,7 @@ list_addentry (GSList ** list, char *cmd, char *name)
/* read it in from a buffer to our linked list */ /* read it in from a buffer to our linked list */
static void 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 cmd[384];
char name[128]; char name[128];
@@ -110,36 +110,28 @@ list_load_from_data (GSList ** list, char *ibuf, int size)
} }
void void
list_loadconf (char *file, GSList ** list, char *defaultconf) list_loadconf (char *filename, GSList ** list, char *defaultconf)
{ {
char *filebuf; GFile *file;
char *ibuf; char *data;
int fd; gsize len;
struct stat st;
filebuf = g_build_filename (get_xdir (), file, NULL); file = hexchat_open_gfile (filename);
fd = g_open (filebuf, O_RDONLY | OFLAGS, 0);
g_free (filebuf);
if (fd == -1) if (!g_file_query_exists (file, NULL))
{ {
if (defaultconf) if (defaultconf)
list_load_from_data (list, defaultconf, strlen (defaultconf)); list_load_from_data (list, defaultconf, strlen (defaultconf));
return; return;
} }
if (fstat (fd, &st) != 0)
if (g_file_load_contents (file, NULL, &data, &len, NULL, NULL))
{ {
perror ("fstat"); list_load_from_data (list, data, len);
abort (); g_free (data);
} }
ibuf = g_malloc (st.st_size); g_object_unref (file);
read (fd, ibuf, st.st_size);
close (fd);
list_load_from_data (list, ibuf, st.st_size);
g_free (ibuf);
} }
void void
@@ -214,40 +206,25 @@ cfg_get_str (char *cfg, const char *var, char *dest, int dest_len)
} }
} }
static int int
cfg_put_str (int fh, char *var, char *value) cfg_put_str (GOutputStream *ostream, const char *var, const char *value)
{ {
char buf[512]; return (stream_writef (ostream, "%s = %s\n", var, value) != 0);
int len;
g_snprintf (buf, sizeof buf, "%s = %s\n", var, value);
len = strlen (buf);
return (write (fh, buf, len) == len);
} }
int 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]; return (stream_writef (ostream, "%s = %04x %04x %04x\n", var, r, g, b) != 0);
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);
} }
int 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) if (value == -1)
value = 1; value = 1;
g_snprintf (buf, sizeof buf, "%s = %d\n", var, value); return (stream_writef (ostream, "%s = %d\n", var, value) != 0);
len = strlen (buf);
return (write (fh, buf, len) == len);
} }
int int
@@ -338,18 +315,6 @@ check_config_dir (void)
return g_access (get_xdir (), F_OK); 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!! */ /* Keep these sorted!! */
const struct prefs vars[] = const struct prefs vars[] =
@@ -373,7 +338,9 @@ const struct prefs vars[] =
{"dcc_blocksize", P_OFFINT (hex_dcc_blocksize), TYPE_INT}, {"dcc_blocksize", P_OFFINT (hex_dcc_blocksize), TYPE_INT},
{"dcc_completed_dir", P_OFFSET (hex_dcc_completed_dir), TYPE_STR}, {"dcc_completed_dir", P_OFFSET (hex_dcc_completed_dir), TYPE_STR},
{"dcc_dir", P_OFFSET (hex_dcc_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}, {"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_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_global_max_send_cps", P_OFFINT (hex_dcc_global_max_send_cps), TYPE_INT},
{"dcc_ip", P_OFFSET (hex_dcc_ip), TYPE_STR}, {"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_show_once = 1;
prefs.hex_away_track = 1; prefs.hex_away_track = 1;
prefs.hex_dcc_auto_resume = 1; prefs.hex_dcc_auto_resume = 1;
#ifndef WIN32
prefs.hex_dcc_fast_send = 1; prefs.hex_dcc_fast_send = 1;
#endif
prefs.hex_gui_autoopen_chat = 1; prefs.hex_gui_autoopen_chat = 1;
prefs.hex_gui_autoopen_dialog = 1; prefs.hex_gui_autoopen_dialog = 1;
prefs.hex_gui_autoopen_recv = 1; prefs.hex_gui_autoopen_recv = 1;
@@ -949,13 +918,21 @@ make_dcc_dirs (void)
int int
load_config (void) load_config (void)
{ {
GFile *file;
char *cfg, *sp; char *cfg, *sp;
int res, val, i; int res, val, i;
g_assert(check_config_dir () == 0); 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; return -1;
}
g_object_unref (file);
/* If the config is incomplete we have the default values loaded */ /* If the config is incomplete we have the default values loaded */
load_default_config(); load_default_config();
@@ -997,26 +974,26 @@ load_config (void)
int int
save_config (void) save_config (void)
{ {
int fh, i; GFile *file, *tmpfile;
char *config, *new_config; GOutputStream *ostream;
GFileIOStream *tmpstream;
gboolean ret;
int i;
if (check_config_dir () != 0) if (check_config_dir () != 0)
make_config_dirs (); 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); tmpfile = g_file_new_tmp (NULL, &tmpstream, NULL);
if (fh == -1) if (!tmpfile)
{ {
g_free (new_config);
return 0; 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_object_unref (tmpfile);
g_free (new_config);
return 0; return 0;
} }
@@ -1026,19 +1003,17 @@ save_config (void)
switch (vars[i].type) switch (vars[i].type)
{ {
case TYPE_STR: 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_object_unref (tmpfile);
g_free (new_config);
return 0; return 0;
} }
break; break;
case TYPE_INT: case TYPE_INT:
case TYPE_BOOL: 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_object_unref (tmpfile);
g_free (new_config);
return 0; return 0;
} }
} }
@@ -1046,23 +1021,15 @@ save_config (void)
} }
while (vars[i].name); while (vars[i].name);
if (close (fh) == -1) g_object_unref (ostream);
{
g_free (new_config);
return 0;
}
#ifdef WIN32 file = hexchat_open_gfile ("hexchat.conf");
g_unlink (config); /* win32 can't rename to an existing file */ ret = g_file_move (tmpfile, file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL);
#endif
if (g_rename (new_config, config) == -1)
{
g_free (new_config);
return 0;
}
g_free (new_config);
return 1; g_object_unref (tmpfile);
g_object_unref (file);
return ret;
} }
static void static void
@@ -1353,3 +1320,69 @@ hexchat_fopen_file (const char *file, const char *mode, int xof_flags)
return fh; 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;
}

View File

@@ -30,12 +30,13 @@ extern char *xdir;
extern const char * const languages[LANGUAGES_LENGTH]; extern const char * const languages[LANGUAGES_LENGTH];
char *cfg_get_str (char *cfg, const char *var, char *dest, int dest_len); 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_bool (char *var);
int cfg_get_int_with_result (char *cfg, char *var, int *result); int cfg_get_int_with_result (char *cfg, char *var, int *result);
int cfg_get_int (char *cfg, char *var); 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_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); char *get_xdir (void);
int check_config_dir (void); int check_config_dir (void);
void load_default_config (void); void load_default_config (void);
@@ -44,12 +45,15 @@ int make_dcc_dirs (void);
int load_config (void); int load_config (void);
int save_config (void); int save_config (void);
void list_free (GSList ** list); 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); int list_delentry (GSList ** list, char *name);
void list_addentry (GSList ** list, char *cmd, char *name); void list_addentry (GSList ** list, char *cmd, char *name);
int cmd_set (session *sess, char *tbuf, char *word[], char *word_eol[]); 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); 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); 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_DOMODE 1
#define XOF_FULLPATH 2 #define XOF_FULLPATH 2

View File

@@ -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) #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) dcc_connect_sok (struct DCC *dcc)
{ {
int sok;
struct sockaddr_in addr; struct sockaddr_in addr;
dcc->sok = socket(AF_INET, SOCK_STREAM, 0); sok = socket (AF_INET, SOCK_STREAM, 0);
if (dcc->sok == -1) if (sok == -1)
{ return -1;
return;
}
memset (&addr, 0, sizeof (addr)); memset (&addr, 0, sizeof (addr));
addr.sin_family = AF_INET; 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)) if (!dcc_lookup_proxy (prefs.hex_net_proxy_host, &addr))
{ {
closesocket (dcc->sok); closesocket (sok);
dcc->sok = - 1; return -1;
return;
} }
addr.sin_port = htons (prefs.hex_net_proxy_port); 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); addr.sin_addr.s_addr = htonl (dcc->addr);
} }
set_nonblocking (dcc->sok); set_nonblocking (sok);
connect (dcc->sok, (struct sockaddr *) &addr, sizeof (addr)); connect (sok, (struct sockaddr *) &addr, sizeof (addr));
#ifdef WIN32 return sok;
dcc->channel = g_io_channel_win32_new_socket (dcc->sok);
#else
dcc->channel = g_io_channel_unix_new (dcc->sok);
#endif
} }
static void static void
@@ -372,22 +366,16 @@ dcc_close (struct DCC *dcc, int dccstat, int destroy)
{ {
if (dcc->wiotag) if (dcc->wiotag)
{ {
g_source_remove (dcc->wiotag); fe_input_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
} }
if (dcc->iotag) if (dcc->iotag)
{ {
g_source_remove (dcc->iotag); fe_input_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
} }
if (dcc->channel != NULL)
{
g_io_channel_unref (dcc->channel);
dcc->channel = NULL;
}
if (dcc->sok != -1) if (dcc->sok != -1)
{ {
closesocket (dcc->sok); closesocket (dcc->sok);
@@ -581,15 +569,13 @@ dcc_read_chat (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
{ {
if (dcc->throttled) if (dcc->throttled)
{ {
g_source_remove (dcc->iotag); fe_input_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
return FALSE; return FALSE;
} }
if (!dcc->iotag) if (!dcc->iotag)
{ dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read_chat, dcc);
dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_read_chat, dcc);
}
len = recv (dcc->sok, lbuf, sizeof (lbuf) - 2, 0); len = recv (dcc->sok, lbuf, sizeof (lbuf) - 2, 0);
if (len < 1) if (len < 1)
@@ -722,15 +708,13 @@ dcc_read (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
if (need_ack) if (need_ack)
dcc_send_ack (dcc); dcc_send_ack (dcc);
g_source_remove (dcc->iotag); fe_input_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
return FALSE; return FALSE;
} }
if (!dcc->iotag) if (!dcc->iotag)
{ dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read, dcc);
dcc->iotag = g_io_add_watch (dcc->channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI, dcc_read, dcc);
}
n = recv (dcc->sok, buf, sizeof (buf), 0); n = recv (dcc->sok, buf, sizeof (buf), 0);
if (n < 1) if (n < 1)
@@ -844,7 +828,7 @@ dcc_connect_finished (GIOChannel *source, GIOCondition condition, struct DCC *dc
if (dcc->iotag) if (dcc->iotag)
{ {
g_source_remove (dcc->iotag); fe_input_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
} }
@@ -857,22 +841,24 @@ dcc_connect_finished (GIOChannel *source, GIOCondition condition, struct DCC *dc
switch (dcc->type) switch (dcc->type)
{ {
case TYPE_RECV: 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, EMIT_SIGNAL (XP_TE_DCCCONRECV, dcc->serv->front_session,
dcc->nick, host, dcc->file, NULL, 0); dcc->nick, host, dcc->file, NULL, 0);
break; break;
case TYPE_SEND: case TYPE_SEND:
/* passive send */ /* passive send */
dcc->fastsend = prefs.hex_dcc_fast_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); if (dcc->fastsend)
dcc_send_data (NULL, 0, (gpointer) dcc); 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, EMIT_SIGNAL (XP_TE_DCCCONSEND, dcc->serv->front_session,
dcc->nick, host, dcc->file, NULL, 0); dcc->nick, host, dcc->file, NULL, 0);
break; break;
case TYPE_CHATSEND: /* pchat */ case TYPE_CHATSEND: /* pchat */
dcc_open_query (dcc->serv, dcc->nick); dcc_open_query (dcc->serv, dcc->nick);
case TYPE_CHATRECV: /* normal chat */ 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); dcc->dccchat = g_new0 (struct dcc_chat, 1);
EMIT_SIGNAL (XP_TE_DCCCONCHAT, dcc->serv->front_session, EMIT_SIGNAL (XP_TE_DCCCONCHAT, dcc->serv->front_session,
dcc->nick, host, NULL, NULL, 0); dcc->nick, host, NULL, NULL, 0);
@@ -905,7 +891,7 @@ read_proxy (struct DCC *dcc)
fe_dcc_update (dcc); fe_dcc_update (dcc);
if (dcc->iotag) if (dcc->iotag)
{ {
g_source_remove (dcc->iotag); fe_input_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
} }
return FALSE; return FALSE;
@@ -935,7 +921,7 @@ write_proxy (struct DCC *dcc)
fe_dcc_update (dcc); fe_dcc_update (dcc);
if (dcc->wiotag) if (dcc->wiotag)
{ {
g_source_remove (dcc->wiotag); fe_input_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
} }
return FALSE; return FALSE;
@@ -973,14 +959,15 @@ dcc_wingate_proxy_traverse (GIOChannel *source, GIOCondition condition, struct D
"%s %d\r\n", net_ip(dcc->addr), "%s %d\r\n", net_ip(dcc->addr),
dcc->port); dcc->port);
proxy->bufferused = 0; 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; ++proxy->phase;
} }
if (proxy->phase == 1) if (proxy->phase == 1)
{ {
if (!read_proxy (dcc)) if (!read_proxy (dcc))
return TRUE; return TRUE;
g_source_remove (dcc->wiotag); fe_input_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
dcc_connect_finished (source, 0, dcc); 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)); memcpy (proxy->buffer, &sc, sizeof (sc));
proxy->buffersize = 8 + strlen (sc.username) + 1; proxy->buffersize = 8 + strlen (sc.username) + 1;
proxy->bufferused = 0; 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; ++proxy->phase;
} }
@@ -1019,11 +1007,12 @@ dcc_socks_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
{ {
if (!write_proxy (dcc)) if (!write_proxy (dcc))
return TRUE; return TRUE;
g_source_remove (dcc->wiotag); fe_input_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
proxy->bufferused = 0; proxy->bufferused = 0;
proxy->buffersize = 8; 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; ++proxy->phase;
} }
@@ -1031,7 +1020,7 @@ dcc_socks_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
{ {
if (!read_proxy (dcc)) if (!read_proxy (dcc))
return TRUE; return TRUE;
g_source_remove (dcc->iotag); fe_input_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
if (proxy->buffer[1] == 90) if (proxy->buffer[1] == 90)
dcc_connect_finished (source, 0, dcc); 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); memcpy (proxy->buffer, &sc1, 3);
proxy->buffersize = 3; proxy->buffersize = 3;
proxy->bufferused = 0; 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; ++proxy->phase;
} }
@@ -1077,11 +1067,12 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
{ {
if (!write_proxy (dcc)) if (!write_proxy (dcc))
return TRUE; return TRUE;
g_source_remove (dcc->wiotag); fe_input_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
proxy->bufferused = 0; proxy->bufferused = 0;
proxy->buffersize = 2; 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; ++proxy->phase;
} }
@@ -1089,7 +1080,7 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
{ {
if (!read_proxy (dcc)) if (!read_proxy (dcc))
return TRUE; return TRUE;
g_source_remove (dcc->iotag); fe_input_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
/* did the server say no auth required? */ /* 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->buffersize = 3 + len_u + len_p;
proxy->bufferused = 0; 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; ++proxy->phase;
} }
else else
@@ -1143,11 +1135,12 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
{ {
if (!write_proxy (dcc)) if (!write_proxy (dcc))
return TRUE; return TRUE;
g_source_remove (dcc->wiotag); fe_input_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
proxy->buffersize = 2; proxy->buffersize = 2;
proxy->bufferused = 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_socks5_proxy_traverse, dcc); dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX,
dcc_socks5_proxy_traverse, dcc);
++proxy->phase; ++proxy->phase;
} }
@@ -1157,7 +1150,7 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
return TRUE; return TRUE;
if (dcc->iotag) if (dcc->iotag)
{ {
g_source_remove (dcc->iotag); fe_input_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
} }
if (proxy->buffer[1] != 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->buffer[9] = (dcc->port & 0xFF);
proxy->buffersize = 10; proxy->buffersize = 10;
proxy->bufferused = 0; 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; ++proxy->phase;
} }
@@ -1193,11 +1187,12 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
{ {
if (!write_proxy (dcc)) if (!write_proxy (dcc))
return TRUE; return TRUE;
g_source_remove (dcc->wiotag); fe_input_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
proxy->buffersize = 4; proxy->buffersize = 4;
proxy->bufferused = 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_socks5_proxy_traverse, dcc); dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX,
dcc_socks5_proxy_traverse, dcc);
++proxy->phase; ++proxy->phase;
} }
@@ -1207,7 +1202,7 @@ dcc_socks5_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DC
return TRUE; return TRUE;
if (proxy->buffer[0] != 5 || proxy->buffer[1] != 0) if (proxy->buffer[0] != 5 || proxy->buffer[1] != 0)
{ {
g_source_remove (dcc->iotag); fe_input_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
if (proxy->buffer[1] == 2) if (proxy->buffer[1] == 2)
PrintText (dcc->serv->front_session, "SOCKS\tProxy refused to connect to host (not allowed).\n"); 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? */ /* everything done? */
if (proxy->bufferused == proxy->buffersize) if (proxy->bufferused == proxy->buffersize)
{ {
g_source_remove (dcc->iotag); fe_input_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
dcc_connect_finished (source, 0, dcc); dcc_connect_finished (source, 0, dcc);
} }
@@ -1271,7 +1266,8 @@ dcc_http_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
proxy->buffersize = n; proxy->buffersize = n;
proxy->bufferused = 0; proxy->bufferused = 0;
memcpy (proxy->buffer, buf, proxy->buffersize); 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; ++proxy->phase;
} }
@@ -1279,10 +1275,11 @@ dcc_http_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
{ {
if (!write_proxy (dcc)) if (!write_proxy (dcc))
return TRUE; return TRUE;
g_source_remove (dcc->wiotag); fe_input_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
proxy->bufferused = 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; ++proxy->phase;
} }
@@ -1294,7 +1291,7 @@ dcc_http_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
if (proxy->bufferused < 12 || if (proxy->bufferused < 12 ||
memcmp (proxy->buffer, "HTTP/", 5) || memcmp (proxy->buffer + 9, "200", 3)) memcmp (proxy->buffer, "HTTP/", 5) || memcmp (proxy->buffer + 9, "200", 3))
{ {
g_source_remove (dcc->iotag); fe_input_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
PrintText (dcc->serv->front_session, proxy->buffer); PrintText (dcc->serv->front_session, proxy->buffer);
dcc->dccstat = STAT_FAILED; dcc->dccstat = STAT_FAILED;
@@ -1324,7 +1321,7 @@ dcc_http_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
else else
return TRUE; return TRUE;
} }
g_source_remove (dcc->iotag); fe_input_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
dcc_connect_finished (source, 0, dcc); dcc_connect_finished (source, 0, dcc);
} }
@@ -1335,7 +1332,7 @@ dcc_http_proxy_traverse (GIOChannel *source, GIOCondition condition, struct DCC
static gboolean static gboolean
dcc_proxy_connect (GIOChannel *source, GIOCondition condition, struct DCC *dcc) dcc_proxy_connect (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
{ {
g_source_remove (dcc->iotag); fe_input_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
if (!dcc_did_connect (source, condition, dcc)) if (!dcc_did_connect (source, condition, dcc))
@@ -1387,7 +1384,7 @@ dcc_connect (struct DCC *dcc)
} }
else else
{ {
dcc_connect_sok (dcc); dcc->sok = dcc_connect_sok (dcc);
if (dcc->sok == -1) if (dcc->sok == -1)
{ {
dcc->dccstat = STAT_FAILED; dcc->dccstat = STAT_FAILED;
@@ -1395,13 +1392,9 @@ dcc_connect (struct DCC *dcc)
return; return;
} }
if (DCC_USE_PROXY ()) if (DCC_USE_PROXY ())
{ dcc->iotag = fe_input_add (dcc->sok, FIA_WRITE|FIA_EX, dcc_proxy_connect, dcc);
g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR | G_IO_PRI, dcc_proxy_connect, dcc);
}
else else
{ dcc->iotag = fe_input_add (dcc->sok, FIA_WRITE|FIA_EX, dcc_connect_finished, dcc);
g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR | G_IO_PRI, dcc_connect_finished, dcc);
}
} }
fe_dcc_update (dcc); fe_dcc_update (dcc);
@@ -1421,7 +1414,7 @@ dcc_send_data (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
if (dcc->throttled) if (dcc->throttled)
{ {
g_source_remove (dcc->wiotag); fe_input_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
return FALSE; return FALSE;
} }
@@ -1431,6 +1424,8 @@ dcc_send_data (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
if (dcc->ack < (dcc->pos & 0xFFFFFFFF)) if (dcc->ack < (dcc->pos & 0xFFFFFFFF))
return TRUE; 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); buf = g_malloc (prefs.hex_dcc_blocksize);
@@ -1456,18 +1451,13 @@ abortit:
dcc->lasttime = time (0); dcc->lasttime = time (0);
} }
if (dcc->pos < dcc->size) /* have we sent it all yet? */
{ 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
{ {
/* it's all sent now, so remove the WRITE/SEND handler */
if (dcc->wiotag) if (dcc->wiotag)
{ {
g_source_remove (dcc->wiotag); fe_input_remove (dcc->wiotag);
dcc->wiotag = 0; dcc->wiotag = 0;
} }
} }
@@ -1566,7 +1556,7 @@ dcc_accept (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
len = sizeof (CAddr); len = sizeof (CAddr);
sok = accept (dcc->sok, (struct sockaddr *) &CAddr, &len); sok = accept (dcc->sok, (struct sockaddr *) &CAddr, &len);
g_source_remove (dcc->iotag); fe_input_remove (dcc->iotag);
dcc->iotag = 0; dcc->iotag = 0;
closesocket (dcc->sok); closesocket (dcc->sok);
if (sok < 0) if (sok < 0)
@@ -1592,18 +1582,16 @@ dcc_accept (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
{ {
case TYPE_SEND: case TYPE_SEND:
if (dcc->fastsend) if (dcc->fastsend)
{ dcc->wiotag = fe_input_add (sok, FIA_WRITE, dcc_send_data, dcc);
dcc->wiotag = g_io_add_watch (dcc->channel, G_IO_OUT | G_IO_ERR, 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);
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);
EMIT_SIGNAL (XP_TE_DCCCONSEND, dcc->serv->front_session, EMIT_SIGNAL (XP_TE_DCCCONSEND, dcc->serv->front_session,
dcc->nick, host, dcc->file, NULL, 0); dcc->nick, host, dcc->file, NULL, 0);
break; break;
case TYPE_CHATSEND: case TYPE_CHATSEND:
dcc_open_query (dcc->serv, dcc->nick); 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); dcc->dccchat = g_new0 (struct dcc_chat, 1);
EMIT_SIGNAL (XP_TE_DCCCONCHAT, dcc->serv->front_session, EMIT_SIGNAL (XP_TE_DCCCONCHAT, dcc->serv->front_session,
dcc->nick, host, NULL, NULL, 0); dcc->nick, host, NULL, NULL, 0);
@@ -1720,7 +1708,7 @@ dcc_listen_init (struct DCC *dcc, session *sess)
listen (dcc->sok, 1); listen (dcc->sok, 1);
set_blocking (dcc->sok); 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; return TRUE;
} }

View File

@@ -47,7 +47,6 @@ struct DCC
guint32 addr; /* the 32bit IP number, host byte order */ guint32 addr; /* the 32bit IP number, host byte order */
int fp; /* file pointer */ int fp; /* file pointer */
int sok; int sok;
GIOChannel* channel;
int iotag; /* reading io tag */ int iotag; /* reading io tag */
int wiotag; /* writing/sending io tag */ int wiotag; /* writing/sending io tag */
int port; int port;

View File

@@ -64,7 +64,7 @@ void fe_message (char *msg, int flags);
#define FIA_WRITE 2 #define FIA_WRITE 2
#define FIA_EX 4 #define FIA_EX 4
#define FIA_FD 8 #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_input_remove (int tag);
void fe_idle_add (void *func, void *data); void fe_idle_add (void *func, void *data);
void fe_set_topic (struct session *sess, char *topic, char *stripped_topic); void fe_set_topic (struct session *sess, char *topic, char *stripped_topic);

View File

@@ -447,7 +447,6 @@ session_new (server *serv, char *from, int type, int focus)
sess->server = serv; sess->server = serv;
sess->logfd = -1; sess->logfd = -1;
sess->scrollfd = -1;
sess->type = type; sess->type = type;
sess->alert_beep = SET_DEFAULT; sess->alert_beep = SET_DEFAULT;

View File

@@ -377,7 +377,8 @@ typedef struct session
char channelkey[64]; /* XXX correct max length? */ char channelkey[64]; /* XXX correct max length? */
int limit; /* channel user limit */ int limit; /* channel user limit */
int logfd; int logfd;
int scrollfd; /* scrollback filedes */
GFile *scrollfile; /* scrollback file */
int scrollwritten; /* number of lines written */ int scrollwritten; /* number of lines written */
char lastnick[NICKLEN]; /* last nick you /msg'ed */ char lastnick[NICKLEN]; /* last nick you /msg'ed */

View File

@@ -78,40 +78,72 @@ notc_msg (struct session *sess)
static char * static char *
random_line (char *file_name) random_line (char *file_name)
{ {
FILE *fh; GFile *file;
char buf[512]; char *data, *p, *ret = NULL;
int lines, ran; int lines = 0, ran;
gsize len;
if (!file_name[0]) if (!file_name[0])
goto nofile; return g_strdup ("");
fh = hexchat_fopen_file (file_name, "r", 0); file = hexchat_open_gfile (file_name);
if (!fh)
if (!g_file_query_exists (file, NULL))
{ {
nofile:
/* reason is not a file, an actual reason! */ /* reason is not a file, an actual reason! */
return g_strdup (file_name); return g_strdup (file_name);
} }
/* count number of lines in file */ if (!g_file_load_contents (file, NULL, &data, &len, NULL, NULL))
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
{ {
fgets (buf, sizeof (buf), fh); g_object_unref (file);
lines--; return g_strdup (file_name);
} }
while (lines > ran);
fclose (fh); g_object_unref (file);
return g_strdup (buf);
/* 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 void
@@ -2487,30 +2519,32 @@ cmd_list (struct session *sess, char *tbuf, char *word[], char *word_eol[])
} }
gboolean gboolean
load_perform_file (session *sess, char *file) load_perform_file (session *sess, char *filename)
{ {
char tbuf[1024 + 4]; GFile *file;
char *nl; GDataInputStream *istream;
FILE *fp; gchar *buf;
fp = hexchat_fopen_file (file, "r", 0); /* load files from config dir */ file = hexchat_open_gfile (filename);
if (!fp)
return FALSE;
tbuf[1024] = 0; istream = file_get_datainputstream (file);
while (fgets (tbuf, 1024, fp)) if (!istream)
{ {
nl = strchr (tbuf, '\n'); g_object_unref (file);
if (nl == tbuf) /* skip empty commands */ return FALSE;
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);
} }
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; return TRUE;
} }

View File

@@ -998,9 +998,9 @@ servlist_load_defaults (void)
static int static int
servlist_load (void) servlist_load (void)
{ {
FILE *fp; GFile *file;
char buf[2048]; GDataInputStream *istream;
int len; gchar *buf;
ircnet *net = NULL; ircnet *net = NULL;
/* simple migration we will keep for a short while */ /* simple migration we will keep for a short while */
@@ -1015,15 +1015,16 @@ servlist_load (void)
g_free (oldfile); g_free (oldfile);
g_free (newfile); 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; 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) if (net)
{ {
switch (buf[0]) switch (buf[0])
@@ -1096,8 +1097,12 @@ servlist_load (void)
} }
if (buf[0] == 'N') if (buf[0] == 'N')
net = servlist_net_add (buf + 2, /* comment */ NULL, FALSE); net = servlist_net_add (buf + 2, /* comment */ NULL, FALSE);
g_free (buf);
} }
fclose (fp);
g_object_unref (file);
g_object_unref (istream);
return TRUE; return TRUE;
} }
@@ -1138,8 +1143,9 @@ servlist_check_encoding (char *charset)
int int
servlist_save (void) servlist_save (void)
{ {
FILE *fp; GFile *file;
char *buf; GOutputStream *ostream;
gchar *buf;
ircnet *net; ircnet *net;
ircserver *serv; ircserver *serv;
commandentry *cmd; commandentry *cmd;
@@ -1148,52 +1154,37 @@ servlist_save (void)
GSList *netlist; GSList *netlist;
GSList *cmdlist; GSList *cmdlist;
GSList *favlist; GSList *favlist;
#ifndef WIN32
int first = FALSE;
buf = g_build_filename (get_xdir (), "servlist.conf", NULL); file = hexchat_open_gfile ("servlist.conf");
if (g_access (buf, F_OK) != 0)
first = TRUE;
#endif
fp = hexchat_fopen_file ("servlist.conf", "w", 0); ostream = G_OUTPUT_STREAM(g_file_replace (file, NULL, TRUE,
if (!fp) G_FILE_CREATE_PRIVATE, NULL, NULL));
{ if (!ostream)
#ifndef WIN32
g_free (buf);
#endif
return FALSE; return FALSE;
}
#ifndef WIN32 stream_writef (ostream, "v=%s\n\n", PACKAGE_VERSION);
if (first)
g_chmod (buf, 0600);
g_free (buf);
#endif
fprintf (fp, "v=" PACKAGE_VERSION "\n\n");
list = network_list; list = network_list;
while (list) while (list)
{ {
net = list->data; net = list->data;
fprintf (fp, "N=%s\n", net->name); stream_writef (ostream, "N=%s\n", net->name);
if (net->nick) if (net->nick)
fprintf (fp, "I=%s\n", net->nick); stream_writef (ostream, "I=%s\n", net->nick);
if (net->nick2) if (net->nick2)
fprintf (fp, "i=%s\n", net->nick2); stream_writef (ostream, "i=%s\n", net->nick2);
if (net->user) if (net->user)
fprintf (fp, "U=%s\n", net->user); stream_writef (ostream, "U=%s\n", net->user);
if (net->real) if (net->real)
fprintf (fp, "R=%s\n", net->real); stream_writef (ostream, "R=%s\n", net->real);
if (net->pass) if (net->pass)
fprintf (fp, "P=%s\n", net->pass); stream_writef (ostream, "P=%s\n", net->pass);
if (net->logintype) if (net->logintype)
fprintf (fp, "L=%d\n", net->logintype); stream_writef (ostream, "L=%d\n", net->logintype);
if (net->encoding) if (net->encoding)
{ {
fprintf (fp, "E=%s\n", net->encoding); stream_writef (ostream, "E=%s\n", net->encoding);
if (!servlist_check_encoding (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."), 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; netlist = net->servlist;
while (netlist) while (netlist)
{ {
serv = netlist->data; serv = netlist->data;
fprintf (fp, "S=%s\n", serv->hostname); stream_writef (ostream, "S=%s\n", serv->hostname);
netlist = netlist->next; netlist = netlist->next;
} }
@@ -1217,7 +1208,7 @@ servlist_save (void)
while (cmdlist) while (cmdlist)
{ {
cmd = cmdlist->data; cmd = cmdlist->data;
fprintf (fp, "C=%s\n", cmd->command); stream_writef (ostream, "C=%s\n", cmd->command);
cmdlist = cmdlist->next; cmdlist = cmdlist->next;
} }
@@ -1228,26 +1219,24 @@ servlist_save (void)
if (favchan->key) 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 else
{ {
fprintf (fp, "J=%s\n", favchan->name); stream_writef (ostream, "J=%s\n", favchan->name);
} }
favlist = favlist->next; favlist = favlist->next;
} }
if (fprintf (fp, "\n") < 1) if (!stream_writef (ostream, "\n"))
{
fclose (fp);
return FALSE; return FALSE;
}
list = list->next; list = list->next;
} }
fclose (fp); g_object_unref (file);
g_object_unref (ostream);
return TRUE; return TRUE;
} }

View File

@@ -65,13 +65,15 @@ struct pevt_stage1
static ca_context *ca_con; static ca_context *ca_con;
#endif #endif
#define SCROLLBACK_MAX 32000
static void mkdir_p (char *filename); static void mkdir_p (char *filename);
static char *log_create_filename (char *channame); static char *log_create_filename (char *channame);
static char * static char *
scrollback_get_filename (session *sess) scrollback_get_filename (session *sess)
{ {
char *net, *chan, *buf; char *net, *chan, *buf, *ret = NULL;
net = server_get_network (sess->server, FALSE); net = server_get_network (sess->server, FALSE);
if (!net) if (!net)
@@ -88,54 +90,19 @@ scrollback_get_filename (session *sess)
buf = NULL; buf = NULL;
g_free (chan); 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 void
scrollback_close (session *sess) scrollback_close (session *sess)
{ {
if (sess->scrollfd != -1) g_clear_object (&sess->scrollfile);
{
close (sess->scrollfd);
sess->scrollfd = -1;
}
} }
/* shrink the file to roughly prefs.hex_text_max_lines */ /* shrink the file to roughly prefs.hex_text_max_lines */
@@ -143,29 +110,13 @@ scrollback_close (session *sess)
static void static void
scrollback_shrink (session *sess) scrollback_shrink (session *sess)
{ {
char *file; char *buf, *p;
char *buf;
int fh;
int lines;
int line;
gsize len; gsize len;
char *p; gint offset, lines = 0;
const gint max_lines = MIN(prefs.hex_text_max_lines, SCROLLBACK_MAX);
scrollback_close (sess); if (!g_file_load_contents (sess->scrollfile, NULL, &buf, &len, NULL, NULL))
sess->scrollwritten = 0;
lines = 0;
if ((file = scrollback_get_filename (sess)) == NULL)
{
g_free (file);
return; return;
}
if (!g_file_get_contents (file, &buf, &len, NULL))
{
g_free (file);
return;
}
/* count all lines */ /* count all lines */
p = buf; p = buf;
@@ -176,41 +127,37 @@ scrollback_shrink (session *sess)
p++; p++;
} }
fh = g_open (file, O_CREAT | O_TRUNC | O_APPEND | O_WRONLY | OFLAGS, 0644); offset = lines - max_lines;
g_free (file);
if (fh == -1)
{
g_free (buf);
return;
}
line = 0; /* now just go back to where we want to start the file */
p = buf; p = buf;
lines = 0;
while (p != buf + len) while (p != buf + len)
{ {
if (*p == '\n') if (*p == '\n')
{ {
line++; lines++;
if (line >= lines - prefs.hex_text_max_lines && if (lines == offset)
p + 1 != buf + len)
{ {
p++; p++;
write (fh, p, len - (p - buf));
break; break;
} }
} }
p++; 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); g_free (buf);
} }
static void static void
scrollback_save (session *sess, char *text, time_t stamp) scrollback_save (session *sess, char *text, time_t stamp)
{ {
GOutputStream *ostream;
char *buf; char *buf;
int len;
if (sess->type == SESS_SERVER && prefs.hex_gui_tab_server == 1) if (sess->type == SESS_SERVER && prefs.hex_gui_tab_server == 1)
return; return;
@@ -226,16 +173,25 @@ scrollback_save (session *sess, char *text, time_t stamp)
return; return;
} }
if (sess->scrollfd == -1) if (!sess->scrollfile)
{ {
if ((buf = scrollback_get_filename (sess)) == NULL) if ((buf = scrollback_get_filename (sess)) == NULL)
return; 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); 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) if (!stamp)
stamp = time(0); stamp = time(0);
@@ -243,31 +199,29 @@ scrollback_save (session *sess, char *text, time_t stamp)
buf = g_strdup_printf ("T %d ", (int) stamp); buf = g_strdup_printf ("T %d ", (int) stamp);
else else
buf = g_strdup_printf ("T %" G_GINT64_FORMAT " ", (gint64)stamp); buf = g_strdup_printf ("T %" G_GINT64_FORMAT " ", (gint64)stamp);
write (sess->scrollfd, buf, strlen (buf));
g_free (buf);
len = strlen (text); g_output_stream_write (ostream, buf, strlen (buf), NULL, NULL);
write (sess->scrollfd, text, len); g_output_stream_write (ostream, text, strlen (text), NULL, NULL);
if (len && text[len - 1] != '\n') if (!g_str_has_suffix (text, "\n"))
write (sess->scrollfd, "\n", 1); g_output_stream_write (ostream, "\n", 1, NULL, NULL);
g_free (buf);
g_object_unref (ostream);
sess->scrollwritten++; sess->scrollwritten++;
if ((sess->scrollwritten * 2 > prefs.hex_text_max_lines && prefs.hex_text_max_lines > 0) || if ((sess->scrollwritten > prefs.hex_text_max_lines && prefs.hex_text_max_lines > 0) ||
sess->scrollwritten > 32000) sess->scrollwritten > SCROLLBACK_MAX)
scrollback_shrink (sess); scrollback_shrink (sess);
} }
void void
scrollback_load (session *sess) scrollback_load (session *sess)
{ {
char *buf; GDataInputStream *istream;
char *text; gchar *buf, *text;
gint lines = 0;
time_t stamp; time_t stamp;
int lines;
GIOChannel *io;
GError *file_error = NULL;
GError *io_err = NULL;
if (sess->text_scrollback == SET_DEFAULT) if (sess->text_scrollback == SET_DEFAULT)
{ {
@@ -280,32 +234,28 @@ scrollback_load (session *sess)
return; return;
} }
if ((buf = scrollback_get_filename (sess)) == NULL) if (!sess->scrollfile)
return; {
if ((buf = scrollback_get_filename (sess)) == NULL)
return;
io = g_io_channel_new_file (buf, "r", &file_error); sess->scrollfile = g_file_new_for_path (buf);
g_free (buf); g_free (buf);
if (!io) }
return;
lines = 0; istream = file_get_datainputstream (sess->scrollfile);
if (!istream)
return;
while (1) while (1)
{ {
GError *err = NULL;
gsize n_bytes; gsize n_bytes;
GIOStatus io_status;
io_status = g_io_channel_read_line (io, &buf, &n_bytes, NULL, &io_err); buf = g_data_input_stream_read_line_utf8 (istream, &n_bytes, NULL, &err);
if (io_status == G_IO_STATUS_NORMAL) 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 scrollback lines have three blanks after the timestamp and a newline
* Some have only one blank and a newline * Some have only one blank and a newline
@@ -349,12 +299,27 @@ scrollback_load (session *sess)
g_free (buf); 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; break;
}
else /* No new line */
{
break;
}
} }
g_io_channel_unref (io); g_object_unref (istream);
sess->scrollwritten = lines; 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 static void
mkdir_p (char *filename) 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);
g_free (dirname_fs);
} }
static char * static char *

View File

@@ -68,42 +68,47 @@ url_clear (void)
} }
static int 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; return TRUE;
} }
void 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) file = hexchat_open_gfile (fname);
fd = hexchat_fopen_file (fname, mode, XOF_FULLPATH);
else
fd = hexchat_fopen_file (fname, mode, 0);
if (fd == NULL)
return;
tree_foreach (url_tree, (tree_traverse_func *)url_save_cb, fd); ostream = G_OUTPUT_STREAM(g_file_append_to (file, G_FILE_CREATE_NONE, NULL, NULL));
fclose (fd); if (ostream)
{
tree_foreach (url_tree, (tree_traverse_func *)url_save_cb, ostream);
g_object_unref (ostream);
}
g_object_unref (file);
} }
static void static void
url_save_node (char* url) url_save_node (char* url)
{ {
FILE *fd; GFile *file;
GOutputStream *ostream;
/* open <config>/url.log in append mode */ /* open <config>/url.log in append mode */
fd = hexchat_fopen_file ("url.log", "a", 0); file = hexchat_open_gfile ("url.log");
if (fd == NULL)
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); g_object_unref (file);
fclose (fd);
} }
static int static int

View File

@@ -33,7 +33,7 @@ extern void *url_tree;
#define WORD_PATH -2 #define WORD_PATH -2
void url_clear (void); 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_last (int *, int *);
int url_check_word (const char *word); int url_check_word (const char *word);
void url_check_line (char *buf); void url_check_line (char *buf);

View File

@@ -530,7 +530,7 @@ get_sys_str (int with_cpu)
#endif #endif
int 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; int pos = *position, spos = pos;

View File

@@ -44,7 +44,7 @@ char *file_part (char *file);
void for_files (char *dirname, char *mask, void callback (char *file)); void for_files (char *dirname, char *mask, void callback (char *file));
int rfc_casecmp (const char *, const char *); int rfc_casecmp (const char *, const char *);
int rfc_ncasecmp (char *, char *, int); 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 *nocasestrstr (const char *text, const char *tofind);
char *country (char *); char *country (char *);
void country_search (char *pattern, void *ud, void (*print)(void *, char *, ...)); void country_search (char *pattern, void *ud, void (*print)(void *, char *, ...));

View File

@@ -468,7 +468,7 @@ fe_input_remove (int tag)
} }
int 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; int tag, type = 0;
GIOChannel *channel; GIOChannel *channel;
@@ -489,7 +489,7 @@ fe_input_add (int sok, int flags, GIOFunc func, void *data)
if (flags & FIA_EX) if (flags & FIA_EX)
type |= G_IO_PRI; 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); g_io_channel_unref (channel);
return tag; return tag;

View File

@@ -146,26 +146,33 @@ palette_load (void)
void void
palette_save (void) palette_save (void)
{ {
int i, j, fh; GFile *file;
GOutputStream *ostream;
int i, j;
char prefname[256]; char prefname[256];
fh = hexchat_open_file ("colors.conf", O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE); file = hexchat_open_gfile ("colors.conf");
if (fh != -1)
ostream = G_OUTPUT_STREAM(g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL));
if (ostream)
{ {
/* mIRC colors 0-31 are here */ /* mIRC colors 0-31 are here */
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
{ {
g_snprintf (prefname, sizeof prefname, "color_%d", 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+ */ /* our special colors are mapped at 256+ */
for (i = 256, j = 32; j < MAX_COL+1; i++, j++) for (i = 256, j = 32; j < MAX_COL+1; i++, j++)
{ {
g_snprintf (prefname, sizeof prefname, "color_%d", i); 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);
} }

View File

@@ -138,7 +138,7 @@ url_save_callback (void *arg1, char *file)
{ {
if (file) if (file)
{ {
url_save_tree (file, "w", TRUE); url_save_tree (file);
} }
} }

View File

@@ -422,7 +422,7 @@ fe_input_remove (int tag)
} }
int 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; int tag, type = 0;
GIOChannel *channel; GIOChannel *channel;
@@ -443,7 +443,7 @@ fe_input_add (int sok, int flags, GIOFunc func, void *data)
if (flags & FIA_EX) if (flags & FIA_EX)
type |= G_IO_PRI; 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); g_io_channel_unref (channel);
return tag; return tag;