Annotation of 43BSDReno/usr.bin/talk/invite.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1983 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that: (1) source distributions retain this entire copyright
                      7:  * notice and comment, and (2) distributions including binaries display
                      8:  * the following acknowledgement:  ``This product includes software
                      9:  * developed by the University of California, Berkeley and its contributors''
                     10:  * in the documentation or other materials provided with the distribution
                     11:  * and in all advertising materials mentioning features or use of this
                     12:  * software. Neither the name of the University nor the names of its
                     13:  * contributors may be used to endorse or promote products derived
                     14:  * from this software without specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #ifndef lint
                     21: static char sccsid[] = "@(#)invite.c   5.7 (Berkeley) 6/1/90";
                     22: #endif /* not lint */
                     23: 
                     24: #include "talk_ctl.h"
                     25: #include <sys/time.h>
                     26: #include <signal.h>
                     27: #include <setjmp.h>
                     28: 
                     29: /*
                     30:  * There wasn't an invitation waiting, so send a request containing
                     31:  * our sockt address to the remote talk daemon so it can invite
                     32:  * him 
                     33:  */
                     34: 
                     35: /*
                     36:  * The msg.id's for the invitations
                     37:  * on the local and remote machines.
                     38:  * These are used to delete the 
                     39:  * invitations.
                     40:  */
                     41: int    local_id, remote_id;
                     42: void   re_invite();
                     43: jmp_buf invitebuf;
                     44: 
                     45: invite_remote()
                     46: {
                     47:        int nfd, read_mask, template, new_sockt;
                     48:        struct itimerval itimer;
                     49:        CTL_RESPONSE response;
                     50: 
                     51:        itimer.it_value.tv_sec = RING_WAIT;
                     52:        itimer.it_value.tv_usec = 0;
                     53:        itimer.it_interval = itimer.it_value;
                     54:        if (listen(sockt, 5) != 0)
                     55:                p_error("Error on attempt to listen for caller");
                     56: #ifdef MSG_EOR
                     57:        /* copy new style sockaddr to old, swap family (short in old) */
                     58:        msg.addr = *(struct osockaddr *)&my_addr;  /* XXX new to old  style*/
                     59:        msg.addr.sa_family = htons(my_addr.sin_family);
                     60: #else
                     61:        msg.addr = *(struct sockaddr *)&my_addr;
                     62: #endif
                     63:        msg.id_num = htonl(-1);         /* an impossible id_num */
                     64:        invitation_waiting = 1;
                     65:        announce_invite();
                     66:        /*
                     67:         * Shut off the automatic messages for a while,
                     68:         * so we can use the interupt timer to resend the invitation
                     69:         */
                     70:        end_msgs();
                     71:        setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0);
                     72:        message("Waiting for your party to respond");
                     73:        signal(SIGALRM, re_invite);
                     74:        (void) setjmp(invitebuf);
                     75:        while ((new_sockt = accept(sockt, 0, 0)) < 0) {
                     76:                if (errno == EINTR)
                     77:                        continue;
                     78:                p_error("Unable to connect with your party");
                     79:        }
                     80:        close(sockt);
                     81:        sockt = new_sockt;
                     82: 
                     83:        /*
                     84:         * Have the daemons delete the invitations now that we
                     85:         * have connected.
                     86:         */
                     87:        current_state = "Waiting for your party to respond";
                     88:        start_msgs();
                     89: 
                     90:        msg.id_num = htonl(local_id);
                     91:        ctl_transact(my_machine_addr, msg, DELETE, &response);
                     92:        msg.id_num = htonl(remote_id);
                     93:        ctl_transact(his_machine_addr, msg, DELETE, &response);
                     94:        invitation_waiting = 0;
                     95: }
                     96: 
                     97: /*
                     98:  * Routine called on interupt to re-invite the callee
                     99:  */
                    100: void
                    101: re_invite()
                    102: {
                    103: 
                    104:        message("Ringing your party again");
                    105:        current_line++;
                    106:        /* force a re-announce */
                    107:        msg.id_num = htonl(remote_id + 1);
                    108:        announce_invite();
                    109:        longjmp(invitebuf, 1);
                    110: }
                    111: 
                    112: static char *answers[] = {
                    113:        "answer #0",                                    /* SUCCESS */
                    114:        "Your party is not logged on",                  /* NOT_HERE */
                    115:        "Target machine is too confused to talk to us", /* FAILED */
                    116:        "Target machine does not recognize us",         /* MACHINE_UNKNOWN */
                    117:        "Your party is refusing messages",              /* PERMISSION_REFUSED */
                    118:        "Target machine can not handle remote talk",    /* UNKNOWN_REQUEST */
                    119:        "Target machine indicates protocol mismatch",   /* BADVERSION */
                    120:        "Target machine indicates protocol botch (addr)",/* BADADDR */
                    121:        "Target machine indicates protocol botch (ctl_addr)",/* BADCTLADDR */
                    122: };
                    123: #define        NANSWERS        (sizeof (answers) / sizeof (answers[0]))
                    124: 
                    125: /*
                    126:  * Transmit the invitation and process the response
                    127:  */
                    128: announce_invite()
                    129: {
                    130:        CTL_RESPONSE response;
                    131: 
                    132:        current_state = "Trying to connect to your party's talk daemon";
                    133:        ctl_transact(his_machine_addr, msg, ANNOUNCE, &response);
                    134:        remote_id = response.id_num;
                    135:        if (response.answer != SUCCESS) {
                    136:                if (response.answer < NANSWERS)
                    137:                        message(answers[response.answer]);
                    138:                quit();
                    139:        }
                    140:        /* leave the actual invitation on my talk daemon */
                    141:        ctl_transact(my_machine_addr, msg, LEAVE_INVITE, &response);
                    142:        local_id = response.id_num;
                    143: }
                    144: 
                    145: /*
                    146:  * Tell the daemon to remove your invitation
                    147:  */
                    148: send_delete()
                    149: {
                    150: 
                    151:        msg.type = DELETE;
                    152:        /*
                    153:         * This is just a extra clean up, so just send it
                    154:         * and don't wait for an answer
                    155:         */
                    156:        msg.id_num = htonl(remote_id);
                    157:        daemon_addr.sin_addr = his_machine_addr;
                    158:        if (sendto(ctl_sockt, &msg, sizeof (msg), 0, &daemon_addr,
                    159:            sizeof (daemon_addr)) != sizeof(msg))
                    160:                perror("send_delete (remote)");
                    161:        msg.id_num = htonl(local_id);
                    162:        daemon_addr.sin_addr = my_machine_addr;
                    163:        if (sendto(ctl_sockt, &msg, sizeof (msg), 0, &daemon_addr,
                    164:            sizeof (daemon_addr)) != sizeof (msg))
                    165:                perror("send_delete (local)");
                    166: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.