|
|
1.1 ! root 1: /* $Header: /a/guest/moore/talk/RCS/invite.c,v 1.7 83/07/06 00:17:32 moore 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: invite_remote() ! 22: { ! 23: int nfd, read_mask, template, new_sockt; ! 24: struct itimerval itimer; ! 25: CTL_RESPONSE response; ! 26: ! 27: itimer.it_value.tv_sec = RING_WAIT; ! 28: itimer.it_value.tv_usec = 0; ! 29: itimer.it_interval = itimer.it_value; ! 30: ! 31: if (listen(sockt, 5) != 0) { ! 32: p_error("Error on attempt to listen for caller"); ! 33: } ! 34: ! 35: msg.addr = my_addr; ! 36: msg.id_num = -1; /* an impossible id_num */ ! 37: ! 38: invitation_waiting = 1; ! 39: ! 40: announce_invite(); ! 41: ! 42: /* ! 43: * shut off the automatic messages for a while, ! 44: * so we can use the interupt timer to resend the invitation ! 45: */ ! 46: ! 47: end_msgs(); ! 48: setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0); ! 49: message("Waiting for your party to respond"); ! 50: signal(SIGALRM, re_invite); ! 51: (void) setjmp(invitebuf); ! 52: ! 53: while ((new_sockt = accept(sockt, 0, 0)) < 0) { ! 54: if (errno != EINTR) { ! 55: p_error("Unable to connect with your party"); ! 56: } else { ! 57: /* we just returned from a interupt, keep trying */ ! 58: continue; ! 59: } ! 60: } ! 61: ! 62: close(sockt); ! 63: sockt = new_sockt; ! 64: ! 65: /* have the daemons delete the invitations now that we ! 66: have connected. ! 67: */ ! 68: ! 69: current_state = "Waiting for your party to respond"; ! 70: start_msgs(); ! 71: ! 72: msg.id_num = local_id; ! 73: ctl_transact(my_machine_addr, msg, DELETE, &response); ! 74: msg.id_num = remote_id; ! 75: ctl_transact(his_machine_addr, msg, DELETE, &response); ! 76: invitation_waiting = 0; ! 77: } ! 78: ! 79: /* routine called on interupt to re-invite the callee */ ! 80: ! 81: void re_invite() ! 82: { ! 83: message("Ringing your party again"); ! 84: current_line++; ! 85: /* force a re-announce */ ! 86: msg.id_num = remote_id + 1; ! 87: announce_invite(); ! 88: longjmp(invitebuf, 1); ! 89: } ! 90: ! 91: /* transmit the invitation and process the response */ ! 92: ! 93: announce_invite() ! 94: { ! 95: CTL_RESPONSE response; ! 96: ! 97: current_state = "Trying to connect to your party's talk daemon"; ! 98: ! 99: ctl_transact(his_machine_addr, msg, ANNOUNCE, &response); ! 100: remote_id = response.id_num; ! 101: ! 102: if (response.answer != SUCCESS) { ! 103: ! 104: switch (response.answer) { ! 105: ! 106: case NOT_HERE : ! 107: message("Your party is not logged on"); ! 108: break; ! 109: ! 110: case MACHINE_UNKNOWN : ! 111: message("Target machine does not recognize us"); ! 112: break; ! 113: ! 114: case UNKNOWN_REQUEST : ! 115: message("Target machine can not handle remote talk"); ! 116: break; ! 117: ! 118: case FAILED : ! 119: message("Target machine is too confused to talk to us"); ! 120: break; ! 121: ! 122: case PERMISSION_DENIED : ! 123: message("Your party is refusing messages"); ! 124: break; ! 125: } ! 126: ! 127: quit(); ! 128: } ! 129: ! 130: /* leave the actual invitation on my talk daemon */ ! 131: ! 132: ctl_transact(my_machine_addr, msg, LEAVE_INVITE, &response); ! 133: local_id = response.id_num; ! 134: } ! 135: ! 136: send_delete() ! 137: { ! 138: /* tell the daemon to remove your invitation */ ! 139: ! 140: msg.type = DELETE; ! 141: ! 142: /* this is just a extra clean up, so just send it ! 143: and don't wait for an answer */ ! 144: ! 145: msg.id_num = remote_id; ! 146: daemon_addr.sin_addr = his_machine_addr; ! 147: if (sendto(ctl_sockt, &msg, sizeof(CTL_MSG), 0, &daemon_addr, ! 148: sizeof(daemon_addr)) != sizeof(CTL_MSG)) { ! 149: perror("send_delete remote"); ! 150: } ! 151: ! 152: msg.id_num = local_id; ! 153: daemon_addr.sin_addr = my_machine_addr; ! 154: if (sendto(ctl_sockt, &msg, sizeof(CTL_MSG), 0, &daemon_addr, ! 155: sizeof(daemon_addr)) != sizeof(CTL_MSG)) { ! 156: perror("send_delete local"); ! 157: } ! 158: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.