-static char *prnpstate P((pstate_t s));
-static char *prnaction P((action_t s));
-#ifdef PROTO_DEBUG
-static char *prnpktype P((pktype_t s));
-#endif
-static void pending_enqueue P((proto_t *newp));
-static proto_t *pending_dequeue P((void));
-static void pending_remove P((proto_t *p));
-static void alloc_handle P((proto_t *p));
-static void free_handle P((proto_t *p));
-static void hex P((char *str, int digits, unsigned int v));
-static int unhex P((char *str, int digits));
-static proto_t *handle2ptr P((char *str));
-static char *ptr2handle P((proto_t *p));
-static void eat_string P((dgram_t *msg, char *str));
-static int parse_integer P((dgram_t *msg));
-static char *parse_string P((dgram_t *msg));
-static char *parse_line P((dgram_t *msg));
-void parse_pkt_header P((pkt_t *pkt));
-static void setup_dgram P((proto_t *p, dgram_t *msg,
- char *security, char *typestr));
-static void send_req P((proto_t *p));
-static void send_ack P((proto_t *p));
-static void send_ack_repl P((pkt_t *pkt));
-static void state_machine P((proto_t *p, action_t action, pkt_t *pkt));
-static void add_bsd_security P((proto_t *p));
-static int select_til P((time_t waketime));
-static int packet_arrived P((void));
-static void handle_incoming_packet P((void));
-
-
-/* -------------- */
-
-
-static char *prnpstate(s)
-pstate_t s;
-{
- static char str[80];
-
- switch(s) {
- case S_BOGUS: return "S_BOGUS";
- case S_STARTUP: return "S_STARTUP";
- case S_SENDREQ: return "S_SENDREQ";
- case S_ACKWAIT: return "S_ACKWAIT";
- case S_REPWAIT: return "S_REPWAIT";
- case S_SUCCEEDED: return "S_SUCCEEDED";
- case S_FAILED: return "S_FAILED";
- default:
- ap_snprintf(str, sizeof(str), "<bad state %d>", s);
- return str;
- }
-}
-
-static char *prnaction(s)
-action_t s;
-{
- static char str[80];
-
- switch(s) {
- case A_BOGUS: return "A_BOGUS";
- case A_START: return "A_START";
- case A_TIMEOUT: return "A_TIMEOUT";
- case A_RCVDATA: return "A_RCVDATA";
- default:
- ap_snprintf(str, sizeof(str), "<bad action %d>", s);
- return str;
- }
-}
-
-#ifdef PROTO_DEBUG
-
-static char *prnpktype(s)
-pktype_t s;
-{
- static char str[80];
-
- switch(s) {
- case P_BOGUS: return "P_BOGUS";
- case P_REQ: return "P_REQ";
- case P_REP: return "P_REP";
- case P_ACK: return "P_ACK";
- case P_NAK: return "P_NAK";
- default:
- ap_snprintf(str, sizeof(str), "<bad pktype %d>", s);
- return str;
- }
-}
-
-#endif
-
-
-void proto_init(socket, startseq, handles)
-int socket, startseq, handles;
-{
- int i;
-
-#ifdef PROTO_DEBUG
- dbprintf(("%s: proto_init(socket %d, startseq %d, handles %d)\n",
- debug_prefix_time(": protocol"),
- socket,
- startseq,
- handles));
-#endif
- if(socket < 0 || socket >= FD_SETSIZE) {
- error("proto_init: socket %d out of range (0 .. %d)\n",
- socket, FD_SETSIZE-1);
- }
- proto_socket = socket;
- proto_global_seq = startseq;
- proto_handles = handles;
-
- proto_handle_table = alloc(proto_handles * sizeof(proto_t *));
- malloc_mark(proto_handle_table);
- proto_next_handle = proto_handle_table;
- for(i = 0; i < proto_handles; i++)
- proto_handle_table[i] = NULL;
- proto_init_time = time(0);
-}