1 /*
2  * uhub - A tiny ADC p2p connection hub
3  * Copyright (C) 2007-2014, Jan Vidar Krey
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  */
19 
20 #ifndef HAVE_UHUB_ADC_CLIENT_H
21 #define HAVE_UHUB_ADC_CLIENT_H
22 
23 #include "uhub.h"
24 
25 #define ADC_BUFSIZE 16384
26 
27 struct ADC_client;
28 
29 enum ADC_client_callback_type
30 {
31 	ADC_CLIENT_NAME_LOOKUP      = 1000,
32 	ADC_CLIENT_CONNECTING       = 1001,
33 	ADC_CLIENT_CONNECTED        = 1002,
34 	ADC_CLIENT_DISCONNECTED     = 1003,
35 	ADC_CLIENT_SSL_HANDSHAKE    = 1101,
36 	ADC_CLIENT_SSL_OK           = 1102,
37 
38 	ADC_CLIENT_LOGGING_IN       = 2001,
39 	ADC_CLIENT_PASSWORD_REQ     = 2002,
40 	ADC_CLIENT_LOGGED_IN        = 2003,
41 	ADC_CLIENT_LOGIN_ERROR      = 2004,
42 
43 	ADC_CLIENT_PROTOCOL_STATUS  = 3001,
44 	ADC_CLIENT_MESSAGE          = 3002,
45 	ADC_CLIENT_CONNECT_REQ      = 3003,
46 	ADC_CLIENT_REVCONNECT_REQ   = 3004,
47 	ADC_CLIENT_SEARCH_REQ       = 3005,
48 	ADC_CLIENT_SEARCH_REP       = 3006,
49 
50 	ADC_CLIENT_USER_JOIN        = 4001,
51 	ADC_CLIENT_USER_QUIT        = 4002,
52 	ADC_CLIENT_USER_UPDATE      = 4003,
53 
54 	ADC_CLIENT_HUB_INFO         = 5001,
55 };
56 
57 struct ADC_hub_info
58 {
59 	char* name;
60 	char* description;
61 	char* version;
62 };
63 
64 enum ADC_chat_message_flags
65 {
66 	chat_flags_none = 0,
67 	chat_flags_action = 1,
68 	chat_flags_private = 2
69 };
70 
71 struct ADC_chat_message
72 {
73 	sid_t from_sid;
74 	sid_t to_sid;
75 	char* message;
76 	int flags;
77 };
78 
79 #define MAX_DESC_LEN 128
80 struct ADC_user
81 {
82 	sid_t sid;
83 	char cid[MAX_CID_LEN+1];
84 	char name[MAX_NICK_LEN+1];
85 	char description[MAX_DESC_LEN+1];
86 	char address[INET6_ADDRSTRLEN+1];
87 	char version[MAX_UA_LEN+1];
88 };
89 
90 struct ADC_client_quit_reason
91 {
92 	sid_t sid;
93 	sid_t initator; // 0 = default/hub.
94 	char message[128]; // optional
95 	int flags;
96 };
97 
98 struct ADC_client_tls_info
99 {
100 	const char* cipher;
101 	const char* version;
102 };
103 
104 struct ADC_client_callback_data
105 {
106 	union {
107 		struct ADC_hub_info* hubinfo;
108 		struct ADC_chat_message* chat;
109 		struct ADC_user* user;
110 		struct ADC_client_quit_reason* quit;
111 		struct ADC_client_tls_info* tls_info;
112 	};
113 };
114 
115 sid_t ADC_client_get_sid(const struct ADC_client* client);
116 const char* ADC_client_get_nick(const struct ADC_client* client);
117 const char* ADC_client_get_description(const struct ADC_client* client);
118 void* ADC_client_get_ptr(const struct ADC_client* client);
119 
120 typedef int (*adc_client_cb)(struct ADC_client*, enum ADC_client_callback_type, struct ADC_client_callback_data* data);
121 
122 struct ADC_client* ADC_client_create(const char* nickname, const char* description, void* ptr);
123 void ADC_client_set_callback(struct ADC_client* client, adc_client_cb);
124 void ADC_client_destroy(struct ADC_client* client);
125 int ADC_client_connect(struct ADC_client* client, const char* address);
126 void ADC_client_disconnect(struct ADC_client* client);
127 void ADC_client_send(struct ADC_client* client, struct adc_message* msg);
128 
129 #endif /* HAVE_UHUB_ADC_CLIENT_H */
130 
131 
132