Annotation of cci/usr/src/ucb/talk/invite.c, revision 1.1.1.1

1.1       root        1: /* $Header: invite.c,v 1.2 85/01/09 13:04:57 rcs Exp $ */
                      2: 
                      3: #include "talk_ctl.h"
                      4: #include <sys/time.h>
                      5: #include <signal.h>
                      6: #include <setjmp.h>
                      7:     
                      8:     /*
                      9:      * there wasn't an invitation waiting, so send a request containing
                     10:      * our sockt address to the remote talk daemon so it can invite
                     11:      * him 
                     12:      */
                     13: 
                     14: int local_id, remote_id;       /* the msg.id's for the invitations
                     15:                                   on the local and remote machines.
                     16:                                   These are used to delete the 
                     17:                                   invitations. */
                     18: void re_invite();
                     19: jmp_buf        invitebuf;
                     20: 
                     21: int    vaxbyteorder;           /* if set, messages are sent in vax-byte-order*/
                     22: int    tonetmsg();
                     23: int    tonetresp();
                     24: 
                     25: invite_remote()
                     26: {
                     27:     int nfd, read_mask, template, new_sockt;
                     28:     struct itimerval itimer;
                     29:     CTL_RESPONSE response;
                     30: 
                     31:     itimer.it_value.tv_sec = RING_WAIT;
                     32:     itimer.it_value.tv_usec = 0;
                     33:     itimer.it_interval = itimer.it_value;
                     34: 
                     35:     if (listen(sockt, 5) != 0) {
                     36:        p_error("Error on attempt to listen for caller");
                     37:     }
                     38: 
                     39:     msg.ctlm_addr = my_addr;
                     40:     msg.ctlm_id_num = -1;              /* an impossible id_num */
                     41: 
                     42:     invitation_waiting = 1;
                     43: 
                     44:     announce_invite();
                     45: 
                     46:        /*
                     47:         * shut off the automatic messages for a while,
                     48:         * so we can use the interupt timer to resend the invitation
                     49:         */
                     50: 
                     51:     end_msgs();
                     52:     setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0);
                     53:     message("Waiting for your party to respond");
                     54:     signal(SIGALRM, re_invite);
                     55:     (void) setjmp(invitebuf);
                     56: 
                     57:     while ((new_sockt = accept(sockt, 0, 0)) < 0) {
                     58:        if (errno != EINTR) {
                     59:            p_error("Unable to connect with your party");
                     60:        } else {
                     61:            /* we just returned from a interupt, keep trying */
                     62:            continue;
                     63:        }
                     64:     }
                     65: 
                     66:     close(sockt);
                     67:     sockt = new_sockt;
                     68: 
                     69:        /* have the daemons delete the invitations now that we
                     70:           have connected.
                     71:         */
                     72: 
                     73:     current_state = "Waiting for your party to respond";
                     74:     start_msgs();
                     75: 
                     76:     msg.ctlm_id_num = local_id;
                     77:     ctl_transact(my_machine_addr, msg, DELETE, &response);
                     78:     msg.ctlm_id_num = remote_id;
                     79:     ctl_transact(his_machine_addr, msg, DELETE, &response);
                     80:     invitation_waiting = 0;
                     81: }
                     82: 
                     83:     /* routine called on interupt to re-invite the callee */
                     84: 
                     85: void re_invite()
                     86: {
                     87:     message("Ringing your party again");
                     88:     current_line++;
                     89:        /* force a re-announce */
                     90:     msg.ctlm_id_num = remote_id + 1;
                     91:     announce_invite();
                     92:     longjmp(invitebuf, 1);
                     93: }
                     94: 
                     95:     /* transmit the invitation and process the response */
                     96: 
                     97: announce_invite()
                     98: {
                     99:     CTL_RESPONSE response;
                    100: 
                    101:     current_state = "Trying to connect to your party's talk daemon";
                    102: 
                    103:     ctl_transact(his_machine_addr, msg, ANNOUNCE, &response);
                    104:     remote_id = response.ctlr_id_num;
                    105: 
                    106:     if (response.ctlr_answer != SUCCESS) {
                    107: 
                    108:        switch (response.ctlr_answer) {
                    109:            
                    110:            case NOT_HERE :
                    111:                message("Your party is not logged on");
                    112:                break;
                    113: 
                    114:            case MACHINE_UNKNOWN :
                    115:                message("Target machine does not recognize us");
                    116:                break;
                    117: 
                    118:            case UNKNOWN_REQUEST :
                    119:                message("Target machine can not handle remote talk");
                    120:                break;
                    121: 
                    122:            case FAILED :
                    123:                message("Target machine is too confused to talk to us");
                    124:                break;
                    125: 
                    126:            case PERMISSION_DENIED :
                    127:                message("Your party is refusing messages");
                    128:                break;
                    129:        }
                    130: 
                    131:        quit();
                    132:     }
                    133: 
                    134:        /* leave the actual invitation on my talk daemon */
                    135: 
                    136: #ifdef DEBUG
                    137:     printf("tell my daemon\n");
                    138: #endif
                    139:     ctl_transact(my_machine_addr, msg, LEAVE_INVITE, &response);
                    140:     local_id = response.ctlr_id_num;
                    141: }
                    142:     
                    143: send_delete()
                    144: {
                    145:     NETCTL_MSG netmsg;         /* for conversion to VAX Berkeley format */
                    146: 
                    147:        /* tell the daemon to remove your invitation */
                    148: 
                    149:     msg.ctlm_type = DELETE;
                    150: 
                    151:        /* this is just a extra clean up, so just send it
                    152:           and don't wait for an answer */
                    153: 
                    154:     msg.ctlm_id_num = remote_id;
                    155:     daemon_addr.sin_addr = his_machine_addr;
                    156:     tonetmsg(&msg, &netmsg, vaxbyteorder);
                    157:     if (sendto(ctl_sockt, &netmsg, sizeof(netmsg), 0, &daemon_addr,
                    158:                    sizeof(daemon_addr)) != sizeof(netmsg)) {
                    159:            perror("send_delete remote");
                    160:     }
                    161: 
                    162:     msg.ctlm_id_num = local_id;
                    163:     daemon_addr.sin_addr = my_machine_addr;
                    164:     tonetmsg(&msg, &netmsg, vaxbyteorder);
                    165:     if (sendto(ctl_sockt, &netmsg, sizeof(netmsg), 0, &daemon_addr,
                    166:                    sizeof(daemon_addr)) != sizeof(netmsg)) {
                    167:            perror("send_delete local");
                    168:     }
                    169: }

unix.superglobalmegacorp.com

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