/* * This part deals with the history database and had * been originally written by * * Kai Uwe Rommel * * Bug reports related to THIS heavily modified version * should be sent to * * harald@os2point.ping.de * harald@haport.sesam.com * Fido: 2:2448/434 * */ #include #include #include #include #include #include #include #include #include #include #include #include /************************************************************************/ /* */ /* gethistart */ /* */ /* Finds an article entry in the history file by it's id and */ /* returns the path name of this article if found. */ /* */ /* Parameter Description */ /* ------------ ------------------------------------------------------- */ /* historyfile Points to a string that specifies the name of the */ /* history data base. Usually this will be "history". */ /* */ /* msg_id Points to a string that specifies the id of the */ /* message to search for. */ /* */ /* artpath Points to a buffer that receives the path to the */ /* message if found. This buffer must be preinitialized */ /* with the name of the newsgroup's home directory. */ /* If the caller doesn't need the path then this pointer */ /* may be NULL. */ /* ------------ ------------------------------------------------------- */ /* Return value True if found, false otherwise. */ /* */ /************************************************************************/ int gethistart(const char *historyfile, char *msg_id, char *artpath) { register char *cp; register char *cp1; char *line; DBM *db; datum key, val; char *histpag; int isvirgin; /* * If no history file exists we assume that we were * started in a virgin environment. We check this first * to avoid an error message while opening the database. */ histpag = malloc(strlen(historyfile) + 5); strcat(strcpy(histpag, historyfile), ".pag"); isvirgin = access(histpag, 0); free(histpag); if(isvirgin) return(0); /* * Fetch the entry with the given message id */ if((db = dbm_open(historyfile, O_RDONLY, 0)) != NULL) { key.dptr = msg_id; key.dsize = strlen(msg_id) + 1; val = dbm_fetch(db, key); if (val.dptr == NULL) { dbm_close(db); return(0); /* article not found */ } if(artpath == NULL) { dbm_close(db); return(1); /* article found, caller doesn't need path */ } /* * We need to copy the history line because dbm_close * will free the read buffer of the database. */ line = strdup(val.dptr); dbm_close(db); } else { lprintf("Failed to open %s", historyfile); return(0); } /* * We assume this structure of our history line *