# 2.11BSD#431 - /usr/src/ucb/talk/invite.c

##### Functions

    announce_invite   X
    invite_remote     X
    re_invite         X
    send_delete       X

##### Variables

    invitebuf         X
    local_id          X
    remote_id         X

##### Macros

    NANSWERS          X

       1: /*
       2:  * Copyright (c) 1983 Regents of the University of California.
       3:  * All rights reserved.  The Berkeley software License Agreement
       4:  * specifies the terms and conditions for redistribution.
       5:  */
       6:
       7: #ifndef lint
       8: static char sccsid[] = "@(#)invite.c	5.2 (Berkeley) 3/13/86";
       9: #endif not lint
      10:
      11: #include "talk_ctl.h"
      12: #include <sys/time.h>
      13: #include <signal.h>
      14: #include <setjmp.h>
      15:
      16: /*
      17:  * There wasn't an invitation waiting, so send a request containing
      18:  * our sockt address to the remote talk daemon so it can invite
      19:  * him
      20:  */
      21:
      22: /*
      23:  * The msg.id's for the invitations
      24:  * on the local and remote machines.
      25:  * These are used to delete the
      26:  * invitations.
      27:  */
      28: long    local_id, remote_id;
      29: void    re_invite();
      30: jmp_buf invitebuf;
      31:
      32: invite_remote()
      33: {
      34:     int nfd, read_mask, template, new_sockt;
      35:     struct itimerval itimer;
      36:     CTL_RESPONSE response;
      37:
      38:     itimer.it_value.tv_sec = RING_WAIT;
      39:     itimer.it_value.tv_usec = 0;
      40:     itimer.it_interval = itimer.it_value;
      41:     if (listen(sockt, 5) != 0)
      42:         p_error("Error on attempt to listen for caller");
      43:     msg.addr = *(struct sockaddr *)&my_addr;
      44:     msg.addr.sa_family = htons(msg.addr.sa_family);
      45:     msg.id_num = htonl(-1L);        /* an impossible id_num */
      46:     invitation_waiting = 1;
      47:     announce_invite();
      48:     /*
      49: 	 * Shut off the automatic messages for a while,
      50: 	 * so we can use the interupt timer to resend the invitation
      51: 	 */
      52:     end_msgs();
      53:     setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0);
      54:     message("Waiting for your party to respond");
      55:     signal(SIGALRM, re_invite);
      56:     (void) setjmp(invitebuf);
      57:     while ((new_sockt = accept(sockt, 0, 0)) < 0) {
      58:         if (errno == EINTR)
      59:             continue;
      60:         p_error("Unable to connect with your party");
      61:     }
      62:     close(sockt);
      63:     sockt = new_sockt;
      64:
      65:     /*
      66: 	 * Have the daemons delete the invitations now that we
      67: 	 * have connected.
      68: 	 */
      69:     current_state = "Waiting for your party to respond";
      70:     start_msgs();
      71:
      72:     msg.id_num = htonl(local_id);
      73:     ctl_transact(my_machine_addr, msg, DELETE, &response);
      74:     msg.id_num = htonl(remote_id);
      75:     ctl_transact(his_machine_addr, msg, DELETE, &response);
      76:     invitation_waiting = 0;
      77: }
      78:
      79: /*
      80:  * Routine called on interrupt to re-invite the callee
      81:  */
      82: void
      83: re_invite()
      84: {
      85:
      86:     message("Ringing your party again");
      87:     current_line++;
      88:     /* force a re-announce */
      89:     msg.id_num = htonl(remote_id + 1);
      90:     announce_invite();
      91:     longjmp(invitebuf, 1);
      92: }
      93:
      94: static  char *answers[] = {
      95:     "answer #0",                    /* SUCCESS */
      96:     "Your party is not logged on",          /* NOT_HERE */
      97:     "Target machine is too confused to talk to us", /* FAILED */
      98:     "Target machine does not recognize us",     /* MACHINE_UNKNOWN */
      99:     "Your party is refusing messages",      /* PERMISSION_REFUSED */
     100:     "Target machine can not handle remote talk",    /* UNKNOWN_REQUEST */
     101:     "Target machine indicates protocol mismatch",   /* BADVERSION */
     102:     "Target machine indicates protocol botch (addr)",/* BADADDR */
     103:     "Target machine indicates protocol botch (ctl_addr)",/* BADCTLADDR */
     104: };
     105: #define NANSWERS    (sizeof (answers) / sizeof (answers[0]))
     106:
     107: /*
     108:  * Transmit the invitation and process the response
     109:  */
     110: announce_invite()
     111: {
     112:     CTL_RESPONSE response;
     113:
     114:     current_state = "Trying to connect to your party's talk daemon";
     115:     ctl_transact(his_machine_addr, msg, ANNOUNCE, &response);
     116:     remote_id = response.id_num;
     117:     if (response.answer != SUCCESS) {
     118:         if (response.answer < NANSWERS)
     119:             message(answers[response.answer]);
     120:         quit();
     121:     }
     122:     /* leave the actual invitation on my talk daemon */
     123:     ctl_transact(my_machine_addr, msg, LEAVE_INVITE, &response);
     124:     local_id = response.id_num;
     125: }
     126:
     127: /*
     128:  * Tell the daemon to remove your invitation
     129:  */
     130: send_delete()
     131: {
     132:
     133:     msg.type = DELETE;
     134:     /*
     135: 	 * This is just a extra clean up, so just send it
     136: 	 * and don't wait for an answer
     137: 	 */
     138:     msg.id_num = htonl(remote_id);
     139:     daemon_addr.sin_addr = his_machine_addr;
     140:     if (sendto(ctl_sockt, &msg, sizeof (msg), 0, &daemon_addr,
     141:         sizeof (daemon_addr)) != sizeof(msg))
     142:         perror("send_delete (remote)");
     143:     msg.id_num = htonl(local_id);
     144:     daemon_addr.sin_addr = my_machine_addr;
     145:     if (sendto(ctl_sockt, &msg, sizeof (msg), 0, &daemon_addr,
     146:         sizeof (daemon_addr)) != sizeof (msg))
     147:         perror("send_delete (local)");
     148: }

#### Defined functions

announce_invite defined in line 110; used 2 times

- in line 47, 90

invite_remote defined in line 32; used 1 times

- in /usr/src/ucb/talk/talk.c line 44

re_invite defined in line 82; used 2 times

- in line 29, 55

send_delete defined in line 130; used 1 times

- in /usr/src/ucb/talk/init_disp.c line 115

#### Defined variables

answers defined in line 94; used 3 times

- in line 105(2), 119

invitebuf defined in line 30; used 2 times

- in line 56, 91

local_id defined in line 28; used 3 times

- in line 72, 124, 143

remote_id defined in line 28; used 4 times

- in line 74, 89, 116, 138

sccsid defined in line 8; never used

#### Defined macros

NANSWERS defined in line 105; used 1 times

- in line 118

Last modified: 1988-06-13 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1373 |