A LOT updates. Cannot separate. :)
[silc.git] / lib / silccore / silcprotocol.h
1 /*
2
3   silcprotocol.h
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 1997 - 2000 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; either version 2 of the License, or
12   (at your option) any later version.
13   
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18
19 */
20
21 #ifndef SILCPROTOCOL_H
22 #define SILCPROTOCOL_H
23
24 /* Protocol type definition. */
25 typedef unsigned char SilcProtocolType;
26
27 /* Protocol state definition. */
28 typedef unsigned char SilcProtocolState;
29
30 /* Protocol states. Do NOT change the values of these states, especially
31    the START state or you break every protocol. */
32 #define SILC_PROTOCOL_STATE_UNKNOWN 0
33 #define SILC_PROTOCOL_STATE_START 1
34 #define SILC_PROTOCOL_STATE_END 252
35 #define SILC_PROTOCOL_STATE_FAILURE 253  /* Received failure from remote */
36 #define SILC_PROTOCOL_STATE_ERROR 254    /* Local error at our end */
37
38 /* Connection Authentication protocols' authentication methods */
39 #define SILC_PROTOCOL_CONN_AUTH_NONE 0
40 #define SILC_PROTOCOL_CONN_AUTH_PASSWORD 1
41 #define SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY 2
42
43 /* XXX These don't belong here really! */
44 /* Connection authentication protocol status message */
45 #define SILC_CONN_AUTH_OK 0
46 #define SILC_CONN_AUTH_FAILED 1
47
48 /* Type definition for above auth methods */
49 typedef unsigned char SilcProtocolAuthMeth;
50
51 /* 
52    SILC Protocol Object.
53
54    Short description of the field following:
55    
56    SilcProtocolType type
57
58        Protocol type. This is enumeration.
59   
60    SilcProtocolCallback callback;
61
62        Callback function for the protocol. This is SilcTaskCallback function
63        pointer as the protocols in SILC are executed as timeout tasks.
64
65    The object expands to another structure as well. Short description of 
66    these fields following:
67
68    SilcProtocolObject *protocol
69
70        This is the pointer to the protocol object defined above.
71
72    SilcProtocolState state
73
74        Protocol state. This is enumeration. The state of the protocol can
75        be changed in the callback function.
76
77    void *context
78
79        Context to be sent for the callback function. This is usually 
80        object for either SILC client or server. However, this abstraction 
81        makes it possible that this pointer could be some other object as well. 
82
83    SilcProtocolExecute execute;
84
85        Executes the protocol and its states. The correct state must be set
86        before calling this function. The state is usually set in the protocol
87        specific routines.
88
89    SilcProtocolExecute execute_final;
90
91        Executes the final callback function of the protocol. Read on.
92
93    SilcProtocolFinalCallback final_callback;
94
95        This is a callback function that is called with timeout _after_ the
96        protocol has finished or error occurs. If this is NULL, naturally 
97        nothing will be executed. Protocol should call this function only at 
98        SILC_PROTOCOL_STATE_END and SILC_PROTOCOL_STATE_ERROR states.
99
100 */
101 typedef SilcTaskCallback SilcProtocolCallback;
102
103 typedef struct SilcProtocolObjectStruct {
104   SilcProtocolType type;
105   SilcProtocolCallback callback;
106
107   struct SilcProtocolObjectStruct *next;
108 } SilcProtocolObject;
109
110 typedef SilcTaskCallback SilcProtocolFinalCallback;
111 typedef SilcTaskCallback SilcProtocolExecute;
112
113 typedef struct SilcProtocolStruct {
114   SilcProtocolObject *protocol;
115   SilcProtocolState state;
116   void *context;
117
118   //  SilcProtocolExecute execute;
119   void (*execute)(void *, int, void *, int, long, long);
120   SilcProtocolExecute execute_final;
121   SilcProtocolFinalCallback final_callback;
122 } *SilcProtocol;
123
124 /* Prototypes */
125 void silc_protocol_register(SilcProtocolType type,
126                             SilcProtocolCallback callback);
127 void silc_protocol_unregister(SilcProtocolType type,
128                               SilcProtocolCallback callback);
129 void silc_protocol_alloc(SilcProtocolType type, SilcProtocol *new_protocol,
130                          void *context, SilcProtocolFinalCallback callback);
131 void silc_protocol_free(SilcProtocol protocol);
132 void silc_protocol_execute(void *qptr, int type,
133                            void *context, int fd,
134                            long secs, long usecs);
135 void silc_protocol_execute_final(void *qptr, int type, 
136                                  void *context, int fd);
137
138 #endif