1 /* $Id: overchan.c 6135 2003-01-19 01:15:40Z rra $
3 ** Parse input to add to news overview database.
8 #include "portable/time.h"
13 #include "inn/innconf.h"
14 #include "inn/messages.h"
21 unsigned int StartTime;
22 unsigned int TotOvTime;
25 * Timer function (lifted from innd/timer.c).
26 * This function is designed to report the number of milliseconds since
27 * the first invocation. I wanted better resolution than time(), and
28 * something easier to work with than gettimeofday()'s struct timeval's.
31 static unsigned gettime(void)
34 static struct timeval start_tv;
38 gettimeofday(&start_tv, NULL);
41 gettimeofday(&tv, NULL);
42 return((tv.tv_sec - start_tv.tv_sec) * 1000 + (tv.tv_usec - start_tv.tv_usec) / 1000);
46 ** Process the input. Data comes from innd in the form:
50 #define TEXT_TOKEN_LEN (2*sizeof(TOKEN)+2)
51 static void ProcessIncoming(QIOSTATE *qp)
56 unsigned int starttime, endtime;
60 /* Read the first line of data. */
61 if ((Data = QIOread(qp)) == NULL) {
63 warn("line too long");
69 if (Data[0] != '@' || strlen(Data) < TEXT_TOKEN_LEN+2
70 || Data[TEXT_TOKEN_LEN-1] != '@' || Data[TEXT_TOKEN_LEN] != ' ') {
71 warn("malformed token %s", Data);
74 token = TextToToken(Data);
75 Data += TEXT_TOKEN_LEN+1; /* skip over token and space */
76 for (p = Data; !ISWHITE(*p) ;p++) ;
78 Time = (time_t)atol(Data);
79 for (Data = p; !ISWHITE(*p) ;p++) ;
81 Expires = (time_t)atol(Data);
84 starttime = gettime();
85 if (OVadd(token, Data, strlen(Data), Time, Expires) == OVADDFAILED)
86 syswarn("cannot write overview %s", Data);
88 TotOvTime += endtime - starttime;
94 int main(int ac, char *av[])
99 /* First thing, set up our identity. */
100 message_program_name = "overchan";
102 /* Log warnings and fatal errors to syslog unless we were given command
103 line arguments, since we're probably running under innd. */
105 openlog("overchan", L_OPENLOG_FLAGS | LOG_PID, LOG_INN_PROG);
106 message_handlers_warn(1, message_log_syslog_err);
107 message_handlers_die(1, message_log_syslog_err);
108 message_handlers_notice(1, message_log_syslog_notice);
112 if (!innconf_read(NULL))
115 if (innconf->enableoverview && !innconf->useoverchan)
116 warn("overchan is running while innd is creating overview data (you"
117 " can ignore this message if you are running makehistory -F)");
122 if (!OVopen(OV_WRITE))
123 die("cannot open overview");
125 StartTime = gettime();
127 ProcessIncoming(QIOfdopen(STDIN_FILENO));
130 if (strcmp(*av, "-") == 0)
131 ProcessIncoming(QIOfdopen(STDIN_FILENO));
132 else if ((qp = QIOopen(*av)) == NULL)
133 syswarn("cannot open %s", *av);
139 notice("timings %u arts %u of %u ms", NumArts, TotOvTime, now - StartTime);