2 * Dolda Connect - Modular multiuser Direct Connect-style client
3 * Copyright (C) 2007 Fredrik Tolf (fredrik@dolda2000.com)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 static regex_t *filter = NULL;
37 static pid_t fetchpid = 0;
38 static int listfd = -1;
39 static int iotag = -1;
40 static int (*handler)(int, char *, size_t) = NULL;
41 static char readbuf[65536];
42 static off_t bufpos = 0;
44 void aborthublist(void)
47 gdk_input_remove(iotag);
51 kill(fetchpid, SIGINT);
59 handler(PHO_FINI, NULL, 0);
65 int validhub(char *field, ...)
73 va_start(args, field);
75 if(!regexec(filter, field, 0, NULL, 0)) {
79 } while((field = va_arg(args, char *)) != NULL);
84 static void readcb(gpointer data, gint source, GdkInputCondition cond)
88 if(!(cond & GDK_INPUT_READ))
90 if(bufpos == sizeof(readbuf))
92 ret = read(listfd, readbuf + bufpos, sizeof(readbuf) - bufpos);
95 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not read from public hub listing process: %s"), strerror(errno));
97 handler(PHO_EOF, NULL, 0);
101 if((ret = handler(PHO_DATA, readbuf, (size_t)bufpos)) < 0)
104 memmove(readbuf, readbuf + ret, bufpos -= ret);
108 void fetchhublist(char *url, regex_t *flt)
117 if((fetchpid = fork()) == 0) {
121 execlp("wget", "wget", "-qO", "-", url, NULL);
129 if((len > 4) && !strncmp(p - 4, ".bz2", 4)) {
139 execlp("bzcat", "bzcat", NULL);
147 if((len > 4) && !strncmp(p - 4, ".xml", 4)) {
150 handler = pubhubxmlhandler;
152 handler = pubhuboldhandler;
155 handler(PHO_INIT, NULL, 0);
156 iotag = gdk_input_add(listfd, GDK_INPUT_READ, readcb, NULL);