summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2012-05-13 19:50:19 +0200
committerYorhel <git@yorhel.nl>2012-05-13 19:50:19 +0200
commitab8ff0025bbfea14035ab457a6ac238fe1bf6bf5 (patch)
tree212a832949057bfbff194b8f649d807e592707ea
parentf5692e4b3904f64f5edf0aacc96e80b9f1608ca1 (diff)
Programming style: typedef all structs with name_t and use those
This change is only partially because my own programming style has just changed a bit in this direction.* The other (and more practical) reason is that makeheaders already creates the typedefs automatically, I've just never used them. This automatic typedef creation was a bit problematic in makeheaders' dependency resolution. E.g. 'struct hub' was typedeffed to put the name 'hub' has a global type, but I also use 'hub' as a variable in various places. This conflict is not really a problem for plain C, as types and variables live in different namespaces, but makeheaders doesn't really know that, and considered the hub structure and its dependencies as a dependency of db.c, which uses the variable 'hub'. That's somewhat inefficient and messy... These changes where mostly made by some runs of sed. If there were any errors in these changes, I suspect the compiler would have found them. (That is not to say I haven't done any basic verification myself, but, you know, this change affects a *lot* of code >_>) *) Not entirely, though. I was going more in the direction of using the old struct names directly as typedefs, without the _t. This has the same downside as mentioned above, so doesn't really work. :-(
-rw-r--r--doc/gendoc.c6
-rw-r--r--src/cc.c144
-rw-r--r--src/commands.c124
-rw-r--r--src/db.c46
-rw-r--r--src/dl.c228
-rw-r--r--src/doc.h18
-rw-r--r--src/fl_load.c44
-rw-r--r--src/fl_local.c131
-rw-r--r--src/fl_save.c24
-rw-r--r--src/fl_util.c78
-rw-r--r--src/hub.c144
-rw-r--r--src/listen.c38
-rw-r--r--src/main.c2
-rw-r--r--src/net.c20
-rw-r--r--src/proto.c10
-rw-r--r--src/search.c70
-rw-r--r--src/tth.c26
-rw-r--r--src/ui.c356
-rw-r--r--src/ui_util.c92
-rw-r--r--src/util.c48
-rw-r--r--src/vars.c30
-rw-r--r--src/xmlread.c42
22 files changed, 863 insertions, 858 deletions
diff --git a/doc/gendoc.c b/doc/gendoc.c
index 6a5f43d..d24d055 100644
--- a/doc/gendoc.c
+++ b/doc/gendoc.c
@@ -36,7 +36,7 @@
static void gen_cmd() {
- const struct doc_cmd *c = doc_cmds;
+ const doc_cmd_t *c = doc_cmds;
printf("=over\n\n");
for(; *c->name; c++) {
printf("=item B</%s>", c->name);
@@ -51,7 +51,7 @@ static void gen_cmd() {
static void gen_set() {
- const struct doc_set *s = doc_sets;
+ const doc_set_t *s = doc_sets;
printf("=over\n\n");
for(; s->name; s++) {
printf("=item B<%s> %s\n\n", s->name, s->type);
@@ -63,7 +63,7 @@ static void gen_set() {
static void gen_key() {
- const struct doc_key *k = doc_keys;
+ const doc_key_t *k = doc_keys;
printf("=over\n\n");
for(; k->sect; k++) {
printf("=item B<%s>\n\n ", k->title);
diff --git a/src/cc.c b/src/cc.c
index 8d13cc6..994d187 100644
--- a/src/cc.c
+++ b/src/cc.c
@@ -39,7 +39,7 @@
// the list is otherwise managed in commands.c.
GHashTable *cc_granted = NULL;
-void cc_grant(struct hub_user *u) {
+void cc_grant(hub_user_t *u) {
if(!g_hash_table_lookup(cc_granted, &u->uid))
g_hash_table_insert(cc_granted, g_memdup(&u->uid, 8), (void *)1);
}
@@ -49,8 +49,8 @@ void cc_grant(struct hub_user *u) {
static int cc_grant_cmp(const void *pa, const void *pb) {
guint64 a = *((guint64 *)pa);
guint64 b = *((guint64 *)pb);
- struct hub_user *ua = g_hash_table_lookup(hub_uids, &a);
- struct hub_user *ub = g_hash_table_lookup(hub_uids, &b);
+ hub_user_t *ua = g_hash_table_lookup(hub_uids, &a);
+ hub_user_t *ub = g_hash_table_lookup(hub_uids, &b);
return !ua && !ub ? (a > b ? 1 : a < b ? -1 : 0) :
ua && !ub ? 1 : !ua && ub ? -1 : g_utf8_collate(ua->name, ub->name);
}
@@ -76,8 +76,8 @@ guint64 *cc_grant_list() {
// List of expected incoming or outgoing connections. This is list managed by
// the functions below, in addition to cc_init_global() and cc_remove_hub(),
-struct cc_expect {
- struct hub *hub;
+typedef struct cc_expect_t {
+ hub_t *hub;
char *nick; // NMDC, hub encoding. Also set on ADC, but only for debugging purposes
guint64 uid;
guint16 port;
@@ -88,14 +88,14 @@ struct cc_expect {
int timeout_src;
gboolean adc : 1;
gboolean dl : 1; // if we were the one starting the connection (i.e. we want to download)
-};
+} cc_expect_t;
static GQueue *cc_expected;
-static void cc_expect_rm(GList *n, struct cc *success) {
- struct cc_expect *e = n->data;
+static void cc_expect_rm(GList *n, cc_t *success) {
+ cc_expect_t *e = n->data;
if(e->dl && !success)
dl_user_cc(e->uid, FALSE);
else if(e->dl)
@@ -105,22 +105,22 @@ static void cc_expect_rm(GList *n, struct cc *success) {
g_slice_free1(32, e->kp);
g_free(e->token);
g_free(e->nick);
- g_slice_free(struct cc_expect, e);
+ g_slice_free(cc_expect_t, e);
g_queue_delete_link(cc_expected, n);
}
static gboolean cc_expect_timeout(gpointer data) {
GList *n = data;
- struct cc_expect *e = n->data;
+ cc_expect_t *e = n->data;
g_message("Expected connection from %s on %s, but received none.", e->nick, e->hub->tab->name);
cc_expect_rm(n, NULL);
return FALSE;
}
-void cc_expect_add(struct hub *hub, struct hub_user *u, guint16 port, char *t, gboolean dl) {
- struct cc_expect *e = g_slice_new0(struct cc_expect);
+void cc_expect_add(hub_t *hub, hub_user_t *u, guint16 port, char *t, gboolean dl) {
+ cc_expect_t *e = g_slice_new0(cc_expect_t);
e->adc = hub->adc;
e->hub = hub;
e->dl = dl;
@@ -146,10 +146,10 @@ void cc_expect_add(struct hub *hub, struct hub_user *u, guint16 port, char *t, g
// Checks the expects list for the current connection, sets cc->dl, cc->uid,
// cc->hub and cc->kp_user and removes it from the expects list. cc->cid and
// cc->token must be known.
-static gboolean cc_expect_adc_rm(struct cc *cc) {
+static gboolean cc_expect_adc_rm(cc_t *cc) {
GList *n;
for(n=cc_expected->head; n; n=n->next) {
- struct cc_expect *e = n->data;
+ cc_expect_t *e = n->data;
if(e->adc && e->port == cc->port && memcmp(cc->cid, e->cid, 8) == 0 && strcmp(cc->token, e->token) == 0) {
cc->uid = e->uid;
cc->hub = e->hub;
@@ -165,10 +165,10 @@ static gboolean cc_expect_adc_rm(struct cc *cc) {
// Same as above, but for NMDC. Sets cc->dl, cc->uid and cc->hub. cc->nick_raw
// must be known, and for passive connections cc->hub must also be known.
-static gboolean cc_expect_nmdc_rm(struct cc *cc) {
+static gboolean cc_expect_nmdc_rm(cc_t *cc) {
GList *n;
for(n=cc_expected->head; n; n=n->next) {
- struct cc_expect *e = n->data;
+ cc_expect_t *e = n->data;
if(cc->hub && cc->hub != e->hub)
continue;
if(!e->adc && e->port == cc->port && strcmp(e->nick, cc->nick_raw) == 0) {
@@ -190,45 +190,45 @@ static gboolean cc_expect_nmdc_rm(struct cc *cc) {
#define THROTTLE_INTV 3600
#define THROTTLE_BURST 10
-struct throttle_get {
+typedef struct throttle_get_t {
char tth[24];
guint64 uid;
guint64 offset;
time_t throttle;
-};
+} throttle_get_t;
static GHashTable *throttle_list; // initialized in cc_init_global()
static guint throttle_hash(gconstpointer key) {
- const struct throttle_get *t = key;
+ const throttle_get_t *t = key;
guint *tth = (guint *)t->tth;
return *tth + (gint)t->offset + (gint)t->uid;
}
static gboolean throttle_equal(gconstpointer a, gconstpointer b) {
- const struct throttle_get *x = a;
- const struct throttle_get *y = b;
+ const throttle_get_t *x = a;
+ const throttle_get_t *y = b;
return x->uid == y->uid && memcmp(x->tth, y->tth, 24) == 0 && x->offset == y->offset;
}
static void throttle_free(gpointer dat) {
- g_slice_free(struct throttle_get, dat);
+ g_slice_free(throttle_get_t, dat);
}
-static gboolean throttle_check(struct cc *cc, char *tth, guint64 offset) {
+static gboolean throttle_check(cc_t *cc, char *tth, guint64 offset) {
// construct a key
- struct throttle_get key;
+ throttle_get_t key;
memcpy(key.tth, tth, 24);
key.uid = cc->uid;
key.offset = offset;
time(&key.throttle);
// lookup
- struct throttle_get *val = g_hash_table_lookup(throttle_list, &key);
+ throttle_get_t *val = g_hash_table_lookup(throttle_list, &key);
// value present and above threshold, throttle!
if(val && val->throttle-key.throttle > THROTTLE_BURST*THROTTLE_INTV)
return TRUE;
@@ -238,14 +238,14 @@ static gboolean throttle_check(struct cc *cc, char *tth, guint64 offset) {
return FALSE;
}
// value not present, add it
- val = g_slice_dup(struct throttle_get, &key);
+ val = g_slice_dup(throttle_get_t, &key);
g_hash_table_insert(throttle_list, val, val);
return FALSE;
}
static gboolean throttle_purge_func(gpointer key, gpointer val, gpointer dat) {
- struct throttle_get *v = val;
+ throttle_get_t *v = val;
time_t *t = dat;
return v->throttle < *t ? TRUE : FALSE;
}
@@ -275,9 +275,9 @@ static gboolean throttle_purge(gpointer dat) {
#define CCS_TRANSFER 3 // check cc->dl whether it's up or down
#define CCS_DISCONN 4 // waiting to get removed on a timeout
-struct cc {
+struct cc_t {
struct net *net;
- struct hub *hub;
+ hub_t *hub;
char *nick_raw; // (NMDC)
char *nick;
char *hub_name; // Copy of hub->tab->name when hub is reset to NULL
@@ -396,7 +396,7 @@ void cc_global_init() {
void cc_global_close() {
GSequenceIter *i = g_sequence_get_begin_iter(cc_list);
for(; !g_sequence_iter_is_end(i); i=g_sequence_iter_next(i)) {
- struct cc *c = g_sequence_get(i);
+ cc_t *c = g_sequence_get(i);
if(c->state != CCS_DISCONN)
cc_disconnect(c, TRUE);
}
@@ -411,7 +411,7 @@ void cc_global_close() {
void cc_global_onlinecheck() {
GSequenceIter *i = g_sequence_get_begin_iter(cc_list);
for(; !g_sequence_iter_is_end(i); i=g_sequence_iter_next(i)) {
- struct cc *c = g_sequence_get(i);
+ cc_t *c = g_sequence_get(i);
if((c->state == CCS_IDLE || c->state == CCS_TRANSFER) // idle or transfer mode
&& !g_hash_table_lookup(hub_uids, &c->uid) // user offline
&& var_get_bool(c->hub?c->hub->id:0, VAR_disconnect_offline)) // 'disconnect_offline' enabled
@@ -428,11 +428,11 @@ void cc_global_onlinecheck() {
// $MyNick's being exchanged.)
// Note that the connection will remain hubless even when the same hub is later
// opened again. I don't think this is a huge problem, however.
-void cc_remove_hub(struct hub *hub) {
+void cc_remove_hub(hub_t *hub) {
// Remove from cc objects
GSequenceIter *i = g_sequence_get_begin_iter(cc_list);
for(; !g_sequence_iter_is_end(i); i=g_sequence_iter_next(i)) {
- struct cc *c = g_sequence_get(i);
+ cc_t *c = g_sequence_get(i);
if(c->hub == hub) {
c->hub_name = g_strdup(hub->tab->name);
c->hub = NULL;
@@ -443,7 +443,7 @@ void cc_remove_hub(struct hub *hub) {
GList *p, *n;
for(n=cc_expected->head; n;) {
p = n->next;
- struct cc_expect *e = n->data;
+ cc_expect_t *e = n->data;
if(e->hub == hub)
cc_expect_rm(n, NULL);
n = p;
@@ -461,7 +461,7 @@ int cc_slots_in_use(int *mini) {
int m = 0;
GSequenceIter *i = g_sequence_get_begin_iter(cc_list);
for(; !g_sequence_iter_is_end(i); i=g_sequence_iter_next(i)) {
- struct cc *c = g_sequence_get(i);
+ cc_t *c = g_sequence_get(i);
if(!c->dl && c->state == CCS_TRANSFER)
num++;
if(!c->dl && c->state == CCS_TRANSFER && c->slot_mini)
@@ -476,7 +476,7 @@ int cc_slots_in_use(int *mini) {
// To be called when an upload or download has finished. Will get info from the
// cc struct and write it to the transfer log.
-static void xfer_log_add(struct cc *cc) {
+static void xfer_log_add(cc_t *cc) {
g_return_if_fail(cc->state == CCS_TRANSFER && cc->last_file);
// we don't log tthl transfers or transfers that hadn't been started yet
if(cc->last_tthl || !cc->last_length)
@@ -485,7 +485,7 @@ static void xfer_log_add(struct cc *cc) {
if(!var_get_bool(0, cc->dl ? VAR_log_downloads : VAR_log_uploads))
return;
- static struct logfile *log = NULL;
+ static logfile_t *log = NULL;
if(!log)
log = logfile_create("transfers");
@@ -525,10 +525,10 @@ static void xfer_log_add(struct cc *cc) {
// Returns the cc object of a connection with the same user, if there is one.
-static struct cc *cc_check_dupe(struct cc *cc) {
+static cc_t *cc_check_dupe(cc_t *cc) {
GSequenceIter *i = g_sequence_get_begin_iter(cc_list);
for(; !g_sequence_iter_is_end(i); i=g_sequence_iter_next(i)) {
- struct cc *c = g_sequence_get(i);
+ cc_t *c = g_sequence_get(i);
if(cc != c && c->state != CCS_DISCONN && !!c->adc == !!cc->adc && c->uid == cc->uid)
return c;
}
@@ -536,7 +536,7 @@ static struct cc *cc_check_dupe(struct cc *cc) {
}
-static gboolean request_slot(struct cc *cc, gboolean need_full) {
+static gboolean request_slot(cc_t *cc, gboolean need_full) {
int minislots;
int slots = cc_slots_in_use(&minislots);
@@ -566,7 +566,7 @@ static gboolean request_slot(struct cc *cc, gboolean need_full) {
// Called from dl.c
-void cc_download(struct cc *cc, struct dl *dl) {
+void cc_download(cc_t *cc, dl_t *dl) {
g_return_if_fail(cc->dl && cc->state == CCS_IDLE);
memcpy(cc->last_hash, dl->hash, 24);
@@ -608,7 +608,7 @@ static void handle_recvdone(struct net *n, void *dat) {
// If the connection is still active, log the transfer and check for more
// stuff to download
if(n && net_is_connected(n)) {
- struct cc *cc = n->handle;
+ cc_t *cc = n->handle;
net_readmsg(cc->net, cc->adc ? '\n' : '|', cc->adc ? adc_handle : nmdc_handle);
xfer_log_add(cc);
cc->state = CCS_IDLE;
@@ -618,7 +618,7 @@ static void handle_recvdone(struct net *n, void *dat) {
static void handle_recvtth(struct net *n, char *buf, int read) {
- struct cc *cc = n->handle;
+ cc_t *cc = n->handle;
g_return_if_fail(read == cc->last_length);
dl_settthl(cc->uid, cc->last_hash, buf, cc->last_length);
@@ -631,8 +631,8 @@ static void handle_recvtth(struct net *n, char *buf, int read) {
}
-static void handle_adcsnd(struct cc *cc, gboolean tthl, guint64 start, gint64 bytes) {
- struct dl *dl = g_hash_table_lookup(dl_queue, cc->last_hash);
+static void handle_adcsnd(cc_t *cc, gboolean tthl, guint64 start, gint64 bytes) {
+ dl_t *dl = g_hash_table_lookup(dl_queue, cc->last_hash);
if(!dl) {
g_set_error_literal(&cc->err, 1, 0, "Download interrupted.");
cc_disconnect(cc, FALSE);
@@ -673,13 +673,13 @@ static void handle_adcsnd(struct cc *cc, gboolean tthl, guint64 start, gint64 by
static void handle_sendcomplete(struct net *net) {
- struct cc *cc = net->handle;
+ cc_t *cc = net->handle;
xfer_log_add(cc);
cc->state = CCS_IDLE;
}
-static void send_file(struct cc *cc, const char *path, guint64 start, int len, gboolean flush, GError **err) {
+static void send_file(cc_t *cc, const char *path, guint64 start, int len, gboolean flush, GError **err) {
int fd = 0;
if((fd = open(path, O_RDONLY)) < 0 || lseek(fd, start, SEEK_SET) == (off_t)-1) {
// Don't give a detailed error message, the remote shouldn't know too much about us.
@@ -697,7 +697,7 @@ static void send_file(struct cc *cc, const char *path, guint64 start, int len, g
// 51: File not available
// 53: No slots
// Handles both ADC GET and the NMDC $ADCGET.
-static void handle_adcget(struct cc *cc, char *type, char *id, guint64 start, gint64 bytes, GError **err) {
+static void handle_adcget(cc_t *cc, char *type, char *id, guint64 start, gint64 bytes, GError **err) {
// tthl
if(strcmp(type, "tthl") == 0) {
if(strncmp(id, "TTH/", 4) != 0 || !istth(id+4) || start != 0 || bytes != -1) {
@@ -725,7 +725,7 @@ static void handle_adcget(struct cc *cc, char *type, char *id, guint64 start, gi
g_set_error_literal(err, 1, 40, "Invalid arguments");
return;
}
- struct fl_list *f = fl_local_list ? fl_list_from_path(fl_local_list, id) : NULL;
+ fl_list_t *f = fl_local_list ? fl_list_from_path(fl_local_list, id) : NULL;
if(!f || f->isfile) {
g_set_error_literal(err, 1, 51, "File Not Available");
return;
@@ -757,7 +757,7 @@ static void handle_adcget(struct cc *cc, char *type, char *id, guint64 start, gi
// TODO: files.xml? (Required by ADC, but I doubt it's used)
char *path = NULL;
char *vpath = NULL;
- struct fl_list *f = NULL;
+ fl_list_t *f = NULL;
gboolean needslot = TRUE;
// files.xml.bz2
@@ -837,7 +837,7 @@ static void handle_adcget(struct cc *cc, char *type, char *id, guint64 start, gi
// To be called when we know with which user and on which hub this connection is.
-static void handle_id(struct cc *cc, struct hub_user *u) {
+static void handle_id(cc_t *cc, hub_user_t *u) {
cc->nick = g_strdup(u->name);
cc->isop = u->isop;
cc->uid = u->uid;
@@ -868,7 +868,7 @@ static void handle_id(struct cc *cc, struct hub_user *u) {
// (up/down). For NMDC, the purpose of this connection is determined when we
// receive a $Direction, so it's only checked here for ADC.
if(cc->adc) {
- struct cc *dup = cc_check_dupe(cc);
+ cc_t *dup = cc_check_dupe(cc);
if(dup && !!cc->dl == !!dup->dl) {
g_set_error_literal(&(cc->err), 1, 0, "too many open connections with this user");
cc_disconnect(cc, FALSE);
@@ -881,14 +881,14 @@ static void handle_id(struct cc *cc, struct hub_user *u) {
static void adc_handle(struct net *net, char *msg, int _len) {
- struct cc *cc = net->handle;
+ cc_t *cc = net->handle;
if(!*msg)
return;
g_clear_error(&cc->err);
g_return_if_fail(cc->state != CCS_CONN && cc->state != CCS_DISCONN);
net_readmsg(net, '\n', adc_handle);
- struct adc_cmd cmd;
+ adc_cmd_t cmd;
GError *err = NULL;
adc_parse(msg, &cmd, NULL, &err);
@@ -950,7 +950,7 @@ static void adc_handle(struct net *net, char *msg, int _len) {
cc->token = g_strdup(token);
memcpy(cc->cid, cid, 24);
cc_expect_adc_rm(cc);
- struct hub_user *u = cc->uid ? g_hash_table_lookup(hub_uids, &cc->uid) : NULL;
+ hub_user_t *u = cc->uid ? g_hash_table_lookup(hub_uids, &cc->uid) : NULL;
if(!u) {
g_set_error_literal(&cc->err, 1, 0, "Protocol error.");
g_message("CC:%s: Unexpected ADC connection: %s", net_remoteaddr(cc->net), msg);
@@ -1019,7 +1019,7 @@ static void adc_handle(struct net *net, char *msg, int _len) {
cc_disconnect(cc, TRUE);
} else {
// Get file
- struct fl_list *f = NULL;
+ fl_list_t *f = NULL;
if(cmd.argv[1][0] == '/' && fl_local_list) {
f = fl_list_from_path(fl_local_list, cmd.argv[1]);
} else if(strncmp(cmd.argv[1], "TTH/", 4) == 0 && istth(cmd.argv[1]+4)) {
@@ -1103,7 +1103,7 @@ static void adc_handle(struct net *net, char *msg, int _len) {
}
-static void nmdc_mynick(struct cc *cc, const char *nick) {
+static void nmdc_mynick(cc_t *cc, const char *nick) {
if(cc->nick_raw) {
g_message("CC:%s: Received $MyNick twice.", net_remoteaddr(cc->net));
cc_disconnect(cc, TRUE);
@@ -1121,7 +1121,7 @@ static void nmdc_mynick(struct cc *cc, const char *nick) {
return;
}
- struct hub_user *u = g_hash_table_lookup(cc->hub->users, nick);
+ hub_user_t *u = g_hash_table_lookup(cc->hub->users, nick);
if(!u) {
g_set_error_literal(&(cc->err), 1, 0, "User not online.");
cc_disconnect(cc, FALSE);
@@ -1137,7 +1137,7 @@ static void nmdc_mynick(struct cc *cc, const char *nick) {
}
-static void nmdc_direction(struct cc *cc, gboolean down, int num) {
+static void nmdc_direction(cc_t *cc, gboolean down, int num) {
gboolean old_dl = cc->dl;
// if they want to download and we don't, then it's simple.
@@ -1163,7 +1163,7 @@ static void nmdc_direction(struct cc *cc, gboolean down, int num) {
cc->dl = cc->dir > num;
// Now that this connection has a purpose, make sure it's the only connection with that purpose.
- struct cc *dup = cc_check_dupe(cc);
+ cc_t *dup = cc_check_dupe(cc);
if(dup && !!cc->dl == !!dup->dl) {
g_set_error_literal(&cc->err, 1, 0, "Too many open connections with this user");
cc_disconnect(cc, FALSE);
@@ -1182,7 +1182,7 @@ static void nmdc_direction(struct cc *cc, gboolean down, int num) {
static void nmdc_handle(struct net *net, char *cmd, int _len) {
- struct cc *cc = net->handle;
+ cc_t *cc = net->handle;
if(!*cmd)
return;
g_clear_error(&cc->err);
@@ -1358,7 +1358,7 @@ static void nmdc_handle(struct net *net, char *cmd, int _len) {
static void handle_error(struct net *n, int action, const char *err) {
- struct cc *cc = n->handle;
+ cc_t *cc = n->handle;
if(!cc->err) // ignore network errors if there already was a protocol error
g_set_error_literal(&cc->err, 1, 0, err);
@@ -1373,8 +1373,8 @@ static void handle_error(struct net *n, int action, const char *err) {
// Hub may be unknown when this is an incoming connection
-struct cc *cc_create(struct hub *hub) {
- struct cc *cc = g_new0(struct cc, 1);
+cc_t *cc_create(hub_t *hub) {
+ cc_t *cc = g_new0(cc_t, 1);
cc->net = net_new(cc, handle_error);
cc->hub = hub;
cc->iter = g_sequence_append(cc_list, cc);
@@ -1388,7 +1388,7 @@ struct cc *cc_create(struct hub *hub) {
// Simply stores the keyprint of the certificate in cc->kp_real, it will be
// checked when receiving CINF.
static void handle_handshake(struct net *n, const char *kpr) {
- struct cc *c = n->handle;
+ cc_t *c = n->handle;
if(kpr) {
if(!c->kp_real)
c->kp_real = g_slice_alloc(32);
@@ -1403,7 +1403,7 @@ static void handle_handshake(struct net *n, const char *kpr) {
static void handle_connect(struct net *n, const char *addr) {
if(addr)
return;
- struct cc *cc = n->handle;
+ cc_t *cc = n->handle;
strncpy(cc->remoteaddr, net_remoteaddr(cc->net), sizeof(cc->remoteaddr));
if(!cc->hub) {
cc_disconnect(cc, FALSE);
@@ -1433,7 +1433,7 @@ static void handle_connect(struct net *n, const char *addr) {
}
-void cc_nmdc_connect(struct cc *cc, const char *addr, const char *laddr, gboolean tls) {
+void cc_nmdc_connect(cc_t *cc, const char *addr, const char *laddr, gboolean tls) {
g_return_if_fail(cc->state == CCS_CONN);
strncpy(cc->remoteaddr, addr, sizeof(cc->remoteaddr));
cc->tls = tls;
@@ -1442,7 +1442,7 @@ void cc_nmdc_connect(struct cc *cc, const char *addr, const char *laddr, gboolea
}
-void cc_adc_connect(struct cc *cc, struct hub_user *u, const char *laddr, unsigned short port, gboolean tls, char *token) {
+void cc_adc_connect(cc_t *cc, hub_user_t *u, const char *laddr, unsigned short port, gboolean tls, char *token) {
g_return_if_fail(cc->state == CCS_CONN);
g_return_if_fail(cc->hub);
g_return_if_fail(u && u->active && u->ip4);
@@ -1477,7 +1477,7 @@ void cc_adc_connect(struct cc *cc, struct hub_user *u, const char *laddr, unsign
static void handle_detectprotocol(struct net *net, char *dat, int len) {
g_return_if_fail(len > 0);
- struct cc *cc = net->handle;
+ cc_t *cc = net->handle;
// Enable TLS
if(!cc->tls && (cc->active_type == LBT_TLS || ((cc->active_type & LBT_TLS) && *dat >= 0x14 && *dat <= 0x17))) {
@@ -1494,7 +1494,7 @@ static void handle_detectprotocol(struct net *net, char *dat, int len) {
}
-void cc_incoming(struct cc *cc, guint16 port, int sock, const char *addr, int type) {
+void cc_incoming(cc_t *cc, guint16 port, int sock, const char *addr, int type) {
net_connected(cc->net, sock, addr);
if(!net_is_connected(cc->net))
return;
@@ -1513,7 +1513,7 @@ static gboolean handle_timeout(gpointer dat) {
}
-void cc_disconnect(struct cc *cc, gboolean force) {
+void cc_disconnect(cc_t *cc, gboolean force) {
g_return_if_fail(cc->state != CCS_DISCONN);
if(cc->state == CCS_TRANSFER)
xfer_log_add(cc);
@@ -1530,7 +1530,7 @@ void cc_disconnect(struct cc *cc, gboolean force) {
}
-void cc_free(struct cc *cc) {
+void cc_free(cc_t *cc) {
if(!cc->timeout_src)
cc_disconnect(cc, TRUE);
if(cc->timeout_src)
diff --git a/src/commands.c b/src/commands.c
index 490c3d1..3b772d7 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -36,20 +36,20 @@
#define DOC_SET
#include "doc.h"
-struct cmd {
+typedef struct cmd_t {
char name[16];
void (*f)(char *);
void (*suggest)(char *, char **);
- struct doc_cmd *doc;
-};
+ doc_cmd_t *doc;
+} cmd_t;
// tentative definition of the cmd list
-static struct cmd cmds[];
+static cmd_t cmds[];
// get a command by name. performs a linear search. can be rewritten to use a
// binary search, but I doubt the performance difference really matters.
-static struct cmd *getcmd(const char *name) {
- struct cmd *c;
+static cmd_t *getcmd(const char *name) {
+ cmd_t *c;
for(c=cmds; *c->name; c++)
if(strcmp(c->name, name) == 0)
break;
@@ -59,11 +59,11 @@ static struct cmd *getcmd(const char *name) {
// Get documentation for a command. May be slow at first, but caches the doc
// structure later on.
-static struct doc_cmd *getdoc(struct cmd *cmd) {
- struct doc_cmd empty = { "", NULL, "No documentation available." };
+static doc_cmd_t *getdoc(cmd_t *cmd) {
+ doc_cmd_t empty = { "", NULL, "No documentation available." };
if(cmd->doc)
return cmd->doc;
- struct doc_cmd *i = (struct doc_cmd *)doc_cmds;
+ doc_cmd_t *i = (doc_cmd_t *)doc_cmds;
for(; *i->name; i++)
if(strcmp(i->name, cmd->name) == 0)
break;
@@ -80,7 +80,7 @@ static void c_quit(char *args) {
// handle /say and /me
static void sayme(char *args, gboolean me) {
- struct ui_tab *tab = ui_tab_cur->data;
+ ui_tab_t *tab = ui_tab_cur->data;
if(tab->type != UIT_HUB && tab->type != UIT_MSG)
ui_m(NULL, 0, "This command can only be used on hub and message tabs.");
else if(!tab->hub->nick_valid)
@@ -90,7 +90,7 @@ static void sayme(char *args, gboolean me) {
else if(tab->type == UIT_HUB)
hub_say(tab->hub, args, me);
else {
- struct hub_user *u = g_hash_table_lookup(hub_uids, &tab->uid);
+ hub_user_t *u = g_hash_table_lookup(hub_uids, &tab->uid);
if(!u)
ui_m(NULL, 0, "User is not online.");
else
@@ -115,7 +115,7 @@ static void c_msg(char *args) {
*sep = 0;
while(*(++sep) == ' ');
}
- struct ui_tab *tab = ui_tab_cur->data;
+ ui_tab_t *tab = ui_tab_cur->data;
if(tab->type != UIT_HUB && tab->type != UIT_MSG)
ui_m(NULL, 0, "This command can only be used on hub and message tabs.");
else if(!tab->hub->nick_valid)
@@ -123,12 +123,12 @@ static void c_msg(char *args) {
else if(!args[0])
ui_m(NULL, 0, "No user specified. See `/help msg' for more information.");
else {
- struct hub_user *u = hub_user_get(tab->hub, args);
+ hub_user_t *u = hub_user_get(tab->hub, args);
if(!u)
ui_m(NULL, 0, "No user found with that name. Note that usernames are case-sensitive.");
else {
// get or open tab and make sure it's selected
- struct ui_tab *t = g_hash_table_lookup(ui_msg_tabs, &u->uid);
+ ui_tab_t *t = g_hash_table_lookup(ui_msg_tabs, &u->uid);
if(!t)
ui_tab_open(ui_msg_create(tab->hub, u), TRUE, tab);
else
@@ -149,7 +149,7 @@ static void c_help(char *args) {
// list available commands
if(!args[0]) {
ui_m(NULL, 0, "\nAvailable commands:");
- struct cmd *c = cmds;
+ cmd_t *c = cmds;
for(; c->f; c++)
ui_mf(NULL, 0, " /%s - %s", c->name, getdoc(c)->sum);
ui_m(NULL, 0, "\nFor help on key bindings, use `/help keys'.\n");
@@ -157,7 +157,7 @@ static void c_help(char *args) {
// list information on a setting
} else if((strcmp(args, "set") == 0 || strcmp(args, "hset") == 0) && sec) {
sec = strncmp(sec, "color_", 6) == 0 ? "color_*" : sec;
- struct doc_set *s = (struct doc_set *)doc_sets;
+ doc_set_t *s = (doc_set_t *)doc_sets;
for(; s->name; s++)
if(strcmp(s->name, sec) == 0)
break;
@@ -169,14 +169,14 @@ static void c_help(char *args) {
// list available key sections
} else if(strcmp(args, "keys") == 0 && !sec) {
ui_m(NULL, 0, "\nAvailable sections:");
- const struct doc_key *k = doc_keys;
+ const doc_key_t *k = doc_keys;
for(; k->sect; k++)
ui_mf(NULL, 0, " %s - %s", k->sect, k->title);
ui_m(NULL, 0, "\nUse `/help keys <name>' to get help on the key bindings for the selected section.\n");
// get information on a particular key section
} else if(strcmp(args, "keys") == 0 && sec) {
- const struct doc_key *k = doc_keys;
+ const doc_key_t *k = doc_keys;
for(; k->sect; k++)
if(strcmp(k->sect, sec) == 0)
break;
@@ -189,11 +189,11 @@ static void c_help(char *args) {
} else if(!sec) {
if(*args == '/')
args++;
- struct cmd *c = getcmd(args);
+ cmd_t *c = getcmd(args);
if(!c)
ui_mf(NULL, 0, "\nUnknown command '%s'.", args);
else {
- struct doc_cmd *d = getdoc(c);
+ doc_cmd_t *d = getdoc(c);
ui_mf(NULL, 0, "\nUsage: /%s %s\n %s\n", c->name, d->args ? d->args : "", d->sum);
if(d->desc)
ui_mf(NULL, 0, "%s\n", d->desc);
@@ -218,7 +218,7 @@ static void c_help_sug(char *args, char **sug) {
// help keys ..
if(strncmp(args, "keys ", 5) == 0) {
int i = 0, len = strlen(args)-5;
- const struct doc_key *k;
+ const doc_key_t *k;
for(k=doc_keys; i<20 && k->sect; k++)
if(strncmp(k->sect, args+5, len) == 0 && strlen(k->sect) != len)
sug[i++] = g_strdup(k->sect);
@@ -228,7 +228,7 @@ static void c_help_sug(char *args, char **sug) {
// help command
int i = 0, len = strlen(args);
gboolean ckeys = FALSE;
- struct cmd *c;
+ cmd_t *c;
for(c=cmds; i<20 && c->f; c++) {
// Somehow merge "keys" into the list
if(!ckeys && strcmp(c->name, "keys") > 0) {
@@ -271,7 +271,7 @@ static gboolean c_connect_set_hubaddr(char *addr) {
char *port = g_match_info_fetch(nfo, 3);
g_match_info_free(nfo);
- struct ui_tab *tab = ui_tab_cur->data;
+ ui_tab_t *tab = ui_tab_cur->data;
char *old = g_strdup(var_get(tab->hub->id, VAR_hubaddr));
// Reconstruct (without the kp) and save
@@ -296,7 +296,7 @@ static gboolean c_connect_set_hubaddr(char *addr) {
static void c_connect(char *args) {
- struct ui_tab *tab = ui_tab_cur->data;
+ ui_tab_t *tab = ui_tab_cur->data;
if(tab->type != UIT_HUB)
ui_m(NULL, 0, "This command can only be used on hub tabs.");
else if(!net_is_idle(tab->hub->net))
@@ -314,7 +314,7 @@ static void c_connect(char *args) {
// only autocompletes "dchub://" or the hubaddr, when set
static void c_connect_sug(char *args, char **sug) {
- struct ui_tab *t = ui_tab_cur->data;
+ ui_tab_t *t = ui_tab_cur->data;
if(t->type != UIT_HUB)
return;
int i = 0, len = strlen(args);
@@ -334,7 +334,7 @@ static void c_connect_sug(char *args, char **sug) {
static void c_disconnect(char *args) {
- struct ui_tab *tab = ui_tab_cur->data;
+ ui_tab_t *tab = ui_tab_cur->data;
if(args[0])
ui_m(NULL, 0, "This command does not accept any arguments.");
else if(tab->type == UIT_HUB) {
@@ -356,7 +356,7 @@ static void c_disconnect(char *args) {
static void c_reconnect(char *args) {
- struct ui_tab *tab = ui_tab_cur->data;
+ ui_tab_t *tab = ui_tab_cur->data;
if(args[0])
ui_m(NULL, 0, "This command does not accept any arguments.");
else if(tab->type == UIT_HUB) {
@@ -382,7 +382,7 @@ static void c_reconnect(char *args) {
static void c_accept(char *args) {
- struct ui_tab *tab = ui_tab_cur->data;
+ ui_tab_t *tab = ui_tab_cur->data;
if(args[0])
ui_m(NULL, 0, "This command does not accept any arguments.");
else if(tab->type != UIT_HUB)
@@ -401,7 +401,7 @@ static void c_accept(char *args) {
static void c_open(char *args) {
- struct ui_tab *tab = ui_tab_cur->data;
+ ui_tab_t *tab = ui_tab_cur->data;
gboolean conn = TRUE;
if(strncmp(args, "-n ", 3) == 0) {
conn = FALSE;
@@ -423,7 +423,7 @@ static void c_open(char *args) {
// Look for existing tab
GList *n;
for(n=ui_tabs; n; n=n->next) {
- char *tmp = ((struct ui_tab *)n->data)->name;
+ char *tmp = ((ui_tab_t *)n->data)->name;
if(tmp[0] == '#' && strcmp(tmp+1, name) == 0)
break;
}
@@ -462,7 +462,7 @@ static void c_close(char *args) {
ui_m(NULL, 0, "This command does not accept any arguments.");
return;
}
- struct ui_tab *tab = ui_tab_cur->data;
+ ui_tab_t *tab = ui_tab_cur->data;
switch(tab->type) {
case UIT_MAIN: ui_m(NULL, 0, "Main tab cannot be closed."); break;
case UIT_HUB: ui_hub_close(tab); listen_refresh(); break;
@@ -479,7 +479,7 @@ static void c_close(char *args) {
static void c_clear(char *args) {
- struct ui_tab *tab = ui_tab_cur->data;
+ ui_tab_t *tab = ui_tab_cur->data;
if(args[0])
ui_m(NULL, 0, "This command does not accept any arguments.");
else if(tab->log)
@@ -488,7 +488,7 @@ static void c_clear(char *args) {
static void c_userlist(char *args) {
- struct ui_tab *tab = ui_tab_cur->data;
+ ui_tab_t *tab = ui_tab_cur->data;
if(args[0])
ui_m(NULL, 0, "This command does not accept any arguments.");
else if(tab->type != UIT_HUB)
@@ -499,13 +499,13 @@ static void c_userlist(char *args) {
static void listshares() {
- struct db_share_item *l = db_share_list();
+ db_share_item_t *l = db_share_list();
if(!l->name)
ui_m(NULL, 0, "Nothing shared.");
else {
ui_m(NULL, 0, "");
for(; l->name; l++) {
- struct fl_list *fl = fl_local_list ? fl_list_file(fl_local_list, l->name) : NULL;
+ fl_list_t *fl = fl_local_list ? fl_list_file(fl_local_list, l->name) : NULL;
ui_mf(NULL, 0, " /%s -> %s (%s)", l->name, l->path, fl ? str_formatsize(fl->size) : "-");
}
ui_m(NULL, 0, "");
@@ -539,7 +539,7 @@ static void c_share(char *args) {
ui_m(NULL, 0, "Not a directory.");
else {
// Check whether it (or a subdirectory) is already shared
- struct db_share_item *l = db_share_list();
+ db_share_item_t *l = db_share_list();
for(; l->name; l++)
if(strncmp(l->path, path, MIN(strlen(l->path), strlen(path))) == 0)
break;
@@ -609,7 +609,7 @@ static void c_unshare_sug(char *args, char **sug) {
int len = strlen(args), i = 0;
if(args[0] == '/')
args++;
- struct db_share_item *l = db_share_list();
+ db_share_item_t *l = db_share_list();
for(; l->name; l++)
if(strncmp(args, l->name, len) == 0 && strlen(l->name) != len)
sug[i++] = g_strdup(l->name);
@@ -617,7 +617,7 @@ static void c_unshare_sug(char *args, char **sug) {
static void c_refresh(char *args) {
- struct fl_list *n = fl_local_from_path(args);
+ fl_list_t *n = fl_local_from_path(args);
if(!n)
ui_mf(NULL, 0, "Directory `%s' not found.", args);
else
@@ -626,7 +626,7 @@ static void c_refresh(char *args) {
static void nick_sug(char *args, char **sug, gboolean append) {
- struct ui_tab *t = ui_tab_cur->data;
+ ui_tab_t *t = ui_tab_cur->data;
if(!t->hub)
return;
// get starting point of the nick
@@ -713,7 +713,7 @@ static void c_gc(char *args) {
static void c_whois(char *args) {
- struct ui_tab *tab = ui_tab_cur->data;
+ ui_tab_t *tab = ui_tab_cur->data;
char *u = NULL;
guint64 uid = 0;
gboolean utf8 = TRUE;
@@ -742,7 +742,7 @@ static void listgrants() {
ui_m(NULL, 0, "\nGranted slots to:");
guint64 *n = list;
for(; *n; n++) {
- struct hub_user *u = g_hash_table_lookup(hub_uids, n);
+ hub_user_t *u = g_hash_table_lookup(hub_uids, n);
if(u)
ui_mf(NULL, 0, " %"G_GINT64_MODIFIER"x (%s on %s)", *n, u->name, u->hub->tab->name);
else
@@ -755,8 +755,8 @@ static void listgrants() {
static void c_grant(char *args) {
- struct ui_tab *tab = ui_tab_cur->data;
- struct hub_user *u = NULL;
+ ui_tab_t *tab = ui_tab_cur->data;
+ hub_user_t *u = NULL;
if((!*args && tab->type != UIT_MSG) || strcmp(args, "-list") == 0)
listgrants();
else if(tab->type != UIT_HUB && tab->type != UIT_MSG)
@@ -779,7 +779,7 @@ static void c_grant(char *args) {
static void c_ungrant(char *args) {
- struct ui_tab *tab = ui_tab_cur->data;
+ ui_tab_t *tab = ui_tab_cur->data;
guint64 uid = 0;
if(!*args && tab->type != UIT_MSG) {
listgrants();
@@ -792,7 +792,7 @@ static void c_ungrant(char *args) {
GHashTableIter iter;
g_hash_table_iter_init(&iter, cc_granted);
while(g_hash_table_iter_next(&iter, (gpointer *)&key, NULL)) {
- struct hub_user *u = g_hash_table_lookup(hub_uids, key);
+ hub_user_t *u = g_hash_table_lookup(hub_uids, key);
g_snprintf(id, 17, "%"G_GINT64_MODIFIER"x", *key);
if((u && strcasecmp(u->name, args) == 0) || g_ascii_strncasecmp(id, args, strlen(args)) == 0) {
if(uid) {
@@ -818,7 +818,7 @@ static void c_ungrant_sug(char *args, char **sug) {
guint64 *i = list;
int n = 0;
for(; n<20 && *i; i++) {
- struct hub_user *u = g_hash_table_lookup(hub_uids, i);
+ hub_user_t *u = g_hash_table_lookup(hub_uids, i);
g_snprintf(id, 17, "%"G_GINT64_MODIFIER"x", *i);
if((u && strncasecmp(u->name, args, len) == 0))
sug[n++] = g_strdup(u->name);
@@ -830,7 +830,7 @@ static void c_ungrant_sug(char *args, char **sug) {
static void c_password(char *args) {
- struct ui_tab *tab = ui_tab_cur->data;
+ ui_tab_t *tab = ui_tab_cur->data;
if(tab->type != UIT_HUB)
ui_m(NULL, 0, "This command can only be used on hub tabs.");
else if(!net_is_connected(tab->hub->net))
@@ -843,7 +843,7 @@ static void c_password(char *args) {
static void c_kick(char *args) {
- struct ui_tab *tab = ui_tab_cur->data;
+ ui_tab_t *tab = ui_tab_cur->data;
if(tab->type != UIT_HUB)
ui_m(NULL, 0, "This command can only be used on hub tabs.");
else if(!tab->hub->nick_valid)
@@ -853,7 +853,7 @@ static void c_kick(char *args) {
else if(tab->hub->adc)
ui_m(NULL, 0, "This command only works on NMDC hubs.");
else {
- struct hub_user *u = hub_user_get(tab->hub, args);
+ hub_user_t *u = hub_user_get(tab->hub, args);
if(!u)
ui_m(NULL, 0, "No user found with that name.");
else
@@ -863,7 +863,7 @@ static void c_kick(char *args) {
static void c_nick(char *args) {
- struct ui_tab *tab = ui_tab_cur->data;
+ ui_tab_t *tab = ui_tab_cur->data;
guint64 hub = tab->type == UIT_HUB || tab->type == UIT_MSG ? tab->hub->id : 0;
int v = vars_byname("nick");
g_return_if_fail(v >= 0);
@@ -879,8 +879,8 @@ static void c_nick(char *args) {
}
static void c_browse(char *args) {
- struct ui_tab *tab = ui_tab_cur->data;
- struct hub_user *u = NULL;
+ ui_tab_t *tab = ui_tab_cur->data;
+ hub_user_t *u = NULL;
gboolean force = FALSE;
if(!args[0] && !fl_local_list) {
@@ -927,7 +927,7 @@ static void c_search(char *args) {
gboolean allhubs = FALSE;
gboolean stoparg = FALSE;
int qlen = 0;
- struct search_q *q = g_slice_new0(struct search_q);
+ search_q_t *q = g_slice_new0(search_q_t);
q->query = g_new0(char *, argc+1);
q->type = 1;
@@ -997,13 +997,13 @@ static void c_search(char *args) {
}
// validate & send
- struct ui_tab *tab = ui_tab_cur->data;
+ ui_tab_t *tab = ui_tab_cur->data;
if(!allhubs && tab->type != UIT_HUB && tab->type != UIT_MSG) {
ui_m(NULL, 0, "This command can only be used on hub tabs. Use the `-all' option to search on all connected hubs.");
goto c_search_clean;
}
- struct ui_tab *rtab = ui_search_create(allhubs ? NULL : tab->hub, q, &err);
+ ui_tab_t *rtab = ui_search_create(allhubs ? NULL : tab->hub, q, &err);
if(err) {
ui_mf(NULL, 0, "%s%s", rtab ? "Warning: " : "", err->message);
g_error_free(err);
@@ -1051,7 +1051,7 @@ c_search_clean:
guint64 hub = 0;\
char *hubname = "global";\
if(h) {\
- struct ui_tab *tab = ui_tab_cur->data;\
+ ui_tab_t *tab = ui_tab_cur->data;\
if(tab->type != UIT_HUB && tab->type != UIT_MSG) {\
ui_m(NULL, 0, "This command can only be used on hub tabs.");\
return;\
@@ -1163,7 +1163,7 @@ static void c_hunset(char *args) { unsethunset(TRUE, args); }
static void setunset_sug(gboolean set, gboolean h, const char *val, char **sug) {
guint64 hub = 0;
if(h) {
- struct ui_tab *tab = ui_tab_cur->data;
+ ui_tab_t *tab = ui_tab_cur->data;
if(tab->type != UIT_HUB && tab->type != UIT_MSG)
return;
hub = tab->hub->id;
@@ -1215,11 +1215,11 @@ static void c_listen(char *args) {
// TODO: sort the listen_binds and ->hubs lists
GList *l;
for(l=listen_binds; l; l=l->next) {
- struct listen_bind *b = l->data;
+ listen_bind_t *b = l->data;
GString *h = g_string_new("");
GSList *n;
for(n=b->hubs; n; n=n->next) {
- struct hub *hub = hub_global_byid(((struct listen_hub_bind *)n->data)->hubid);
+ hub_t *hub = hub_global_byid(((listen_hub_bind_t *)n->data)->hubid);
if(hub) {
if(h->len > 0)
g_string_append(h, ", ");
@@ -1236,7 +1236,7 @@ static void c_listen(char *args) {
// definition of the command list
-static struct cmd cmds[] = {
+static cmd_t cmds[] = {
{ "accept", c_accept, NULL },
{ "browse", c_browse, c_msg_sug },
{ "clear", c_clear, NULL },
@@ -1305,7 +1305,7 @@ void cmd_handle(char *ostr) {
g_strstrip(args);
// execute command when found, generate an error otherwise
- struct cmd *c = getcmd(cmd);
+ cmd_t *c = getcmd(cmd);
if(c)
c->f(args);
else
@@ -1316,7 +1316,7 @@ void cmd_handle(char *ostr) {
void cmd_suggest(char *ostr, char **sug) {
- struct cmd *c;
+ cmd_t *c;
char *str = g_strdup(ostr);
// complete command name
if(str[0] == '/' && !strchr(str, ' ')) {
diff --git a/src/db.c b/src/db.c
index 828a4a5..ea011b1 100644
--- a/src/db.c
+++ b/src/db.c
@@ -857,7 +857,7 @@ gboolean db_dl_checkhash(const char *root, int num, const char *hash) {
// the main thread. (This is because they do caching)
#if INTERFACE
-struct db_share_item { char *name; char *path; };
+struct db_share_item_t { char *name; char *path; };
#endif
static GArray *db_share_cache = NULL;
@@ -866,13 +866,13 @@ static GArray *db_share_cache = NULL;
// Returns a zero-terminated array of the shared directories. The array is
// ordered by name. The array should not be freed, and may be modified by any
// later call to a db_share_ function.
-struct db_share_item *db_share_list() {
+db_share_item_t *db_share_list() {
// Return cache
if(db_share_cache)
- return (struct db_share_item *)db_share_cache->data;
+ return (db_share_item_t *)db_share_cache->data;
// Otherwise, create the cache
- db_share_cache = g_array_new(TRUE, FALSE, sizeof(struct db_share_item));
+ db_share_cache = g_array_new(TRUE, FALSE, sizeof(db_share_item_t));
GAsyncQueue *a = g_async_queue_new_full(g_free);
db_queue_push(DBF_NOCACHE, "SELECT name, path FROM share ORDER BY name",
DBQ_RES, a, DBQ_TEXT, DBQ_TEXT,
@@ -880,7 +880,7 @@ struct db_share_item *db_share_list() {
);
char *r;
- struct db_share_item i;
+ db_share_item_t i;
while((r = g_async_queue_pop(a)) && darray_get_int32(r) == SQLITE_ROW) {
i.name = g_strdup(darray_get_string(r));
i.path = g_strdup(darray_get_string(r));
@@ -890,7 +890,7 @@ struct db_share_item *db_share_list() {
g_free(r);
g_async_queue_unref(a);
- return (struct db_share_item *)db_share_cache->data;
+ return (db_share_item_t *)db_share_cache->data;
}
@@ -901,7 +901,7 @@ const char *db_share_path(const char *name) {
// The list is always ordered, so a binary search is possible and will be
// more efficient than this linear search. I don't think anyone has enough
// shared directories for that to matter, though.
- struct db_share_item *l = db_share_list();
+ db_share_item_t *l = db_share_list();
for(; l->name; l++)
if(strcmp(name, l->name) == 0)
return l->path;
@@ -914,7 +914,7 @@ void db_share_rm(const char *name) {
// Remove all
if(!name) {
// Purge cache
- db_share_item *l = db_share_list();
+ db_share_item_t *l = db_share_list();
for(; l->name; l++) {
g_free(l->name);
g_free(l->path);
@@ -927,7 +927,7 @@ void db_share_rm(const char *name) {
// Remove one
} else {
// Remove from the cache
- struct db_share_item *l = db_share_list();
+ db_share_item_t *l = db_share_list();
int i;
for(i=0; l->name; l++,i++) {
if(strcmp(name, l->name) == 0) {
@@ -947,11 +947,11 @@ void db_share_rm(const char *name) {
// Add an item to the share.
void db_share_add(const char *name, const char *path) {
// Add to the cache
- struct db_share_item new;
+ db_share_item_t new;
new.name = g_strdup(name);
new.path = g_strdup(path);
- struct db_share_item *l = db_share_list();
+ db_share_item_t *l = db_share_list();
int i;
for(i=0; l->name; l++,i++)
if(strcmp(l->name, name) > 0)
@@ -974,27 +974,27 @@ void db_share_add(const char *name, const char *path) {
// Try to avoid using the db_vars_(get|set) functions directly. Use the
// higher-level vars.c abstraction instead.
-struct db_var_item { char *name; char *val; guint64 hub; };
+typedef struct db_var_item_t { char *name; char *val; guint64 hub; } db_var_item_t;
static GHashTable *db_vars_cache = NULL;
// Hash, equal and free functions for the hash table
static guint db_vars_cachehash(gconstpointer a) {
- const struct db_var_item *i = a;
+ const db_var_item_t *i = a;
return g_str_hash(i->name) + g_int64_hash(&i->hub);
}
static gboolean db_vars_cacheeq(gconstpointer a, gconstpointer b) {
- const struct db_var_item *x = a;
- const struct db_var_item *y = b;
+ const db_var_item_t *x = a;
+ const db_var_item_t *y = b;
return strcmp(x->name, y->name) == 0 && x->hub == y->hub ? TRUE : FALSE;
}
static void db_vars_cachefree(gpointer a) {
- struct db_var_item *i = a;
+ db_var_item_t *i = a;
g_free(i->name);
g_free(i->val);
- g_slice_free(struct db_var_item, i);
+ g_slice_free(db_var_item_t, i);
}
@@ -1012,7 +1012,7 @@ static void db_vars_cacheget() {
char *r;
while((r = g_async_queue_pop(a)) && darray_get_int32(r) == SQLITE_ROW) {
- struct db_var_item *i = g_slice_new(struct db_var_item);
+ db_var_item_t *i = g_slice_new(db_var_item_t);
i->name = g_strdup(darray_get_string(r));
i->hub = darray_get_int64(r);
i->val = g_strdup(darray_get_string(r));
@@ -1027,7 +1027,7 @@ static void db_vars_cacheget() {
// Get a value from the vars table. The return value should not be modified or freed.
char *db_vars_get(guint64 hub, const char *name) {
db_vars_cacheget();
- struct db_var_item i, *r;
+ db_var_item_t i, *r;
i.name = (char *)name;
i.hub = hub;
r = g_hash_table_lookup(db_vars_cache, &i);
@@ -1041,7 +1041,7 @@ void db_vars_rm(guint64 hub, const char *name) {
return;
// Update cache
- struct db_var_item i;
+ db_var_item_t i;
i.name = (char *)name;
i.hub = hub;
g_hash_table_remove(db_vars_cache, &i);
@@ -1064,7 +1064,7 @@ void db_vars_set(guint64 hub, const char *name, const char *val) {
return;
// Update cache
- struct db_var_item *i = g_slice_new(struct db_var_item);;
+ db_var_item_t *i = g_slice_new(db_var_item_t);;
i->hub = hub;
i->name = g_strdup(name);
i->val = g_strdup(val);
@@ -1081,7 +1081,7 @@ guint64 db_vars_hubid(const char *name) {
db_vars_cacheget();
GHashTableIter i;
- struct db_var_item *n;
+ db_var_item_t *n;
g_hash_table_iter_init(&i, db_vars_cache);
while(g_hash_table_iter_next(&i, NULL, (gpointer *)&n))
if(strcmp(n->name, "hubname") == 0 && strcmp(n->val, name) == 0)
@@ -1096,7 +1096,7 @@ char **db_vars_hubs() {
GPtrArray *p = g_ptr_array_new();
GHashTableIter i;
- struct db_var_item *n;
+ db_var_item_t *n;
g_hash_table_iter_init(&i, db_vars_cache);
while(g_hash_table_iter_next(&i, NULL, (gpointer *)&n))
if(strcmp(n->name, "hubname") == 0)
diff --git a/src/dl.c b/src/dl.c
index 8ae717c..ff1e08a 100644
--- a/src/dl.c
+++ b/src/dl.c
@@ -34,9 +34,9 @@
#if INTERFACE
-struct dl_user_dl {
- struct dl *dl;
- struct dl_user *u;
+struct dl_user_dl_t {
+ dl_t *dl;
+ dl_user_t *u;
char error; // DLE_*
char *error_msg;
};
@@ -48,13 +48,13 @@ struct dl_user_dl {
#define DLU_ACT 3 // dl connected, downloading
#define DLU_WAI 4 // Not connected, waiting for reconnect timeout
-struct dl_user {
- int state; // DLU_*
- int timeout; // source id of the timeout function in DLU_WAI
+struct dl_user_t {
+ int state; // DLU_*
+ int timeout; // source id of the timeout function in DLU_WAI
guint64 uid;
- struct cc *cc; // Always when state = IDL or ACT, may be set or NULL in EXP
- GSequence *queue; // list of struct dl_user_dl, ordered by dl_user_dl_sort()
- struct dl_user_dl *active; // when state = DLU_ACT, the dud that is being downloaded (NULL if it had been removed from the queue while downloading)
+ cc_t *cc; // Always when state = IDL or ACT, may be set or NULL in EXP
+ GSequence *queue; // list of dl_user_dl_t, ordered by dl_user_dl_sort()
+ dl_user_dl_t *active; // when state = DLU_ACT, the dud that is being downloaded (NULL if it had been removed from the queue while downloading)
};
/* State machine for dl_user.state:
@@ -101,29 +101,29 @@ struct dl_user {
#define DLE_HASH 5 // Hash check failed
-struct dl {
+struct dl_t {
gboolean islist : 1;
gboolean hastthl : 1;
- gboolean active : 1; // Whether it is being downloaded by someone
- gboolean flopen : 1; // For lists: Whether to open a browse tab after completed download
- gboolean flmatch : 1; // For lists: Whether to match queue after completed download
- gboolean dlthread : 1; // Whether a dl thread is active
- gboolean delete : 1; // Pending delection
- char prio; // DLP_*
- char error; // DLE_*
- int incfd; // file descriptor for this file in <incoming_dir>
- char *error_msg; // if error != DLE_NONE
- char *flsel; // path to file/dir to select for filelists
- struct ui_tab *flpar; // parent of the file list browser tab for filelists (might be a dangling pointer!)
- char hash[24]; // TTH for files, tiger(uid) for filelists
- GPtrArray *u; // list of users who have this file (GSequenceIter pointers into dl_user.queue)
- guint64 size; // total size of the file
- guint64 have; // what we have so far
- char *inc; // path to the incomplete file (<incoming_dir>/<base32-hash>)
- char *dest; // destination path (must be on same filesystem as the incomplete file)
- guint64 hash_block; // number of bytes that each block represents
- struct tth_ctx *hash_tth; // TTH state of the last block that we have
- GSequenceIter *iter; // used by UIT_DL
+ gboolean active : 1; // Whether it is being downloaded by someone
+ gboolean flopen : 1; // For lists: Whether to open a browse tab after completed download
+ gboolean flmatch : 1; // For lists: Whether to match queue after completed download
+ gboolean dlthread : 1; // Whether a dl thread is active
+ gboolean delete : 1; // Pending delection
+ char prio; // DLP_*
+ char error; // DLE_*
+ int incfd; // file descriptor for this file in <incoming_dir>
+ char *error_msg; // if error != DLE_NONE
+ char *flsel; // path to file/dir to select for filelists
+ ui_tab_t *flpar; // parent of the file list browser tab for filelists (might be a dangling pointer!)
+ char hash[24]; // TTH for files, tiger(uid) for filelists
+ GPtrArray *u; // list of users who have this file (GSequenceIter pointers into dl_user.queue)
+ guint64 size; // total size of the file
+ guint64 have; // what we have so far
+ char *inc; // path to the incomplete file (<incoming_dir>/<base32-hash>)
+ char *dest; // destination path (must be on same filesystem as the incomplete file)
+ guint64 hash_block; // number of bytes that each block represents
+ tth_ctx_t *hash_tth; // TTH state of the last block that we have
+ GSequenceIter *iter; // used by UIT_DL
};
#endif
@@ -137,7 +137,7 @@ struct dl {
#define DL_MINBLOCKSIZE (1024*1024)
// Download queue.
-// Key = dl->hash, Value = struct dl
+// Key = dl->hash, Value = dl_t
GHashTable *dl_queue = NULL;
@@ -167,10 +167,10 @@ char *dl_strerror(char err, const char *sub) {
-// struct dl_user related functions
+// dl_user_t related functions
static gboolean dl_user_waitdone(gpointer dat);
-static void dl_queue_checkrm(struct dl *dl, gboolean justfin);
+static void dl_queue_checkrm(dl_t *dl, gboolean justfin);
// Determine whether a dl_user_dl struct can be considered as "enabled".
@@ -187,10 +187,10 @@ static void dl_queue_checkrm(struct dl *dl, gboolean justfin);
// itself on their highest-priority file.
// TODO: Give priority to small files (those that can be downloaded using a minislot)
static gint dl_user_dl_sort(gconstpointer a, gconstpointer b, gpointer dat) {
- const struct dl_user_dl *x = a;
- const struct dl_user_dl *y = b;
- const struct dl *dx = x->dl;
- const struct dl *dy = y->dl;
+ const dl_user_dl_t *x = a;
+ const dl_user_dl_t *y = b;
+ const dl_t *dx = x->dl;
+ const dl_t *dy = y->dl;
return
// Disabled? Always last
dl_user_dl_enabled(x) && !dl_user_dl_enabled(y) ? -1 : !dl_user_dl_enabled(x) && dl_user_dl_enabled(y) ? 1
@@ -205,8 +205,8 @@ static gint dl_user_dl_sort(gconstpointer a, gconstpointer b, gpointer dat) {
// Frees a dl_user_dl struct
static void dl_user_dl_free(gpointer x) {
- g_free(((struct dl_user_dl *)x)->error_msg);
- g_slice_free(struct dl_user_dl, x);
+ g_free(((dl_user_dl_t *)x)->error_msg);
+ g_slice_free(dl_user_dl_t, x);
}
@@ -216,10 +216,10 @@ static void dl_user_dl_free(gpointer x) {
// <download_slots> iterations.
// Returns NULL if there is no dl item in the queue that is enabled and not
// being downloaded.
-static struct dl_user_dl *dl_user_getdl(const struct dl_user *du) {
+static dl_user_dl_t *dl_user_getdl(const dl_user_t *du) {
GSequenceIter *i = g_sequence_get_begin_iter(du->queue);
for(; !g_sequence_iter_is_end(i); i=g_sequence_iter_next(i)) {
- struct dl_user_dl *dud = g_sequence_get(i);
+ dl_user_dl_t *dud = g_sequence_get(i);
if(!dl_user_dl_enabled(dud))
break;
if(!dud->dl->active)
@@ -231,7 +231,7 @@ static struct dl_user_dl *dl_user_getdl(const struct dl_user *du) {
// Change the state of a user, use state=-1 when something is removed from
// du->queue.
-static void dl_user_setstate(struct dl_user *du, int state) {
+static void dl_user_setstate(dl_user_t *du, int state) {
// Handle reconnect timeout
// x -> WAI
if(state >= 0 && du->state != DLU_WAI && state == DLU_WAI)
@@ -244,7 +244,7 @@ static void dl_user_setstate(struct dl_user *du, int state) {
// ACT state. These are set in dl_queue_start_user().
// ACT -> x
if(state >= 0 && du->state == DLU_ACT && state != DLU_ACT && du->active) {
- struct dl_user_dl *dud = du->active;
+ dl_user_dl_t *dud = du->active;
du->active = NULL;
dud->dl->active = FALSE;
dl_queue_checkrm(dud->dl, FALSE);
@@ -259,7 +259,7 @@ static void dl_user_setstate(struct dl_user *du, int state) {
if(du->state == DLU_NCO && !g_sequence_get_length(du->queue)) {
g_hash_table_remove(queue_users, &du->uid);
g_sequence_free(du->queue);
- g_slice_free(struct dl_user, du);
+ g_slice_free(dl_user_t, du);
return;
}
@@ -270,7 +270,7 @@ static void dl_user_setstate(struct dl_user *du, int state) {
static gboolean dl_user_waitdone(gpointer dat) {
- struct dl_user *du = dat;
+ dl_user_t *du = dat;
g_return_val_if_fail(du->state == DLU_WAI, FALSE);
dl_user_setstate(du, DLU_NCO);
return FALSE;
@@ -281,9 +281,9 @@ static gboolean dl_user_waitdone(gpointer dat) {
// somehow disconnected from the user.
// Otherwise, it means that the cc connection with the user went into the IDLE
// state, either after the handshake or after a completed download.
-void dl_user_cc(guint64 uid, struct cc *cc) {
+void dl_user_cc(guint64 uid, cc_t *cc) {
g_debug("dl:%016"G_GINT64_MODIFIER"x: cc = %s", uid, cc?"true":"false");
- struct dl_user *du = g_hash_table_lookup(queue_users, &uid);
+ dl_user_t *du = g_hash_table_lookup(queue_users, &uid);
if(!du)
return;
g_return_if_fail(!cc || du->state == DLU_NCO || du->state == DLU_EXP || du->state == DLU_ACT);
@@ -304,13 +304,13 @@ void dl_user_join(guint64 uid) {
// Adds a user to a dl item, making sure to create the user if it's not in the
// queue yet. For internal use only, does not save the changes to the database
// and does not call dl_queue_start().
-static void dl_user_add(struct dl *dl, guint64 uid, char error, const char *error_msg) {
+static void dl_user_add(dl_t *dl, guint64 uid, char error, const char *error_msg) {
g_return_if_fail(!dl->islist || dl->u->len == 0);
// get or create dl_user struct
- struct dl_user *du = g_hash_table_lookup(queue_users, &uid);
+ dl_user_t *du = g_hash_table_lookup(queue_users, &uid);
if(!du) {
- du = g_slice_new0(struct dl_user);
+ du = g_slice_new0(dl_user_t);
du->state = DLU_NCO;
du->uid = uid;
du->queue = g_sequence_new(dl_user_dl_free);
@@ -318,7 +318,7 @@ static void dl_user_add(struct dl *dl, guint64 uid, char error, const char *erro
}
// create and fill dl_user_dl struct
- struct dl_user_dl *dud = g_slice_new0(struct dl_user_dl);
+ dl_user_dl_t *dud = g_slice_new0(dl_user_dl_t);
dud->dl = dl;
dud->u = du;
dud->error = error;
@@ -334,10 +334,10 @@ static void dl_user_add(struct dl *dl, guint64 uid, char error, const char *erro
// Remove a user (dl->u[i]) from a dl item, making sure to also remove it from
// du->queue and possibly free the dl_user item if it's no longer useful. As
// above, for internal use only. Does not save the changes to the database.
-static void dl_user_rm(struct dl *dl, int i) {
+static void dl_user_rm(dl_t *dl, int i) {
GSequenceIter *dudi = g_ptr_array_index(dl->u, i);
- struct dl_user_dl *dud = g_sequence_get(dudi);
- struct dl_user *du = dud->u;
+ dl_user_dl_t *dud = g_sequence_get(dudi);
+ dl_user_t *du = dud->u;
// Make sure to disconnect the user and disable dl->active if we happened to
// be actively downloading the file from this user.
@@ -367,7 +367,7 @@ static gboolean dl_queue_needstart = FALSE;
// Determines whether the user is a possible target to either connect to, or to
// initiate a download with.
-static gboolean dl_queue_start_istarget(struct dl_user *du) {
+static gboolean dl_queue_start_istarget(dl_user_t *du) {
// User must be in the NCO/IDL state and we must have something to download
// from them.
if((du->state != DLU_NCO && du->state != DLU_IDL) || !dl_user_getdl(du))
@@ -376,7 +376,7 @@ static gboolean dl_queue_start_istarget(struct dl_user *du) {
// In the NCO state, the user must also be online, and the hub must be
// properly logged in. Otherwise we won't be able to connect anyway.
if(du->state == DLU_NCO) {
- struct hub_user *u = g_hash_table_lookup(hub_uids, &du->uid);
+ hub_user_t *u = g_hash_table_lookup(hub_uids, &du->uid);
if(!u || !u->hub->nick_valid)
return FALSE;
}
@@ -388,22 +388,22 @@ static gboolean dl_queue_start_istarget(struct dl_user *du) {
// Starts a connection with a user or initiates a download if we're already
// connected.
-static gboolean dl_queue_start_user(struct dl_user *du) {
+static gboolean dl_queue_start_user(dl_user_t *du) {
g_return_val_if_fail(dl_queue_start_istarget(du), FALSE);
// If we're not connected yet, just connect
if(du->state == DLU_NCO) {
g_debug("dl:%016"G_GINT64_MODIFIER"x: trying to open a connection", du->uid);
- struct hub_user *u = g_hash_table_lookup(hub_uids, &du->uid);
+ hub_user_t *u = g_hash_table_lookup(hub_uids, &du->uid);
dl_user_setstate(du, DLU_EXP);
hub_opencc(u->hub, u);
return FALSE;
}
// Otherwise, initiate a download.
- struct dl_user_dl *dud = dl_user_getdl(du);
+ dl_user_dl_t *dud = dl_user_getdl(du);
g_return_val_if_fail(dud, FALSE);
- struct dl *dl = dud->dl;
+ dl_t *dl = dud->dl;
g_debug("dl:%016"G_GINT64_MODIFIER"x: using connection for %s", du->uid, dl->dest);
// For filelists: Don't allow resuming of the download. It could happen that
@@ -433,8 +433,8 @@ static gboolean dl_queue_start_user(struct dl_user *du) {
// iteration. Returns -1 if a has a higher priority than b.
// This function assumes dl_queue_start_istarget() for both arguments.
static gint dl_queue_start_cmp(gconstpointer a, gconstpointer b) {
- const struct dl_user *ua = a;
- const struct dl_user *ub = b;
+ const dl_user_t *ua = a;
+ const dl_user_t *ub = b;
return -1*(
ua->state == DLU_IDL && ub->state != DLU_IDL ? 1 :
ua->state != DLU_IDL && ub->state == DLU_IDL ? -1 :
@@ -456,7 +456,7 @@ static gboolean dl_queue_start_do(gpointer dat) {
// - determine the highest-priority target
// - calculate freeslots
GPtrArray *targets = g_ptr_array_new();
- struct dl_user *du, *target = NULL;
+ dl_user_t *du, *target = NULL;
int target_i = 0;
GHashTableIter iter;
g_hash_table_iter_init(&iter, queue_users);
@@ -528,7 +528,7 @@ void dl_queue_start() {
// Adds a dl item to the queue. dl->inc will be determined and opened here.
// dl->hastthl will be set if the file is small enough to not need TTHL data.
// dl->u is also created here.
-static void dl_queue_insert(struct dl *dl, gboolean init) {
+static void dl_queue_insert(dl_t *dl, gboolean init) {
// Set dl->hastthl for files smaller than MINTTHLSIZE.
if(!dl->islist && !dl->hastthl && dl->size <= DL_MINTTHLSIZE) {
dl->hastthl = TRUE;
@@ -556,9 +556,9 @@ static void dl_queue_insert(struct dl *dl, gboolean init) {
// Add the file list of some user to the queue
-void dl_queue_addlist(struct hub_user *u, const char *sel, struct ui_tab *parent, gboolean open, gboolean match) {
+void dl_queue_addlist(hub_user_t *u, const char *sel, ui_tab_t *parent, gboolean open, gboolean match) {
g_return_if_fail(u && u->hasinfo);
- struct dl *dl = g_slice_new0(struct dl);
+ dl_t *dl = g_slice_new0(dl_t);
dl->islist = TRUE;
if(sel)
dl->flsel = g_strdup(sel);
@@ -566,18 +566,18 @@ void dl_queue_addlist(struct hub_user *u, const char *sel, struct ui_tab *parent
dl->flopen = open;
dl->flmatch = match;
// figure out dl->hash
- tiger_ctx tg;
+ tiger_ctx_t tg;
tiger_init(&tg);
tiger_update(&tg, (char *)&u->uid, 8);
tiger_final(&tg, dl->hash);
- struct dl *dup = g_hash_table_lookup(dl_queue, dl->hash);
+ dl_t *dup = g_hash_table_lookup(dl_queue, dl->hash);
if(dup) {
if(open)
dup->flopen = TRUE;
if(match)
dup->flmatch = TRUE;
g_warning("dl:%016"G_GINT64_MODIFIER"x: files.xml.bz2 already in the queue, updating flags.", u->uid);
- g_slice_free(struct dl, dl);
+ g_slice_free(dl_t, dl);
return;
}
// figure out dl->dest
@@ -598,7 +598,7 @@ static gboolean dl_queue_addfile(guint64 uid, char *hash, guint64 size, char *fn
if(g_hash_table_lookup(dl_queue, hash))
return FALSE;
g_return_val_if_fail(size >= 0, FALSE);
- struct dl *dl = g_slice_new0(struct dl);
+ dl_t *dl = g_slice_new0(dl_t);
memcpy(dl->hash, hash, 24);
dl->size = size;
// Figure out dl->dest
@@ -615,7 +615,7 @@ static gboolean dl_queue_addfile(guint64 uid, char *hash, guint64 size, char *fn
// Recursively adds a file or directory to the queue. *excl will only be
// checked for files in subdirectories, if *fl is a file it will always be
// added.
-void dl_queue_add_fl(guint64 uid, struct fl_list *fl, char *base, GRegex *excl) {
+void dl_queue_add_fl(guint64 uid, fl_list_t *fl, char *base, GRegex *excl) {
// check excl
if(base && excl && g_regex_match(excl, fl->name, 0, NULL)) {
ui_mf(NULL, 0, "Ignoring `%s': excluded by regex.", fl->name);
@@ -638,7 +638,7 @@ void dl_queue_add_fl(guint64 uid, struct fl_list *fl, char *base, GRegex *excl)
// Add a search result to the queue. (Only for files)
-void dl_queue_add_res(struct search_r *r) {
+void dl_queue_add_res(search_r_t *r) {
char *name = strrchr(r->file, '/');
if(name)
name++;
@@ -657,12 +657,12 @@ void dl_queue_add_res(struct search_r *r) {
// 0 Found, but user already queued
// 1 Found and user added to the queue
int dl_queue_matchfile(guint64 uid, char *tth) {
- struct dl *dl = g_hash_table_lookup(dl_queue, tth);
+ dl_t *dl = g_hash_table_lookup(dl_queue, tth);
if(!dl)
return -1;
int i;
for(i=0; i<dl->u->len; i++)
- if(((struct dl_user_dl *)g_sequence_get(g_ptr_array_index(dl->u, i)))->u->uid == uid)
+ if(((dl_user_dl_t *)g_sequence_get(g_ptr_array_index(dl->u, i)))->u->uid == uid)
return 0;
dl_user_add(dl, uid, 0, NULL);
db_dl_adduser(dl->hash, uid, 0, NULL);
@@ -674,7 +674,7 @@ int dl_queue_matchfile(guint64 uid, char *tth) {
// Recursively walks through the file list and adds the user to matching dl
// items. Returns the number of items found, and the number of items for which
// the user was added is stored in *added (should be initialized to zero).
-int dl_queue_match_fl(guint64 uid, struct fl_list *fl, int *added) {
+int dl_queue_match_fl(guint64 uid, fl_list_t *fl, int *added) {
if(fl->isfile && fl->hastth) {
int r = dl_queue_matchfile(uid, fl->tth);
if(r == 1)
@@ -697,7 +697,7 @@ int dl_queue_match_fl(guint64 uid, struct fl_list *fl, int *added) {
// Removing stuff from the queue and changing priorities
// removes an item from the queue
-void dl_queue_rm(struct dl *dl) {
+void dl_queue_rm(dl_t *dl) {
dl->delete = TRUE;
// remove from the user info (this will also force a disconnect if the item
@@ -730,13 +730,13 @@ void dl_queue_rm(struct dl *dl) {
// free and remove dl struct
// and free
if(dl->hash_tth)
- g_slice_free(struct tth_ctx, dl->hash_tth);
+ g_slice_free(tth_ctx_t, dl->hash_tth);
g_ptr_array_unref(dl->u);
g_free(dl->inc);
g_free(dl->flsel);
g_free(dl->dest);
g_free(dl->error_msg);
- g_slice_free(struct dl, dl);
+ g_slice_free(dl_t, dl);
}
@@ -745,7 +745,7 @@ void dl_queue_rm(struct dl *dl) {
// struct is not removed while active is true. Otherwise the user will be
// forcibly disconnected in dl_user_rm(). (Which is what you want if you remove
// it while downloading, not if it's removed after finishing the download).
-static void dl_queue_checkrm(struct dl *dl, gboolean justfin) {
+static void dl_queue_checkrm(dl_t *dl, gboolean justfin) {
if(dl->delete)
return;
@@ -763,7 +763,7 @@ static void dl_queue_checkrm(struct dl *dl, gboolean justfin) {
int i = 0;
while(i<dl->u->len) {
GSequenceIter *iter = g_ptr_array_index(dl->u, i);
- struct dl_user_dl *dud = g_sequence_get(iter);
+ dl_user_dl_t *dud = g_sequence_get(iter);
if(dud != dud->u->active)
dl_user_rm(dl, i);
else {
@@ -777,7 +777,7 @@ static void dl_queue_checkrm(struct dl *dl, gboolean justfin) {
}
-void dl_queue_setprio(struct dl *dl, char prio) {
+void dl_queue_setprio(dl_t *dl, char prio) {
gboolean enabled = dl->prio <= DLP_OFF && prio > DLP_OFF;
dl->prio = prio;
db_dl_setstatus(dl->hash, dl->prio, dl->error, dl->error_msg);
@@ -804,8 +804,8 @@ void dl_queue_setprio(struct dl *dl, char prio) {
// Set a user-specific error. If tth = NULL, the error will be set for all
// files in the queue.
void dl_queue_setuerr(guint64 uid, char *tth, char e, const char *emsg) {
- struct dl *dl = tth ? g_hash_table_lookup(dl_queue, tth) : NULL;
- struct dl_user *du = g_hash_table_lookup(queue_users, &uid);
+ dl_t *dl = tth ? g_hash_table_lookup(dl_queue, tth) : NULL;
+ dl_user_t *du = g_hash_table_lookup(queue_users, &uid);
if(!dl || (tth && !du))
return;
@@ -816,7 +816,7 @@ void dl_queue_setuerr(guint64 uid, char *tth, char e, const char *emsg) {
int i;
for(i=0; i<dl->u->len; i++) {
GSequenceIter *iter = g_ptr_array_index(dl->u, i);
- struct dl_user_dl *dud = g_sequence_get(iter);
+ dl_user_dl_t *dud = g_sequence_get(iter);
if(dud->u == du) {
dud->error = e;
g_free(dud->error_msg);
@@ -830,7 +830,7 @@ void dl_queue_setuerr(guint64 uid, char *tth, char e, const char *emsg) {
} else {
GSequenceIter *i = g_sequence_get_begin_iter(du->queue);
for(; !g_sequence_iter_is_end(i); i=g_sequence_iter_next(i)) {
- struct dl_user_dl *dud = g_sequence_get(i);
+ dl_user_dl_t *dud = g_sequence_get(i);
dud->error = e;
g_free(dud->error_msg);
dud->error_msg = emsg ? g_strdup(emsg) : NULL;
@@ -850,8 +850,8 @@ void dl_queue_setuerr(guint64 uid, char *tth, char e, const char *emsg) {
// Remove a user from the queue for a certain file. If tth = NULL, the user
// will be removed from the queue entirely.
void dl_queue_rmuser(guint64 uid, char *tth) {
- struct dl *dl = tth ? g_hash_table_lookup(dl_queue, tth) : NULL;
- struct dl_user *du = g_hash_table_lookup(queue_users, &uid);
+ dl_t *dl = tth ? g_hash_table_lookup(dl_queue, tth) : NULL;
+ dl_user_t *du = g_hash_table_lookup(queue_users, &uid);
if(!du || (tth && !dl))
return;
@@ -859,7 +859,7 @@ void dl_queue_rmuser(guint64 uid, char *tth) {
if(dl) {
int i;
for(i=0; i<dl->u->len; i++) {
- if(((struct dl_user_dl *)g_sequence_get(g_ptr_array_index(dl->u, i)))->u == du) {
+ if(((dl_user_dl_t *)g_sequence_get(g_ptr_array_index(dl->u, i)))->u == du) {
dl_user_rm(dl, i);
break;
}
@@ -878,7 +878,7 @@ void dl_queue_rmuser(guint64 uid, char *tth) {
while(run) {
n = g_sequence_iter_next(i);
run = !g_sequence_iter_is_end(n);
- struct dl *dl = ((struct dl_user_dl *)g_sequence_get(i))->dl;
+ dl_t *dl = ((dl_user_dl_t *)g_sequence_get(i))->dl;
int j;
for(j=0; j<dl->u->len; j++) {
if(g_ptr_array_index(dl->u, j) == i) {
@@ -903,7 +903,7 @@ void dl_queue_rmuser(guint64 uid, char *tth) {
// Managing of active downloads
// Called when we've got a complete file
-static void dl_finished(struct dl *dl) {
+static void dl_finished(dl_t *dl) {
g_debug("dl: download of `%s' finished, removing from queue", dl->dest);
// close
if(dl->incfd > 0)
@@ -945,7 +945,7 @@ static void dl_finished(struct dl *dl) {
g_return_if_fail(dl->u->len == 1);
// Ugly hack: make sure to not select the browse tab, if one is opened
GList *cur = ui_tab_cur;
- ui_fl_queue(((struct dl_user_dl *)g_sequence_get(g_ptr_array_index(dl->u, 0)))->u->uid,
+ ui_fl_queue(((dl_user_dl_t *)g_sequence_get(g_ptr_array_index(dl->u, 0)))->u->uid,
FALSE, dl->flsel, dl->flpar, dl->flopen, dl->flmatch);
ui_tab_cur = cur;
}
@@ -957,8 +957,8 @@ static void dl_finished(struct dl *dl) {
// Called when we've received TTHL data. The *tthl data may be modified
// in-place.
void dl_settthl(guint64 uid, char *tth, char *tthl, int len) {
- struct dl *dl = g_hash_table_lookup(dl_queue, tth);
- struct dl_user *du = g_hash_table_lookup(queue_users, &uid);
+ dl_t *dl = g_hash_table_lookup(dl_queue, tth);
+ dl_user_t *du = g_hash_table_lookup(queue_users, &uid);
if(!dl || !du)
return;
g_return_if_fail(du->state == DLU_ACT);
@@ -1005,7 +1005,7 @@ void dl_settthl(guint64 uid, char *tth, char *tthl, int len) {
// Data receive background thread
-// The background thread access the following struct dl members:
+// The background thread access the following dl_t members:
// - size (read only - not changed in an other thread, no problem)
// - have (read/write - also read in other threads - TODO: this could be a problem)
// - hash_block (read only - not changed in an other thread, no problem)
@@ -1013,18 +1013,18 @@ void dl_settthl(guint64 uid, char *tth, char *tthl, int len) {
// - incfd (read/write - not used in other threads, no problem)
// - islist (read only - not changed in an other thread, no problem)
-struct recv_ctx {
- struct dl *dl;
+typedef struct recv_ctx_t {
+ dl_t *dl;
guint64 uid;
char *err_msg, *uerr_msg;
char err, uerr;
- struct fadv adv;
-};
+ fadv_t adv;
+} recv_ctx_t;
void *dl_recv_create(guint64 uid, const char *tth) {
- struct dl *dl = g_hash_table_lookup(dl_queue, tth);
- struct dl_user *du = g_hash_table_lookup(queue_users, &uid);
+ dl_t *dl = g_hash_table_lookup(dl_queue, tth);
+ dl_user_t *du = g_hash_table_lookup(queue_users, &uid);
if(!dl || !du)
return NULL;
g_return_val_if_fail(!dl->dlthread, NULL);
@@ -1043,7 +1043,7 @@ void *dl_recv_create(guint64 uid, const char *tth) {
// Create context and mark the dl item als being active
dl->dlthread = TRUE;
- struct recv_ctx *c = g_slice_new0(struct recv_ctx);
+ recv_ctx_t *c = g_slice_new0(recv_ctx_t);
c->uid = uid;
c->dl = dl;
fadv_init(&c->adv, dl->incfd, dl->have, VAR_FFC_DOWNLOAD);
@@ -1053,7 +1053,7 @@ void *dl_recv_create(guint64 uid, const char *tth) {
void dl_recv_done(void *dat) {
- struct recv_ctx *c = dat;
+ recv_ctx_t *c = dat;
fadv_close(&c->adv);
@@ -1079,11 +1079,11 @@ void dl_recv_done(void *dat) {
// Clean up
g_free(c->uerr_msg);
g_free(c->err_msg);
- g_slice_free(struct recv_ctx, c);
+ g_slice_free(recv_ctx_t, c);
}
-static gboolean dl_recv_check(struct dl *dl, int num, char *tth) {
+static gboolean dl_recv_check(dl_t *dl, int num, char *tth) {
// We don't have TTHL data for small files, so check against the root hash instead.
if(dl->size < dl->hash_block) {
g_return_val_if_fail(num == 0, FALSE);
@@ -1099,13 +1099,13 @@ static gboolean dl_recv_check(struct dl *dl, int num, char *tth) {
// point where the newly received data will be written to.
// Returns -1 if nothing went wrong, any other number to indicate which block
// failed the hash check.
-static int dl_recv_update(struct dl *dl, const char *buf, int length) {
+static int dl_recv_update(dl_t *dl, const char *buf, int length) {
int block = dl->have / dl->hash_block;
guint64 cur = dl->have % dl->hash_block;
if(!dl->hash_tth) {
g_return_val_if_fail(!cur, FALSE);
- dl->hash_tth = g_slice_new(struct tth_ctx);
+ dl->hash_tth = g_slice_new(tth_ctx_t);
tth_init(dl->hash_tth);
}
@@ -1133,7 +1133,7 @@ static int dl_recv_update(struct dl *dl, const char *buf, int length) {
// Called directly from net.c.
gboolean dl_recv_data(void *dat, const char *buf, int length) {
- struct recv_ctx *c = dat;
+ recv_ctx_t *c = dat;
while(length > 0) {
// write
@@ -1188,7 +1188,7 @@ gboolean dl_recv_data(void *dat, const char *buf, int length) {
// Checks the incoming file for what we already have and modifies dl->have and
// dl->hash_tth accordingly.
-void dl_load_partial(struct dl *dl) {
+void dl_load_partial(dl_t *dl) {
// get size of the incomplete file, but only if we have tthl info
char *fn = NULL;
if(dl->hastthl) {
@@ -1232,11 +1232,11 @@ void dl_load_partial(struct dl *dl) {
}
-// Creates and inserts a struct dl item from the database in the queue
+// Creates and inserts a dl_t item from the database in the queue
void dl_load_dl(const char *tth, guint64 size, const char *dest, char prio, char error, const char *error_msg, int tthllen) {
g_return_if_fail(dest);
- struct dl *dl = g_slice_new0(struct dl);
+ dl_t *dl = g_slice_new0(dl_t);
memcpy(dl->hash, tth, 24);
dl->size = size;
dl->prio = prio;
@@ -1256,9 +1256,9 @@ void dl_load_dl(const char *tth, guint64 size, const char *dest, char prio, char
}
-// Creates and adds a struct dl_user/dl_user_dl from the database in the queue
+// Creates and adds a dl_user_t/dl_user_dl from the database in the queue
void dl_load_dlu(const char *tth, guint64 uid, char error, const char *error_msg) {
- struct dl *dl = g_hash_table_lookup(dl_queue, tth);
+ dl_t *dl = g_hash_table_lookup(dl_queue, tth);
g_return_if_fail(dl);
dl_user_add(dl, uid, error, error_msg);
}
@@ -1271,7 +1271,7 @@ void dl_init_global() {
db_dl_getdls(dl_load_dl);
db_dl_getdlus(dl_load_dlu);
// load/check the data we've already downloaded
- struct dl *dl;
+ dl_t *dl;
GHashTableIter iter;
g_hash_table_iter_init(&iter, dl_queue);
while(g_hash_table_iter_next(&iter, NULL, (gpointer *)&dl))
@@ -1284,7 +1284,7 @@ void dl_init_global() {
void dl_close_global() {
// Delete incomplete file lists. They won't be completed anyway.
GHashTableIter iter;
- struct dl *dl;
+ dl_t *dl;
g_hash_table_iter_init(&iter, dl_queue);
while(g_hash_table_iter_next(&iter, NULL, (gpointer *)&dl))
if(dl->islist)
diff --git a/src/doc.h b/src/doc.h
index 876aef6..7cb4a65 100644
--- a/src/doc.h
+++ b/src/doc.h
@@ -26,9 +26,11 @@
#ifdef DOC_CMD
-static const struct doc_cmd {
+typedef struct doc_cmd_t {
char const name[16], *args, *sum, *desc;
-} doc_cmds[] = {
+} doc_cmd_t;
+
+static const doc_cmd_t doc_cmds[] = {
{ "accept", NULL, "Accept the TLS certificate of a hub.",
"Use this command to accept the TLS certificate of a hub. This command is"
@@ -252,11 +254,13 @@ static const struct doc_cmd {
#ifdef DOC_SET
-static const struct doc_set {
+typedef struct doc_set_t {
char const *name;
int hub;
char const *type, *desc;
-} doc_sets[] = {
+} doc_set_t;
+
+static const doc_set_t doc_sets[] = {
{ "active", 1, "<boolean>",
"Enables or disables active mode. You may have to configure your router"
@@ -560,9 +564,11 @@ static const struct doc_set {
"PgUp/PgDown Select one page of items up/down.\n"\
"End/Home Select last/first item in the list.\n"
-static const struct doc_key {
+typedef struct doc_key_t {
char const *sect, *title, *desc;
-} doc_keys[] = {
+} doc_key_t;
+
+static const doc_key_t doc_keys[] = {
{ "global", "Global key bindings",
"Alt+j Open previous tab.\n"
diff --git a/src/fl_load.c b/src/fl_load.c
index 1700b8e..4d30555 100644
--- a/src/fl_load.c
+++ b/src/fl_load.c
@@ -42,7 +42,7 @@
#define S_UNKNOWN 6 // In some tag we didn't recognize
#define S_END 7 // Received </FileListing>
-struct ctx {
+typedef struct ctx_t {
BZFILE *fh_bz;
FILE *fh_f;
gboolean eof;
@@ -54,14 +54,14 @@ struct ctx {
gboolean filehastth;
guint64 filesize;
gboolean dirincomplete;
- struct fl_list *root;
- struct fl_list *cur;
+ fl_list_t *root;
+ fl_list_t *cur;
int unknown_level;
-};
+} ctx_t;
static int readcb(void *context, char *buf, int len, GError **err) {
- struct ctx *x = context;
+ ctx_t *x = context;
if(x->fh_bz) {
if(x->eof)
@@ -88,7 +88,7 @@ static int readcb(void *context, char *buf, int len, GError **err) {
static int entitycb(void *context, int type, const char *arg1, const char *arg2, GError **err) {
- struct ctx *x = context;
+ ctx_t *x = context;
//printf("%d,%d: %s, %s\n", x->state, type, arg1, arg2);
switch(x->state) {
@@ -122,7 +122,7 @@ static int entitycb(void *context, int type, const char *arg1, const char *arg2,
return -1;
}
// Create the directory entry
- struct fl_list *new = fl_list_create(x->name, FALSE);
+ fl_list_t *new = fl_list_create(x->name, FALSE);
new->isfile = FALSE;
new->sub = g_ptr_array_new_with_free_func(fl_list_free);
fl_list_add(x->cur, new, -1);
@@ -200,7 +200,7 @@ static int entitycb(void *context, int type, const char *arg1, const char *arg2,
return -1;
}
// Create the file entry
- struct fl_list *new = fl_list_create(x->name, x->local);
+ fl_list_t *new = fl_list_create(x->name, x->local);
new->isfile = TRUE;
new->size = x->filesize;
new->hastth = TRUE;
@@ -255,8 +255,8 @@ static int entitycb(void *context, int type, const char *arg1, const char *arg2,
}
-static int ctx_open(struct ctx *x, const char *file, GError **err) {
- memset(x, 0, sizeof(struct ctx));
+static int ctx_open(ctx_t *x, const char *file, GError **err) {
+ memset(x, 0, sizeof(ctx_t));
// open file
x->fh_f = fopen(file, "r");
@@ -279,7 +279,7 @@ static int ctx_open(struct ctx *x, const char *file, GError **err) {
}
-static void ctx_close(struct ctx *x) {
+static void ctx_close(ctx_t *x) {
if(x->fh_bz) {
int bzerr;
BZ2_bzReadClose(&bzerr, x->fh_bz);
@@ -293,10 +293,10 @@ static void ctx_close(struct ctx *x) {
}
-struct fl_list *fl_load(const char *file, GError **err, gboolean local) {
+fl_list_t *fl_load(const char *file, GError **err, gboolean local) {
g_return_val_if_fail(err == NULL || *err == NULL, NULL);
- struct ctx x;
+ ctx_t x;
GError *ierr = NULL;
if(ctx_open(&x, file, &ierr))
goto end;
@@ -330,26 +330,26 @@ end:
// Async version of fl_load(). Performs the load in a background thread. Only
// used for non-local filelists.
-struct async_dat {
+typedef struct async_t {
char *file;
- void (*cb)(struct fl_list *, GError *, void *);
+ void (*cb)(fl_list_t *, GError *, void *);
void *dat;
GError *err;
- struct fl_list *fl;
-};
+ fl_list_t *fl;
+} async_t;
static gboolean async_d(gpointer dat) {
- struct async_dat *arg = dat;
+ async_t *arg = dat;
arg->cb(arg->fl, arg->err, arg->dat);
g_free(arg->file);
- g_slice_free(struct async_dat, arg);
+ g_slice_free(async_t, arg);
return FALSE;
}
static void async_f(gpointer dat, gpointer udat) {
- struct async_dat *arg = dat;
+ async_t *arg = dat;
arg->fl = fl_load(arg->file, &arg->err, FALSE);
g_idle_add(async_d, arg);
}
@@ -357,11 +357,11 @@ static void async_f(gpointer dat, gpointer udat) {
// Ownership of both the file list and the error is passed to the callback
// function.
-void fl_load_async(const char *file, void (*cb)(struct fl_list *, GError *, void *), void *dat) {
+void fl_load_async(const char *file, void (*cb)(fl_list_t *, GError *, void *), void *dat) {
static GThreadPool *pool = NULL;
if(!pool)
pool = g_thread_pool_new(async_f, NULL, 2, FALSE, NULL);
- struct async_dat *arg = g_slice_new0(struct async_dat);
+ async_t *arg = g_slice_new0(async_t);
arg->file = g_strdup(file);
arg->dat = dat;
arg->cb = cb;
diff --git a/src/fl_local.c b/src/fl_local.c
index 10c269b..c5796c3 100644
--- a/src/fl_local.c
+++ b/src/fl_local.c
@@ -33,7 +33,7 @@
char *fl_local_list_file;
-struct fl_list *fl_local_list = NULL;
+fl_list_t *fl_local_list = NULL;
GQueue *fl_refresh_queue = NULL;
time_t fl_refresh_last = 0; // time when the last full file list refresh has been queued
static gboolean fl_needflush = FALSE;
@@ -45,13 +45,13 @@ int fl_local_list_length; // total number of unique files in the sha
static GThreadPool *fl_scan_pool;
static GThreadPool *fl_hash_pool;
-GHashTable *fl_hash_queue = NULL; // set of files-to-hash
-guint64 fl_hash_queue_size = 0;
-static struct fl_list *fl_hash_cur = NULL; // most recent file initiated for hashing
-struct ratecalc fl_hash_rate;
-static guint64 fl_hash_reset = 0; // increased when fl_hash_cur is removed from the queue (to stop current hash operation)
-static GMutex *fl_hash_resetlock;
-static GCond *fl_hash_resetcond;
+GHashTable *fl_hash_queue = NULL; // set of files-to-hash
+guint64 fl_hash_queue_size = 0;
+static fl_list_t *fl_hash_cur = NULL; // most recent file initiated for hashing
+ratecalc_t fl_hash_rate;
+static guint64 fl_hash_reset = 0; // increased when fl_hash_cur is removed from the queue (to stop current hash operation)
+static GMutex *fl_hash_resetlock;
+static GCond *fl_hash_resetcond;
#define TTH_BUFSIZE (512*1024)
@@ -60,11 +60,11 @@ static GCond *fl_hash_resetcond;
// Get full path to an item in our list. Result should be free'd. This function
// isn't particularly fast.
-char *fl_local_path(struct fl_list *fl) {
+char *fl_local_path(fl_list_t *fl) {
if(!fl->parent->parent)
return g_strdup(db_share_path(fl->name));
char *tmp, *path = g_strdup(fl->name);
- struct fl_list *cur = fl->parent;
+ fl_list_t *cur = fl->parent;
while(cur->parent && cur->parent->parent) {
tmp = path;
path = g_build_filename(cur->name, path, NULL);
@@ -82,10 +82,10 @@ char *fl_local_path(struct fl_list *fl) {
// the path must be absolute and "real" (i.e., what realpath() would return),
// since that is the path that is stored in the config file. This function
// makes no attempt to convert the given path into a real path.
-struct fl_list *fl_local_from_path(const char *path) {
- struct fl_list *n = fl_list_from_path(fl_local_list, path);
+fl_list_t *fl_local_from_path(const char *path) {
+ fl_list_t *n = fl_list_from_path(fl_local_list, path);
if(!n && path[0] == '/') {
- struct db_share_item *l = db_share_list();
+ db_share_item_t *l = db_share_list();
for(; l->name; l++)
if(strncmp(path, l->path, strlen(l->path)) == 0)
break;
@@ -136,7 +136,7 @@ gboolean fl_flush(gpointer dat) {
// fl_local_list_size and _length stay correct.
// Add to the hash index
-static void fl_hashindex_insert(struct fl_list *fl) {
+static void fl_hashindex_insert(fl_list_t *fl) {
GSList *cur = g_hash_table_lookup(fl_hash_index, fl->tth);
if(cur) {
g_return_if_fail(cur == g_slist_insert(cur, fl, 1)); // insert item without modifying the pointer
@@ -151,7 +151,7 @@ static void fl_hashindex_insert(struct fl_list *fl) {
// ...and remove a file. This is done when a file is actually removed from the
// share, or when its TTH information has been invalidated.
-static void fl_hashindex_del(struct fl_list *fl) {
+static void fl_hashindex_del(fl_list_t *fl) {
if(!fl->hastth)
return;
GSList *cur = g_hash_table_lookup(fl_hash_index, fl->tth);
@@ -163,7 +163,7 @@ static void fl_hashindex_del(struct fl_list *fl) {
fl_local_list_size -= fl->size;
// there's another file with the same TTH.
} else
- g_hash_table_replace(fl_hash_index, ((struct fl_list *)cur->data)->tth, cur);
+ g_hash_table_replace(fl_hash_index, ((fl_list_t *)cur->data)->tth, cur);
fl_local_list_length = g_hash_table_size(fl_hash_index);
}
@@ -172,28 +172,27 @@ static void fl_hashindex_del(struct fl_list *fl) {
// Scanning directories
-// TODO: rewrite this with the new SQLite backend idea
// Note: The `file' structure points to a (sub-)item in fl_local_list, and will
// be accessed from both the scan thread and the main thread. It is therefore
// important that no changes are made to the local file list while the scan
// thread is active.
-struct fl_scan_args {
- struct fl_list **file, **res;
+typedef struct fl_scan_t {
+ fl_list_t **file, **res;
char **path;
GRegex *excl_regex;
gboolean inc_hidden;
gboolean (*donefun)(gpointer);
-};
+} fl_scan_t;
// Removes duplicate files (that is, files with the same name in a
// case-insensitive context) from a dirtectory.
-static void fl_scan_rmdupes(struct fl_list *fl, const char *vpath) {
+static void fl_scan_rmdupes(fl_list_t *fl, const char *vpath) {
int i = 1;
while(i<fl->sub->len) {
- struct fl_list *a = g_ptr_array_index(fl->sub, i-1);
- struct fl_list *b = g_ptr_array_index(fl->sub, i);
+ fl_list_t *a = g_ptr_array_index(fl->sub, i-1);
+ fl_list_t *b = g_ptr_array_index(fl->sub, i);
if(fl_list_cmp_strict(a, b) == 0) {
char *tmp = g_build_filename(vpath, b->name, NULL);
ui_mf(ui_main, UIP_MED, "Not sharing \"%s\": Other file with same name (but different case) already shared.", tmp);
@@ -224,13 +223,13 @@ static void fl_scan_invalidate(gint64 id, gboolean force_flush) {
// Fetches TTH information either from the database or from *oldpar, and
// invalidates this data if the file has changed.
-static void fl_scan_check(struct fl_list *oldpar, struct fl_list *new, const char *real) {
+static void fl_scan_check(fl_list_t *oldpar, fl_list_t *new, const char *real) {
time_t oldlastmod;
guint64 oldsize;
char oldhash[24];
gint64 oldid = 0;
- struct fl_list *old = oldpar && oldpar->sub ? fl_list_file_strict(oldpar, new) : NULL;
+ fl_list_t *old = oldpar && oldpar->sub ? fl_list_file_strict(oldpar, new) : NULL;
// Get from the previous in-memory structure
if(old && fl_list_getlocal(old).id) {
oldid = fl_list_getlocal(old).id;
@@ -256,13 +255,13 @@ static void fl_scan_check(struct fl_list *oldpar, struct fl_list *new, const cha
// *name is in filesystem encoding. For *path and *vpath see fl_scan_dir().
-static struct fl_list *fl_scan_item(struct fl_list *old, const char *path, const char *vpath, const char *name, GRegex *excl) {
+static fl_list_t *fl_scan_item(fl_list_t *old, const char *path, const char *vpath, const char *name, GRegex *excl) {
char *uname = NULL; // name-to-UTF8
char *vcpath = NULL; // vpath + uname
char *ename = NULL; // uname-to-filesystem
char *cpath = NULL; // path + ename
char *real = NULL; // realpath(cpath)-to-UTF8
- struct fl_list *node = NULL;
+ fl_list_t *node = NULL;
// Try to get a UTF-8 filename
uname = g_filename_to_utf8(name, -1, NULL, NULL, NULL);
@@ -340,7 +339,7 @@ done:
// recursive
// Doesn't handle paths longer than PATH_MAX, but I don't think it matters all that much.
// *path is the filesystem path in filename encoding, vpath is the virtual path in UTF-8.
-static void fl_scan_dir(struct fl_list *parent, struct fl_list *old, const char *path, const char *vpath, gboolean inc_hidden, GRegex *excl) {
+static void fl_scan_dir(fl_list_t *parent, fl_list_t *old, const char *path, const char *vpath, gboolean inc_hidden, GRegex *excl) {
GError *err = NULL;
GDir *dir = g_dir_open(path, 0, &err);
if(!dir) {
@@ -355,7 +354,7 @@ static void fl_scan_dir(struct fl_list *parent, struct fl_list *old, const char
if(!inc_hidden && name[0] == '.')
continue;
// check with *excl, stat and create
- struct fl_list *item = fl_scan_item(old, path, vpath, name, excl);
+ fl_list_t *item = fl_scan_item(old, path, vpath, name, excl);
// and add it
if(item)
fl_list_add(parent, item, -1);
@@ -370,7 +369,7 @@ static void fl_scan_dir(struct fl_list *parent, struct fl_list *old, const char
// directories opened at the same time. Costs some extra CPU cycles, though...)
int i;
for(i=0; i<parent->sub->len; i++) {
- struct fl_list *cur = g_ptr_array_index(parent->sub, i);
+ fl_list_t *cur = g_ptr_array_index(parent->sub, i);
if(!cur->isfile) {
char *enc = g_filename_from_utf8(cur->name, -1, NULL, NULL, NULL);
char *cpath = g_build_filename(path, enc, NULL);
@@ -387,11 +386,11 @@ static void fl_scan_dir(struct fl_list *parent, struct fl_list *old, const char
// Must be called in a separate thread.
static void fl_scan_thread(gpointer data, gpointer udata) {
- struct fl_scan_args *args = data;
+ fl_scan_t *args = data;
int i, len = g_strv_length(args->path);
for(i=0; i<len; i++) {
- struct fl_list *cur = fl_list_create("", FALSE);
+ fl_list_t *cur = fl_list_create("", FALSE);
char *tmp = g_filename_from_utf8(args->path[i], -1, NULL, NULL, NULL);
cur->sub = g_ptr_array_new_with_free_func(fl_list_free);
fl_scan_dir(cur, args->file[i], tmp, args->path[i], args->inc_hidden, args->excl_regex);
@@ -412,8 +411,8 @@ static void fl_scan_thread(gpointer data, gpointer udata) {
// This struct is passed from the main thread to the hasher and back with modifications.
-struct fl_hash_args {
- struct fl_list *file; // only accessed from main thread
+typedef struct fl_hash_t {
+ fl_list_t *file; // only accessed from main thread
char *path; // owned by main thread, read from hash thread
guint64 filesize; // set by main thread
char root[24]; // set by hash thread
@@ -422,7 +421,7 @@ struct fl_hash_args {
gint64 id; // set by hash thread
gdouble time; // set by hash thread
guint64 lastreset; // last value of fl_hash_reset when starting this thread
-};
+} fl_hash_t;
// Maximum number of levels, including root (level 0). The ADC docs specify
// that this should be at least 7, and everyone else uses 10. Since keeping 10
@@ -475,7 +474,7 @@ struct fl_hash_args {
// Recursively deletes a fl_list structure from the hash queue
-static void fl_hash_queue_delrec(struct fl_list *f) {
+static void fl_hash_queue_delrec(fl_list_t *f) {
if(f->isfile)
fl_hash_queue_del(f);
else {
@@ -506,9 +505,9 @@ static int fl_hash_burst(guint64 lastreset) {
static gboolean fl_hash_done(gpointer dat);
static void fl_hash_thread(gpointer data, gpointer udata) {
- struct fl_hash_args *args = data;
+ fl_hash_t *args = data;
// static, since only one hash thread is allowed and this saves stack space
- struct tth_ctx tth;
+ tth_ctx_t tth;
char *buf = g_malloc(TTH_BUFSIZE);
char *blocks = NULL;
int f = -1;
@@ -539,7 +538,7 @@ static void fl_hash_thread(gpointer data, gpointer udata) {
blocks = g_malloc(24*blocks_num);
tth_init(&tth);
- struct fadv adv;
+ fadv_t adv;
fadv_init(&adv, f, 0, VAR_FFC_HASH);
int r, nr;
@@ -624,13 +623,13 @@ static void fl_hash_process() {
// get one item from fl_hash_queue
GHashTableIter iter;
- struct fl_list *file;
+ fl_list_t *file;
g_hash_table_iter_init(&iter, fl_hash_queue);
g_hash_table_iter_next(&iter, (gpointer *)&file, NULL);
fl_hash_cur = file;
// pass stuff to the hash thread
- struct fl_hash_args *args = g_new0(struct fl_hash_args, 1);
+ fl_hash_t *args = g_new0(fl_hash_t, 1);
args->file = file;
char *tmp = fl_local_path(file);
args->path = g_filename_from_utf8(tmp, -1, NULL, NULL, NULL);
@@ -642,8 +641,8 @@ static void fl_hash_process() {
static gboolean fl_hash_done(gpointer dat) {
- struct fl_hash_args *args = dat;
- struct fl_list *fl = args->file;
+ fl_hash_t *args = dat;
+ fl_list_t *fl = args->file;
// remove file from queue, ignore this hash if the file was already removed
// by some other process.
@@ -683,13 +682,13 @@ fl_hash_done_f:
// get or create a root directory
-static struct fl_list *fl_refresh_getroot(const char *name) {
+static fl_list_t *fl_refresh_getroot(const char *name) {
// no root? create!
if(!fl_local_list) {
fl_local_list = fl_list_create("", FALSE);
fl_local_list->sub = g_ptr_array_new_with_free_func(fl_list_free);
}
- struct fl_list *cur = fl_list_file(fl_local_list, name);
+ fl_list_t *cur = fl_list_file(fl_local_list, name);
// dir not present yet? create a stub
if(!cur) {
cur = fl_list_create(name, FALSE);
@@ -702,7 +701,7 @@ static struct fl_list *fl_refresh_getroot(const char *name) {
// Recursively adds the files to either the hash index or the hash queue.
-static void fl_refresh_addhash(struct fl_list *cur) {
+static void fl_refresh_addhash(fl_list_t *cur) {
if(cur->isfile) {
if(cur->hastth)
fl_hashindex_insert(cur);
@@ -719,7 +718,7 @@ static void fl_refresh_addhash(struct fl_list *cur) {
// Recursively removes the files from the hash index. Unlike _addhash(), this
// doesn't touch the hash queue. The files should have been removed from the
// hash queue before doing the refresh.
-static void fl_refresh_delhash(struct fl_list *cur) {
+static void fl_refresh_delhash(fl_list_t *cur) {
if(cur->isfile && cur->hastth)
fl_hashindex_del(cur);
else if(!cur->isfile) {
@@ -730,12 +729,12 @@ static void fl_refresh_delhash(struct fl_list *cur) {
}
-static void fl_refresh_compare(struct fl_list *old, struct fl_list *new) {
+static void fl_refresh_compare(fl_list_t *old, fl_list_t *new) {
int oldi = 0;
int newi = 0;
while(oldi < old->sub->len || newi < new->sub->len) {
- struct fl_list *oldl = oldi >= old->sub->len ? NULL : g_ptr_array_index(old->sub, oldi);
- struct fl_list *newl = newi >= new->sub->len ? NULL : g_ptr_array_index(new->sub, newi);
+ fl_list_t *oldl = oldi >= old->sub->len ? NULL : g_ptr_array_index(old->sub, oldi);
+ fl_list_t *newl = newi >= new->sub->len ? NULL : g_ptr_array_index(new->sub, newi);
// Don't use fl_list_cmp() here, since that one doesn't return 0
int cmp = !oldl ? 1 : !newl ? -1 : fl_list_cmp_strict(oldl, newl);
gboolean check = FALSE, remove = FALSE, insert = FALSE;
@@ -783,7 +782,7 @@ static void fl_refresh_compare(struct fl_list *old, struct fl_list *new) {
// insert
if(insert) {
- struct fl_list *tmp = fl_list_copy(newl);
+ fl_list_t *tmp = fl_list_copy(newl);
fl_list_add(old, tmp, oldi);
fl_refresh_addhash(tmp);
oldi++; // after fl_list_add(), oldi points to the new item. But we don't have to check that one again, so increase.
@@ -817,8 +816,8 @@ static void fl_refresh_process() {
return;
// construct the list of to-be-scanned directories
- struct fl_list *dir = fl_refresh_queue->head->data;
- struct fl_scan_args *args = g_slice_new0(struct fl_scan_args);
+ fl_list_t *dir = fl_refresh_queue->head->data;
+ fl_scan_t *args = g_slice_new0(fl_scan_t);
args->donefun = fl_refresh_scanned;
args->inc_hidden = var_get_bool(0, VAR_share_hidden);
@@ -833,8 +832,8 @@ static void fl_refresh_process() {
// one dir, the simple case
if(dir != fl_local_list) {
- args->file = g_new0(struct fl_list *, 2);
- args->res = g_new0(struct fl_list *, 2);
+ args->file = g_new0(fl_list_t *, 2);
+ args->res = g_new0(fl_list_t *, 2);
args->path = g_new0(char *, 2);
args->file[0] = dir;
args->path[0] = fl_local_path(dir);
@@ -842,12 +841,12 @@ static void fl_refresh_process() {
// refresh the entire share, which consists of multiple dirs.
} else {
time(&fl_refresh_last);
- struct db_share_item *l;
+ db_share_item_t *l;
int i, len = 0;
for(l=db_share_list(); l->name; l++)
len++;
- args->file = g_new0(struct fl_list *, len+1);
- args->res = g_new0(struct fl_list *, len+1);
+ args->file = g_new0(fl_list_t *, len+1);
+ args->res = g_new0(fl_list_t *, len+1);
args->path = g_new0(char *, len+1);
for(i=0,l=db_share_list(); l->name; i++,l++) {
args->file[i] = fl_refresh_getroot(l->name);
@@ -861,7 +860,7 @@ static void fl_refresh_process() {
static gboolean fl_refresh_scanned(gpointer dat) {
- struct fl_scan_args *args = dat;
+ fl_scan_t *args = dat;
int i, len = g_strv_length(args->path);
for(i=0; i<len; i++) {
@@ -880,7 +879,7 @@ static gboolean fl_refresh_scanned(gpointer dat) {
g_regex_unref(args->excl_regex);
g_free(args->file);
g_free(args->res);
- g_slice_free(struct fl_scan_args, args);
+ g_slice_free(fl_scan_t, args);
g_queue_pop_head(fl_refresh_queue);
if(fl_refresh_queue->head)
@@ -891,12 +890,12 @@ static gboolean fl_refresh_scanned(gpointer dat) {
}
-void fl_refresh(struct fl_list *dir) {
+void fl_refresh(fl_list_t *dir) {
if(!dir)
dir = fl_local_list;
GList *n;
for(n=fl_refresh_queue->head; n; n=n->next) {
- struct fl_list *c = n->data;
+ fl_list_t *c = n->data;
// if current dir is part of listed dir then it's already queued
if(dir == c || fl_list_is_child(c, dir))
return;
@@ -928,7 +927,7 @@ void fl_share(const char *dir) {
// present in the config file anymore).
void fl_unshare(const char *dir) {
if(dir) {
- struct fl_list *fl = fl_list_file(fl_local_list, dir);
+ fl_list_t *fl = fl_list_file(fl_local_list, dir);
g_return_if_fail(fl);
fl_hash_queue_delrec(fl);
fl_refresh_delhash(fl);
@@ -954,10 +953,10 @@ void fl_unshare(const char *dir) {
// Walks through the file list and inserts everything into the fl_hashindex.
-static void fl_init_list(struct fl_list *fl) {
+static void fl_init_list(fl_list_t *fl) {
int i;
for(i=0; i<fl->sub->len; i++) {
- struct fl_list *c = g_ptr_array_index(fl->sub, i);
+ fl_list_t *c = g_ptr_array_index(fl->sub, i);
if(c->isfile && c->hastth)
fl_hashindex_insert(c);
else if(!c->isfile)
@@ -1102,7 +1101,7 @@ gboolean fl_gc() {
g_hash_table_iter_init(&iter, fl_hash_index);
while(g_hash_table_iter_next(&iter, NULL, (gpointer *)&l))
for(; l; l=l->next)
- g_array_append_val(fl_gc_active, fl_list_getlocal((struct fl_list *)l->data).id);
+ g_array_append_val(fl_gc_active, fl_list_getlocal((fl_list_t *)l->data).id);
g_array_sort(fl_gc_active, fl_gc_idcmp);
// walk through hashfiles table and fill fl_gc_remove
diff --git a/src/fl_save.c b/src/fl_save.c
index 6e4a65e..c5a94ae 100644
--- a/src/fl_save.c
+++ b/src/fl_save.c
@@ -36,7 +36,7 @@
#define BUFSIZE (32*1024)
-struct ctx {
+typedef struct ctx_t {
GString *buf; // we're always writing to a (temporary) buffer
BZFILE *fh_bz; // if BZ2 compression is enabled (implies fh_h!=NULL)
FILE *fh_f; // if we're writing to a file
@@ -44,11 +44,11 @@ struct ctx {
char *tmpfile; // Temp filename
gboolean freebuf; // Whether we should free the buffer on close (otherwise it's passed back to the application)
GError *err;
-};
+} ctx_t;
// Flushes the write buffer to the underlying bzip2/file object (if any).
-static int doflush(struct ctx *x) {
+static int doflush(ctx_t *x) {
if(x->fh_bz) {
int bzerr;
BZ2_bzWrite(&bzerr, x->fh_bz, x->buf->str, x->buf->len);
@@ -93,7 +93,7 @@ static int doflush(struct ctx *x) {
// XML-escape and write a string literal
-static int al(struct ctx *x, const char *str) {
+static int al(ctx_t *x, const char *str) {
while(*str) {
switch(*str) {
case '&': as("&amp;"); break;
@@ -109,10 +109,10 @@ static int al(struct ctx *x, const char *str) {
// Recursively write the child nodes of an fl_list item.
-static int af(struct ctx *x, struct fl_list *fl, int level) {
+static int af(ctx_t *x, fl_list_t *fl, int level) {
int i;
for(i=0; i<fl->sub->len; i++) {
- struct fl_list *cur = g_ptr_array_index(fl->sub, i);
+ fl_list_t *cur = g_ptr_array_index(fl->sub, i);
if(cur->isfile && cur->hastth) {
char tth[40] = {};
@@ -149,7 +149,7 @@ static int af(struct ctx *x, struct fl_list *fl, int level) {
// Write the top-level XML
-static int at(struct ctx *x, struct fl_list *fl, int level) {
+static int at(ctx_t *x, fl_list_t *fl, int level) {
as("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
as("<FileListing Version=\"1\" Generator=\"");
if(al(x, PACKAGE_STRING))
@@ -181,8 +181,8 @@ static int at(struct ctx *x, struct fl_list *fl, int level) {
}
-static int ctx_open(struct ctx *x, const char *file, GString *buf) {
- memset(x, 0, sizeof(struct ctx));
+static int ctx_open(ctx_t *x, const char *file, GString *buf) {
+ memset(x, 0, sizeof(ctx_t));
x->buf = buf;
x->file = file;
@@ -223,7 +223,7 @@ static int ctx_open(struct ctx *x, const char *file, GString *buf) {
// Flushes the buffer, closes/renames the file and frees some memory. Does not
// free x->file (not our property) and x->err (still used).
-static int ctx_close(struct ctx *x) {
+static int ctx_close(ctx_t *x) {
if(!x->err)
doflush(x);
@@ -250,10 +250,10 @@ static int ctx_close(struct ctx *x) {
}
-gboolean fl_save(struct fl_list *fl, const char *file, GString *buf, int level, GError **err) {
+gboolean fl_save(fl_list_t *fl, const char *file, GString *buf, int level, GError **err) {
g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
- struct ctx x;
+ ctx_t x;
if(!ctx_open(&x, file, buf))
at(&x, fl, level);
ctx_close(&x);
diff --git a/src/fl_util.c b/src/fl_util.c
index d08cbc9..acf6a57 100644
--- a/src/fl_util.c
+++ b/src/fl_util.c
@@ -33,8 +33,8 @@
// file list
-struct fl_list {
- struct fl_list *parent; // root = NULL
+struct fl_list_t {
+ fl_list_t *parent; // root = NULL
GPtrArray *sub;
guint64 size; // including sub-items
char tth[24];
@@ -49,7 +49,7 @@ struct fl_list {
// region as the fl_list struct itself, but is placed somewhere after the name
// field. Use the respecive macros to get access to this data.
-struct fl_list_local {
+struct fl_list_local_t {
time_t lastmod;
gint64 id;
};
@@ -66,27 +66,27 @@ struct fl_list_local {
#if INTERFACE
// Calculates the minimum required size for a non-local fl_list allocation.
-#define fl_list_minsize(n) (G_STRUCT_OFFSET(struct fl_list, name) + strlen(n) + 1)
+#define fl_list_minsize(n) (G_STRUCT_OFFSET(fl_list_t, name) + strlen(n) + 1)
// Calculates the offset to the fl_list_local struct, given a name. Padding
// bytes are added to ensure that the struct is aligned at 8-byte boundary.
#define fl_list_local_offset(n) ((fl_list_minsize(n) + 7) & ~7)
// Calculates the size required for a local fl_list allocation.
-#define fl_list_localsize(n) (fl_list_local_offset(n) + sizeof(struct fl_list_local))
+#define fl_list_localsize(n) (fl_list_local_offset(n) + sizeof(fl_list_local_t))
// Calculates the actual size of a fl_list.
#define fl_list_size(n, l) (l ? fl_list_localsize(n) : fl_list_minsize(n))
// Get the fl_list_local part of a fl_list struct.
-#define fl_list_getlocal(f) G_STRUCT_MEMBER(struct fl_list_local, f, fl_list_local_offset((f)->name))
+#define fl_list_getlocal(f) G_STRUCT_MEMBER(fl_list_local_t, f, fl_list_local_offset((f)->name))
#endif
// only frees the given item and its childs. leaves the parent(s) untouched
void fl_list_free(gpointer dat) {
- struct fl_list *fl = dat;
+ fl_list_t *fl = dat;
if(!fl)
return;
if(fl->sub)
@@ -97,8 +97,8 @@ void fl_list_free(gpointer dat) {
// Create a new fl_list structure with the given name. Can't be renamed later
// on due to the way the data is stored in memory.
-struct fl_list *fl_list_create(const char *name, gboolean local) {
- struct fl_list *fl = g_slice_alloc0(fl_list_size(name, local));
+fl_list_t *fl_list_create(const char *name, gboolean local) {
+ fl_list_t *fl = g_slice_alloc0(fl_list_size(name, local));
strcpy(fl->name, name);
fl->islocal = local;
return fl;
@@ -109,15 +109,15 @@ struct fl_list *fl_list_create(const char *name, gboolean local) {
// equivalent (that is, have the same name). File names are case-insensitive,
// as required by the ADC protocol.
gint fl_list_cmp_strict(gconstpointer a, gconstpointer b) {
- return str_casecmp(((struct fl_list *)a)->name, ((struct fl_list *)b)->name);
+ return str_casecmp(((fl_list_t *)a)->name, ((fl_list_t *)b)->name);
}
// A more lenient comparison function, equivalent to fl_list_cmp_strict() in
// all cases except when that one would return 0. This function will return
// zero only if the file list names are byte-equivalent.
gint fl_list_cmp(gconstpointer a, gconstpointer b) {
- const struct fl_list *la = a;
- const struct fl_list *lb = b;
+ const fl_list_t *la = a;
+ const fl_list_t *lb = b;
gint r = str_casecmp(la->name, lb->name);
if(!r)
r = strcmp(la->name, lb->name);
@@ -126,13 +126,13 @@ gint fl_list_cmp(gconstpointer a, gconstpointer b) {
// A sort function suitable for g_ptr_array_sort()
static gint fl_list_cmp_sort(gconstpointer a, gconstpointer b) {
- return fl_list_cmp(*((struct fl_list **)a), *((struct fl_list **)b));
+ return fl_list_cmp(*((fl_list_t **)a), *((fl_list_t **)b));
}
// Adds `cur' to the directory `parent'. Make sure to call fl_list_sort()
// afterwards.
-void fl_list_add(struct fl_list *parent, struct fl_list *cur, int before) {
+void fl_list_add(fl_list_t *parent, fl_list_t *cur, int before) {
cur->parent = parent;
if(before >= 0)
ptr_array_insert_before(parent->sub, before, cur);
@@ -148,7 +148,7 @@ void fl_list_add(struct fl_list *parent, struct fl_list *cur, int before) {
// Sort the contents of a directory. Should be called after doing a (batch of)
// fl_list_add().
-void fl_list_sort(struct fl_list *fl) {
+void fl_list_sort(fl_list_t *fl) {
g_return_if_fail(!fl->isfile && fl->sub);
g_ptr_array_sort(fl->sub, fl_list_cmp_sort);
}
@@ -156,9 +156,9 @@ void fl_list_sort(struct fl_list *fl) {
// Removes an item from the file list, making sure to update the parents.
// This function assumes that the list has been properly sorted.
-void fl_list_remove(struct fl_list *fl) {
+void fl_list_remove(fl_list_t *fl) {
// update parents size
- struct fl_list *par = fl->parent;
+ fl_list_t *par = fl->parent;
while(par) {
par->size -= fl->size;
par = par->parent;
@@ -176,9 +176,9 @@ void fl_list_remove(struct fl_list *fl) {
}
-struct fl_list *fl_list_copy(const struct fl_list *fl) {
+fl_list_t *fl_list_copy(const fl_list_t *fl) {
int size = fl_list_size(fl->name, fl->islocal);
- struct fl_list *cur = g_slice_alloc(size);
+ fl_list_t *cur = g_slice_alloc(size);
memcpy(cur, fl, size);
cur->parent = NULL;
if(fl->sub) {
@@ -186,7 +186,7 @@ struct fl_list *fl_list_copy(const struct fl_list *fl) {
g_ptr_array_set_free_func(cur->sub, fl_list_free);
int i;
for(i=0; i<fl->sub->len; i++) {
- struct fl_list *tmp = fl_list_copy(g_ptr_array_index(fl->sub, i));
+ fl_list_t *tmp = fl_list_copy(g_ptr_array_index(fl->sub, i));
tmp->parent = cur;
g_ptr_array_add(cur->sub, tmp);
}
@@ -197,12 +197,12 @@ struct fl_list *fl_list_copy(const struct fl_list *fl) {
// Determines whether a directory is "empty", i.e. it has no subdirectories or
// hashed files.
-gboolean fl_list_isempty(struct fl_list *fl) {
+gboolean fl_list_isempty(fl_list_t *fl) {
g_return_val_if_fail(!fl->isfile, FALSE);
int i;
for(i=0; i<fl->sub->len; i++) {
- struct fl_list *f = g_ptr_array_index(fl->sub, i);
+ fl_list_t *f = g_ptr_array_index(fl->sub, i);
if(!f->isfile || f->hastth)
return FALSE;
}
@@ -211,8 +211,8 @@ gboolean fl_list_isempty(struct fl_list *fl) {
// Get a file by name in a directory. This search is case-insensitive.
-struct fl_list *fl_list_file(const struct fl_list *dir, const char *name) {
- struct fl_list *cmp = fl_list_create(name, FALSE);
+fl_list_t *fl_list_file(const fl_list_t *dir, const char *name) {
+ fl_list_t *cmp = fl_list_create(name, FALSE);
int i = ptr_array_search(dir->sub, cmp, fl_list_cmp);
fl_list_free(cmp);
return i < 0 ? NULL : g_ptr_array_index(dir->sub, i);
@@ -220,13 +220,13 @@ struct fl_list *fl_list_file(const struct fl_list *dir, const char *name) {
// Get a file name in a directory with the same name as *fl. This search is case-sensitive.
-struct fl_list *fl_list_file_strict(const struct fl_list *dir, const struct fl_list *fl) {
+fl_list_t *fl_list_file_strict(const fl_list_t *dir, const fl_list_t *fl) {
int i = ptr_array_search(dir->sub, fl, fl_list_cmp_strict);
return i < 0 ? NULL : g_ptr_array_index(dir->sub, i);
}
-gboolean fl_list_is_child(const struct fl_list *parent, const struct fl_list *child) {
+gboolean fl_list_is_child(const fl_list_t *parent, const fl_list_t *child) {
for(child=child->parent; child; child=child->parent)
if(child == parent)
return TRUE;
@@ -235,11 +235,11 @@ gboolean fl_list_is_child(const struct fl_list *parent, const struct fl_list *ch
// Get the virtual path to a file
-char *fl_list_path(struct fl_list *fl) {
+char *fl_list_path(fl_list_t *fl) {
if(!fl->parent)
return g_strdup("/");
char *tmp, *path = g_strdup(fl->name);
- struct fl_list *cur = fl->parent;
+ fl_list_t *cur = fl->parent;
while(cur->parent) {
tmp = path;
path = g_build_filename(cur->name, path, NULL);
@@ -257,7 +257,7 @@ char *fl_list_path(struct fl_list *fl) {
// support stuff like ./ and ../, and '/' is assumed to refer to the given
// root. (So '/dir' and 'dir' are simply equivalent)
// Case-insensitive, and '/' is the only recognised path separator
-struct fl_list *fl_list_from_path(struct fl_list *root, const char *path) {
+fl_list_t *fl_list_from_path(fl_list_t *root, const char *path) {
while(path[0] == '/')
path++;
if(!path[0])
@@ -265,7 +265,7 @@ struct fl_list *fl_list_from_path(struct fl_list *root, const char *path) {
g_return_val_if_fail(root->sub, NULL);
int slash = strcspn(path, "/");
char *name = g_strndup(path, slash);
- struct fl_list *n = fl_list_file(root, name);
+ fl_list_t *n = fl_list_file(root, name);
g_free(name);
if(!n)
return NULL;
@@ -278,8 +278,8 @@ struct fl_list *fl_list_from_path(struct fl_list *root, const char *path) {
// Auto-complete for fl_list_from_path()
-void fl_list_suggest(struct fl_list *root, char *opath, char **sug) {
- struct fl_list *parent = root;
+void fl_list_suggest(fl_list_t *root, char *opath, char **sug) {
+ fl_list_t *parent = root;
char *path = g_strdup(opath);
char *name = path;
char *sep = strrchr(path, '/');
@@ -296,7 +296,7 @@ void fl_list_suggest(struct fl_list *root, char *opath, char **sug) {
// Note: performance can be improved by using a binary search instead
int i;
for(i=0; i<parent->sub->len && n<20; i++) {
- struct fl_list *f = g_ptr_array_index(parent->sub, i);
+ fl_list_t *f = g_ptr_array_index(parent->sub, i);
if(strncmp(f->name, name, len) == 0)
sug[n++] = f->isfile ? g_strconcat(path, "/", f->name, NULL) : g_strconcat(path, "/", f->name, "/", NULL);
}
@@ -314,7 +314,7 @@ void fl_list_suggest(struct fl_list *root, char *opath, char **sug) {
#if INTERFACE
-struct fl_search {
+struct fl_search_t {
char sizem; // -2 any, -1 <=, 0 ==, 1 >=
char filedir; // 1 = file, 2 = dir, 3 = any
guint64 size;
@@ -391,7 +391,7 @@ static int fl_search_and_len(GRegex **l) {
// Only matches against fl->name itself, not the path to it (AND keywords
// matched in the path are assumed to be removed already)
-gboolean fl_search_match_name(struct fl_list *fl, struct fl_search *s) {
+gboolean fl_search_match_name(fl_list_t *fl, fl_search_t *s) {
GRegex **tmpr;
for(tmpr=s->and; tmpr&&*tmpr; tmpr++)
if(G_LIKELY(!g_regex_match(*tmpr, fl->name, 0, NULL)))
@@ -418,7 +418,7 @@ gboolean fl_search_match_name(struct fl_list *fl, struct fl_search *s) {
// Recursive depth-first search through the list, used for replying to non-TTH
// $Search and SCH requests. Not exactly fast, but what did you expect? :-(
-int fl_search_rec(struct fl_list *parent, struct fl_search *s, struct fl_list **res, int max) {
+int fl_search_rec(fl_list_t *parent, fl_search_t *s, fl_list_t **res, int max) {
if(!parent || !parent->sub)
return 0;
// weed out stuff from 'and' if it's already matched in parent (I'm assuming
@@ -435,7 +435,7 @@ int fl_search_rec(struct fl_list *parent, struct fl_search *s, struct fl_list **
// loop through the directory
int n = 0;
for(i=0; n<max && i<parent->sub->len; i++) {
- struct fl_list *f = g_ptr_array_index(parent->sub, i);
+ fl_list_t *f = g_ptr_array_index(parent->sub, i);
if(fl_search_match(f, s))
res[n++] = f;
if(!f->isfile && n < max)
@@ -447,12 +447,12 @@ int fl_search_rec(struct fl_list *parent, struct fl_search *s, struct fl_list **
// Similar to fl_search_match(), but also matches the name of the parents.
-gboolean fl_search_match_full(struct fl_list *fl, struct fl_search *s) {
+gboolean fl_search_match_full(fl_list_t *fl, fl_search_t *s) {
// weed out stuff from 'and' if it's already matched in any of its parents.
GRegex **oand = s->and;
int len = fl_search_and_len(s->and);
GRegex *nand[len];
- struct fl_list *p = fl->parent;
+ fl_list_t *p = fl->parent;
int i;
memcpy(nand, s->and, len*sizeof(GRegex *));
for(; p && p->parent; p=p->parent)
diff --git a/src/hub.c b/src/hub.c
index a21cd74..a3d9a1d 100644
--- a/src/hub.c
+++ b/src/hub.c
@@ -34,7 +34,7 @@
#if INTERFACE
-struct hub_user {
+struct hub_user_t {
gboolean hasinfo : 1;
gboolean isop : 1;
gboolean isjoined : 1; // managed by ui_hub_userchange()
@@ -50,7 +50,7 @@ struct hub_user {
unsigned int as; // auto-open slot if upload is below n bytes/s
guint32 ip4;
int sid; // for ADC
- struct hub *hub;
+ hub_t *hub;
char *name; // UTF-8
char *name_hub; // hub-encoded (NMDC)
char *desc;
@@ -65,11 +65,11 @@ struct hub_user {
}
-struct hub {
+struct hub_t {
gboolean adc : 16; // TRUE = ADC, FALSE = NMDC protocol.
gboolean tls : 16;
int state; // (ADC) ADC_S_*
- struct ui_tab *tab;
+ ui_tab_t *tab;
struct net *net;
// Hub info / config
@@ -132,19 +132,19 @@ GHashTable *hub_uids = NULL;
-// struct hub_user related functions
+// hub_user_t related functions
// cid is required for ADC. expected to be base32-encoded.
-static struct hub_user *user_add(struct hub *hub, const char *name, const char *cid) {
- struct hub_user *u = g_hash_table_lookup(hub->users, name);
+static hub_user_t *user_add(hub_t *hub, const char *name, const char *cid) {
+ hub_user_t *u = g_hash_table_lookup(hub->users, name);
if(u)
return u;
- struct tiger_ctx t;
+ tiger_ctx_t t;
char tmp[24];
tiger_init(&t);
tiger_update(&t, (char *)&(hub->id), 8);
- u = g_slice_new0(struct hub_user);
+ u = g_slice_new0(hub_user_t);
u->hub = hub;
if(hub->adc) {
u->name = g_strdup(name);
@@ -175,7 +175,7 @@ static struct hub_user *user_add(struct hub *hub, const char *name, const char *
static void user_free(gpointer dat) {
- struct hub_user *u = dat;
+ hub_user_t *u = dat;
// remove from hub_uids
g_hash_table_remove(hub_uids, &(u->uid));
// remove from hub->sessions
@@ -191,26 +191,26 @@ static void user_free(gpointer dat) {
g_free(u->conn);
g_free(u->mail);
g_free(u->client);
- g_slice_free(struct hub_user, u);
+ g_slice_free(hub_user_t, u);
}
// Get a user by a UTF-8 string. May fail for NMDC if the UTF-8 -> hub encoding
// is not really one-to-one.
-struct hub_user *hub_user_get(struct hub *hub, const char *name) {
+hub_user_t *hub_user_get(hub_t *hub, const char *name) {
if(hub->adc)
return g_hash_table_lookup(hub->users, name);
char *name_hub = charset_convert(hub, FALSE, name);
- struct hub_user *u = g_hash_table_lookup(hub->users, name_hub);
+ hub_user_t *u = g_hash_table_lookup(hub->users, name_hub);
g_free(name_hub);
return u;
}
// Auto-complete suggestions for hub_user_get()
-void hub_user_suggest(struct hub *hub, char *str, char **sug) {
+void hub_user_suggest(hub_t *hub, char *str, char **sug) {
GHashTableIter iter;
- struct hub_user *u;
+ hub_user_t *u;
int i=0, len = strlen(str);
g_hash_table_iter_init(&iter, hub->users);
while(i<20 && g_hash_table_iter_next(&iter, NULL, (gpointer *)&u))
@@ -229,7 +229,7 @@ void hub_user_suggest(struct hub *hub, char *str, char **sug) {
#endif
-char *hub_user_tag(struct hub_user *u) {
+char *hub_user_tag(hub_user_t *u) {
if(!u->client || !u->slots)
return NULL;
GString *t = g_string_new("");
@@ -249,7 +249,7 @@ char *hub_user_tag(struct hub_user *u) {
(str)[strlen(str)-1] = 0;\
} while(0)
-static void user_nmdc_nfo(struct hub *hub, struct hub_user *u, char *str) {
+static void user_nmdc_nfo(hub_t *hub, hub_user_t *u, char *str) {
// these all point into *str. *str is modified to contain zeroes in the correct positions
char *next, *tmp;
char *desc = NULL;
@@ -354,7 +354,7 @@ static void user_nmdc_nfo(struct hub *hub, struct hub_user *u, char *str) {
#define P(a,b) (((a)<<8) + (b))
-static void user_adc_nfo(struct hub *hub, struct hub_user *u, struct adc_cmd *cmd) {
+static void user_adc_nfo(hub_t *hub, hub_user_t *u, adc_cmd_t *cmd) {
u->hasinfo = TRUE;
// sid
if(!u->sid) {
@@ -449,10 +449,10 @@ static void user_adc_nfo(struct hub *hub, struct hub_user *u, struct adc_cmd *cm
// hub stuff
// Linear search at the moment, not too efficient.
-struct hub *hub_global_byid(guint64 id) {
+hub_t *hub_global_byid(guint64 id) {
GList *l;
for(l=ui_tabs; l; l=l->next) {
- struct ui_tab *t = l->data;
+ ui_tab_t *t = l->data;
if(t->type == UIT_HUB && t->hub->id == id)
return t->hub;
}
@@ -464,7 +464,7 @@ struct hub *hub_global_byid(guint64 id) {
void hub_global_nfochange() {
GList *n;
for(n=ui_tabs; n; n=n->next) {
- struct ui_tab *t = n->data;
+ ui_tab_t *t = n->data;
if(t->type == UIT_HUB && t->hub->nick_valid)
hub_send_nfo(t->hub);
}
@@ -472,13 +472,13 @@ void hub_global_nfochange() {
// Get the current active IP used for this hub. (If we're active)
-guint32 hub_ip4(struct hub *hub) {
+guint32 hub_ip4(hub_t *hub) {
guint32 conf = ip4_pack(var_get((hub)->id, VAR_active_ip));
return conf ? conf : hub->ip4;
}
-void hub_password(struct hub *hub, char *pass) {
+void hub_password(hub_t *hub, char *pass) {
g_return_if_fail(hub->adc ? hub->state == ADC_S_VERIFY : !hub->nick_valid);
if(!pass)
@@ -490,7 +490,7 @@ void hub_password(struct hub *hub, char *pass) {
} else if(hub->adc) {
char enc[40] = {};
char res[24];
- struct tiger_ctx t;
+ tiger_ctx_t t;
tiger_init(&t);
tiger_update(&t, pass, strlen(pass));
tiger_update(&t, hub->gpa_salt, hub->gpa_salt_len);
@@ -505,14 +505,14 @@ void hub_password(struct hub *hub, char *pass) {
}
-void hub_kick(struct hub *hub, struct hub_user *u) {
+void hub_kick(hub_t *hub, hub_user_t *u) {
g_return_if_fail(!hub->adc && hub->nick_valid && u);
net_writef(hub->net, "$Kick %s|", u->name_hub);
}
// Initiate a C-C connection with a user
-void hub_opencc(struct hub *hub, struct hub_user *u) {
+void hub_opencc(hub_t *hub, hub_user_t *u) {
char token[20];
if(hub->adc)
g_snprintf(token, 19, "%"G_GUINT32_FORMAT, g_random_int());
@@ -550,7 +550,7 @@ void hub_opencc(struct hub *hub, struct hub_user *u) {
// Send a search request
-void hub_search(struct hub *hub, struct search_q *q) {
+void hub_search(hub_t *hub, search_q_t *q) {
// ADC
if(hub->adc) {
// TODO: use FSCH to only get results from active users when we are passive?
@@ -617,7 +617,7 @@ void hub_search(struct hub *hub, struct search_q *q) {
#define eq(a) (a == hub->nfo_##a)
#define beq(a) (!!a == !!hub->nfo_##a)
-void hub_send_nfo(struct hub *hub) {
+void hub_send_nfo(hub_t *hub) {
if(hub->net->state != NETST_ASY)
return;
@@ -642,7 +642,7 @@ void hub_send_nfo(struct hub *hub) {
h_norm = h_reg = h_op = 0;
GList *n;
for(n=ui_tabs; n; n=n->next) {
- struct ui_tab *t = n->data;
+ ui_tab_t *t = n->data;
if(t->type != UIT_HUB || !t->hub->nick_valid)
continue;
if(t->hub->isop)
@@ -757,7 +757,7 @@ void hub_send_nfo(struct hub *hub) {
#undef streq
-void hub_say(struct hub *hub, const char *str, gboolean me) {
+void hub_say(hub_t *hub, const char *str, gboolean me) {
if(!hub->nick_valid)
return;
if(hub->adc) {
@@ -776,7 +776,7 @@ void hub_say(struct hub *hub, const char *str, gboolean me) {
}
-void hub_msg(struct hub *hub, struct hub_user *user, const char *str, gboolean me, int dest) {
+void hub_msg(hub_t *hub, hub_user_t *user, const char *str, gboolean me, int dest) {
if(hub->adc) {
GString *c = adc_generate('E', ADCC_MSG, hub->sid, dest ? dest : user->sid);
adc_append(c, NULL, str);
@@ -802,7 +802,7 @@ void hub_msg(struct hub *hub, struct hub_user *user, const char *str, gboolean m
// Call this when the hub tells us our IP.
-static void setownip(struct hub *hub, guint32 ip) {
+static void setownip(hub_t *hub, guint32 ip) {
if(ip != hub->ip4) {
guint32 old = hub_ip4(hub);
hub->ip4 = ip;
@@ -815,7 +815,7 @@ static void setownip(struct hub *hub, guint32 ip) {
}
-static void adc_sch_reply_send(struct hub *hub, const char *dest, GString *r, gboolean udp, const char *key) {
+static void adc_sch_reply_send(hub_t *hub, const char *dest, GString *r, gboolean udp, const char *key) {
if(!udp) {
net_writestr(hub->net, r->str);
return;
@@ -858,7 +858,7 @@ static void adc_sch_reply_send(struct hub *hub, const char *dest, GString *r, gb
}
-static void adc_sch_reply(struct hub *hub, struct adc_cmd *cmd, struct hub_user *u, struct fl_list **res, int len) {
+static void adc_sch_reply(hub_t *hub, adc_cmd_t *cmd, hub_user_t *u, fl_list_t **res, int len) {
#if SUDP_SUPPORT
char *ky = adc_getparam(cmd->argv, "KY", NULL); // SUDP key
#else
@@ -909,7 +909,7 @@ static void adc_sch_reply(struct hub *hub, struct adc_cmd *cmd, struct hub_user
}
-static void adc_sch(struct hub *hub, struct adc_cmd *cmd) {
+static void adc_sch(hub_t *hub, adc_cmd_t *cmd) {
char *an = adc_getparam(cmd->argv, "AN", NULL); // and
char *no = adc_getparam(cmd->argv, "NO", NULL); // not
char *ex = adc_getparam(cmd->argv, "EX", NULL); // ext
@@ -929,7 +929,7 @@ static void adc_sch(struct hub *hub, struct adc_cmd *cmd) {
return;
// Actually matching the tree depth is rather resouce-intensive, since we
- // don't store it in struct fl_list. Instead, just assume fl_hash_keep_level
+ // don't store it in fl_list_t. Instead, just assume fl_hash_keep_level
// for everything. This may be wrong, but if it is, it's most likely to be a
// pessimistic estimate, which happens in the case TTH data is converted from
// a DC++ client to ncdc.
@@ -939,12 +939,12 @@ static void adc_sch(struct hub *hub, struct adc_cmd *cmd) {
if(tr && !istth(tr))
return;
- struct hub_user *u = g_hash_table_lookup(hub->sessions, GINT_TO_POINTER(cmd->source));
+ hub_user_t *u = g_hash_table_lookup(hub->sessions, GINT_TO_POINTER(cmd->source));
if(!u)
return;
// create search struct
- struct fl_search s = {};
+ fl_search_t s = {};
s.sizem = eq ? 0 : le ? -1 : ge ? 1 : -2;
s.size = s.sizem == -2 ? 0 : g_ascii_strtoull(eq ? eq : le ? le : ge, NULL, 10);
s.filedir = !ty ? 3 : ty[0] == '1' ? 1 : 2;
@@ -958,7 +958,7 @@ static void adc_sch(struct hub *hub, struct adc_cmd *cmd) {
int i = 0;
int max = u->hasudp4 ? 10 : 5;
- struct fl_list *res[max];
+ fl_list_t *res[max];
// TTH lookup
if(tr) {
@@ -967,7 +967,7 @@ static void adc_sch(struct hub *hub, struct adc_cmd *cmd) {
GSList *l = fl_local_from_tth(root);
// it still has to match the other requirements...
for(; i<max && l; l=l->next) {
- struct fl_list *c = l->data;
+ fl_list_t *c = l->data;
if(fl_search_match_full(c, &s))
res[i++] = c;
}
@@ -992,10 +992,10 @@ static void adc_sch(struct hub *hub, struct adc_cmd *cmd) {
#define is_valid_proto(p) (is_adc_proto(p) || is_adcs_proto(p))
static void adc_handle(struct net *net, char *msg, int _len) {
- struct hub *hub = net->handle;
+ hub_t *hub = net->handle;
net_readmsg(net, '\n', adc_handle);
- struct adc_cmd cmd;
+ adc_cmd_t cmd;
GError *err = NULL;
if(!msg[0])
@@ -1047,7 +1047,7 @@ static void adc_handle(struct net *net, char *msg, int _len) {
}
// inf from user
} else if(cmd.type == 'B') {
- struct hub_user *u = g_hash_table_lookup(hub->sessions, GINT_TO_POINTER(cmd.source));
+ hub_user_t *u = g_hash_table_lookup(hub->sessions, GINT_TO_POINTER(cmd.source));
if(!u) {
char *nick = adc_getparam(cmd.argv, "NI", NULL);
char *cid = adc_getparam(cmd.argv, "ID", NULL);
@@ -1086,7 +1086,7 @@ static void adc_handle(struct net *net, char *msg, int _len) {
g_message("Invalid message from %s: %s", net_remoteaddr(hub->net), msg);
else {
int sid = ADC_DFCC(cmd.argv[0]);
- struct hub_user *u = g_hash_table_lookup(hub->sessions, GINT_TO_POINTER(sid));
+ hub_user_t *u = g_hash_table_lookup(hub->sessions, GINT_TO_POINTER(sid));
if(sid == hub->sid) {
char *rd = adc_getparam(cmd.argv, "RD", NULL);
char *ms = adc_getparam(cmd.argv, "MS", NULL);
@@ -1137,7 +1137,7 @@ static void adc_handle(struct net *net, char *msg, int _len) {
net_writestr(hub->net, r->str);
g_string_free(r, TRUE);
} else {
- struct hub_user *u = g_hash_table_lookup(hub->sessions, GINT_TO_POINTER(cmd.source));
+ hub_user_t *u = g_hash_table_lookup(hub->sessions, GINT_TO_POINTER(cmd.source));
int port = strtol(cmd.argv[1], NULL, 0);
if(!u)
g_message("CTM from user who is not on the hub (%s): %s", net_remoteaddr(hub->net), msg);
@@ -1174,7 +1174,7 @@ static void adc_handle(struct net *net, char *msg, int _len) {
net_writestr(hub->net, r->str);
g_string_free(r, TRUE);
} else {
- struct hub_user *u = g_hash_table_lookup(hub->sessions, GINT_TO_POINTER(cmd.source));
+ hub_user_t *u = g_hash_table_lookup(hub->sessions, GINT_TO_POINTER(cmd.source));
if(!u)
g_message("RCM from user who is not on the hub (%s): %s", net_remoteaddr(hub->net), msg);
else {
@@ -1197,8 +1197,8 @@ static void adc_handle(struct net *net, char *msg, int _len) {
else {
char *pm = adc_getparam(cmd.argv+1, "PM", NULL);
gboolean me = adc_getparam(cmd.argv+1, "ME", NULL) != NULL;
- struct hub_user *u = cmd.type != 'I' ? g_hash_table_lookup(hub->sessions, GINT_TO_POINTER(cmd.source)) : NULL;
- struct hub_user *d = (cmd.type == 'E' || cmd.type == 'D') && cmd.source == hub->sid
+ hub_user_t *u = cmd.type != 'I' ? g_hash_table_lookup(hub->sessions, GINT_TO_POINTER(cmd.source)) : NULL;
+ hub_user_t *d = (cmd.type == 'E' || cmd.type == 'D') && cmd.source == hub->sid
? g_hash_table_lookup(hub->sessions, GINT_TO_POINTER(cmd.dest)) : NULL;
if(cmd.type != 'I' && !u && !d)
g_message("Message from someone not on this hub. (%s: %s)", net_remoteaddr(hub->net), msg);
@@ -1253,10 +1253,10 @@ static void adc_handle(struct net *net, char *msg, int _len) {
#undef is_valid_proto
-static void nmdc_search(struct hub *hub, char *from, int size_m, guint64 size, int type, char *query) {
+static void nmdc_search(hub_t *hub, char *from, int size_m, guint64 size, int type, char *query) {
int max = from[0] == 'H' ? 5 : 10;
- struct fl_list *res[max];
- struct fl_search s = {};
+ fl_list_t *res[max];
+ fl_search_t s = {};
s.filedir = type == 1 ? 3 : type == 8 ? 2 : 1;
s.ext = search_types[type].exts;
s.size = size;
@@ -1274,7 +1274,7 @@ static void nmdc_search(struct hub *hub, char *from, int size_m, guint64 size, i
GSList *l = fl_local_from_tth(root);
// it still has to match the other requirements...
for(; i<max && l; l=l->next) {
- struct fl_list *c = l->data;
+ fl_list_t *c = l->data;
if(fl_search_match_full(c, &s))
res[i++] = c;
}
@@ -1334,7 +1334,7 @@ static void nmdc_search(struct hub *hub, char *from, int size_m, guint64 size, i
static void nmdc_handle(struct net *net, char *cmd, int _len) {
- struct hub *hub = net->handle;
+ hub_t *hub = net->handle;
// Immediately queue next read. It will be cancelled when net_disconnect() is
// called anyway.
net_readmsg(net, '|', nmdc_handle);
@@ -1408,7 +1408,7 @@ static void nmdc_handle(struct net *net, char *cmd, int _len) {
dl_user_join(0);
}
} else {
- struct hub_user *u = user_add(hub, nick, NULL);
+ hub_user_t *u = user_add(hub, nick, NULL);
if(!u->hasinfo && !hub->supports_nogetinfo)
net_writef(hub->net, "$GetINFO %s|", nick);
}
@@ -1419,7 +1419,7 @@ static void nmdc_handle(struct net *net, char *cmd, int _len) {
// $Quit
if(g_regex_match(quit, cmd, 0, &nfo)) { // 1 = nick
char *nick = g_match_info_fetch(nfo, 1);
- struct hub_user *u = g_hash_table_lookup(hub->users, nick);
+ hub_user_t *u = g_hash_table_lookup(hub->users, nick);
if(u) {
ui_hub_userchange(hub->tab, UIHUB_UC_QUIT, u);
if(u->hasinfo) {
@@ -1440,7 +1440,7 @@ static void nmdc_handle(struct net *net, char *cmd, int _len) {
g_free(str);
char **cur;
for(cur=list; *cur&&**cur; cur++) {
- struct hub_user *u = user_add(hub, *cur, NULL);
+ hub_user_t *u = user_add(hub, *cur, NULL);
if(!u->hasinfo && !hub->supports_nogetinfo)
net_writef(hub->net, "$GetINFO %s %s|", *cur, hub->nick_hub);
}
@@ -1461,7 +1461,7 @@ static void nmdc_handle(struct net *net, char *cmd, int _len) {
// inefficient and not all that important at this point.
hub->isop = FALSE;
for(cur=list; *cur&&**cur; cur++) {
- struct hub_user *u = user_add(hub, *cur, NULL);
+ hub_user_t *u = user_add(hub, *cur, NULL);
if(!u->isop) {
u->isop = TRUE;
ui_hub_userchange(hub->tab, UIHUB_UC_NFO, u);
@@ -1486,7 +1486,7 @@ static void nmdc_handle(struct net *net, char *cmd, int _len) {
if(!sep)
continue;
*sep = 0;
- struct hub_user *u = user_add(hub, *cur, NULL);
+ hub_user_t *u = user_add(hub, *cur, NULL);
guint32 new = ip4_pack(sep+1);
if(new != u->ip4) {
u->ip4 = new;
@@ -1504,7 +1504,7 @@ static void nmdc_handle(struct net *net, char *cmd, int _len) {
if(g_regex_match(myinfo, cmd, 0, &nfo)) { // 1 = nick, 2 = info string
char *nick = g_match_info_fetch(nfo, 1);
char *str = g_match_info_fetch(nfo, 2);
- struct hub_user *u = user_add(hub, nick, NULL);
+ hub_user_t *u = user_add(hub, nick, NULL);
if(!u->hasinfo)
hub->sharecount++;
else
@@ -1535,7 +1535,7 @@ static void nmdc_handle(struct net *net, char *cmd, int _len) {
char *to = g_match_info_fetch(nfo, 1);
char *from = g_match_info_fetch(nfo, 2);
char *msg = g_match_info_fetch(nfo, 3);
- struct hub_user *u = g_hash_table_lookup(hub->users, from);
+ hub_user_t *u = g_hash_table_lookup(hub->users, from);
if(!u)
g_message("[hub: %s] Got a $To from `%s', who is not on this hub!", hub->tab->name, from);
else {
@@ -1579,7 +1579,7 @@ static void nmdc_handle(struct net *net, char *cmd, int _len) {
if(g_regex_match(revconnecttome, cmd, 0, &nfo)) { // 1 = other, 2 = me
char *other = g_match_info_fetch(nfo, 1);
char *me = g_match_info_fetch(nfo, 2);
- struct hub_user *u = g_hash_table_lookup(hub->users, other);
+ hub_user_t *u = g_hash_table_lookup(hub->users, other);
if(strcmp(me, hub->nick_hub) != 0)
g_message("Received a $RevConnectToMe for someone else (to %s from %s)", me, other);
else if(!u)
@@ -1668,7 +1668,7 @@ static void nmdc_handle(struct net *net, char *cmd, int _len) {
static gboolean check_nfo(gpointer data) {
- struct hub *hub = data;
+ hub_t *hub = data;
if(hub->nick_valid)
hub_send_nfo(hub);
return TRUE;
@@ -1677,13 +1677,13 @@ static gboolean check_nfo(gpointer data) {
static gboolean reconnect_timer(gpointer dat) {
hub_connect(dat);
- ((struct hub *)dat)->reconnect_timer = 0;
+ ((hub_t *)dat)->reconnect_timer = 0;
return FALSE;
}
static gboolean joincomplete_timer(gpointer dat) {
- struct hub *hub = dat;
+ hub_t *hub = dat;
hub->joincomplete = TRUE;
hub->joincomplete_timer = 0;
return FALSE;
@@ -1691,7 +1691,7 @@ static gboolean joincomplete_timer(gpointer dat) {
static void handle_error(struct net *n, int action, const char *err) {
- struct hub *hub = n->handle;
+ hub_t *hub = n->handle;
ui_mf(hub->tab, 0, "%s: %s",
action == NETERR_CONN ? "Could not connect to hub" :
@@ -1701,8 +1701,8 @@ static void handle_error(struct net *n, int action, const char *err) {
}
-struct hub *hub_create(struct ui_tab *tab) {
- struct hub *hub = g_new0(struct hub, 1);
+hub_t *hub_create(ui_tab_t *tab) {
+ hub_t *hub = g_new0(hub_t, 1);
// Get or create the hub id
hub->id = db_vars_hubid(tab->name);
@@ -1722,7 +1722,7 @@ struct hub *hub_create(struct ui_tab *tab) {
static void handle_handshake(struct net *n, const char *kpr) {
g_return_if_fail(kpr != NULL);
- struct hub *hub = n->handle;
+ hub_t *hub = n->handle;
g_return_if_fail(!hub->kp);
char kpf[53] = {};
@@ -1759,7 +1759,7 @@ static void handle_handshake(struct net *n, const char *kpr) {
static void handle_connect(struct net *n, const char *addr) {
- struct hub *hub = n->handle;
+ hub_t *hub = n->handle;
if(addr) {
ui_mf(hub->tab, 0, "Trying %s...", addr);
return;
@@ -1785,7 +1785,7 @@ static void handle_connect(struct net *n, const char *addr) {
}
-void hub_connect(struct hub *hub) {
+void hub_connect(hub_t *hub) {
char *oaddr = var_get(hub->id, VAR_hubaddr);
char *addr = oaddr;
g_return_if_fail(addr);
@@ -1828,7 +1828,7 @@ void hub_connect(struct hub *hub) {
}
-void hub_disconnect(struct hub *hub, gboolean recon) {
+void hub_disconnect(hub_t *hub, gboolean recon) {
if(hub->reconnect_timer) {
g_source_remove(hub->reconnect_timer);
hub->reconnect_timer = 0;
@@ -1866,7 +1866,7 @@ void hub_disconnect(struct hub *hub, gboolean recon) {
}
-void hub_free(struct hub *hub) {
+void hub_free(hub_t *hub) {
// Make sure to disconnect before calling cc_remove_hub(). dl_queue_expect(),
// called from cc_remove_hub() will look in the global userlist for
// alternative hubs. Users of this hub must not be present in the list,
diff --git a/src/listen.c b/src/listen.c
index 8cbb409..f94468d 100644
--- a/src/listen.c
+++ b/src/listen.c
@@ -44,7 +44,7 @@
#define LBT_STR(x) ((x) == LBT_TCP ? "TCP" : (x) == LBT_UDP ? "UDP" : (x) == LBT_TLS ? "TLS" : "TLS+TCP")
// port + ip4 are "cached" for convenience.
-struct listen_bind {
+struct listen_bind_t {
guint16 type; // LBT_*
guint16 port;
guint32 ip4;
@@ -54,9 +54,9 @@ struct listen_bind {
};
-struct listen_hub_bind {
+struct listen_hub_bind_t {
guint64 hubid;
- struct listen_bind *tcp, *udp, *tls;
+ listen_bind_t *tcp, *udp, *tls;
};
#endif
@@ -80,23 +80,23 @@ static guint16 random_tcp_port, random_udp_port;
// Public interface to fetch current listen configuration
gboolean listen_hub_active(guint64 hub) {
- struct listen_hub_bind *b = g_hash_table_lookup(listen_hub_binds, &hub);
+ listen_hub_bind_t *b = g_hash_table_lookup(listen_hub_binds, &hub);
return b && b->tcp;
}
// These all returns 0 if passive or disabled
guint16 listen_hub_tcp(guint64 hub) {
- struct listen_hub_bind *b = g_hash_table_lookup(listen_hub_binds, &hub);
+ listen_hub_bind_t *b = g_hash_table_lookup(listen_hub_binds, &hub);
return b && b->tcp ? b->tcp->port : 0;
}
guint16 listen_hub_tls(guint64 hub) {
- struct listen_hub_bind *b = g_hash_table_lookup(listen_hub_binds, &hub);
+ listen_hub_bind_t *b = g_hash_table_lookup(listen_hub_binds, &hub);
return b && b->tls ? b->tls->port : b && b->tcp && (b->tcp->type & LBT_TLS) ? b->tcp->port : 0;
}
guint16 listen_hub_udp(guint64 hub) {
- struct listen_hub_bind *b = g_hash_table_lookup(listen_hub_binds, &hub);
+ listen_hub_bind_t *b = g_hash_table_lookup(listen_hub_binds, &hub);
return b && b->udp ? b->udp->port : 0;
}
@@ -116,7 +116,7 @@ static void listen_stop() {
GList *n, *b = listen_binds;
while(b) {
n = b->next;
- struct listen_bind *lb = b->data;
+ listen_bind_t *lb = b->data;
if(lb->src)
g_source_remove(lb->src);
if(lb->sock)
@@ -131,7 +131,7 @@ static void listen_stop() {
static gboolean listen_tcp_handle(gpointer dat) {
- struct listen_bind *b = dat;
+ listen_bind_t *b = dat;
struct sockaddr_in a = {};
socklen_t len = sizeof(a);
int c = accept(b->sock, (struct sockaddr *)&a, &len);
@@ -158,7 +158,7 @@ static gboolean listen_tcp_handle(gpointer dat) {
static gboolean listen_udp_handle(gpointer dat) {
static char buf[5000]; // can be static, this function is only called in the main thread.
- struct listen_bind *b = dat;
+ listen_bind_t *b = dat;
struct sockaddr_in a = {};
socklen_t len = sizeof(a);
@@ -208,14 +208,14 @@ static gboolean listen_udp_handle(gpointer dat) {
#define lbt_canmerge(t1, t2) (t1 == t2 || !(t1 & (LBT_TLS|LBT_TCP)) == !(t2 & (LBT_TLS|LBT_TCP)))
-static void bind_add(struct listen_hub_bind *b, int type, guint32 ip, guint16 port) {
+static void bind_add(listen_hub_bind_t *b, int type, guint32 ip, guint16 port) {
if(!port)
port = type == LBT_UDP ? random_udp_port : random_tcp_port;
g_debug("Listen: Adding %s %s:%d", LBT_STR(type), ip4_unpack(ip), port);
// First: look if we can re-use an existing bind and look for any unresolvable conflicts.
GList *c;
for(c=listen_binds; c; c=c->next) {
- struct listen_bind *i = c->data;
+ listen_bind_t *i = c->data;
// Same? Just re-use.
if(lbt_canmerge(type, i->type) && (i->ip4 == ip || !i->ip4) && i->port == port) {
g_debug("Listen: Re-using!");
@@ -226,7 +226,7 @@ static void bind_add(struct listen_hub_bind *b, int type, guint32 ip, guint16 po
}
// Create and add bind item
- struct listen_bind *lb = g_new0(struct listen_bind, 1);
+ listen_bind_t *lb = g_new0(listen_bind_t, 1);
lb->type = type;
lb->ip4 = ip;
lb->port = port;
@@ -236,7 +236,7 @@ static void bind_add(struct listen_hub_bind *b, int type, guint32 ip, guint16 po
GList *n;
for(c=listen_binds; !lb->ip4&&c; c=n) {
n = c->next;
- struct listen_bind *i = c->data;
+ listen_bind_t *i = c->data;
if(i->port != lb->port || !lbt_canmerge(i->type, lb->type))
continue;
g_debug("Listen: Merging!");
@@ -244,7 +244,7 @@ static void bind_add(struct listen_hub_bind *b, int type, guint32 ip, guint16 po
// Move over all hubs to *lb
GSList *in;
for(in=i->hubs; in; in=in->next)
- bind_hub_add(lb, (struct listen_hub_bind *)in->data);
+ bind_hub_add(lb, (listen_hub_bind_t *)in->data);
g_slist_free(i->hubs);
// And remove this bind
g_free(i);
@@ -255,7 +255,7 @@ static void bind_add(struct listen_hub_bind *b, int type, guint32 ip, guint16 po
}
-static void bind_create(struct listen_bind *b) {
+static void bind_create(listen_bind_t *b) {
g_debug("Listen: binding %s %s:%d", LBT_STR(b->type), ip4_unpack(b->ip4), b->port);
int err = 0;
@@ -309,12 +309,12 @@ void listen_refresh() {
// Walk through ui_tabs to get a list of hubs and their config
GList *l;
for(l=ui_tabs; l; l=l->next) {
- struct ui_tab *t = l->data;
+ ui_tab_t *t = l->data;
// We only look at hubs on which we are active
if(t->type != UIT_HUB || !hub_ip4(t->hub) || !var_get_bool(t->hub->id, VAR_active))
continue;
// Add to listen_hub_binds
- struct listen_hub_bind *b = g_new0(struct listen_hub_bind, 1);
+ listen_hub_bind_t *b = g_new0(listen_hub_bind_t, 1);
b->hubid = t->hub->id;
g_hash_table_insert(listen_hub_binds, &b->hubid, b);
// And add the required binds for this hub (Due to the conflict resolution in binds_add(), this is O(n^2))
@@ -335,6 +335,6 @@ void listen_refresh() {
// Now walk through *listen_binds and actually create the listen sockets
for(l=listen_binds; l; listen_binds ? (l=l->next) : (l=NULL))
- bind_create((struct listen_bind *)l->data);
+ bind_create((listen_bind_t *)l->data);
}
diff --git a/src/main.c b/src/main.c
index 6209293..17638e7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -61,7 +61,7 @@ GMainLoop *main_loop;
#define ctrl_to_ascii(x) ((x) == 127 ? '?' : g_ascii_tolower((x)+64))
static void handle_input() {
- /* Mapping from get_wch() to struct input_key:
+ /* Mapping from get_wch() to input_key_t:
* KEY_CODE_YES -> KEY(code)
* KEY_CODE_NO:
* char == 127 -> KEY(KEY_BACKSPACE)
diff --git a/src/net.c b/src/net.c
index a420ce3..f93a33f 100644
--- a/src/net.c
+++ b/src/net.c
@@ -45,7 +45,7 @@
// global network stats
-struct ratecalc net_in, net_out;
+ratecalc_t net_in, net_out;
#define NET_RECV_SIZE ( 8*1024)
#define NET_MAX_RBUF (1024*1024)
@@ -74,8 +74,8 @@ struct synfer;
struct net {
int state;
- struct ratecalc *rate_in;
- struct ratecalc *rate_out;
+ ratecalc_t *rate_in;
+ ratecalc_t *rate_out;
struct dnscon *dnscon; // state DNS,CON. Setting ->net to NULL 'cancels' DNS resolving.
int sock; // state CON,ASY,SYN,DIS
@@ -368,7 +368,7 @@ static int syn_wait(struct synfer *s, int sock, gboolean write) {
#ifdef HAVE_SENDFILE
-static void syn_upload_sendfile(struct synfer *s, int sock, struct fadv *adv) {
+static void syn_upload_sendfile(struct synfer *s, int sock, fadv_t *adv) {
off_t off = lseek(s->fd, 0, SEEK_CUR);
if(off == (off_t)-1) {
s->err = g_strdup(g_strerror(errno));
@@ -425,7 +425,7 @@ static void syn_upload_sendfile(struct synfer *s, int sock, struct fadv *adv) {
#endif
-static void syn_upload_buf(struct synfer *s, int sock, struct fadv *adv) {
+static void syn_upload_buf(struct synfer *s, int sock, fadv_t *adv) {
char *buf = g_malloc(NET_TRANS_BUF);
while(s->left > 0 && !s->err && !s->cancel) {
@@ -512,7 +512,7 @@ static void syn_thread(gpointer dat, gpointer udat) {
g_static_mutex_unlock(&s->lock);
if(sock && !s->cancel && s->upl) {
- struct fadv adv;
+ fadv_t adv;
if(s->flush)
fadv_init(&adv, s->fd, lseek(s->fd, 0, SEEK_CUR), VAR_FFC_UPLOAD);
@@ -1226,8 +1226,8 @@ struct net *net_new(void *handle, void(*err)(struct net *, int, const char *)) {
n->ref = 1;
n->handle = handle;
n->cb_err = err;
- n->rate_in = g_slice_new0(struct ratecalc);
- n->rate_out = g_slice_new0(struct ratecalc);
+ n->rate_in = g_slice_new0(ratecalc_t);
+ n->rate_out = g_slice_new0(ratecalc_t);
ratecalc_init(n->rate_in);
ratecalc_init(n->rate_out);
time(&n->timeout_last);
@@ -1346,8 +1346,8 @@ void net_unref(struct net *n) {
if(!g_atomic_int_dec_and_test(&n->ref))
return;
g_return_if_fail(n->state == NETST_IDL);
- g_slice_free(struct ratecalc, n->rate_in);
- g_slice_free(struct ratecalc, n->rate_out);
+ g_slice_free(ratecalc_t, n->rate_in);
+ g_slice_free(ratecalc_t, n->rate_out);
g_free(n);
}
diff --git a/src/proto.c b/src/proto.c
index 9278df4..646e278 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -31,14 +31,14 @@
// NMDC support
-char *charset_convert(struct hub *hub, gboolean to_utf8, const char *str) {
+char *charset_convert(hub_t *hub, gboolean to_utf8, const char *str) {
char *fmt = var_get(hub->id, VAR_encoding);
char *res = str_convert(to_utf8?"UTF-8":fmt, !to_utf8?"UTF-8":fmt, str);
return res;
}
-char *nmdc_encode_and_escape(struct hub *hub, const char *str) {
+char *nmdc_encode_and_escape(hub_t *hub, const char *str) {
char *enc = charset_convert(hub, FALSE, str);
GString *dest = g_string_sized_new(strlen(enc));
char *tmp = enc;
@@ -58,7 +58,7 @@ char *nmdc_encode_and_escape(struct hub *hub, const char *str) {
}
-char *nmdc_unescape_and_decode(struct hub *hub, const char *str) {
+char *nmdc_unescape_and_decode(hub_t *hub, const char *str) {
GString *dest = g_string_sized_new(strlen(str));
while(*str) {
if(strncmp(str, "&#36;", 5) == 0) {
@@ -195,7 +195,7 @@ enum adc_cmd_type {
};
-struct adc_cmd {
+struct adc_cmd_t {
char type; // B|C|D|E|F|H|I|U
adc_cmd_type cmd; // ADCC_*, but can also be something else. Unhandled commands should be ignored anyway.
int source; // Only when type = B|D|E|F
@@ -223,7 +223,7 @@ static gboolean int_in_array(const int *arr, int needle) {
}
-gboolean adc_parse(const char *str, struct adc_cmd *c, int *feats, GError **err) {
+gboolean adc_parse(const char *str, adc_cmd_t *c, int *feats, GError **err) {
if(!g_utf8_validate(str, -1, NULL)) {
g_set_error_literal(err, 1, 0, "Invalid encoding.");
return FALSE;
diff --git a/src/search.c b/src/search.c
index 30bd24d..98c84ba 100644
--- a/src/search.c
+++ b/src/search.c
@@ -37,9 +37,9 @@
// Callback function, to be called when a search result has been received on an
// active search_q.
-typedef void (*search_cb)(struct search_r *r, void *dat);
+typedef void (*search_cb)(search_r_t *r, void *dat);
-struct search_q {
+struct search_q_t {
char type; // NMDC search type (if 9, ignore all fields except tth)
gboolean ge; // TRUE -> match >= size; FALSE -> match <= size
guint64 size; // 0 = disabled.
@@ -55,7 +55,7 @@ struct search_q {
};
// Represents a search result, coming from either NMDC $SR or ADC RES.
-struct search_r {
+struct search_r_t {
guint64 uid;
char *file; // full path + filename. Slashes as path saparator, no trailing slash
guint64 size; // file size, G_MAXUINT64 = directory
@@ -63,7 +63,7 @@ struct search_r {
char tth[24]; // TTH root (for regular files)
}
-struct search_type {
+struct search_type_t {
char *name;
char *exts[25];
};
@@ -77,7 +77,7 @@ static GHashTable *search_list = NULL;
// NMDC search types and the relevant ADC SEGA extensions.
-struct search_type search_types[] = { {},
+search_type_t search_types[] = { {},
{ "any" }, // 1
{ "audio", { "ape", "flac", "m4a", "mid", "mp3", "mpc", "ogg", "ra", "wav", "wma" } },
{ "archive", { "7z", "ace", "arj", "bz2", "gz", "lha", "lzh", "rar", "tar", "tz", "z", "zip" } },
@@ -90,18 +90,18 @@ struct search_type search_types[] = { {},
};
-void search_q_free(struct search_q *q) {
+void search_q_free(search_q_t *q) {
if(!q)
return;
if(q->query)
g_strfreev(q->query);
- g_slice_free(struct search_q, q);
+ g_slice_free(search_q_t, q);
}
// Convenience function to create a search_q for a TTH search.
-struct search_q * search_q_new_tth(const char *tth) {
- struct search_q *q = g_slice_new0(struct search_q);
+search_q_t * search_q_new_tth(const char *tth) {
+ search_q_t *q = g_slice_new0(search_q_t);
memcpy(q->tth, tth, 24);
q->type = 9;
return q;
@@ -110,23 +110,23 @@ struct search_q * search_q_new_tth(const char *tth) {
// Can be used as a GDestroyNotify callback
void search_r_free(gpointer data) {
- struct search_r *r = data;
+ search_r_t *r = data;
if(!r)
return;
g_free(r->file);
- g_slice_free(struct search_r, r);
+ g_slice_free(search_r_t, r);
}
-struct search_r *search_r_copy(struct search_r *r) {
- struct search_r *res = g_slice_dup(struct search_r, r);
+search_r_t *search_r_copy(search_r_t *r) {
+ search_r_t *res = g_slice_dup(search_r_t, r);
res->file = g_strdup(r->file);
return res;
}
// Generate the required /search command for a query.
-char *search_command(struct search_q *q, gboolean onhub) {
+char *search_command(search_q_t *q, gboolean onhub) {
GString *str = g_string_new("/search");
g_string_append(str, onhub ? " -hub" : " -all");
if(q->type == 9) {
@@ -169,7 +169,7 @@ char *search_command(struct search_q *q, gboolean onhub) {
// search list and must be freed/removed with search_remove() when there's no
// interest in results anymore.
// q->cb() will be called for each result that arrives, until search_remove().
-gboolean search_add(struct hub *hub, struct search_q *q, GError **err) {
+gboolean search_add(hub_t *hub, search_q_t *q, GError **err) {
if((!q->query || !*q->query) && q->type != 9) {
g_set_error(err, 1, 0, "No search query given.");
search_q_free(q);
@@ -197,7 +197,7 @@ gboolean search_add(struct hub *hub, struct search_q *q, GError **err) {
GList *n;
gboolean one = FALSE;
for(n=ui_tabs; n; n=n->next) {
- struct ui_tab *t = n->data;
+ ui_tab_t *t = n->data;
if(t->type == UIT_HUB && t->hub->nick_valid && !var_get_bool(t->hub->id, VAR_chat_only)) {
hub_search(t->hub, q);
one = TRUE;
@@ -219,14 +219,14 @@ gboolean search_add(struct hub *hub, struct search_q *q, GError **err) {
// Remove a query from the active searches.
-void search_remove(struct search_q *q) {
+void search_remove(search_q_t *q) {
if(search_list && g_hash_table_remove(search_list, q))
search_q_free(q);
}
// Match a search result with a query.
-static gboolean match(struct search_q *q, struct search_r *r) {
+static gboolean match(search_q_t *q, search_r_t *r) {
// TTH match is fast and easy
if(q->type == 9)
return r->size == G_MAXUINT64 ? FALSE : memcmp(q->tth, r->tth, 24) == 0 ? TRUE : FALSE;
@@ -263,12 +263,12 @@ static gboolean match(struct search_q *q, struct search_r *r) {
// Match the search result against any active searches and runs the q->cb
// callbacks.
-static void dispatch(struct search_r *r) {
+static void dispatch(search_r_t *r) {
if(!search_list)
return;
GHashTableIter i;
g_hash_table_iter_init(&i, search_list);
- struct search_q *q;
+ search_q_t *q;
while(g_hash_table_iter_next(&i, (gpointer *)&q, NULL))
if(q->cb && match(q, r))
q->cb(r, q->cb_dat);
@@ -276,8 +276,8 @@ static void dispatch(struct search_r *r) {
// Modifies msg in-place for temporary stuff.
-static struct search_r *parse_nmdc(struct hub *hub, char *msg) {
- struct search_r r = {};
+static search_r_t *parse_nmdc(hub_t *hub, char *msg) {
+ search_r_t r = {};
char *tmp, *tmp2;
gboolean hastth = FALSE;
@@ -357,7 +357,7 @@ static struct search_r *parse_nmdc(struct hub *hub, char *msg) {
int colon = strchr(tmp, ':') - tmp;
GList *n;
for(n=ui_tabs; n; n=n->next) {
- struct ui_tab *t = n->data;
+ ui_tab_t *t = n->data;
if(t->type != UIT_HUB || !t->hub->nick_valid || t->hub->adc)
continue;
// Excact hub:ip match, stop searching
@@ -377,20 +377,20 @@ static struct search_r *parse_nmdc(struct hub *hub, char *msg) {
}
// Figure out r.uid
- struct hub_user *u = g_hash_table_lookup(hub->users, user);
+ hub_user_t *u = g_hash_table_lookup(hub->users, user);
if(!u)
return NULL;
r.uid = u->uid;
// If we're here, then we can safely copy and return the result.
- struct search_r *res = g_slice_dup(struct search_r, &r);
+ search_r_t *res = g_slice_dup(search_r_t, &r);
res->file = nmdc_unescape_and_decode(hub, r.file);
return res;
}
-static struct search_r *parse_adc(struct hub *hub, struct adc_cmd *cmd) {
- struct search_r r = {};
+static search_r_t *parse_adc(hub_t *hub, adc_cmd_t *cmd) {
+ search_r_t r = {};
char *tmp, *tmp2;
// If this came from UDP, fetch the users' CID
@@ -436,7 +436,7 @@ static struct search_r *parse_adc(struct hub *hub, struct adc_cmd *cmd) {
// uid - passive
if(hub) {
- struct hub_user *u = g_hash_table_lookup(hub->sessions, GINT_TO_POINTER(cmd->source));
+ hub_user_t *u = g_hash_table_lookup(hub->sessions, GINT_TO_POINTER(cmd->source));
if(!u)
return NULL;
r.uid = u->uid;
@@ -450,7 +450,7 @@ static struct search_r *parse_adc(struct hub *hub, struct adc_cmd *cmd) {
guint64 hubid = g_ascii_strtoull(tmp, &tmp2, 10);
if(tmp == tmp2 || !tmp2 || *tmp2)
return NULL;
- struct tiger_ctx t;
+ tiger_ctx_t t;
tiger_init(&t);
tiger_update(&t, (char *)&hubid, 8);
tiger_update(&t, cid, 24);
@@ -464,8 +464,8 @@ static struct search_r *parse_adc(struct hub *hub, struct adc_cmd *cmd) {
}
-gboolean search_handle_adc(struct hub *hub, struct adc_cmd *cmd) {
- struct search_r *r = parse_adc(hub, cmd);
+gboolean search_handle_adc(hub_t *hub, adc_cmd_t *cmd) {
+ search_r_t *r = parse_adc(hub, cmd);
if(!r)
return FALSE;
@@ -476,8 +476,8 @@ gboolean search_handle_adc(struct hub *hub, struct adc_cmd *cmd) {
// May modify *msg in-place.
-gboolean search_handle_nmdc(struct hub *hub, char *msg) {
- struct search_r *r = parse_nmdc(hub, msg);
+gboolean search_handle_nmdc(hub_t *hub, char *msg) {
+ search_r_t *r = parse_nmdc(hub, msg);
if(!r)
return FALSE;
@@ -541,7 +541,7 @@ gboolean search_handle_udp(const char *addr, char *pack, int len) {
char *buf = g_malloc(len);
GHashTableIter i;
g_hash_table_iter_init(&i, search_list);
- struct search_q *q;
+ search_q_t *q;
while(g_hash_table_iter_next(&i, (gpointer *)&q, NULL)) {
char *new = try_decrypt(q->key, pack, len, buf);
if(new && (strncmp(new, "$SR ", 4) == 0 || strncmp(new, "URES ", 5) == 0)) {
@@ -571,7 +571,7 @@ gboolean search_handle_udp(const char *addr, char *pack, int len) {
g_debug("%s:%s< %s", sudp ? "SUDP" : "UDP", addr, msg);
if(adc) {
- struct adc_cmd cmd;
+ adc_cmd_t cmd;
if(!adc_parse(msg, &cmd, NULL, NULL)) {
g_free(pack);
return FALSE;
diff --git a/src/tth.c b/src/tth.c
index 919e2df..41d7782 100644
--- a/src/tth.c
+++ b/src/tth.c
@@ -52,7 +52,7 @@
#define tiger_block_size 64
-struct tiger_ctx {
+struct tiger_ctx_t {
guint64 hash[3]; /* algorithm 192-bit state */
char message[tiger_block_size]; /* 512-bit buffer for leftovers */
guint64 length; /* processed message length */
@@ -76,7 +76,7 @@ static guint64 tiger_sboxes[4][256];
#define t4 tiger_sboxes[3]
-void tiger_init(struct tiger_ctx *ctx) {
+void tiger_init(tiger_ctx_t *ctx) {
ctx->length = 0;
/* initialize algorithm state */
@@ -189,7 +189,7 @@ static void tiger_process_block(guint64 state[3], guint64 *block) {
}
-void tiger_update(struct tiger_ctx *ctx, const char *msg, size_t size) {
+void tiger_update(tiger_ctx_t *ctx, const char *msg, size_t size) {
size_t index = (size_t)ctx->length & 63;
size_t left;
ctx->length += size;
@@ -227,7 +227,7 @@ void tiger_update(struct tiger_ctx *ctx, const char *msg, size_t size) {
}
-void tiger_final(struct tiger_ctx *ctx, char result[24]) {
+void tiger_final(tiger_ctx_t *ctx, char result[24]) {
unsigned index = (unsigned)ctx->length & 63;
guint64 *msg64 = (guint64 *)ctx->message;
@@ -270,8 +270,8 @@ void tiger_final(struct tiger_ctx *ctx, char result[24]) {
#if INTERFACE
-struct tth_ctx {
- struct tiger_ctx tiger;
+struct tth_ctx_t {
+ tiger_ctx_t tiger;
int leafnum; // There can be 2^29 leafs. Fits in an integer.
int gotfirst;
// Stack used to calculate the hash.
@@ -301,7 +301,7 @@ struct tth_ctx {
#define tth_combine(left, right, res) do {\
- struct tiger_ctx x;\
+ tiger_ctx_t x;\
tiger_init(&x);\
tiger_update(&x, "\1", 1);\
tiger_update(&x, left, 24);\
@@ -310,13 +310,13 @@ struct tth_ctx {
} while(0)
-void tth_init(struct tth_ctx *ctx) {
+void tth_init(tth_ctx_t *ctx) {
tth_new_leaf(ctx);
ctx->leafnum = ctx->gotfirst = 0;
}
-void tth_update_leaf(struct tth_ctx *ctx, const char *leaf) {
+void tth_update_leaf(tth_ctx_t *ctx, const char *leaf) {
int pos = 0;
char tmp[24];
int it;
@@ -333,7 +333,7 @@ void tth_update_leaf(struct tth_ctx *ctx, const char *leaf) {
}
-void tth_update(struct tth_ctx *ctx, const char *msg, size_t len) {
+void tth_update(tth_ctx_t *ctx, const char *msg, size_t len) {
char leaf[24];
int left;
if(len > 0)
@@ -356,7 +356,7 @@ void tth_update(struct tth_ctx *ctx, const char *msg, size_t len) {
// combine everything on the stack to produce the last hash (based on RHash code)
-static void tth_stack_final(struct tth_ctx *ctx, char *result) {
+static void tth_stack_final(tth_ctx_t *ctx, char *result) {
guint64 it = 1;
int pos = 0;
char *last;
@@ -375,7 +375,7 @@ static void tth_stack_final(struct tth_ctx *ctx, char *result) {
}
-void tth_final(struct tth_ctx *ctx, char *result) {
+void tth_final(tth_ctx_t *ctx, char *result) {
// finish up last leaf
if(!ctx->gotfirst || ctx->tiger.length > 1) {
tiger_final(&ctx->tiger, result);
@@ -391,7 +391,7 @@ void tth_final(struct tth_ctx *ctx, char *result) {
// Calculate the root from a list of leaf/intermetiate hashes. All hashes must
// be at the same level.
void tth_root(char *blocks, int num, char *result) {
- struct tth_ctx t;
+ tth_ctx_t t;
tth_init(&t);
int i;
for(i=0; i<num; i++)
diff --git a/src/ui.c b/src/ui.c
index 915a5d6..21b0dc8 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -47,19 +47,19 @@
#define UIT_DL 6
#define UIT_SEARCH 7 // ?query
-struct ui_tab {
+struct ui_tab_t {
int type; // UIT_ type
int prio; // UIP_ type
char *name;
- struct ui_tab *parent; // the tab that opened this tab (may be NULL or dangling)
- struct ui_logwindow *log; // MAIN, HUB, MSG
- struct hub *hub; // HUB, USERLIST, MSG, SEARCH
- struct ui_listing *list; // USERLIST, CONN, FL, DL, SEARCH
- guint64 uid; // FL, MSG
- int order : 4; // USERLIST, SEARCH, FL (has different interpretation per tab)
- gboolean o_reverse : 1; // USERLIST, SEARCH
- gboolean details : 1; // USERLIST, CONN, DL
- time_t t_open; // FL, SEARCH
+ ui_tab_t *parent; // the tab that opened this tab (may be NULL or dangling)
+ ui_logwindow_t *log; // MAIN, HUB, MSG
+ hub_t *hub; // HUB, USERLIST, MSG, SEARCH
+ ui_listing_t *list; // USERLIST, CONN, FL, DL, SEARCH
+ guint64 uid; // FL, MSG
+ int order : 4; // USERLIST, SEARCH, FL (has different interpretation per tab)
+ gboolean o_reverse : 1; // USERLIST, SEARCH
+ gboolean details : 1; // USERLIST, CONN, DL
+ time_t t_open; // FL, SEARCH
// USERLIST
gboolean user_opfirst : 1;
gboolean user_hide_desc : 1;
@@ -71,9 +71,9 @@ struct ui_tab {
gboolean hub_joincomplete : 1;
GRegex *hub_highlight;
char *hub_nick;
- struct ui_tab *userlist_tab;
+ ui_tab_t *userlist_tab;
// FL
- struct fl_list *fl_list;
+ fl_list_t *fl_list;
char *fl_uname;
gboolean fl_loading : 1;
gboolean fl_dirfirst : 1;
@@ -81,10 +81,10 @@ struct ui_tab {
GError *fl_err;
char *fl_sel;
// DL
- struct dl *dl_cur;
- struct ui_listing *dl_users;
+ dl_t *dl_cur;
+ ui_listing_t *dl_users;
// SEARCH
- struct search_q *search_q;
+ search_q_t *search_q;
gboolean search_hide_hub : 1;
// MSG
int msg_replyto;
@@ -111,10 +111,10 @@ GHashTable *ui_msg_tabs = NULL;
// these is only one main tab, so this can be static
-struct ui_tab *ui_main;
+ui_tab_t *ui_main;
-static struct ui_tab *ui_main_create() {
- ui_main = g_new0(struct ui_tab, 1);
+static ui_tab_t *ui_main_create() {
+ ui_main = g_new0(ui_tab_t, 1);
ui_main->name = "main";
ui_main->log = ui_logwindow_create("main", 0);
ui_main->type = UIT_MAIN;
@@ -166,10 +166,10 @@ static void ui_main_keys(const char *s) {
// User message tab
-struct ui_tab *ui_msg_create(struct hub *hub, struct hub_user *user) {
+ui_tab_t *ui_msg_create(hub_t *hub, hub_user_t *user) {
g_return_val_if_fail(!g_hash_table_lookup(ui_msg_tabs, &user->uid), NULL);
- struct ui_tab *tab = g_new0(struct ui_tab, 1);
+ ui_tab_t *tab = g_new0(ui_tab_t, 1);
tab->type = UIT_MSG;
tab->hub = hub;
tab->uid = user->uid;
@@ -185,7 +185,7 @@ struct ui_tab *ui_msg_create(struct hub *hub, struct hub_user *user) {
}
-void ui_msg_close(struct ui_tab *tab) {
+void ui_msg_close(ui_tab_t *tab) {
g_hash_table_remove(ui_msg_tabs, &tab->uid);
ui_tab_remove(tab);
ui_logwindow_free(tab->log);
@@ -196,7 +196,7 @@ void ui_msg_close(struct ui_tab *tab) {
// *u may be NULL if change = QUIT. A QUIT is always done before the user is
// removed from the hub_uids table.
-static void ui_msg_userchange(struct ui_tab *tab, int change, struct hub_user *u) {
+static void ui_msg_userchange(ui_tab_t *tab, int change, hub_user_t *u) {
switch(change) {
case UIHUB_UC_JOIN:
ui_mf(tab, 0, "--> %s has joined.", u->name);
@@ -220,7 +220,7 @@ static void ui_msg_userchange(struct ui_tab *tab, int change, struct hub_user *u
}
-static void ui_msg_draw(struct ui_tab *tab) {
+static void ui_msg_draw(ui_tab_t *tab) {
ui_logwindow_draw(tab->log, 1, 0, winrows-4, wincols);
mvaddstr(winrows-3, 0, tab->name);
@@ -230,13 +230,13 @@ static void ui_msg_draw(struct ui_tab *tab) {
}
-static char *ui_msg_title(struct ui_tab *tab) {
+static char *ui_msg_title(ui_tab_t *tab) {
return g_strdup_printf("Chatting with %s on %s%s.",
tab->name+1, tab->hub->tab->name, g_hash_table_lookup(hub_uids, &tab->uid) ? "" : " (offline)");
}
-static void ui_msg_key(struct ui_tab *tab, guint64 key) {
+static void ui_msg_key(ui_tab_t *tab, guint64 key) {
char *str = NULL;
if(!ui_logwindow_key(tab->log, key, winrows) &&
ui_textinput_key(ui_global_textinput, key, &str) && str) {
@@ -246,7 +246,7 @@ static void ui_msg_key(struct ui_tab *tab, guint64 key) {
}
-static void ui_msg_msg(struct ui_tab *tab, const char *msg, int replyto) {
+static void ui_msg_msg(ui_tab_t *tab, const char *msg, int replyto) {
ui_m(tab, UIP_HIGH, msg);
tab->msg_replyto = replyto;
}
@@ -267,7 +267,7 @@ static void ui_msg_msg(struct ui_tab *tab, const char *msg, int replyto) {
// Also used for ui_msg_*
int ui_hub_log_checkchat(void *dat, char *nick, char *msg) {
- struct ui_tab *tab = dat;
+ ui_tab_t *tab = dat;
tab = tab->hub->tab;
if(!tab->hub_nick)
return 0;
@@ -285,7 +285,7 @@ int ui_hub_log_checkchat(void *dat, char *nick, char *msg) {
// Called by hub.c when hub->nick is set or changed. (Not called when hub->nick is reset to NULL)
// A local hub_nick field is kept in the hub tab struct to still provide
// highlighting for it after disconnecting from the hub.
-void ui_hub_setnick(struct ui_tab *tab) {
+void ui_hub_setnick(ui_tab_t *tab) {
if(!tab->hub->nick)
return;
g_free(tab->hub_nick);
@@ -300,8 +300,8 @@ void ui_hub_setnick(struct ui_tab *tab) {
}
-struct ui_tab *ui_hub_create(const char *name, gboolean conn) {
- struct ui_tab *tab = g_new0(struct ui_tab, 1);
+ui_tab_t *ui_hub_create(const char *name, gboolean conn) {
+ ui_tab_t *tab = g_new0(ui_tab_t, 1);
// NOTE: tab name is also used as configuration group
tab->name = g_strdup_printf("#%s", name);
tab->type = UIT_HUB;
@@ -316,14 +316,14 @@ struct ui_tab *ui_hub_create(const char *name, gboolean conn) {
}
-void ui_hub_close(struct ui_tab *tab) {
+void ui_hub_close(ui_tab_t *tab) {
// close the userlist tab
if(tab->userlist_tab)
ui_userlist_close(tab->userlist_tab);
// close msg and search tabs
GList *n;
for(n=ui_tabs; n;) {
- struct ui_tab *t = n->data;
+ ui_tab_t *t = n->data;
n = n->next;
if((t->type == UIT_MSG || t->type == UIT_SEARCH) && t->hub == tab->hub) {
if(t->type == UIT_MSG)
@@ -345,7 +345,7 @@ void ui_hub_close(struct ui_tab *tab) {
}
-static void ui_hub_draw(struct ui_tab *tab) {
+static void ui_hub_draw(ui_tab_t *tab) {
ui_logwindow_draw(tab->log, 1, 0, winrows-5, wincols);
attron(UIC(separator));
@@ -380,7 +380,7 @@ static void ui_hub_draw(struct ui_tab *tab) {
}
-static char *ui_hub_title(struct ui_tab *tab) {
+static char *ui_hub_title(ui_tab_t *tab) {
return g_strdup_printf("%s: %s", tab->name,
net_is_connecting(tab->hub->net) ? "Connecting..." :
!net_is_connected(tab->hub->net) ? "Not connected." :
@@ -389,7 +389,7 @@ static char *ui_hub_title(struct ui_tab *tab) {
}
-static void ui_hub_key(struct ui_tab *tab, guint64 key) {
+static void ui_hub_key(ui_tab_t *tab, guint64 key) {
char *str = NULL;
if(!ui_logwindow_key(tab->log, key, winrows) &&
ui_textinput_key(ui_global_textinput, key, &str) && str) {
@@ -400,13 +400,13 @@ static void ui_hub_key(struct ui_tab *tab, guint64 key) {
}
-void ui_hub_userchange(struct ui_tab *tab, int change, struct hub_user *user) {
+void ui_hub_userchange(ui_tab_t *tab, int change, hub_user_t *user) {
// notify the userlist, when it is open
if(tab->userlist_tab)
ui_userlist_userchange(tab->userlist_tab, change, user);
// notify the MSG tab, if we have one open for this user
- struct ui_tab *mt = g_hash_table_lookup(ui_msg_tabs, &user->uid);
+ ui_tab_t *mt = g_hash_table_lookup(ui_msg_tabs, &user->uid);
if(mt)
ui_msg_userchange(mt, change, user);
@@ -424,22 +424,22 @@ void ui_hub_userchange(struct ui_tab *tab, int change, struct hub_user *user) {
// Called when the hub is disconnected. Notifies any msg tabs and the userlist
// tab, if there's one open.
-void ui_hub_disconnect(struct ui_tab *tab) {
+void ui_hub_disconnect(ui_tab_t *tab) {
// userlist
if(tab->userlist_tab)
ui_userlist_disconnect(tab->userlist_tab);
// msg tabs
GList *n = ui_tabs;
for(; n; n=n->next) {
- struct ui_tab *t = n->data;
+ ui_tab_t *t = n->data;
if(t->type == UIT_MSG && t->hub == tab->hub)
ui_msg_userchange(t, UIHUB_UC_QUIT, NULL);
}
}
-void ui_hub_msg(struct ui_tab *tab, struct hub_user *user, const char *msg, int replyto) {
- struct ui_tab *t = g_hash_table_lookup(ui_msg_tabs, &user->uid);
+void ui_hub_msg(ui_tab_t *tab, hub_user_t *user, const char *msg, int replyto) {
+ ui_tab_t *t = g_hash_table_lookup(ui_msg_tabs, &user->uid);
if(!t) {
t = ui_msg_create(tab->hub, user);
ui_tab_open(t, FALSE, tab);
@@ -448,7 +448,7 @@ void ui_hub_msg(struct ui_tab *tab, struct hub_user *user, const char *msg, int
}
-void ui_hub_userlist_open(struct ui_tab *tab) {
+void ui_hub_userlist_open(ui_tab_t *tab) {
if(tab->userlist_tab)
ui_tab_cur = g_list_find(ui_tabs, tab->userlist_tab);
else {
@@ -458,8 +458,8 @@ void ui_hub_userlist_open(struct ui_tab *tab) {
}
-gboolean ui_hub_finduser(struct ui_tab *tab, guint64 uid, const char *user, gboolean utf8) {
- struct hub_user *u =
+gboolean ui_hub_finduser(ui_tab_t *tab, guint64 uid, const char *user, gboolean utf8) {
+ hub_user_t *u =
uid ? g_hash_table_lookup(hub_uids, &uid) :
utf8 ? hub_user_get(tab->hub, user) : g_hash_table_lookup(tab->hub->users, user);
if(!u || u->hub != tab->hub)
@@ -488,9 +488,9 @@ gboolean ui_hub_finduser(struct ui_tab *tab, guint64 uid, const char *user, gboo
static gint ui_userlist_sort_func(gconstpointer da, gconstpointer db, gpointer dat) {
- const struct hub_user *a = da;
- const struct hub_user *b = db;
- struct ui_tab *tab = dat;
+ const hub_user_t *a = da;
+ const hub_user_t *b = db;
+ ui_tab_t *tab = dat;
int p = tab->order;
if(tab->user_opfirst && !a->isop != !b->isop)
@@ -516,8 +516,8 @@ static gint ui_userlist_sort_func(gconstpointer da, gconstpointer db, gpointer d
}
-struct ui_tab *ui_userlist_create(struct hub *hub) {
- struct ui_tab *tab = g_new0(struct ui_tab, 1);
+ui_tab_t *ui_userlist_create(hub_t *hub) {
+ ui_tab_t *tab = g_new0(ui_tab_t, 1);
tab->name = g_strdup_printf("@%s", hub->tab->name+1);
tab->type = UIT_USERLIST;
tab->hub = hub;
@@ -533,7 +533,7 @@ struct ui_tab *ui_userlist_create(struct hub *hub) {
// linked lists, since it uses a faster sorting algorithm)
GHashTableIter iter;
g_hash_table_iter_init(&iter, hub->users);
- struct hub_user *u;
+ hub_user_t *u;
while(g_hash_table_iter_next(&iter, NULL, (gpointer *)&u))
u->iter = g_sequence_insert_sorted(users, u, ui_userlist_sort_func, tab);
tab->list = ui_listing_create(users);
@@ -541,7 +541,7 @@ struct ui_tab *ui_userlist_create(struct hub *hub) {
}
-void ui_userlist_close(struct ui_tab *tab) {
+void ui_userlist_close(ui_tab_t *tab) {
tab->hub->tab->userlist_tab = NULL;
ui_tab_remove(tab);
// To clean things up, we should also reset all hub_user->iter fields. But
@@ -554,7 +554,7 @@ void ui_userlist_close(struct ui_tab *tab) {
}
-static char *ui_userlist_title(struct ui_tab *tab) {
+static char *ui_userlist_title(ui_tab_t *tab) {
return g_strdup_printf("%s / User list", tab->hub->tab->name);
}
@@ -566,14 +566,14 @@ static char *ui_userlist_title(struct ui_tab *tab) {
} while(0)
-struct ui_userlist_draw_opts {
+typedef struct ui_userlist_draw_opts_t {
int cw_user, cw_share, cw_conn, cw_desc, cw_mail, cw_tag, cw_ip;
-};
+} ui_userlist_draw_opts_t;
-static void ui_userlist_draw_row(struct ui_listing *list, GSequenceIter *iter, int row, void *dat) {
- struct hub_user *user = g_sequence_get(iter);
- struct ui_userlist_draw_opts *o = dat;
+static void ui_userlist_draw_row(ui_listing_t *list, GSequenceIter *iter, int row, void *dat) {
+ hub_user_t *user = g_sequence_get(iter);
+ ui_userlist_draw_opts_t *o = dat;
char *tag = hub_user_tag(user);
char *conn = hub_user_conn(user);
@@ -616,7 +616,7 @@ static void ui_userlist_draw_row(struct ui_listing *list, GSequenceIter *iter, i
*
* TODO: abstract this, so that the weights and such don't need repetition.
*/
-static void ui_userlist_calc_widths(struct ui_tab *tab, struct ui_userlist_draw_opts *o) {
+static void ui_userlist_calc_widths(ui_tab_t *tab, ui_userlist_draw_opts_t *o) {
// available width
int w = wincols-5;
@@ -659,8 +659,8 @@ static void ui_userlist_calc_widths(struct ui_tab *tab, struct ui_userlist_draw_
}
-static void ui_userlist_draw(struct ui_tab *tab) {
- struct ui_userlist_draw_opts o;
+static void ui_userlist_draw(ui_tab_t *tab) {
+ ui_userlist_draw_opts_t o;
ui_userlist_calc_widths(tab, &o);
// header
@@ -697,7 +697,7 @@ static void ui_userlist_draw(struct ui_tab *tab) {
if(g_sequence_iter_is_end(tab->list->sel))
mvaddstr(bottom+1, 2, "No user selected.");
else {
- struct hub_user *u = g_sequence_get(tab->list->sel);
+ hub_user_t *u = g_sequence_get(tab->list->sel);
attron(A_BOLD);
mvaddstr(bottom+1, 4, "Username:");
mvaddstr(bottom+1, 41, "Share:");
@@ -727,11 +727,11 @@ static void ui_userlist_draw(struct ui_tab *tab) {
#undef DRAW_COL
-static void ui_userlist_key(struct ui_tab *tab, guint64 key) {
+static void ui_userlist_key(ui_tab_t *tab, guint64 key) {
if(ui_listing_key(tab->list, key, winrows/2))
return;
- struct hub_user *sel = g_sequence_iter_is_end(tab->list->sel) ? NULL : g_sequence_get(tab->list->sel);
+ hub_user_t *sel = g_sequence_iter_is_end(tab->list->sel) ? NULL : g_sequence_get(tab->list->sel);
gboolean sort = FALSE;
switch(key) {
case INPT_CHAR('?'):
@@ -798,7 +798,7 @@ static void ui_userlist_key(struct ui_tab *tab, guint64 key) {
if(!sel)
ui_m(NULL, 0, "No user selected.");
else {
- struct ui_tab *t = g_hash_table_lookup(ui_msg_tabs, &sel->uid);
+ ui_tab_t *t = g_hash_table_lookup(ui_msg_tabs, &sel->uid);
if(!t) {
t = ui_msg_create(tab->hub, sel);
ui_tab_open(t, TRUE, tab);
@@ -842,14 +842,14 @@ static void ui_userlist_key(struct ui_tab *tab, guint64 key) {
// Called when the hub is disconnected. All users should be removed in one go,
// this is faster than a _userchange() for every user.
-void ui_userlist_disconnect(struct ui_tab *tab) {
+void ui_userlist_disconnect(ui_tab_t *tab) {
g_sequence_free(tab->list->list);
ui_listing_free(tab->list);
tab->list = ui_listing_create(g_sequence_new(NULL));
}
-void ui_userlist_userchange(struct ui_tab *tab, int change, struct hub_user *user) {
+void ui_userlist_userchange(ui_tab_t *tab, int change, hub_user_t *user) {
if(change == UIHUB_UC_JOIN) {
user->iter = g_sequence_insert_sorted(tab->list->list, user, ui_userlist_sort_func, tab);
ui_listing_inserted(tab->list);
@@ -867,12 +867,12 @@ void ui_userlist_userchange(struct ui_tab *tab, int change, struct hub_user *use
// these can only be one connections tab, so this can be static
-struct ui_tab *ui_conn;
+ui_tab_t *ui_conn;
static gint ui_conn_sort_func(gconstpointer da, gconstpointer db, gpointer dat) {
- const struct cc *a = da;
- const struct cc *b = db;
+ const cc_t *a = da;
+ const cc_t *b = db;
int o = 0;
if(!o && !a->nick != !b->nick)
o = a->nick ? 1 : -1;
@@ -884,8 +884,8 @@ static gint ui_conn_sort_func(gconstpointer da, gconstpointer db, gpointer dat)
}
-struct ui_tab *ui_conn_create() {
- ui_conn = g_new0(struct ui_tab, 1);
+ui_tab_t *ui_conn_create() {
+ ui_conn = g_new0(ui_tab_t, 1);
ui_conn->name = "connections";
ui_conn->type = UIT_CONN;
// sort the connection list
@@ -933,8 +933,8 @@ static char *ui_conn_title() {
}
-static void ui_conn_draw_row(struct ui_listing *list, GSequenceIter *iter, int row, void *dat) {
- struct cc *cc = g_sequence_get(iter);
+static void ui_conn_draw_row(ui_listing_t *list, GSequenceIter *iter, int row, void *dat) {
+ cc_t *cc = g_sequence_get(iter);
attron(iter == list->sel ? UIC(list_select) : UIC(list_default));
mvhline(row, 0, ' ', wincols);
@@ -993,7 +993,7 @@ static void ui_conn_draw_row(struct ui_listing *list, GSequenceIter *iter, int r
static void ui_conn_draw_details(int l) {
- struct cc *cc = g_sequence_iter_is_end(ui_conn->list->sel) ? NULL : g_sequence_get(ui_conn->list->sel);
+ cc_t *cc = g_sequence_iter_is_end(ui_conn->list->sel) ? NULL : g_sequence_get(ui_conn->list->sel);
if(!cc) {
mvaddstr(l+1, 0, "Nothing selected.");
return;
@@ -1087,7 +1087,7 @@ static void ui_conn_key(guint64 key) {
if(ui_listing_key(ui_conn->list, key, (winrows-10)/2))
return;
- struct cc *cc = g_sequence_iter_is_end(ui_conn->list->sel) ? NULL : g_sequence_get(ui_conn->list->sel);
+ cc_t *cc = g_sequence_iter_is_end(ui_conn->list->sel) ? NULL : g_sequence_get(ui_conn->list->sel);
switch(key) {
case INPT_CHAR('?'):
@@ -1111,11 +1111,11 @@ static void ui_conn_key(guint64 key) {
else if(!cc->hub || !cc->uid)
ui_m(NULL, 0, "User or hub unknown.");
else {
- struct ui_tab *t = g_hash_table_lookup(ui_msg_tabs, &cc->uid);
+ ui_tab_t *t = g_hash_table_lookup(ui_msg_tabs, &cc->uid);
if(t) {
ui_tab_cur = g_list_find(ui_tabs, t);
} else {
- struct hub_user *u = g_hash_table_lookup(hub_uids, &cc->uid);
+ hub_user_t *u = g_hash_table_lookup(hub_uids, &cc->uid);
if(!u) {
ui_m(NULL, 0, "User has left the hub.");
} else {
@@ -1139,7 +1139,7 @@ static void ui_conn_key(guint64 key) {
else if(!cc->dl || !cc->last_file)
ui_m(NULL, 0, "Not downloading a file.");
else {
- struct dl *dl = g_hash_table_lookup(dl_queue, cc->last_hash);
+ dl_t *dl = g_hash_table_lookup(dl_queue, cc->last_hash);
if(!dl)
ui_m(NULL, 0, "File has been removed from the queue.");
else {
@@ -1168,9 +1168,9 @@ static void ui_conn_key(guint64 key) {
static gint ui_fl_sort(gconstpointer a, gconstpointer b, gpointer dat) {
- const struct fl_list *la = a;
- const struct fl_list *lb = b;
- struct ui_tab *tab = dat;
+ const fl_list_t *la = a;
+ const fl_list_t *lb = b;
+ ui_tab_t *tab = dat;
// dirs before files
if(tab->fl_dirfirst && !!la->isfile != !!lb->isfile)
@@ -1183,7 +1183,7 @@ static gint ui_fl_sort(gconstpointer a, gconstpointer b, gpointer dat) {
}
-static void ui_fl_setdir(struct ui_tab *tab, struct fl_list *fl, struct fl_list *sel) {
+static void ui_fl_setdir(ui_tab_t *tab, fl_list_t *fl, fl_list_t *sel) {
// Free previously opened dir
if(tab->list) {
g_sequence_free(tab->list->list);
@@ -1205,7 +1205,7 @@ static void ui_fl_setdir(struct ui_tab *tab, struct fl_list *fl, struct fl_list
}
-static void ui_fl_matchqueue(struct ui_tab *tab, struct fl_list *root) {
+static void ui_fl_matchqueue(ui_tab_t *tab, fl_list_t *root) {
if(!tab->fl_list) {
tab->fl_match = TRUE;
return;
@@ -1223,11 +1223,11 @@ static void ui_fl_matchqueue(struct ui_tab *tab, struct fl_list *root) {
}
-static void ui_fl_dosel(struct ui_tab *tab, struct fl_list *fl, const char *sel) {
- struct fl_list *root = fl;
+static void ui_fl_dosel(ui_tab_t *tab, fl_list_t *fl, const char *sel) {
+ fl_list_t *root = fl;
while(root->parent)
root = root->parent;
- struct fl_list *n = fl_list_from_path(root, sel);
+ fl_list_t *n = fl_list_from_path(root, sel);
if(!n)
ui_mf(tab, 0, "Can't select `%s': item not found.", sel);
// open the parent directory and select item
@@ -1237,10 +1237,10 @@ static void ui_fl_dosel(struct ui_tab *tab, struct fl_list *fl, const char *sel)
// Callback function for use in ui_fl_queue() - not associated with any tab.
// Will just match the list against the queue and free it.
-static void ui_fl_loadmatch(struct fl_list *fl, GError *err, void *dat) {
+static void ui_fl_loadmatch(fl_list_t *fl, GError *err, void *dat) {
guint64 uid = *(guint64 *)dat;
g_free(dat);
- struct hub_user *u = g_hash_table_lookup(hub_uids, &uid);
+ hub_user_t *u = g_hash_table_lookup(hub_uids, &uid);
char *user = u
? g_strdup_printf("%s on %s", u->name, u->hub->tab->name)
: g_strdup_printf("%016"G_GINT64_MODIFIER"x (user offline)", uid);
@@ -1259,11 +1259,11 @@ static void ui_fl_loadmatch(struct fl_list *fl, GError *err, void *dat) {
// Open/match or queue a file list. (Not really a ui_* function, but where else would it belong?)
-void ui_fl_queue(guint64 uid, gboolean force, const char *sel, struct ui_tab *parent, gboolean open, gboolean match) {
+void ui_fl_queue(guint64 uid, gboolean force, const char *sel, ui_tab_t *parent, gboolean open, gboolean match) {
if(!open && !match)
return;
- struct hub_user *u = g_hash_table_lookup(hub_uids, &uid);
+ hub_user_t *u = g_hash_table_lookup(hub_uids, &uid);
// check for u == we
if(u && (u->hub->adc ? u->hub->sid == u->sid : u->hub->nick_valid && strcmp(u->hub->nick_hub, u->name_hub) == 0)) {
u = NULL;
@@ -1273,7 +1273,7 @@ void ui_fl_queue(guint64 uid, gboolean force, const char *sel, struct ui_tab *pa
// check for existing tab
GList *n;
- struct ui_tab *t;
+ ui_tab_t *t;
for(n=ui_tabs; n; n=n->next) {
t = n->data;
if(t->type == UIT_FL && t->uid == uid)
@@ -1331,7 +1331,7 @@ void ui_fl_queue(guint64 uid, gboolean force, const char *sel, struct ui_tab *pa
}
-static void ui_fl_loaddone(struct fl_list *fl, GError *err, void *dat) {
+static void ui_fl_loaddone(fl_list_t *fl, GError *err, void *dat) {
// If the tab has been closed, then we can ignore the result
if(!g_list_find(ui_tabs, dat)) {
if(fl)
@@ -1341,7 +1341,7 @@ static void ui_fl_loaddone(struct fl_list *fl, GError *err, void *dat) {
return;
}
// Otherwise, update state
- struct ui_tab *tab = dat;
+ ui_tab_t *tab = dat;
tab->fl_err = err;
tab->fl_loading = FALSE;
tab->prio = err ? UIP_HIGH : UIP_MED;
@@ -1355,12 +1355,12 @@ static void ui_fl_loaddone(struct fl_list *fl, GError *err, void *dat) {
}
-struct ui_tab *ui_fl_create(guint64 uid, const char *sel) {
+ui_tab_t *ui_fl_create(guint64 uid, const char *sel) {
// get user
- struct hub_user *u = uid ? g_hash_table_lookup(hub_uids, &uid) : NULL;
+ hub_user_t *u = uid ? g_hash_table_lookup(hub_uids, &uid) : NULL;
// create tab
- struct ui_tab *tab = g_new0(struct ui_tab, 1);
+ ui_tab_t *tab = g_new0(ui_tab_t, 1);
tab->type = UIT_FL;
tab->name = !uid ? g_strdup("/own") : u ? g_strdup_printf("/%s", u->name) : g_strdup_printf("/%016"G_GINT64_MODIFIER"x", uid);
tab->fl_uname = u ? g_strdup(u->name) : NULL;
@@ -1371,7 +1371,7 @@ struct ui_tab *ui_fl_create(guint64 uid, const char *sel) {
// get file list
if(!uid) {
- struct fl_list *fl = fl_local_list ? fl_list_copy(fl_local_list) : NULL;
+ fl_list_t *fl = fl_local_list ? fl_list_copy(fl_local_list) : NULL;
tab->prio = UIP_MED;
if(fl && fl->sub && sel)
ui_fl_dosel(tab, fl, sel);
@@ -1396,13 +1396,13 @@ struct ui_tab *ui_fl_create(guint64 uid, const char *sel) {
}
-void ui_fl_close(struct ui_tab *tab) {
+void ui_fl_close(ui_tab_t *tab) {
if(tab->list) {
g_sequence_free(tab->list->list);
ui_listing_free(tab->list);
}
ui_tab_remove(tab);
- struct fl_list *p = tab->fl_list;
+ fl_list_t *p = tab->fl_list;
while(p && p->parent)
p = p->parent;
if(p)
@@ -1416,7 +1416,7 @@ void ui_fl_close(struct ui_tab *tab) {
}
-static char *ui_fl_title(struct ui_tab *tab) {
+static char *ui_fl_title(ui_tab_t *tab) {
char *t = !tab->uid ? g_strdup_printf("Browsing own file list.")
: tab->fl_uname ? g_strdup_printf("Browsing file list of %s (%016"G_GINT64_MODIFIER"x)", tab->fl_uname, tab->uid)
: g_strdup_printf("Browsing file list of %016"G_GINT64_MODIFIER"x (user offline)", tab->uid);
@@ -1426,8 +1426,8 @@ static char *ui_fl_title(struct ui_tab *tab) {
}
-static void ui_fl_draw_row(struct ui_listing *list, GSequenceIter *iter, int row, void *dat) {
- struct fl_list *fl = g_sequence_get(iter);
+static void ui_fl_draw_row(ui_listing_t *list, GSequenceIter *iter, int row, void *dat) {
+ fl_list_t *fl = g_sequence_get(iter);
attron(iter == list->sel ? UIC(list_select) : UIC(list_default));
mvhline(row, 0, ' ', wincols);
@@ -1445,7 +1445,7 @@ static void ui_fl_draw_row(struct ui_listing *list, GSequenceIter *iter, int row
}
-static void ui_fl_draw(struct ui_tab *tab) {
+static void ui_fl_draw(ui_tab_t *tab) {
// first line
mvhline(1, 0, ACS_HLINE, wincols);
mvaddch(1, 3, ' ');
@@ -1467,7 +1467,7 @@ static void ui_fl_draw(struct ui_tab *tab) {
mvaddstr(3, 2, "Directory empty.");
// footer
- struct fl_list *sel = pos >= 0 && !g_sequence_iter_is_end(tab->list->sel) ? g_sequence_get(tab->list->sel) : NULL;
+ fl_list_t *sel = pos >= 0 && !g_sequence_iter_is_end(tab->list->sel) ? g_sequence_get(tab->list->sel) : NULL;
attron(UIC(separator));
mvhline(winrows-3, 0, ' ', wincols);
if(pos >= 0)
@@ -1493,11 +1493,11 @@ static void ui_fl_draw(struct ui_tab *tab) {
}
-static void ui_fl_key(struct ui_tab *tab, guint64 key) {
+static void ui_fl_key(ui_tab_t *tab, guint64 key) {
if(tab->list && ui_listing_key(tab->list, key, winrows/2))
return;
- struct fl_list *sel = !tab->list || g_sequence_iter_is_end(tab->list->sel) ? NULL : g_sequence_get(tab->list->sel);
+ fl_list_t *sel = !tab->list || g_sequence_iter_is_end(tab->list->sel) ? NULL : g_sequence_get(tab->list->sel);
gboolean sort = FALSE;
switch(key) {
@@ -1593,12 +1593,12 @@ static void ui_fl_key(struct ui_tab *tab, guint64 key) {
// Download queue tab (UIT_DL)
// these can only be one download queue tab, so this can be static
-struct ui_tab *ui_dl;
+ui_tab_t *ui_dl;
static gint ui_dl_sort_func(gconstpointer da, gconstpointer db, gpointer dat) {
- const struct dl *a = da;
- const struct dl *b = db;
+ const dl_t *a = da;
+ const dl_t *b = db;
return a->islist && !b->islist ? -1 : !a->islist && b->islist ? 1 : strcmp(a->dest, b->dest);
}
@@ -1609,16 +1609,16 @@ static gint ui_dl_sort_func(gconstpointer da, gconstpointer db, gpointer dat) {
// removed/recreated every time an other dl item is selected. This sorting is
// just better than having the users in completely random order all the time.
static gint ui_dl_dud_sort_func(gconstpointer da, gconstpointer db, gpointer dat) {
- const struct dl_user_dl *a = da;
- const struct dl_user_dl *b = db;
- struct hub_user *ua = g_hash_table_lookup(hub_uids, &a->u->uid);
- struct hub_user *ub = g_hash_table_lookup(hub_uids, &b->u->uid);
+ const dl_user_dl_t *a = da;
+ const dl_user_dl_t *b = db;
+ hub_user_t *ua = g_hash_table_lookup(hub_uids, &a->u->uid);
+ hub_user_t *ub = g_hash_table_lookup(hub_uids, &b->u->uid);
return !ua && !ub ? (a->u->uid > b->u->uid ? 1 : a->u->uid < b->u->uid ? -1 : 0) :
ua && !ub ? 1 : !ua && ub ? -1 : g_utf8_collate(ua->name, ub->name);
}
-static void ui_dl_setusers(struct dl *dl) {
+static void ui_dl_setusers(dl_t *dl) {
if(ui_dl->dl_cur == dl)
return;
// free
@@ -1642,15 +1642,15 @@ static void ui_dl_setusers(struct dl *dl) {
}
-struct ui_tab *ui_dl_create() {
- ui_dl = g_new0(struct ui_tab, 1);
+ui_tab_t *ui_dl_create() {
+ ui_dl = g_new0(ui_tab_t, 1);
ui_dl->name = "queue";
ui_dl->type = UIT_DL;
// create and pupulate the list
GSequence *l = g_sequence_new(NULL);
GHashTableIter iter;
g_hash_table_iter_init(&iter, dl_queue);
- struct dl *dl;
+ dl_t *dl;
while(g_hash_table_iter_next(&iter, NULL, (gpointer *)&dl))
dl->iter = g_sequence_insert_sorted(l, dl, ui_dl_sort_func, NULL);
ui_dl->list = ui_listing_create(l);
@@ -1658,7 +1658,7 @@ struct ui_tab *ui_dl_create() {
}
-void ui_dl_select(struct dl *dl, guint64 uid) {
+void ui_dl_select(dl_t *dl, guint64 uid) {
g_return_if_fail(ui_dl);
// dl->iter should always be valid if the dl tab is open
@@ -1670,7 +1670,7 @@ void ui_dl_select(struct dl *dl, guint64 uid) {
ui_dl_setusers(dl);
GSequenceIter *i = g_sequence_get_begin_iter(ui_dl->dl_users->list);
for(; !g_sequence_iter_is_end(i); i=g_sequence_iter_next(i))
- if(((struct dl_user_dl *)g_sequence_get(i))->u->uid == uid) {
+ if(((dl_user_dl_t *)g_sequence_get(i))->u->uid == uid) {
ui_dl->dl_users->sel = i;
break;
}
@@ -1694,7 +1694,7 @@ void ui_dl_close() {
#endif
-void ui_dl_listchange(struct dl *dl, int change) {
+void ui_dl_listchange(dl_t *dl, int change) {
g_return_if_fail(ui_dl);
switch(change) {
case UICONN_ADD:
@@ -1711,7 +1711,7 @@ void ui_dl_listchange(struct dl *dl, int change) {
}
-void ui_dl_dud_listchange(struct dl_user_dl *dud, int change) {
+void ui_dl_dud_listchange(dl_user_dl_t *dud, int change) {
g_return_if_fail(ui_dl);
if(dud->dl != ui_dl->dl_cur || !ui_dl->dl_users)
return;
@@ -1742,8 +1742,8 @@ static char *ui_dl_title() {
}
-static void ui_dl_draw_row(struct ui_listing *list, GSequenceIter *iter, int row, void *dat) {
- struct dl *dl = g_sequence_get(iter);
+static void ui_dl_draw_row(ui_listing_t *list, GSequenceIter *iter, int row, void *dat) {
+ dl_t *dl = g_sequence_get(iter);
attron(iter == list->sel ? UIC(list_select) : UIC(list_default));
mvhline(row, 0, ' ', wincols);
@@ -1753,7 +1753,7 @@ static void ui_dl_draw_row(struct ui_listing *list, GSequenceIter *iter, int row
int online = 0;
int i;
for(i=0; i<dl->u->len; i++)
- if(g_hash_table_lookup(hub_uids, &(((struct dl_user_dl *)g_sequence_get(g_ptr_array_index(dl->u, i)))->u->uid)))
+ if(g_hash_table_lookup(hub_uids, &(((dl_user_dl_t *)g_sequence_get(g_ptr_array_index(dl->u, i)))->u->uid)))
online++;
mvprintw(row, 2, "%2d/%2d", online, dl->u->len);
@@ -1783,15 +1783,15 @@ static void ui_dl_draw_row(struct ui_listing *list, GSequenceIter *iter, int row
}
-static void ui_dl_dud_draw_row(struct ui_listing *list, GSequenceIter *iter, int row, void *dat) {
- struct dl_user_dl *dud = g_sequence_get(iter);
+static void ui_dl_dud_draw_row(ui_listing_t *list, GSequenceIter *iter, int row, void *dat) {
+ dl_user_dl_t *dud = g_sequence_get(iter);
attron(iter == list->sel ? UIC(list_select) : UIC(list_default));
mvhline(row, 0, ' ', wincols);
if(iter == list->sel)
mvaddstr(row, 0, ">");
- struct hub_user *u = g_hash_table_lookup(hub_uids, &dud->u->uid);
+ hub_user_t *u = g_hash_table_lookup(hub_uids, &dud->u->uid);
if(u) {
mvaddnstr(row, 2, u->name, str_offset_from_columns(u->name, 19));
mvaddnstr(row, 22, u->hub->tab->name, str_offset_from_columns(u->hub->tab->name, 13));
@@ -1826,7 +1826,7 @@ static void ui_dl_draw() {
int bottom = ui_dl->details ? winrows-14 : winrows-4;
int pos = ui_listing_draw(ui_dl->list, 2, bottom-1, ui_dl_draw_row, NULL);
- struct dl *sel = g_sequence_iter_is_end(ui_dl->list->sel) ? NULL : g_sequence_get(ui_dl->list->sel);
+ dl_t *sel = g_sequence_iter_is_end(ui_dl->list->sel) ? NULL : g_sequence_get(ui_dl->list->sel);
// footer / separator
attron(UIC(separator));
@@ -1864,8 +1864,8 @@ static void ui_dl_key(guint64 key) {
if(ui_listing_key(ui_dl->list, key, (winrows-(ui_dl->details?14:4))/2))
return;
- struct dl *sel = g_sequence_iter_is_end(ui_dl->list->sel) ? NULL : g_sequence_get(ui_dl->list->sel);
- struct dl_user_dl *usel = NULL;
+ dl_t *sel = g_sequence_iter_is_end(ui_dl->list->sel) ? NULL : g_sequence_get(ui_dl->list->sel);
+ dl_user_dl_t *usel = NULL;
if(!ui_dl->details)
usel = NULL;
else {
@@ -1894,7 +1894,7 @@ static void ui_dl_key(guint64 key) {
if(!usel)
ui_m(NULL, 0, "No user selected.");
else {
- struct hub_user *u = g_hash_table_lookup(hub_uids, &usel->u->uid);
+ hub_user_t *u = g_hash_table_lookup(hub_uids, &usel->u->uid);
if(!u)
ui_m(NULL, 0, "User is not online.");
else
@@ -1915,10 +1915,10 @@ static void ui_dl_key(guint64 key) {
else if(!sel->active)
ui_m(NULL, 0, "Download not in progress.");
else {
- struct cc *cc = NULL;
+ cc_t *cc = NULL;
int i;
for(i=0; i<sel->u->len; i++) {
- struct dl_user_dl *dud = g_sequence_get(g_ptr_array_index(sel->u, i));
+ dl_user_dl_t *dud = g_sequence_get(g_ptr_array_index(sel->u, i));
if(dud->u->active == dud) {
cc = dud->u->cc;
break;
@@ -2007,8 +2007,8 @@ static void ui_dl_key(guint64 key) {
// Compares users, uses a hub comparison as fallback
static int ui_search_cmp_user(guint64 ua, guint64 ub) {
- struct hub_user *a = g_hash_table_lookup(hub_uids, &ua);
- struct hub_user *b = g_hash_table_lookup(hub_uids, &ub);
+ hub_user_t *a = g_hash_table_lookup(hub_uids, &ua);
+ hub_user_t *b = g_hash_table_lookup(hub_uids, &ub);
int o =
!a && !b ? (ua > ub ? 1 : ua < ub ? -1 : 0) :
a && !b ? 1 : !a && b ? -1 : g_utf8_collate(a->name, b->name);
@@ -2026,9 +2026,9 @@ static int ui_search_cmp_file(const char *fa, const char *fb) {
static gint ui_search_sort_func(gconstpointer da, gconstpointer db, gpointer dat) {
- const struct search_r *a = da;
- const struct search_r *b = db;
- struct ui_tab *tab = dat;
+ const search_r_t *a = da;
+ const search_r_t *b = db;
+ ui_tab_t *tab = dat;
int p = tab->order;
/* Sort columns and their alternatives:
@@ -2056,8 +2056,8 @@ static gint ui_search_sort_func(gconstpointer da, gconstpointer db, gpointer dat
// Callback from search.c when we have a new result.
-void ui_search_result(struct search_r *r, void *dat) {
- struct ui_tab *tab = dat;
+void ui_search_result(search_r_t *r, void *dat) {
+ ui_tab_t *tab = dat;
g_sequence_insert_sorted(tab->list->list, search_r_copy(r), ui_search_sort_func, tab);
ui_listing_inserted(tab->list);
tab->prio = MAX(tab->prio, UIP_LOW);
@@ -2067,8 +2067,8 @@ void ui_search_result(struct search_r *r, void *dat) {
// Performs a seach and opens a new tab for the results.
// May return NULL on error, behaves similarly to search_add() w.r.t *err.
// Ownership of q is passed to the tab, and will be freed on error or close.
-struct ui_tab *ui_search_create(struct hub *hub, struct search_q *q, GError **err) {
- struct ui_tab *tab = g_new0(struct ui_tab, 1);
+ui_tab_t *ui_search_create(hub_t *hub, search_q_t *q, GError **err) {
+ ui_tab_t *tab = g_new0(ui_tab_t, 1);
tab->type = UIT_SEARCH;
tab->search_q = q;
tab->hub = hub;
@@ -2107,9 +2107,9 @@ struct ui_tab *ui_search_create(struct hub *hub, struct search_q *q, GError **er
// Open a new tab for a TTH search on all hubs, or write a message to ui_m() on
// error.
-void ui_search_open_tth(const char *tth, struct ui_tab *parent) {
+void ui_search_open_tth(const char *tth, ui_tab_t *parent) {
GError *err = NULL;
- struct ui_tab *rtab = ui_search_create(NULL, search_q_new_tth(tth), &err);
+ ui_tab_t *rtab = ui_search_create(NULL, search_q_new_tth(tth), &err);
if(err) {
ui_mf(NULL, 0, "%s%s", rtab ? "Warning: " : "", err->message);
g_error_free(err);
@@ -2119,7 +2119,7 @@ void ui_search_open_tth(const char *tth, struct ui_tab *parent) {
}
-void ui_search_close(struct ui_tab *tab) {
+void ui_search_close(ui_tab_t *tab) {
search_remove(tab->search_q);
g_sequence_free(tab->list->list);
ui_listing_free(tab->list);
@@ -2129,7 +2129,7 @@ void ui_search_close(struct ui_tab *tab) {
}
-static char *ui_search_title(struct ui_tab *tab) {
+static char *ui_search_title(ui_tab_t *tab) {
char *sq = search_command(tab->search_q, tab->hub?TRUE:FALSE);
char *r = tab->hub
? g_strdup_printf("Results on %s for: %s", tab->hub->tab->name, sq)
@@ -2140,16 +2140,16 @@ static char *ui_search_title(struct ui_tab *tab) {
// TODO: mark already shared and queued files?
-static void ui_search_draw_row(struct ui_listing *list, GSequenceIter *iter, int row, void *dat) {
- struct search_r *r = g_sequence_get(iter);
- struct ui_tab *tab = dat;
+static void ui_search_draw_row(ui_listing_t *list, GSequenceIter *iter, int row, void *dat) {
+ search_r_t *r = g_sequence_get(iter);
+ ui_tab_t *tab = dat;
attron(iter == list->sel ? UIC(list_select) : UIC(list_default));
mvhline(row, 0, ' ', wincols);
if(iter == list->sel)
mvaddstr(row, 0, ">");
- struct hub_user *u = g_hash_table_lookup(hub_uids, &r->uid);
+ hub_user_t *u = g_hash_table_lookup(hub_uids, &r->uid);
if(u) {
mvaddnstr(row, 2, u->name, str_offset_from_columns(u->name, 19));
if(!tab->search_hide_hub)
@@ -2180,7 +2180,7 @@ static void ui_search_draw_row(struct ui_listing *list, GSequenceIter *iter, int
}
-static void ui_search_draw(struct ui_tab *tab) {
+static void ui_search_draw(ui_tab_t *tab) {
attron(UIC(list_header));
mvhline(1, 0, ' ', wincols);
mvaddstr(1, 2, "User");
@@ -2195,7 +2195,7 @@ static void ui_search_draw(struct ui_tab *tab) {
int bottom = winrows-4;
int pos = ui_listing_draw(tab->list, 2, bottom-1, ui_search_draw_row, tab);
- struct search_r *sel = g_sequence_iter_is_end(tab->list->sel) ? NULL : g_sequence_get(tab->list->sel);
+ search_r_t *sel = g_sequence_iter_is_end(tab->list->sel) ? NULL : g_sequence_get(tab->list->sel);
// footer
attron(UIC(separator));
@@ -2217,11 +2217,11 @@ static void ui_search_draw(struct ui_tab *tab) {
}
-static void ui_search_key(struct ui_tab *tab, guint64 key) {
+static void ui_search_key(ui_tab_t *tab, guint64 key) {
if(ui_listing_key(tab->list, key, (winrows-4)/2))
return;
- struct search_r *sel = g_sequence_iter_is_end(tab->list->sel) ? NULL : g_sequence_get(tab->list->sel);
+ search_r_t *sel = g_sequence_iter_is_end(tab->list->sel) ? NULL : g_sequence_get(tab->list->sel);
gboolean sort = FALSE;
switch(key) {
@@ -2233,7 +2233,7 @@ static void ui_search_key(struct ui_tab *tab, guint64 key) {
if(!sel)
ui_m(NULL, 0, "Nothing selected.");
else {
- struct hub_user *u = g_hash_table_lookup(hub_uids, &sel->uid);
+ hub_user_t *u = g_hash_table_lookup(hub_uids, &sel->uid);
if(!u)
ui_m(NULL, 0, "User is not online.");
else
@@ -2245,7 +2245,7 @@ static void ui_search_key(struct ui_tab *tab, guint64 key) {
if(!sel)
ui_m(NULL, 0, "Nothing selected.");
else {
- struct hub_user *u = g_hash_table_lookup(hub_uids, &sel->uid);
+ hub_user_t *u = g_hash_table_lookup(hub_uids, &sel->uid);
if(!u)
ui_m(NULL, 0, "User is not online.");
else
@@ -2278,7 +2278,7 @@ static void ui_search_key(struct ui_tab *tab, guint64 key) {
int n = 0, a = 0;
GSequenceIter *i = g_sequence_get_begin_iter(tab->list->list);
for(; !g_sequence_iter_is_end(i); i=g_sequence_iter_next(i)) {
- struct search_r *r = g_sequence_get(i);
+ search_r_t *r = g_sequence_get(i);
int v = dl_queue_matchfile(r->uid, r->tth);
if(v >= 0)
n++;
@@ -2300,7 +2300,7 @@ static void ui_search_key(struct ui_tab *tab, guint64 key) {
// Use a hash table to avoid checking the same filelist more than once
GHashTable *uids = g_hash_table_new(g_int64_hash, g_int64_equal);
for(; !g_sequence_iter_is_end(i); i=g_sequence_iter_next(i)) {
- struct search_r *r = g_sequence_get(i);
+ search_r_t *r = g_sequence_get(i);
// In the case that this wasn't a TTH search, check whether this search
// result matches the queue before checking the file list.
if(tab->search_q->type == 9 || dl_queue_matchfile(r->uid, r->tth) >= 0)
@@ -2395,11 +2395,11 @@ static char *ui_m_text = NULL;
static guint ui_m_timer;
static gboolean ui_m_updated = FALSE;
-struct ui_m_dat {
+typedef struct ui_m_t {
char *msg;
- struct ui_tab *tab;
+ ui_tab_t *tab;
int flags;
-};
+} ui_m_t;
static gboolean ui_m_timeout(gpointer data) {
@@ -2414,8 +2414,8 @@ static gboolean ui_m_timeout(gpointer data) {
static gboolean ui_m_mainthread(gpointer dat) {
- struct ui_m_dat *msg = dat;
- struct ui_tab *tab = msg->tab;
+ ui_m_t *msg = dat;
+ ui_tab_t *tab = msg->tab;
int prio = msg->flags & 3; // lower two bits
if(!tab)
tab = ui_tab_cur->data;
@@ -2456,8 +2456,8 @@ ui_m_cleanup:
// the hub has no tab, in the "status bar". Calling this function with NULL
// will reset the status bar message. Unlike everything else, this function can
// be called from any thread. (It will queue an idle function, after all)
-void ui_m(struct ui_tab *tab, int flags, const char *msg) {
- struct ui_m_dat *dat = g_new0(struct ui_m_dat, 1);
+void ui_m(ui_tab_t *tab, int flags, const char *msg) {
+ ui_m_t *dat = g_new0(ui_m_t, 1);
dat->msg = (flags & UIM_PASS) ? (char *)msg : g_strdup(msg);
dat->tab = tab;
dat->flags = flags;
@@ -2472,7 +2472,7 @@ void ui_m(struct ui_tab *tab, int flags, const char *msg) {
// UIM_PASS shouldn't be used here (makes no sense).
-void ui_mf(struct ui_tab *tab, int flags, const char *fmt, ...) {
+void ui_mf(ui_tab_t *tab, int flags, const char *fmt, ...) {
va_list va;
va_start(va, fmt);
ui_m(tab, flags | UIM_PASS, g_strdup_vprintf(fmt, va));
@@ -2485,9 +2485,9 @@ void ui_mf(struct ui_tab *tab, int flags, const char *fmt, ...) {
// Global stuff
-struct ui_textinput *ui_global_textinput;
+ui_textinput_t *ui_global_textinput;
-void ui_tab_open(struct ui_tab *tab, gboolean sel, struct ui_tab *parent) {
+void ui_tab_open(ui_tab_t *tab, gboolean sel, ui_tab_t *parent) {
ui_tabs = g_list_append(ui_tabs, tab);
tab->parent = parent;
if(sel)
@@ -2496,11 +2496,11 @@ void ui_tab_open(struct ui_tab *tab, gboolean sel, struct ui_tab *parent) {
// to be called from ui_*_close()
-void ui_tab_remove(struct ui_tab *tab) {
+void ui_tab_remove(ui_tab_t *tab) {
// Look for any tabs that have this one as parent, and let those inherit this tab's parent
GList *n = ui_tabs;
for(; n; n=n->next) {
- struct ui_tab *t = n->data;
+ ui_tab_t *t = n->data;
if(t->parent == tab)
t->parent = tab->parent;
}
@@ -2556,7 +2556,7 @@ static void ui_draw_status() {
}
-#define tabcol(t, n) (2+ceil(log10((n)+1))+str_columns(((struct ui_tab *)(t)->data)->name))
+#define tabcol(t, n) (2+ceil(log10((n)+1))+str_columns(((ui_tab_t *)(t)->data)->name))
#define prio2a(p) ((p) == UIP_LOW ? UIC(tabprio_low) : (p) == UIP_MED ? UIC(tabprio_med) : UIC(tabprio_high))
/* All tabs are in one of the following states:
@@ -2602,7 +2602,7 @@ static void ui_draw_tablist(int xoffset) {
// (This also sets n and i to the start of the visible list)
char maxprio = 0;
for(n=ui_tabs,i=0; i<top; i++,n=n->next) {
- struct ui_tab *t = n->data;
+ ui_tab_t *t = n->data;
if(t->prio > maxprio)
maxprio = t->prio;
}
@@ -2626,7 +2626,7 @@ static void ui_draw_tablist(int xoffset) {
w -= tabcol(n, ++i);
if(w < 0)
break;
- struct ui_tab *t = n->data;
+ ui_tab_t *t = n->data;
addch(' ');
if(n == ui_tab_cur)
attron(A_BOLD);
@@ -2647,7 +2647,7 @@ static void ui_draw_tablist(int xoffset) {
GList *last = n;
maxprio = 0;
for(; n&&maxprio<UIP_HIGH; n=n->next) {
- struct ui_tab *t = n->data;
+ ui_tab_t *t = n->data;
if(t->prio > maxprio)
maxprio = t->prio;
}
@@ -2672,7 +2672,7 @@ static void ui_draw_tablist(int xoffset) {
void ui_draw() {
- struct ui_tab *curtab = ui_tab_cur->data;
+ ui_tab_t *curtab = ui_tab_cur->data;
curtab->prio = UIP_EMPTY;
getmaxyx(stdscr, winrows, wincols);
@@ -2745,7 +2745,7 @@ void ui_draw() {
gboolean ui_checkupdate() {
- struct ui_tab *cur = ui_tab_cur->data;
+ ui_tab_t *cur = ui_tab_cur->data;
return ui_m_updated || ui_beep || (cur->log && cur->log->updated);
}
@@ -2755,7 +2755,7 @@ void ui_daychange(const char *day) {
char *msg = g_strdup_printf("Day changed to %s", day);
GList *n = ui_tabs;
for(; n; n=n->next) {
- struct ui_tab *t = n->data;
+ ui_tab_t *t = n->data;
if(t->log)
ui_logwindow_addline(t->log, msg, TRUE, TRUE);
}
@@ -2764,7 +2764,7 @@ void ui_daychange(const char *day) {
void ui_input(guint64 key) {
- struct ui_tab *curtab = ui_tab_cur->data;
+ ui_tab_t *curtab = ui_tab_cur->data;
switch(key) {
case INPT_CTRL('c'): // ctrl+c
diff --git a/src/ui_util.c b/src/ui_util.c
index 9793e75..144b138 100644
--- a/src/ui_util.c
+++ b/src/ui_util.c
@@ -68,13 +68,13 @@ enum ui_coltype {
};
-struct ui_color {
+struct ui_color_t {
int var;
short fg, bg, d_fg, d_bg;
int x, d_x, a;
};
-struct ui_attr {
+struct ui_attr_t {
char name[11];
gboolean color : 1;
int attr;
@@ -85,7 +85,7 @@ struct ui_attr {
#endif // INTERFACE
-struct ui_color ui_colors[] = {
+ui_color_t ui_colors[] = {
#define C(n, d) { VAR_color_##n },
UI_COLORS
#undef C
@@ -93,7 +93,7 @@ struct ui_color ui_colors[] = {
};
-struct ui_attr ui_attr_names[] = {
+ui_attr_t ui_attr_names[] = {
{ "black", TRUE, COLOR_BLACK },
{ "blink", FALSE, A_BLINK },
{ "blue", TRUE, COLOR_BLUE },
@@ -111,8 +111,8 @@ struct ui_attr ui_attr_names[] = {
};
-static struct ui_attr *ui_attr_by_name(const char *n) {
- struct ui_attr *a = ui_attr_names;
+static ui_attr_t *ui_attr_by_name(const char *n) {
+ ui_attr_t *a = ui_attr_names;
for(; *a->name; a++)
if(strcmp(a->name, n) == 0)
return a;
@@ -121,7 +121,7 @@ static struct ui_attr *ui_attr_by_name(const char *n) {
static char *ui_name_by_attr(int n) {
- struct ui_attr *a = ui_attr_names;
+ ui_attr_t *a = ui_attr_names;
for(; *a->name; a++)
if(a->attr == n)
return a->name;
@@ -139,7 +139,7 @@ gboolean ui_color_str_parse(const char *str, short *fg, short *bg, int *x, GErro
g_strstrip(*arg);
if(!**arg)
continue;
- struct ui_attr *attr = ui_attr_by_name(*arg);
+ ui_attr_t *attr = ui_attr_by_name(*arg);
if(!attr) {
g_set_error(err, 1, 0, "Unknown color or attribute: %s", *arg);
g_strfreev(args);
@@ -174,7 +174,7 @@ char *ui_color_str_gen(int fd, int bg, int x) {
strcat(buf, ",");
strcat(buf, ui_name_by_attr(bg));
}
- struct ui_attr *attr = ui_attr_names;
+ ui_attr_t *attr = ui_attr_names;
for(; attr->name[0]; attr++)
if(!attr->color && x & attr->attr) {
strcat(buf, ",");
@@ -187,7 +187,7 @@ char *ui_color_str_gen(int fd, int bg, int x) {
// TODO: re-use color pairs when we have too many (>64) color groups
void ui_colors_update() {
int pair = 0;
- struct ui_color *c = ui_colors;
+ ui_color_t *c = ui_colors;
for(; c->var>=0; c++) {
g_warn_if_fail(ui_color_str_parse(var_get(0, c->var), &c->fg, &c->bg, &c->x, NULL));
init_pair(++pair, c->fg, c->bg);
@@ -225,10 +225,10 @@ void ui_colors_init() {
#define LOGWIN_BUF 1023 // must be 2^x-1
-struct ui_logwindow {
+struct ui_logwindow_t {
int lastlog;
int lastvis;
- struct logfile *logfile;
+ logfile_t *logfile;
char *buf[LOGWIN_BUF+1];
gboolean updated;
int (*checkchat)(void *, char *, char *);
@@ -238,7 +238,7 @@ struct ui_logwindow {
#endif
-void ui_logwindow_addline(struct ui_logwindow *lw, const char *msg, gboolean raw, gboolean nolog) {
+void ui_logwindow_addline(ui_logwindow_t *lw, const char *msg, gboolean raw, gboolean nolog) {
if(lw->lastlog == lw->lastvis)
lw->lastvis = lw->lastlog + 1;
lw->lastlog++;
@@ -260,7 +260,7 @@ void ui_logwindow_addline(struct ui_logwindow *lw, const char *msg, gboolean raw
}
-static void ui_logwindow_load(struct ui_logwindow *lw, const char *fn, int num) {
+static void ui_logwindow_load(ui_logwindow_t *lw, const char *fn, int num) {
char **l = file_tail(fn, num);
if(!l) {
g_warning("Unable to tail log file '%s': %s", fn, g_strerror(errno));
@@ -304,8 +304,8 @@ static void ui_logwindow_load(struct ui_logwindow *lw, const char *fn, int num)
}
-struct ui_logwindow *ui_logwindow_create(const char *file, int load) {
- struct ui_logwindow *lw = g_new0(struct ui_logwindow, 1);
+ui_logwindow_t *ui_logwindow_create(const char *file, int load) {
+ ui_logwindow_t *lw = g_new0(ui_logwindow_t, 1);
if(file) {
lw->logfile = logfile_create(file);
@@ -316,14 +316,14 @@ struct ui_logwindow *ui_logwindow_create(const char *file, int load) {
}
-void ui_logwindow_free(struct ui_logwindow *lw) {
+void ui_logwindow_free(ui_logwindow_t *lw) {
logfile_free(lw->logfile);
ui_logwindow_clear(lw);
g_free(lw);
}
-void ui_logwindow_add(struct ui_logwindow *lw, const char *msg) {
+void ui_logwindow_add(ui_logwindow_t *lw, const char *msg) {
if(!msg[0]) {
ui_logwindow_addline(lw, "", FALSE, FALSE);
return;
@@ -358,7 +358,7 @@ void ui_logwindow_add(struct ui_logwindow *lw, const char *msg) {
}
-void ui_logwindow_clear(struct ui_logwindow *lw) {
+void ui_logwindow_clear(ui_logwindow_t *lw) {
int i;
for(i=0; i<=LOGWIN_BUF; i++) {
g_free(lw->buf[i]);
@@ -368,7 +368,7 @@ void ui_logwindow_clear(struct ui_logwindow *lw) {
}
-void ui_logwindow_scroll(struct ui_logwindow *lw, int i) {
+void ui_logwindow_scroll(ui_logwindow_t *lw, int i) {
lw->lastvis += i;
// lastvis may never be larger than the last entry present
lw->lastvis = MIN(lw->lastvis, lw->lastlog);
@@ -438,7 +438,7 @@ static int ui_logwindow_calc_wrap(char *str, int cols, int indent, int *rows, in
// Determines the colors each part of a log line should have. Returns the
// highest index to the attr array.
-static int ui_logwindow_calc_color(struct ui_logwindow *lw, char *str, int *sep, int *attr) {
+static int ui_logwindow_calc_color(ui_logwindow_t *lw, char *str, int *sep, int *attr) {
sep[0] = 0;
int mask = 0;
@@ -497,7 +497,7 @@ static int ui_logwindow_calc_color(struct ui_logwindow *lw, char *str, int *sep,
// Draws a line between x and x+cols on row y (continuing on y-1 .. y-(rows+1) for
// multiple rows). Returns the actual number of rows written to.
-static int ui_logwindow_drawline(struct ui_logwindow *lw, int y, int x, int nrows, int cols, char *str) {
+static int ui_logwindow_drawline(ui_logwindow_t *lw, int y, int x, int nrows, int cols, char *str) {
g_return_val_if_fail(nrows > 0, 1);
// Determine the indentation for multi-line rows. This is:
@@ -570,7 +570,7 @@ static int ui_logwindow_drawline(struct ui_logwindow *lw, int y, int x, int nrow
}
-void ui_logwindow_draw(struct ui_logwindow *lw, int y, int x, int rows, int cols) {
+void ui_logwindow_draw(ui_logwindow_t *lw, int y, int x, int rows, int cols) {
int top = rows + y - 1;
int cur = lw->lastvis;
lw->updated = FALSE;
@@ -585,7 +585,7 @@ void ui_logwindow_draw(struct ui_logwindow *lw, int y, int x, int rows, int cols
}
-gboolean ui_logwindow_key(struct ui_logwindow *lw, guint64 key, int rows) {
+gboolean ui_logwindow_key(ui_logwindow_t *lw, guint64 key, int rows) {
switch(key) {
case INPT_KEY(KEY_NPAGE):
ui_logwindow_scroll(lw, rows/2);
@@ -613,15 +613,15 @@ gboolean ui_logwindow_key(struct ui_logwindow *lw, guint64 key, int rows) {
#define CMDHIST_MAXCMD 2000
-struct ui_cmdhist {
+typedef struct ui_cmdhist_t {
char *buf[CMDHIST_BUF+1]; // circular buffer
char *fn;
int last;
gboolean ismod;
-};
+} ui_cmdhist_t;
// we only have one command history, so this can be a global
-static struct ui_cmdhist *cmdhist;
+static ui_cmdhist_t *cmdhist;
static void ui_cmdhist_add(const char *str) {
@@ -649,7 +649,7 @@ static void ui_cmdhist_add(const char *str) {
void ui_cmdhist_init(const char *file) {
static char buf[CMDHIST_MAXCMD+2]; // + \n and \0
- cmdhist = g_new0(struct ui_cmdhist, 1);
+ cmdhist = g_new0(ui_cmdhist_t, 1);
cmdhist->fn = g_build_filename(db_dir, file, NULL);
FILE *f = fopen(cmdhist->fn, "r");
@@ -719,7 +719,7 @@ void ui_cmdhist_close() {
#if INTERFACE
-struct ui_textinput {
+struct ui_textinput_t {
int pos; // position of the cursor, in number of characters
GString *str;
gboolean usehist;
@@ -735,8 +735,8 @@ struct ui_textinput {
-struct ui_textinput *ui_textinput_create(gboolean usehist, void (*complete)(char *, char **)) {
- struct ui_textinput *ti = g_new0(struct ui_textinput, 1);
+ui_textinput_t *ui_textinput_create(gboolean usehist, void (*complete)(char *, char **)) {
+ ui_textinput_t *ti = g_new0(ui_textinput_t, 1);
ti->str = g_string_new("");
ti->usehist = usehist;
ti->s_pos = -1;
@@ -745,7 +745,7 @@ struct ui_textinput *ui_textinput_create(gboolean usehist, void (*complete)(char
}
-static void ui_textinput_complete_reset(struct ui_textinput *ti) {
+static void ui_textinput_complete_reset(ui_textinput_t *ti) {
if(ti->complete) {
g_free(ti->c_q);
g_free(ti->c_last);
@@ -756,7 +756,7 @@ static void ui_textinput_complete_reset(struct ui_textinput *ti) {
}
-static void ui_textinput_complete(struct ui_textinput *ti) {
+static void ui_textinput_complete(ui_textinput_t *ti) {
if(!ti->complete)
return;
if(!ti->c_q) {
@@ -785,7 +785,7 @@ static void ui_textinput_complete(struct ui_textinput *ti) {
}
-void ui_textinput_free(struct ui_textinput *ti) {
+void ui_textinput_free(ui_textinput_t *ti) {
ui_textinput_complete_reset(ti);
g_string_free(ti->str, TRUE);
if(ti->s_q)
@@ -794,19 +794,19 @@ void ui_textinput_free(struct ui_textinput *ti) {
}
-void ui_textinput_set(struct ui_textinput *ti, const char *str) {
+void ui_textinput_set(ui_textinput_t *ti, const char *str) {
g_string_assign(ti->str, str);
ti->pos = g_utf8_strlen(ti->str->str, -1);
}
-char *ui_textinput_get(struct ui_textinput *ti) {
+char *ui_textinput_get(ui_textinput_t *ti) {
return g_strdup(ti->str->str);
}
-char *ui_textinput_reset(struct ui_textinput *ti) {
+char *ui_textinput_reset(ui_textinput_t *ti) {
char *str = ui_textinput_get(ti);
ui_textinput_set(ti, "");
if(ti->usehist) {
@@ -825,7 +825,7 @@ char *ui_textinput_reset(struct ui_textinput *ti) {
// must be drawn last, to keep the cursor position correct
// also not the most efficient function ever, but probably fast enough.
-void ui_textinput_draw(struct ui_textinput *ti, int y, int x, int col) {
+void ui_textinput_draw(ui_textinput_t *ti, int y, int x, int col) {
// | |
// "Some random string etc etc"
// f # l
@@ -873,7 +873,7 @@ void ui_textinput_draw(struct ui_textinput *ti, int y, int x, int col) {
}
-static void ui_textinput_search(struct ui_textinput *ti, gboolean backwards) {
+static void ui_textinput_search(ui_textinput_t *ti, gboolean backwards) {
int start;
if(ti->s_pos < 0) {
if(!backwards) {
@@ -900,7 +900,7 @@ static void ui_textinput_search(struct ui_textinput *ti, gboolean backwards) {
}
-gboolean ui_textinput_key(struct ui_textinput *ti, guint64 key, char **str) {
+gboolean ui_textinput_key(ui_textinput_t *ti, guint64 key, char **str) {
int chars = g_utf8_strlen(ti->str->str, -1);
gboolean completereset = TRUE;
switch(key) {
@@ -1020,7 +1020,7 @@ gboolean ui_textinput_key(struct ui_textinput *ti, guint64 key, char **str) {
#if INTERFACE
-struct ui_listing {
+struct ui_listing_t {
GSequence *list;
GSequenceIter *sel;
GSequenceIter *top;
@@ -1071,14 +1071,14 @@ struct ui_listing {
// does not free the GSequence (we don't control the list, after all)
-#define ui_listing_free(ul) g_slice_free(struct ui_listing, ul)
+#define ui_listing_free(ul) g_slice_free(ui_listing_t, ul)
#endif
-struct ui_listing *ui_listing_create(GSequence *list) {
- struct ui_listing *ul = g_slice_new0(struct ui_listing);
+ui_listing_t *ui_listing_create(GSequence *list) {
+ ui_listing_t *ul = g_slice_new0(ui_listing_t);
ul->list = list;
ul->sel = ul->top = g_sequence_get_begin_iter(list);
ul->topisbegin = ul->selisbegin = TRUE;
@@ -1086,7 +1086,7 @@ struct ui_listing *ui_listing_create(GSequence *list) {
}
-gboolean ui_listing_key(struct ui_listing *ul, guint64 key, int page) {
+gboolean ui_listing_key(ui_listing_t *ul, guint64 key, int page) {
switch(key) {
case INPT_KEY(KEY_NPAGE): // page down
ul->sel = g_sequence_iter_move(ul->sel, page);
@@ -1125,7 +1125,7 @@ gboolean ui_listing_key(struct ui_listing *ul, guint64 key, int page) {
// Every item is assumed to occupy exactly one line.
// Returns the relative position of the current page (in percent)
-int ui_listing_draw(struct ui_listing *ul, int top, int bottom, void (*cb)(struct ui_listing *, GSequenceIter *, int, void *), void *dat) {
+int ui_listing_draw(ui_listing_t *ul, int top, int bottom, void (*cb)(ui_listing_t *, GSequenceIter *, int, void *), void *dat) {
// get or update the top row to make sure sel is visible
int height = 1 + bottom - top;
int row_last = g_sequence_iter_get_position(g_sequence_get_end_iter(ul->list));
diff --git a/src/util.c b/src/util.c
index 58785b5..237d3bf 100644
--- a/src/util.c
+++ b/src/util.c
@@ -929,7 +929,7 @@ char *darray_get_dat(char *v, int *l) {
/* How to use this:
* From main thread:
- * struct ratecalc thing;
+ * ratecalc_t thing;
* ratecalc_init(&thing);
* ratecalc_register(&thing, class);
* From any thread (usually some worker thread):
@@ -952,7 +952,7 @@ char *darray_get_dat(char *v, int *l) {
#define RCC_DOWN 4
#define RCC_MAX RCC_DOWN
-struct ratecalc {
+struct ratecalc_t {
GStaticMutex lock; // protects total, last, rate and burst
gint64 total;
gint64 last;
@@ -991,7 +991,7 @@ struct ratecalc {
GSList *ratecalc_list = NULL;
-void ratecalc_add(struct ratecalc *rc, int b) {
+void ratecalc_add(ratecalc_t *rc, int b) {
g_static_mutex_lock(&rc->lock);
rc->total += b;
rc->burst -= b;
@@ -999,7 +999,7 @@ void ratecalc_add(struct ratecalc *rc, int b) {
}
-int ratecalc_rate(struct ratecalc *rc) {
+int ratecalc_rate(ratecalc_t *rc) {
g_static_mutex_lock(&rc->lock);
int r = rc->rate;
g_static_mutex_unlock(&rc->lock);
@@ -1007,7 +1007,7 @@ int ratecalc_rate(struct ratecalc *rc) {
}
-int ratecalc_burst(struct ratecalc *rc) {
+int ratecalc_burst(ratecalc_t *rc) {
g_static_mutex_lock(&rc->lock);
int r = rc->burst;
g_static_mutex_unlock(&rc->lock);
@@ -1015,7 +1015,7 @@ int ratecalc_burst(struct ratecalc *rc) {
}
-gint64 ratecalc_total(struct ratecalc *rc) {
+gint64 ratecalc_total(ratecalc_t *rc) {
g_static_mutex_lock(&rc->lock);
gint64 r = rc->total;
g_static_mutex_unlock(&rc->lock);
@@ -1042,7 +1042,7 @@ void ratecalc_calc() {
// Pass one: calculate rc->rate, substract negative burst values from left[] and calculate nums[].
for(n=ratecalc_list; n; n=n->next) {
- struct ratecalc *rc = n->data;
+ ratecalc_t *rc = n->data;
g_static_mutex_lock(&rc->lock);
gint64 diff = rc->total - rc->last;
rc->rate = diff + ((rc->rate - diff) / 2);
@@ -1078,7 +1078,7 @@ void ratecalc_calc() {
break;
// Loop through the ratecalc structs and assign it some BW
for(n=ratecalc_list; n; n=n->next) {
- struct ratecalc *rc = n->data;
+ ratecalc_t *rc = n->data;
if(bwp[rc->reg] > 0) {
g_static_mutex_lock(&rc->lock);
int alloc = MIN(maxburst[rc->reg]-rc->burst, bwp[rc->reg]);
@@ -1099,7 +1099,7 @@ void ratecalc_calc() {
// calculates an ETA and formats it into a "?d ?h ?m ?s" thing
-char *ratecalc_eta(struct ratecalc *rc, guint64 left) {
+char *ratecalc_eta(ratecalc_t *rc, guint64 left) {
int sec = left / MAX(1, ratecalc_rate(rc));
return sec > 356*24*3600 ? "-" : str_formatinterval(sec);
}
@@ -1113,7 +1113,7 @@ char *ratecalc_eta(struct ratecalc *rc, guint64 left) {
#if INTERFACE
-struct logfile {
+struct logfile_t {
int file;
char *path;
struct stat st;
@@ -1126,7 +1126,7 @@ static GSList *logfile_instances = NULL;
// (Re-)opens the log file and checks for inode and file size changes.
-static void logfile_checkfile(struct logfile *l) {
+static void logfile_checkfile(logfile_t *l) {
// stat
gboolean restat = l->file < 0;
struct stat st;
@@ -1160,8 +1160,8 @@ static void logfile_checkfile(struct logfile *l) {
}
-struct logfile *logfile_create(const char *name) {
- struct logfile *l = g_slice_new0(struct logfile);
+logfile_t *logfile_create(const char *name) {
+ logfile_t *l = g_slice_new0(logfile_t);
l->file = -1;
char *n = g_strconcat(name, ".log", NULL);
@@ -1174,18 +1174,18 @@ struct logfile *logfile_create(const char *name) {
}
-void logfile_free(struct logfile *l) {
+void logfile_free(logfile_t *l) {
if(!l)
return;
logfile_instances = g_slist_remove(logfile_instances, l);
if(l->file >= 0)
close(l->file);
g_free(l->path);
- g_slice_free(struct logfile, l);
+ g_slice_free(logfile_t, l);
}
-void logfile_add(struct logfile *l, const char *msg) {
+void logfile_add(logfile_t *l, const char *msg) {
logfile_checkfile(l);
if(l->file < 0)
return;
@@ -1211,7 +1211,7 @@ void logfile_add(struct logfile *l, const char *msg) {
void logfile_global_reopen() {
GSList *n = logfile_instances;
for(; n; n=n->next) {
- struct logfile *l = n->data;
+ logfile_t *l = n->data;
if(l->file >= 0) {
close(l->file);
l->file = -1;
@@ -1232,7 +1232,7 @@ void logfile_global_reopen() {
//
// Usage:
// int fd = open(..);
-// struct fadv a;
+// fadv_t a;
// fadv_init(&a, fd, offset, flag);
// while((int len = read(..)) > 0)
// fadv_purge(&a, len);
@@ -1244,7 +1244,7 @@ void logfile_global_reopen() {
#if INTERFACE
-struct fadv {
+struct fadv_t {
int fd;
int chunk;
int flag;
@@ -1277,7 +1277,7 @@ struct fadv {
#ifdef HAVE_POSIX_FADVISE
// call with length = -1 to force a flush
-void fadv_purge(struct fadv *a, int length) {
+void fadv_purge(fadv_t *a, int length) {
if(length > 0)
a->chunk += length;
// flush every 5MB. Some magical value, don't think too much into it.
@@ -1297,10 +1297,10 @@ void fadv_purge(struct fadv *a, int length) {
// A GSource implementation to attach raw fds as a source to the main loop.
-struct fdsrc_obj {
+typedef struct fdsrc_t {
GSource src;
GPollFD fd;
-};
+} fdsrc_t;
static gboolean fdsrc_prepare(GSource *src, gint *timeout) {
*timeout = -1;
@@ -1308,7 +1308,7 @@ static gboolean fdsrc_prepare(GSource *src, gint *timeout) {
}
static gboolean fdsrc_check(GSource *src) {
- return ((struct fdsrc_obj *)src)->fd.revents > 0 ? TRUE : FALSE;
+ return ((fdsrc_t *)src)->fd.revents > 0 ? TRUE : FALSE;
}
static gboolean fdsrc_dispatch(GSource *src, GSourceFunc cb, gpointer dat) {
@@ -1321,7 +1321,7 @@ static void fdsrc_finalize(GSource *src) {
static GSourceFuncs fdsrc_funcs = { fdsrc_prepare, fdsrc_check, fdsrc_dispatch, fdsrc_finalize };
GSource *fdsrc_new(int fd, int ev) {
- struct fdsrc_obj *src = (struct fdsrc_obj *)g_source_new(&fdsrc_funcs, sizeof(struct fdsrc_obj));
+ fdsrc_t *src = (fdsrc_t *)g_source_new(&fdsrc_funcs, sizeof(fdsrc_t));
src->fd.fd = fd;
src->fd.events = ev;
src->fd.revents = 0;
diff --git a/src/vars.c b/src/vars.c
index 01ea2a5..e8cc59a 100644
--- a/src/vars.c
+++ b/src/vars.c
@@ -186,12 +186,12 @@ static gboolean s_active_conf(guint64 hub, const char *key, const char *val, GEr
}
-struct flag_option {
+typedef struct flag_option_t {
int num;
char *name;
-};
+} flag_option_t;
-static int flags_raw(struct flag_option *ops, gboolean multi, const char *val, GError **err) {
+static int flags_raw(flag_option_t *ops, gboolean multi, const char *val, GError **err) {
char **args = g_strsplit(val, ",", 0);
int r = 0, n = 0;
char **arg = args;
@@ -200,7 +200,7 @@ static int flags_raw(struct flag_option *ops, gboolean multi, const char *val, G
if(!**arg)
continue;
- struct flag_option *o = ops;
+ flag_option_t *o = ops;
for(; o->num; o++) {
if(strcmp(o->name, *arg) == 0) {
n++;
@@ -222,7 +222,7 @@ static int flags_raw(struct flag_option *ops, gboolean multi, const char *val, G
return r;
}
-static char *flags_fmt(struct flag_option *o, int val) {
+static char *flags_fmt(flag_option_t *o, int val) {
GString *s = g_string_new("");
for(; o->num; o++) {
if(val & o->num) {
@@ -234,7 +234,7 @@ static char *flags_fmt(struct flag_option *o, int val) {
return g_string_free(s, FALSE);
}
-static void flags_sug(struct flag_option *o, const char *val, char **sug) {
+static void flags_sug(flag_option_t *o, const char *val, char **sug) {
char *v = g_strdup(val);
char *attr = strrchr(v, ',');
if(attr)
@@ -362,7 +362,7 @@ static char *i_cid_pid() {
guint64 r = rand_64();
- struct tiger_ctx t;
+ tiger_ctx_t t;
char pid[24];
tiger_init(&t);
tiger_update(&t, (char *)&r, 8);
@@ -404,7 +404,7 @@ static void su_color(const char *old, const char *v, char **sug) {
else
attr = val;
g_strstrip(attr);
- struct ui_attr *a = ui_attr_names;
+ ui_attr_t *a = ui_attr_names;
int i = 0, len = strlen(attr);
for(; a->name[0] && i<20; a++)
if(strncmp(attr, a->name, len) == 0)
@@ -490,7 +490,7 @@ static char *p_encoding(const char *val, GError **err) {
}
static void su_encoding(const char *old, const char *val, char **sug) {
- static struct flag_option encoding_flags[] = {
+ static flag_option_t encoding_flags[] = {
{1,"CP1250"}, {1,"CP1251"}, {1,"CP1252"}, {1,"ISO-2022-JP"}, {1,"ISO-8859-2"}, {1,"ISO-8859-7"},
{1,"ISO-8859-8"}, {1,"ISO-8859-9"}, {1,"KOI8-R"}, {1,"LATIN1"}, {1,"SJIS"}, {1,"UTF-8"},
{1,"WINDOWS-1250"}, {1,"WINDOWS-1251"}, {1,"WINDOWS-1252"}, {0}
@@ -525,7 +525,7 @@ int var_ffc = 0;
#define VAR_FFC_HASH 8
#endif
-static struct flag_option var_ffc_ops[] = {
+static flag_option_t var_ffc_ops[] = {
{ VAR_FFC_NONE, "none" },
{ VAR_FFC_DOWNLOAD, "download" },
{ VAR_FFC_UPLOAD, "upload" },
@@ -616,7 +616,7 @@ static gboolean s_hubname(guint64 hub, const char *key, const char *val, GError
db_vars_set(hub, key, val);
GList *n;
for(n=ui_tabs; n; n=n->next) {
- struct ui_tab *t = n->data;
+ ui_tab_t *t = n->data;
if(t->type == UIT_HUB && t->hub->id == hub) {
g_free(t->name);
t->name = g_strdup(val);
@@ -675,7 +675,7 @@ static gboolean s_password(guint64 hub, const char *key, const char *val, GError
// send password to hub
GList *tab;
for(tab=ui_tabs; tab; tab=tab->next) {
- struct ui_tab *t = tab->data;
+ ui_tab_t *t = tab->data;
if(t->type == UIT_HUB && t->hub->id == hub && net_is_connected(t->hub->net) && !t->hub->nick_valid)
hub_password(t->hub, NULL);
}
@@ -714,7 +714,7 @@ static char *p_sendfile(const char *val, GError **err) {
#define VAR_TLSP_PREFER 4
#endif
-static struct flag_option var_tls_policy_ops[] = {
+static flag_option_t var_tls_policy_ops[] = {
{ VAR_TLSP_DISABLE, "disabled" },
{ VAR_TLSP_ALLOW, "allow" },
{ VAR_TLSP_PREFER, "prefer" },
@@ -778,7 +778,7 @@ static char *p_tls_priority(const char *val, GError **err) {
#if INTERFACE
-struct var {
+struct var_t {
// Name does not necessarily have to correspond to the name in the 'vars'
// table. Though in that case special getraw() and setraw() functions have to
// be used.
@@ -878,7 +878,7 @@ enum var_type {
#endif
-struct var vars[] = {
+var_t vars[] = {
#define V(n, gl, h, f, p, su, g, s, d) { G_STRINGIFY(n), gl, h, f, p, su, g, s, NULL },
#define C(n, d) { "color_"G_STRINGIFY(n), 1, 0, f_id, p_color, su_color, NULL, s_color, d },
VARS
diff --git a/src/xmlread.c b/src/xmlread.c
index 73bac49..95ea2fc 100644
--- a/src/xmlread.c
+++ b/src/xmlread.c
@@ -90,7 +90,7 @@ typedef int (*xml_read_t)(void *, char *, int, GError **);
#define MAX_DEPTH 50
#define READ_BUF_SIZE (32*1024)
-struct ctx {
+typedef struct ctx_t {
xml_cb_t cb;
xml_read_t read;
void *dat;
@@ -107,14 +107,14 @@ struct ctx {
int byte;
GError *err;
jmp_buf jmp;
-};
+} ctx_t;
// Helper functions
-static void err(struct ctx *x, const char *fmt, ...) {
+static void err(ctx_t *x, const char *fmt, ...) {
va_list arg;
va_start(arg, fmt);
if(!x->err) {
@@ -127,7 +127,7 @@ static void err(struct ctx *x, const char *fmt, ...) {
}
-static void callcb(struct ctx *x, int type, const char *arg1, const char *arg2) {
+static void callcb(ctx_t *x, int type, const char *arg1, const char *arg2) {
if(x->cb(x->dat, type, arg1, arg2, &x->err)) {
g_prefix_error(&x->err, "Line %d:%d: ", x->line, x->byte);
err(x, "Processing aborted by the application");
@@ -138,7 +138,7 @@ static void callcb(struct ctx *x, int type, const char *arg1, const char *arg2)
// Make sure we have more than n bytes in the buffer. Returns the buffer
// length, which may be smaller on EOF. Also validates that the XML data does
// not contain the 0 byte (this simplifies error checking a bit).
-static int fill(struct ctx *x, int n) {
+static int fill(ctx_t *x, int n) {
if(G_LIKELY(x->len >= n))
return x->len;
if(x->readeof)
@@ -166,14 +166,14 @@ static int fill(struct ctx *x, int n) {
// Require n bytes to be present, set error otherwise.
-static void rfill(struct ctx *x, int n) {
+static void rfill(ctx_t *x, int n) {
if(G_UNLIKELY(n >= x->len) && fill(x, n) < n)
err(x, "Unexpected EOF");
}
// consume some characters (also updates ->bytes and ->lines)
-static void con(struct ctx *x, int n) {
+static void con(ctx_t *x, int n) {
int i = 0;
while(i < n) {
if(x->buf[i++] == '\n') {
@@ -188,7 +188,7 @@ static void con(struct ctx *x, int n) {
// Validate and consume a string literal
-static void lit(struct ctx *x, const char *str) {
+static void lit(ctx_t *x, const char *str) {
int len = strlen(str);
rfill(x, len);
if(strncmp(x->buf, str, len) != 0)
@@ -212,7 +212,7 @@ static void lit(struct ctx *x, const char *str) {
// Consumes whitespace until an other character or EOF was found. If req, then
// there must be at least one whitespace character, otherwise it's optional.
-static void S(struct ctx *x, int req) {
+static void S(ctx_t *x, int req) {
if(req) {
rfill(x, 1);
if(!isWhiteSpace(*x->buf))
@@ -223,7 +223,7 @@ static void S(struct ctx *x, int req) {
}
-static void Eq(struct ctx *x) {
+static void Eq(ctx_t *x) {
S(x, 0);
lit(x, "=");
S(x, 0);
@@ -235,7 +235,7 @@ static void Eq(struct ctx *x) {
// Note: CharRef's are parsed but ignored. This is what DC++ does, and
// simplifies things a bit. Custom EntityRefs are not supported, only those
// predefined in the XML standard can be used.
-static int Reference(struct ctx *x, int n) {
+static int Reference(ctx_t *x, int n) {
con(x, 1); // Assuming the caller has already verified that this is indeed a Reference.
// We're currently parsing [^;]* here, while the standard requires a (more
@@ -289,7 +289,7 @@ static int Reference(struct ctx *x, int n) {
// Parses an attribute value and writes its (decoded) contents to x->val.
-static void AttValue(struct ctx *x) {
+static void AttValue(ctx_t *x) {
rfill(x, 2);
char esc = *x->buf;
if(esc != '"' && esc != '\'')
@@ -318,7 +318,7 @@ static void AttValue(struct ctx *x) {
}
-static void comment(struct ctx *x) {
+static void comment(ctx_t *x) {
lit(x, "<!--");
while(1) {
rfill(x, 3);
@@ -334,7 +334,7 @@ static void comment(struct ctx *x) {
// Consumes any number of whitespace and comments. (So it's actually Misc*)
-static void Misc(struct ctx *x) {
+static void Misc(ctx_t *x) {
while(fill(x, 4) >= 4) {
if(strncmp(x->buf, "<!--", 4) == 0) {
comment(x);
@@ -349,7 +349,7 @@ static void Misc(struct ctx *x) {
// Consumes a name and stores it in x->name.
-static void Name(struct ctx *x) {
+static void Name(ctx_t *x) {
rfill(x, 1);
int n = 0;
if(!isNameStartChar(*x->buf))
@@ -367,7 +367,7 @@ static void Name(struct ctx *x) {
// Returns the number of bytes consumed.
-static int CharData(struct ctx *x) {
+static int CharData(ctx_t *x) {
int r = 0;
while(fill(x, 3) >= 3) {
if(!isCharData(*x->buf))
@@ -388,9 +388,9 @@ static int CharData(struct ctx *x) {
}
-static void element(struct ctx *x);
+static void element(ctx_t *x);
-static void content(struct ctx *x) {
+static void content(ctx_t *x) {
CharData(x);
while(1) {
// Getting an EOF 2 bytes after content is always an error regardless of
@@ -411,7 +411,7 @@ static void content(struct ctx *x) {
}
-static void element(struct ctx *x) {
+static void element(ctx_t *x) {
if(x->level <= 0)
err(x, "Maximum element depth exceeded");
@@ -456,7 +456,7 @@ static void element(struct ctx *x) {
}
-static void XMLDecl(struct ctx *x) {
+static void XMLDecl(ctx_t *x) {
if(fill(x, 5) < 5 || strncmp(x->buf, "<?xml", 5) != 0)
return;
@@ -507,7 +507,7 @@ end:
// Parses the complete XML document, returns 0 on success or -1 on error.
int xml_parse(xml_cb_t cb, xml_read_t read, void *dat, GError **e) {
// Don't allocate this the stack, it's fairly large.
- struct ctx *x = g_new(struct ctx, 1);
+ ctx_t *x = g_new(ctx_t, 1);
x->dat = dat;
x->cb = cb;
x->read = read;