Repository navigation
Expand file tree
/
Copy pathproto.c
More file actions
executable file
·142 lines (125 loc) · 3.2 KB
/
Copy pathproto.c
File metadata and controls
executable file
·142 lines (125 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* proto.c Copyright Michael Temari 08/01/1996 All Rights Reserved */
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <net/hton.h>
#include <net/gen/socket.h>
#include <net/gen/in.h>
#include <net/gen/inet.h>
#include <net/gen/tcp.h>
#include <net/gen/udp.h>
#include "talk.h"
#include "proto.h"
#include "net.h"
#include "screen.h"
_PROTOTYPE(static int TalkChk, (int gotreply, struct talk_reply *reply, char *msg));
_PROTOTYPE(static int TalkTrans, (int type, long id, struct talk_reply *reply, int here));
static char *AnswerMsgs[] = {
"Success",
"User Not Logged In",
"Failure",
"Remote Does Not Know who we are",
"User is not accepting calls",
"Are request was not know",
"Incorrect Version",
"Bad Address",
"Bad Control Address"
};
static int TalkChk(gotreply, reply, msg)
int gotreply;
struct talk_reply *reply;
char *msg;
{
if(!gotreply) {
ScreenMsg(msg);
return(-1);
}
if(reply->answer == SUCCESS) return(0);
if(reply->answer < (sizeof(AnswerMsgs) / sizeof(AnswerMsgs[0])))
ScreenMsg(AnswerMsgs[reply->answer]);
else
ScreenMsg("Bad Answer");
return(-1);
}
static int TalkTrans(type, id, reply, here)
int type;
long id;
struct talk_reply *reply;
int here;
{
struct talk_request request;
int tries;
int gotreply;
memset(&request, 0, sizeof(request));
request.version = TALK_VERSION;
request.type = type;
request.id = id;
request.addr.sa_family = htons(AF_INET);
request.addr.sin_port = dataport;
request.addr.sin_addr = laddr;
request.ctl_addr.sa_family = htons(AF_INET);
request.ctl_addr.sin_port = ctlport;
request.ctl_addr.sin_addr = laddr;
request.pid = getpid();
strncpy(request.luser, luser, USER_SIZE);
strncpy(request.ruser, ruser, USER_SIZE);
strncpy(request.rtty, rtty, TTY_SIZE);
tries = 0;
gotreply = 0;
while(!ScreenDone && tries++ < 3 && !gotreply) {
if(!sendrequest(&request, here))
if(!getreply(reply, 5))
gotreply = 1;
if(!gotreply) continue;
if(reply->version != request.version ||
reply->type != request.type)
gotreply = 0;
}
return(gotreply);
}
int TalkInit()
{
struct talk_reply reply;
long id = 0;
long rid;
int s;
int ring;
char buff[32];
/* Check if someone was calling us */
ScreenMsg("Initiating Talk Protocol");
/* Check is someone was calling us */
s = TalkTrans(LOOK_UP, ++id, &reply, 0);
/* Someone was calling us */
if(s && reply.answer == SUCCESS) {
s = NetConnect(reply.addr.sin_port);
if(s == 1) {
ScreenMsg("Your party has hung up");
TalkTrans(DELETE, reply.id, &reply, 0);
}
return(s == 0 ? 0 : -1);
}
ScreenMsg("Ringing User");
ring = 0;
while(!ScreenDone && ring++ < 5) {
if(TalkChk(TalkTrans(ANNOUNCE, -1, &reply, 0),
&reply, "No response to are ring"))
return(-1);
rid = reply.id;
sprintf(buff, "Ring #%d", ring);
ScreenMsg(buff);
if(ring == 1) {
if(TalkChk(TalkTrans(LEAVE_INVITE, ++id, &reply, 1),
&reply, "Could not leave are invitaion locally"))
return(-1);
}
s = NetListen(RING_WAIT);
if(s <= 0) {
TalkTrans(DELETE, reply.id, &reply, 1);
TalkTrans(DELETE, rid, &reply, 0);
return(s);
}
}
return(-1);
}