meillo@367: /* meillo@367: ** MasqMail meillo@367: ** Copyright (C) 1999-2001 Oliver Kurth meillo@367: ** Copyright (C) 2008, 2010 markus schnalke meillo@367: ** meillo@367: ** This program is free software; you can redistribute it and/or modify meillo@367: ** it under the terms of the GNU General Public License as published by meillo@367: ** the Free Software Foundation; either version 2 of the License, or meillo@367: ** (at your option) any later version. meillo@367: ** meillo@367: ** This program is distributed in the hope that it will be useful, meillo@367: ** but WITHOUT ANY WARRANTY; without even the implied warranty of meillo@367: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the meillo@367: ** GNU General Public License for more details. meillo@367: ** meillo@367: ** You should have received a copy of the GNU General Public License meillo@367: ** along with this program; if not, write to the Free Software meillo@367: ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. meillo@0: */ meillo@0: meillo@0: #include meillo@15: meillo@0: #include "masqmail.h" meillo@0: #include "peopen.h" meillo@0: meillo@0: meillo@310: gchar* meillo@310: online_query() meillo@0: { meillo@366: gchar *pipe = conf.online_query; meillo@10: pid_t pid; meillo@10: void (*old_signal) (int); meillo@10: int status; meillo@10: FILE *in; meillo@10: gchar *name = NULL; meillo@0: meillo@310: if (!conf.online_query) { meillo@310: return NULL; meillo@310: } meillo@310: DEBUG(3) debugf("online query `%s'\n", pipe); meillo@310: meillo@10: old_signal = signal(SIGCHLD, SIG_DFL); meillo@0: meillo@10: in = peopen(pipe, "r", environ, &pid); meillo@310: if (!in) { meillo@33: logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", pipe, strerror(errno)); meillo@33: signal(SIGCHLD, old_signal); meillo@33: return NULL; meillo@33: } meillo@33: meillo@33: gchar output[256]; meillo@33: if (fgets(output, 255, in)) { meillo@33: g_strchomp(g_strchug(output)); meillo@33: if (strlen(output) == 0) { meillo@33: logwrite(LOG_ALERT, "only whitespace connection name\n"); meillo@33: name = NULL; meillo@18: } else { meillo@33: name = g_strdup(output); meillo@10: } meillo@33: } else { meillo@33: logwrite(LOG_ALERT, "nothing read from pipe %s\n", pipe); meillo@33: name = NULL; meillo@33: } meillo@33: fclose(in); meillo@33: waitpid(pid, &status, 0); meillo@262: if (WEXITSTATUS(status) != 0) { meillo@33: g_free(name); meillo@33: name = NULL; meillo@33: } meillo@0: meillo@10: signal(SIGCHLD, old_signal); meillo@0: meillo@10: return name; meillo@0: }