From bdef296246f30b38a4d23a28e4ae1fa9e0830542 Mon Sep 17 00:00:00 2001 From: "David C. Jedlinsky" Date: Thu, 25 Feb 1988 14:27:40 +0000 Subject: Changed "hm.h" to "zhm.h", fixed a few things that lint was complaining about. --- zhm/queue.c | 377 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 189 insertions(+), 188 deletions(-) (limited to 'zhm') diff --git a/zhm/queue.c b/zhm/queue.c index 987b2c2..3017e4f 100644 --- a/zhm/queue.c +++ b/zhm/queue.c @@ -11,7 +11,7 @@ * "mit-copyright.h". */ -#include "hm.h" +#include "zhm.h" #ifndef lint #ifndef SABER @@ -20,244 +20,245 @@ static char rcsid_queue_c[] = "$Header$"; #endif lint typedef struct _Queue { - long timeout; - int retries; - ZNotice_t z_notice; - caddr_t z_packet; - struct sockaddr_in reply; + long timeout; + int retries; + ZNotice_t z_notice; + caddr_t z_packet; + struct sockaddr_in reply; } Queue; struct _qelem { - struct _qelem *q_forw; - struct _qelem *q_back; - Queue *q_data; + struct _qelem *q_forw; + struct _qelem *q_back; + Queue *q_data; }; typedef struct _qelem Qelem; Qelem hm_queue = { &hm_queue, &hm_queue, NULL }, *is_in_queue(); -long time(); +extern long time(); extern int timeout_type; Code_t init_queue() { - while (hm_queue.q_forw != &hm_queue) { - free(hm_queue.q_forw->q_data->z_packet); - free(hm_queue.q_forw->q_data); - remque(hm_queue.q_forw); - free(hm_queue.q_forw); - } + while (hm_queue.q_forw != &hm_queue) { + free(hm_queue.q_forw->q_data->z_packet); + free((char *)hm_queue.q_forw->q_data); + remque(hm_queue.q_forw); + free((char *)hm_queue.q_forw); + } - hm_queue.q_forw = hm_queue.q_back = &hm_queue; - hm_queue.q_data = NULL; - DPR ("Queue initialized and flushed.\n"); + hm_queue.q_forw = hm_queue.q_back = &hm_queue; + hm_queue.q_data = NULL; + DPR ("Queue initialized and flushed.\n"); } Code_t add_notice_to_queue(notice, packet, repl, len) - ZNotice_t *notice; - caddr_t packet; - struct sockaddr_in *repl; - int len; +ZNotice_t *notice; +caddr_t packet; +struct sockaddr_in *repl; +int len; { - Qelem *elem; - Queue *entry; - Code_t ret; + Qelem *elem; + Queue *entry; - DPR ("Adding notice to queue...\n"); - if (!is_in_queue(notice)) { - elem = (Qelem *)malloc(sizeof(Qelem)); - entry = (Queue *)malloc(sizeof(Queue)); - entry->timeout = time(NULL) + NOTICE_TIMEOUT; - entry->retries = 0; - entry->z_packet = (char *)malloc(Z_MAXPKTLEN); - bcopy(packet, entry->z_packet, Z_MAXPKTLEN); - if ((ret = ZParseNotice(entry->z_packet, len, &entry->z_notice)) - != ZERR_NONE) { - syslog(LOG_ERR, "ZParseNotice failed, but succeeded before"); - free(entry->z_packet); - } else { - entry->reply = *repl; - elem->q_data = entry; - elem->q_forw = elem; - elem->q_back = elem; - insque(elem, hm_queue.q_back); - } - } + DPR ("Adding notice to queue...\n"); + if (!is_in_queue(notice)) { + elem = (Qelem *)malloc(sizeof(Qelem)); + entry = (Queue *)malloc(sizeof(Queue)); + entry->timeout = time((time_t *)0) + NOTICE_TIMEOUT; + entry->retries = 0; + entry->z_packet = (char *)malloc(Z_MAXPKTLEN); + bcopy(packet, entry->z_packet, Z_MAXPKTLEN); + if (ZParseNotice(entry->z_packet, len, &entry->z_notice) + != ZERR_NONE) { + syslog(LOG_ERR, "ZParseNotice failed, but succeeded before"); + free(entry->z_packet); + } else { + entry->reply = *repl; + elem->q_data = entry; + elem->q_forw = elem; + elem->q_back = elem; + insque(elem, hm_queue.q_back); + } + } #ifdef DEBUG - if (!is_in_queue(notice)) - return(ZERR_NONOTICE); - else + if (!is_in_queue(notice)) + return(ZERR_NONOTICE); + else #endif DEBUG - return(ZERR_NONE); + return(ZERR_NONE); } Code_t remove_notice_from_queue(notice, kind, repl) - ZNotice_t *notice; - ZNotice_Kind_t *kind; - struct sockaddr_in *repl; +ZNotice_t *notice; +ZNotice_Kind_t *kind; +struct sockaddr_in *repl; { - Qelem *elem; + Qelem *elem; - DPR ("Removing notice from queue...\n"); - if ((elem = is_in_queue(notice)) == NULL) - return(ZERR_NONOTICE); - else { - *kind = elem->q_data->z_notice.z_kind; - *repl = elem->q_data->reply; - free(elem->q_data->z_packet); - free(elem->q_data); - remque(elem); - free(elem); - if (hm_queue.q_forw == &hm_queue) - (void)alarm(0); + DPR ("Removing notice from queue...\n"); + if ((elem = is_in_queue(notice)) == NULL) + return(ZERR_NONOTICE); + else { + *kind = elem->q_data->z_notice.z_kind; + *repl = elem->q_data->reply; + free(elem->q_data->z_packet); + free((char *)elem->q_data); + remque(elem); + free((char *)elem); + if (hm_queue.q_forw == &hm_queue) + (void)alarm(0); #ifdef DEBUG - dump_queue(); + dump_queue(); #endif DEBUG - return(ZERR_NONE); - } + return(ZERR_NONE); + } } Code_t retransmit_queue(sin) - struct sockaddr_in *sin; +struct sockaddr_in *sin; { - Qelem *srch; - Code_t ret; + Qelem *srch; + Code_t ret; - DPR ("Retransmitting queue to new server...\n"); - if ((ret = ZSetDestAddr(sin)) != ZERR_NONE) { - Zperr (ret); - com_err("queue", ret, "setting destination"); - } - if ((srch = hm_queue.q_forw) != &hm_queue) { - do { - DPR ("notice:\n"); - DPR2 ("\tz_kind: %d\n", srch->q_data->z_notice.z_kind); - DPR2 ("\tz_port: %u\n", - ntohs(srch->q_data->z_notice.z_port)); - DPR2 ("\tz_class: %s\n", srch->q_data->z_notice.z_class); - DPR2 ("\tz_clss_inst: %s\n", - srch->q_data->z_notice.z_class_inst); - DPR2 ("\tz_opcode: %s\n", srch->q_data->z_notice.z_opcode); - DPR2 ("\tz_sender: %s\n", srch->q_data->z_notice.z_sender); - DPR2 ("\tz_recip: %s\n", srch->q_data->z_notice.z_recipient); - if ((ret = ZSendRawNotice(&srch->q_data->z_notice)) - != ZERR_NONE) { - Zperr (ret); - com_err("queue", ret, "sending raw notice"); - } - srch->q_data->timeout = NOTICE_TIMEOUT; - srch->q_data->retries = 0; - srch = srch->q_forw; - } while (srch != &hm_queue); - timeout_type = NOTICES; - (void)alarm(NOTICE_TIMEOUT); - } + DPR ("Retransmitting queue to new server...\n"); + if ((ret = ZSetDestAddr(sin)) != ZERR_NONE) { + Zperr (ret); + com_err("queue", ret, "setting destination"); + } + if ((srch = hm_queue.q_forw) != &hm_queue) { + do { + DPR ("notice:\n"); + DPR2 ("\tz_kind: %d\n", srch->q_data->z_notice.z_kind); + DPR2 ("\tz_port: %u\n", + ntohs(srch->q_data->z_notice.z_port)); + DPR2 ("\tz_class: %s\n", srch->q_data->z_notice.z_class); + DPR2 ("\tz_clss_inst: %s\n", + srch->q_data->z_notice.z_class_inst); + DPR2 ("\tz_opcode: %s\n", srch->q_data->z_notice.z_opcode); + DPR2 ("\tz_sender: %s\n", srch->q_data->z_notice.z_sender); + DPR2 ("\tz_recip: %s\n", srch->q_data->z_notice.z_recipient); + if ((ret = ZSendRawNotice(&srch->q_data->z_notice)) + != ZERR_NONE) { + Zperr (ret); + com_err("queue", ret, "sending raw notice"); + } + srch->q_data->timeout = NOTICE_TIMEOUT; + srch->q_data->retries = 0; + srch = srch->q_forw; + } while (srch != &hm_queue); + timeout_type = NOTICES; + (void)alarm(NOTICE_TIMEOUT); + } } +#ifdef DEBUG Code_t dump_queue() { - Qelem *srch; - caddr_t mp; - int ml; + Qelem *srch; + caddr_t mp; + int ml; - DPR ("Dumping queue...\n"); - if ((srch = hm_queue.q_forw) == &hm_queue) - printf("Queue is empty.\n"); - else do { - printf("notice:\n"); - printf("\tz_kind: %d\n", srch->q_data->z_notice.z_kind); - printf("\tz_port: %u\n", ntohs(srch->q_data->z_notice.z_port)); - printf("\tz_class: %s\n", srch->q_data->z_notice.z_class); - printf("\tz_clss_inst: %s\n", srch->q_data->z_notice.z_class_inst); - printf("\tz_opcode: %s\n", srch->q_data->z_notice.z_opcode); - printf("\tz_sender: %s\n", srch->q_data->z_notice.z_sender); - printf("\tz_recip: %s\n", srch->q_data->z_notice.z_recipient); - printf("\tMessage:\n"); - mp = srch->q_data->z_notice.z_message; - for (ml = strlen(mp)+1; - ml <= srch->q_data->z_notice.z_message_len; ml++) { - printf("\t%s\n", mp); - mp += strlen(mp)+1; - ml += strlen(mp); - } - srch = srch->q_forw; - } while (srch != &hm_queue); + DPR ("Dumping queue...\n"); + if ((srch = hm_queue.q_forw) == &hm_queue) + printf("Queue is empty.\n"); + else do { + printf("notice:\n"); + printf("\tz_kind: %d\n", srch->q_data->z_notice.z_kind); + printf("\tz_port: %u\n", ntohs(srch->q_data->z_notice.z_port)); + printf("\tz_class: %s\n", srch->q_data->z_notice.z_class); + printf("\tz_clss_inst: %s\n", srch->q_data->z_notice.z_class_inst); + printf("\tz_opcode: %s\n", srch->q_data->z_notice.z_opcode); + printf("\tz_sender: %s\n", srch->q_data->z_notice.z_sender); + printf("\tz_recip: %s\n", srch->q_data->z_notice.z_recipient); + printf("\tMessage:\n"); + mp = srch->q_data->z_notice.z_message; + for (ml = strlen(mp)+1; + ml <= srch->q_data->z_notice.z_message_len; ml++) { + printf("\t%s\n", mp); + mp += strlen(mp)+1; + ml += strlen(mp); + } + srch = srch->q_forw; + } while (srch != &hm_queue); } +#endif DEBUG int queue_len() { - int length = 0; - Qelem *srch; + int length = 0; + Qelem *srch; - if ((srch = hm_queue.q_forw) != &hm_queue) { - do { - length++; - srch = srch->q_forw; - } while (srch != &hm_queue); - } - return(length); + if ((srch = hm_queue.q_forw) != &hm_queue) { + do { + length++; + srch = srch->q_forw; + } while (srch != &hm_queue); + } + return(length); } Qelem *is_in_queue(notice) - ZNotice_t *notice; +ZNotice_t *notice; { - Qelem *srch; + Qelem *srch; - srch = hm_queue.q_forw; - if (srch == &hm_queue) - return(NULL); - do { - if (ZCompareUID(&(srch->q_data->z_notice.z_uid), &(notice->z_uid))) - return(srch); - srch = srch->q_forw; - } while (srch != &hm_queue); - return(NULL); + srch = hm_queue.q_forw; + if (srch == &hm_queue) + return(NULL); + do { + if (ZCompareUID(&(srch->q_data->z_notice.z_uid), &(notice->z_uid))) + return(srch); + srch = srch->q_forw; + } while (srch != &hm_queue); + return(NULL); } void resend_notices(sin) - struct sockaddr_in *sin; +struct sockaddr_in *sin; { - Qelem *srch; - Code_t ret; + Qelem *srch; + Code_t ret; - DPR ("Resending notices...\n"); - if ((ret = ZSetDestAddr(sin)) != ZERR_NONE) { - Zperr(ret); - com_err("queue", ret, "setting destination"); - } - if ((srch = hm_queue.q_forw) == &hm_queue) { - syslog (LOG_INFO, "No notices, shouldn't have happened!"); - } else do { - if (srch->q_data->timeout <= time(NULL)) { - if (++(srch->q_data->retries) > MAXRETRIES) { - new_server(NULL); - break; - } else { - DPR ("notice:\n"); - DPR2 ("\tz_kind: %d\n", srch->q_data->z_notice.z_kind); - DPR2 ("\tz_port: %u\n", - ntohs(srch->q_data->z_notice.z_port)); - DPR2 ("\tz_class: %s\n", - srch->q_data->z_notice.z_class); - DPR2 ("\tz_clss_inst: %s\n", - srch->q_data->z_notice.z_class_inst); - DPR2 ("\tz_opcode: %s\n", - srch->q_data->z_notice.z_opcode); - DPR2 ("\tz_sender: %s\n", - srch->q_data->z_notice.z_sender); - DPR2 ("\tz_recip: %s\n", - srch->q_data->z_notice.z_recipient); - if ((ret = ZSendRawNotice(&srch->q_data->z_notice)) - != ZERR_NONE) { - Zperr(ret); - com_err("queue", ret, "sending raw notice"); - } - srch->q_data->timeout = time(NULL) + NOTICE_TIMEOUT; - srch = srch->q_forw; - } - } - } while (srch != &hm_queue); - timeout_type = NOTICES; - (void)alarm(NOTICE_TIMEOUT); + DPR ("Resending notices...\n"); + if ((ret = ZSetDestAddr(sin)) != ZERR_NONE) { + Zperr(ret); + com_err("queue", ret, "setting destination"); + } + if ((srch = hm_queue.q_forw) == &hm_queue) { + syslog (LOG_INFO, "No notices, shouldn't have happened!"); + } else do { + if (srch->q_data->timeout <= time((time_t *)0)) { + if (++(srch->q_data->retries) > MAXRETRIES) { + new_server((char *)NULL); + break; + } else { + DPR ("notice:\n"); + DPR2 ("\tz_kind: %d\n", srch->q_data->z_notice.z_kind); + DPR2 ("\tz_port: %u\n", + ntohs(srch->q_data->z_notice.z_port)); + DPR2 ("\tz_class: %s\n", + srch->q_data->z_notice.z_class); + DPR2 ("\tz_clss_inst: %s\n", + srch->q_data->z_notice.z_class_inst); + DPR2 ("\tz_opcode: %s\n", + srch->q_data->z_notice.z_opcode); + DPR2 ("\tz_sender: %s\n", + srch->q_data->z_notice.z_sender); + DPR2 ("\tz_recip: %s\n", + srch->q_data->z_notice.z_recipient); + if ((ret = ZSendRawNotice(&srch->q_data->z_notice)) + != ZERR_NONE) { + Zperr(ret); + com_err("queue", ret, "sending raw notice"); + } + srch->q_data->timeout = time((time_t *)0) + NOTICE_TIMEOUT; + srch = srch->q_forw; + } + } + } while (srch != &hm_queue); + timeout_type = NOTICES; + (void)alarm(NOTICE_TIMEOUT); } -- cgit v1.2.3