- phree(serialized_table);
- serialized_table = NULL;
- return(0);
-
- case UT_INSERT:
- /* Bail out if we can't generate a message ID */
- if (msg == NULL) {
- return(0);
- }
- if (msg->cm_fields['I'] == NULL) {
- return(0);
- }
- if (strlen(msg->cm_fields['I']) == 0) {
- return(0);
- }
-
- /* Generate the message ID */
- strcpy(msgid, msg->cm_fields['I']);
- if (haschar(msgid, '@') == 0) {
- strcat(msgid, "@");
- if (msg->cm_fields['N'] != NULL) {
- strcat(msgid, msg->cm_fields['N']);
- }
- else {
- return(0);
- }
- }
-
- /* Compare to the existing list */
- for (uptr = ut; uptr != NULL; uptr = uptr->next) {
- if (!strcasecmp(msgid, uptr->message_id)) {
- return(1);
- }
- }
-
- /* If we got to this point, it's unique: add it. */
- uptr = (struct UseTable *)
- mallok(sizeof(struct UseTable));
- if (uptr == NULL) return(0);
- uptr->next = ut;
- uptr->message_id = strdoop(msgid);
- uptr->timestamp = time(NULL);
- ut = uptr;
- return(0);
-
- case UT_SAVE:
- /* Figure out how big the serialized buffer should be */
- stlen = 0;
- for (uptr = ut; uptr != NULL; uptr = uptr->next) {
- stlen = stlen + strlen(uptr->message_id) + 20;
- }
- serialized_table = mallok(stlen);
- memset(serialized_table, 0, stlen);
-
- while (ut != NULL) {
- if ( (serialized_table != NULL)
- && ( (ut->timestamp - time(NULL)) <
- USETABLE_RETAIN) ) {
- sprintf(&serialized_table[strlen(
- serialized_table)], "%s|%ld\n",
- ut->message_id,
- (long)ut->timestamp);
- }
-
- /* Now free the memory */
- uptr = ut;
- ut = ut->next;
- phree(uptr->message_id);
- phree(uptr);
- }