/* ParseGroup ** ---------- ** Extract the index number, subject etc, from a XOVER command. Expects ** the following format of the line: ** ** <index> <subject> <from> <data> <msgid> [*<thread>] ... ** ** Returns YES if OK, NO on error */ PRIVATE BOOL ParseGroup (HTRequest * request, HTNewsDir *dir, char * line) { int index; int refcnt=0; time_t t=0; char *subject = line; char *from; char *date; char *msgid; char *ptr=NULL; HTList* reflist = NULL; /* Added by MP. */ while (*subject && *subject != DELIMITER) subject++; *subject++ = '\0'; /* Index */ index = atoi(line); from = subject; while (*from && *from != DELIMITER) from++; *from++ = '\0'; /* Subject */ date = from; while (*date && *date != DELIMITER) { if (*date=='<' || *date=='(') { ptr = date+1; *date = '\0'; } if (*date=='>' || *date==')') *date = '\0'; date++; } *date++ = '\0'; if (strchr(from, ATSIGN) && ptr) from = ptr; /* From */ msgid = date; while (*msgid && *msgid != DELIMITER) msgid++; *msgid++ = '\0'; /* Date */ if (*msgid=='<') msgid++; t = HTParseTime(date, HTRequest_userProfile(request), YES); ptr = msgid; while (*ptr && *ptr != DELIMITER) { if (*ptr=='>') *ptr = '\0'; ptr++; } *ptr++ = '\0'; /* MsgId */ while (ptr && *ptr && !isdigit((int) *ptr)) { char* refstart = ptr; /* Added by MP. */ char* refcopy = NULL; char* refstop; while (*ptr && *ptr != DELIMITER && *ptr != ' ') ptr++; refstop = ptr - 1; *ptr++ = '\0'; if (strlen(refstart) > 0) /* Added by MP. */ { refcnt++; if (*refstart == '<') refstart++; if (*refstop == '>') *refstop = '\0'; if (reflist == NULL) reflist = HTList_new(); StrAllocCopy (refcopy, refstart); HTList_addObject (reflist, (void*) refcopy); } } /* Changed by MP. */ return (HTNewsDir_addElement(dir, index, subject, from, t, msgid, refcnt, reflist) != NULL); }
/* ** Last Modified */ PUBLIC time_t HTAnchor_lastModified (HTParentAnchor * me) { if (me) { if (me->last_modified == (time_t) -1 && me->headers) { char * value = HTAssocList_findObject(me->headers,"last-modified"); if (value) me->last_modified = HTParseTime(value, NULL, YES); } return me->last_modified; } return (time_t) -1; }
/* ** Expires */ PUBLIC time_t HTAnchor_expires (HTParentAnchor * me) { if (me) { if (me->expires == (time_t) -1 && me->headers) { char * value = HTAssocList_findObject(me->headers, "expires"); if (value) me->expires = HTParseTime(value, NULL, YES); } return me->expires; } return (time_t) -1; }
/* ** Date */ PUBLIC time_t HTAnchor_date (HTParentAnchor * me) { if (me) { if (me->date == (time_t) -1 && me->headers) { char * value = HTAssocList_findObject(me->headers, "date"); if (value) me->date = HTParseTime(value, NULL, YES); } return me->date; } return (time_t) -1; }
/* ** MIME header parser for the Set-Cookie header field. We parse the cookies ** and create HTCookie objects and store them in the cookie holder so that ** the cookie after filter can deal with them accordingly. */ PRIVATE int HTCookie_parseSetCookie (HTRequest * request, HTResponse * response, char * token, char * value) { char * cookie_name = NULL; char * cookie_value = NULL; if (HTCookie_splitPair(HTNextParam(&value), &cookie_name, &cookie_value) != HT_OK) { return HT_ERROR; /* Malformed Cookie */ } if (cookie_name && *cookie_name && cookie_value) { HTCookie * cookie = HTCookie_new(); char * param_pair; HTCookie_setName(cookie, cookie_name); HTCookie_setValue(cookie, cookie_value); /* Add the cookie to our holder */ HTCookieHolder_addCookie(request, cookie); /* Parse cookie parameters */ while ((param_pair = HTNextParam(&value))) { char * tok = NULL; char * val = NULL; if (HTCookie_splitPair(param_pair, &tok, &val) != HT_OK) { return HT_ERROR; /* Malformed Cookie */ } if (tok) { if (!strcasecomp(tok, "expires") && val && *val) { HTTRACE(STREAM_TRACE, "Cookie...... Expires `%s\'\n" _ val); HTCookie_setExpiration(cookie, HTParseTime(val, NULL, YES)); } else if (!strcasecomp(tok, "domain") && val && *val) { HTTRACE(STREAM_TRACE, "Cookie...... Domain `%s\'\n" _ val); HTCookie_setDomain(cookie, val); } else if (!strcasecomp(tok, "path") && val && *val) { HTTRACE(STREAM_TRACE, "Cookie...... Path `%s\'\n" _ val); HTCookie_setPath(cookie, val); } else if (!strcasecomp(tok, "secure")) { HTTRACE(STREAM_TRACE, "Cookie...... Secure `%s\'\n" _ val); HTCookie_setSecure(cookie, YES); } else HTTRACE(STREAM_TRACE, "Cookie...... Unknown `%s\' with value `%s\'\n" _ tok _ val ? val : "<null>"); } } } return HT_OK; }
int main (int argc, char ** argv) { HTSQL * sql = NULL; char * sqlserver = DEFAULT_SQL_SERVER; char * sqldb = DEFAULT_SQL_DB; char * sqluser = DEFAULT_SQL_USER; char * sqlpw = DEFAULT_SQL_PW; char * cvsuser = DEFAULT_CVS_USER; time_t cvsdate = -1; FILE * fin = stdin; char * input_buffer[BUFSIZE]; HTChunk * loginfo = HTChunk_new(BUFSIZE); int arg = 0; BOOL create_db = YES; /* Initiate libwww */ HTLibInit(APP_NAME, APP_VERSION); /* Scan command line for parameters */ for (arg=1; arg<argc; arg++) { if (*argv[arg] == '-') { if (!strcmp(argv[arg], "-h") || !strcmp(argv[arg], "-?")) { VersionInfo(); Cleanup(0, sql, loginfo); } else if (!strcmp(argv[arg], "-v")) { HTSetTraceMessageMask("q"); } else if (!strcmp(argv[arg], "-nocreate")) { create_db = NO; } else if (!strncmp(argv[arg], "-sqldb", 5)) { sqldb = (arg+1 < argc && *argv[arg+1] != '-') ? argv[++arg] : DEFAULT_SQL_DB; } else if (!strncmp(argv[arg], "-sqlpassword", 5)) { sqlpw = (arg+1 < argc && *argv[arg+1] != '-') ? argv[++arg] : DEFAULT_SQL_PW; } else if (!strncmp(argv[arg], "-sqlserver", 5)) { sqlserver = (arg+1 < argc && *argv[arg+1] != '-') ? argv[++arg] : DEFAULT_SQL_SERVER; } else if (!strncmp(argv[arg], "-sqluser", 5)) { sqluser = (arg+1 < argc && *argv[arg+1] != '-') ? argv[++arg] : DEFAULT_SQL_USER; } else if (!strncmp(argv[arg], "-cvsuser", 5)) { cvsuser = (arg+1 < argc && *argv[arg+1] != '-') ? argv[++arg] : DEFAULT_CVS_USER; } else if (!strncmp(argv[arg], "-cvsdate", 5)) { cvsdate = (arg+1 < argc && *argv[arg+1] != '-') ? HTParseTime(argv[++arg], NULL, NO) : -1; } else { fprintf(stderr, "Bad Argument (%s)\n", argv[arg]); } } else { fprintf(stderr, "Bad Argument (%s)\n", argv[arg]); } } /* Get an SQL object */ if ((sql = HTSQL_new(sqlserver, sqluser, sqlpw, 0)) == NULL) Cleanup(-1, sql, loginfo); /* Connect to the SQL server */ if (HTSQL_connect(sql) != YES) Cleanup(-1, sql, loginfo); /* Select our database */ if (HTSQL_selectDB(sql, sqldb) != YES) Cleanup(-1, sql, loginfo); /* Create our tables */ if (create_db) createTables(sql, 0); /* Read the arguments from stdin */ for (;;) { int status = fread(input_buffer, 1, BUFSIZE, fin); if (status < 0) Cleanup(-1, sql, loginfo); if (status == 0) break; HTChunk_putb(loginfo, (const char *) input_buffer, status); } /* Parse the input chunk */ { char * ptr = HTChunk_data(loginfo); char * noop1 = HTNextField(&ptr); char * noop2 = HTNextField(&ptr); char * root = HTNextField(&ptr); char * operation = NULL; char * files = NULL; char * comment = NULL; int comment_id = -1; int user_id = -1; char * p, * q; #ifdef HT_REENTRANT char *lasts; /* For strtok_r */ #endif /* Find shared log message and get id */ if ((q = HTStrCaseStr(ptr, "\nLog Message:")) != NULL) { comment = q+14; *q = '\0'; } if ((comment_id = add_comment(sql, comment)) < 0) Cleanup(-1, sql, loginfo); /* Add/find user and get id */ if ((user_id = add_user(sql, cvsuser)) < 0) Cleanup(-1, sql, loginfo); /* For each operation, find the files involved */ while ((q = HTStrCaseStr(ptr, " Files:")) != NULL) { /* Find the operation */ files = q+9; for (p=q; p>HTChunk_data(loginfo) && *p && *p!='\n'; p--); p++; operation = HTNextField(&p); /* Find the next line */ if ((q = strchr(files, '\n')) != NULL) { *q++ = '\0'; ptr = q; } /* Create the query */ if (operation && files && comment) { char * file; int location_id = -1; #ifdef HT_REENTRANT if ((file = strtok_r(files, DELIMITERS, &lasts)) != NULL) { #else if ((file = strtok(files, DELIMITERS)) != NULL) { #endif /* HT_REENTRANT */ do { char * path = NULL; StrAllocMCopy(&path, root, "/", file, NULL); /* Add/find location and get id */ if ((location_id = add_location(sql, path)) < 0) { Cleanup(-1, sql, loginfo); break; } #if 0 fprintf(stderr, "location: `%s\', user: `%s\', operation: `%s\', comment: `%s\'\n", path, cvsuser, operation, comment); #endif /* Add log entry */ { char buf[16384]; char * query = HTSQL_printf(buf, 16384, "insert into %s values (%u,%u,%T,%S,%u)", DEFAULT_SQL_LOG_TABLE, location_id, user_id, cvsdate, operation, comment_id); if (HTSQL_query(sql, query) != YES) { Cleanup(-1, sql, loginfo); break; } } HT_FREE(path); #ifdef HT_REENTRANT } while ((file = (char *) strtok_r(NULL, DELIMITERS, &lasts)) != NULL); #else } while ((file = strtok(NULL, DELIMITERS)) != NULL); #endif /* HT_REENTRANT */ } } } } return 0; }