prot-a-send-async.c 4.22 KB
Newer Older
Linus Tolke's avatar
Linus Tolke committed
1
/*
2
 * $Id: prot-a-send-async.c,v 0.13 1996/06/14 15:54:43 byers Exp $
3
 * Copyright (C) 1991, 1993, 1994, 1995  Lysator Academic Computer Association.
Linus Tolke's avatar
Linus Tolke committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * This file is part of the LysKOM server.
 * 
 * LysKOM is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 1, or (at your option) 
 * any later version.
 * 
 * LysKOM is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with LysKOM; see the file COPYING.  If not, write to
 * Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
 * or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
 * MA 02139, USA.
 *
 * Please mail bug reports to bug-lyskom@lysator.liu.se. 
 */
Per Cederqvist's avatar
Per Cederqvist committed
25
26
27
28
/*
 * Asynchronous messages in protocol A.
 */

29
static char *rcsid = "$Id: prot-a-send-async.c,v 0.13 1996/06/14 15:54:43 byers Exp $";
30
31
#include "rcs.h"
USE(rcsid);
Per Cederqvist's avatar
Per Cederqvist committed
32

Per Cederqvist's avatar
Per Cederqvist committed
33
#include <setjmp.h>
34
35
36
37
38
39
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_STDARG_H
#  include <stdarg.h>
#endif
Per Cederqvist's avatar
Per Cederqvist committed
40

Per Cederqvist's avatar
Per Cederqvist committed
41
#include "misc-types.h"
42
#include "s-string.h"
Per Cederqvist's avatar
Per Cederqvist committed
43
#include "kom-types.h"
Per Cederqvist's avatar
Per Cederqvist committed
44
45
46
#include "com.h"
#include "connections.h"
#include "prot-a-send-async.h"
Per Cederqvist's avatar
Per Cederqvist committed
47
#include "async.h"
48
#include "isc-interface.h"
Per Cederqvist's avatar
Per Cederqvist committed
49
#include "mux.h"
Per Cederqvist's avatar
Per Cederqvist committed
50
#include "prot-a-output.h"
Per Cederqvist's avatar
Per Cederqvist committed
51

52

Per Cederqvist's avatar
Per Cederqvist committed
53
54
55
56
57
static void
async_header(Connection *fp,
	     int   no_of_tokens,
	     Async fnc)
{
Per Cederqvist's avatar
Per Cederqvist committed
58
59
    mux_printf(fp, ":%lu %lu", (unsigned long)no_of_tokens, 
	       (unsigned long)fnc);
Per Cederqvist's avatar
Per Cederqvist committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
}



    
static void
async_trailer(Connection *fp)
{
    mux_putc('\n', fp);
    mux_flush(fp);
}


void
prot_a_async_new_text(Connection *cptr,
		      Text_no	      text_no,
		      Text_stat      *text_s)
{
78
    ASYNC_CHECK_ACCEPT(cptr, ay_new_text);
Per Cederqvist's avatar
Per Cederqvist committed
79
80
81
82
83
84
85
86
87
88
89
    async_header(cptr, 16, ay_new_text);
    mux_printf(cptr, " %lu", text_no);
    prot_a_output_text_stat(cptr, text_s);
    async_trailer(cptr);
}


void
prot_a_async_i_am_on(Connection *cptr,
		     Who_info info)
{
90
    ASYNC_CHECK_ACCEPT(cptr, ay_i_am_on);
Per Cederqvist's avatar
Per Cederqvist committed
91
92
93
94
95
96
97
98
99
100
    async_header(cptr, 5, ay_i_am_on);
    prot_a_output_who_info(cptr, &info);
    async_trailer(cptr);
}

void
prot_a_async_logout(Connection *cptr,
		    Pers_no pers_no,
		    Session_no session_no)
{
101
    ASYNC_CHECK_ACCEPT(cptr, ay_logout);
Per Cederqvist's avatar
Per Cederqvist committed
102
    async_header(cptr, 2, ay_logout);
Per Cederqvist's avatar
Per Cederqvist committed
103
104
    mux_printf(cptr, " %lu %lu", (unsigned long)pers_no, 
	       (unsigned long)session_no);
Per Cederqvist's avatar
Per Cederqvist committed
105
106
107
108
109
110
111
112
113
    async_trailer(cptr);
}

void
prot_a_async_new_name(Connection *cptr,
		      Conf_no conf_no,
		      String old_name,
		      String new_name)
{
114
    ASYNC_CHECK_ACCEPT(cptr, ay_new_name);
Per Cederqvist's avatar
Per Cederqvist committed
115
    async_header(cptr, 3, ay_new_name);
Per Cederqvist's avatar
Per Cederqvist committed
116
    mux_printf(cptr, " %lu", (unsigned long)conf_no);
Per Cederqvist's avatar
Per Cederqvist committed
117
118
119
120
121
122
123
124
    prot_a_output_string(cptr, old_name);
    prot_a_output_string(cptr, new_name);
    async_trailer(cptr);
}

void
prot_a_async_sync_db(Connection *cptr)
{
125
    ASYNC_CHECK_ACCEPT(cptr, ay_sync_db);
Per Cederqvist's avatar
Per Cederqvist committed
126
127
128
129
130
131
132
133
    async_header(cptr, 0, ay_sync_db);
    async_trailer(cptr);
}

void
prot_a_async_forced_leave_conf(Connection *cptr,
			       Conf_no         conf_no)
{
134
    ASYNC_CHECK_ACCEPT(cptr, ay_leave_conf);
Per Cederqvist's avatar
Per Cederqvist committed
135
    async_header(cptr, 1, ay_leave_conf);
Per Cederqvist's avatar
Per Cederqvist committed
136
    mux_printf(cptr, " %lu", (unsigned long)conf_no);
Per Cederqvist's avatar
Per Cederqvist committed
137
138
139
140
141
142
143
144
    async_trailer(cptr);
}

void
prot_a_async_login(Connection *cptr,
		   Pers_no	   pers_no,
		   int		   session_no)
{
145
    ASYNC_CHECK_ACCEPT(cptr, ay_login);
Per Cederqvist's avatar
Per Cederqvist committed
146
    async_header(cptr, 2, ay_login);
Per Cederqvist's avatar
Per Cederqvist committed
147
148
    mux_printf(cptr, " %lu %lu", (unsigned long)pers_no, 
	       (unsigned long)session_no);
Per Cederqvist's avatar
Per Cederqvist committed
149
150
    async_trailer(cptr);
}
151

Per Cederqvist's avatar
Per Cederqvist committed
152
153
154
void
prot_a_async_rejected_connection(Connection *cptr)
{
155
    ASYNC_CHECK_ACCEPT(cptr, ay_rejected_connection);
Per Cederqvist's avatar
Per Cederqvist committed
156
157
158
159
160
161
    async_header(cptr, 0, ay_rejected_connection);
    async_trailer(cptr);
}
    
void
prot_a_async_send_message(Connection *cptr,
162
			  Conf_no     recipient,
Per Cederqvist's avatar
Per Cederqvist committed
163
164
165
			  Pers_no     sender,
			  String      message)
{
166
    ASYNC_CHECK_ACCEPT(cptr, ay_send_message);
Per Cederqvist's avatar
Per Cederqvist committed
167
    async_header(cptr, 3, ay_send_message);
Per Cederqvist's avatar
Per Cederqvist committed
168
169
    mux_printf(cptr, " %lu %lu", (unsigned long)recipient,
	       (unsigned long)sender);
Per Cederqvist's avatar
Per Cederqvist committed
170
171
172
    prot_a_output_string(cptr, message);
    async_trailer(cptr);
}