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

unix.superglobalmegacorp.com

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