2009-08-28 12:29:19 +00:00
|
|
|
/*
|
|
|
|
* uhub - A tiny ADC p2p connection hub
|
2013-03-22 19:00:40 +00:00
|
|
|
* Copyright (C) 2007-2013, Jan Vidar Krey
|
2009-08-28 12:29:19 +00:00
|
|
|
*
|
|
|
|
* This program 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HAVE_UHUB_ADC_CLIENT_H
|
|
|
|
#define HAVE_UHUB_ADC_CLIENT_H
|
|
|
|
|
2009-08-28 14:04:45 +00:00
|
|
|
#include "uhub.h"
|
|
|
|
|
2009-08-28 12:29:19 +00:00
|
|
|
#define ADC_BUFSIZE 16384
|
|
|
|
|
|
|
|
struct ADC_client;
|
|
|
|
|
2009-08-28 16:05:58 +00:00
|
|
|
enum ADC_client_callback_type
|
|
|
|
{
|
2012-10-24 21:22:10 +00:00
|
|
|
ADC_CLIENT_NAME_LOOKUP = 1000,
|
2009-08-28 16:05:58 +00:00
|
|
|
ADC_CLIENT_CONNECTING = 1001,
|
|
|
|
ADC_CLIENT_CONNECTED = 1002,
|
|
|
|
ADC_CLIENT_DISCONNECTED = 1003,
|
2011-11-29 15:39:03 +00:00
|
|
|
ADC_CLIENT_SSL_HANDSHAKE = 1101,
|
|
|
|
ADC_CLIENT_SSL_OK = 1102,
|
2009-08-28 16:05:58 +00:00
|
|
|
|
|
|
|
ADC_CLIENT_LOGGING_IN = 2001,
|
|
|
|
ADC_CLIENT_PASSWORD_REQ = 2002,
|
|
|
|
ADC_CLIENT_LOGGED_IN = 2003,
|
|
|
|
ADC_CLIENT_LOGIN_ERROR = 2004,
|
|
|
|
|
|
|
|
ADC_CLIENT_PROTOCOL_STATUS = 3001,
|
|
|
|
ADC_CLIENT_MESSAGE = 3002,
|
|
|
|
ADC_CLIENT_CONNECT_REQ = 3003,
|
|
|
|
ADC_CLIENT_REVCONNECT_REQ = 3004,
|
|
|
|
ADC_CLIENT_SEARCH_REQ = 3005,
|
|
|
|
ADC_CLIENT_SEARCH_REP = 3006,
|
|
|
|
|
|
|
|
ADC_CLIENT_USER_JOIN = 4001,
|
|
|
|
ADC_CLIENT_USER_QUIT = 4002,
|
|
|
|
ADC_CLIENT_USER_UPDATE = 4003,
|
2009-08-28 12:29:19 +00:00
|
|
|
|
2009-08-28 16:05:58 +00:00
|
|
|
ADC_CLIENT_HUB_INFO = 5001,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ADC_hub_info
|
2009-08-28 12:29:19 +00:00
|
|
|
{
|
2009-08-28 16:05:58 +00:00
|
|
|
char* name;
|
|
|
|
char* description;
|
|
|
|
char* version;
|
2009-08-28 12:29:19 +00:00
|
|
|
};
|
|
|
|
|
2012-09-28 13:51:39 +00:00
|
|
|
enum ADC_chat_message_flags
|
|
|
|
{
|
|
|
|
chat_flags_none = 0,
|
|
|
|
chat_flags_action = 1,
|
|
|
|
chat_flags_private = 2
|
|
|
|
};
|
|
|
|
|
2009-08-28 16:05:58 +00:00
|
|
|
struct ADC_chat_message
|
|
|
|
{
|
|
|
|
sid_t from_sid;
|
|
|
|
sid_t to_sid;
|
|
|
|
char* message;
|
|
|
|
int flags;
|
|
|
|
};
|
|
|
|
|
2012-09-28 13:51:39 +00:00
|
|
|
#define MAX_DESC_LEN 128
|
2009-10-06 10:39:31 +00:00
|
|
|
struct ADC_user
|
|
|
|
{
|
|
|
|
sid_t sid;
|
2012-09-28 13:51:39 +00:00
|
|
|
char cid[MAX_CID_LEN+1];
|
|
|
|
char name[MAX_NICK_LEN+1];
|
|
|
|
char description[MAX_DESC_LEN+1];
|
|
|
|
char address[INET6_ADDRSTRLEN+1];
|
|
|
|
char version[MAX_UA_LEN+1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ADC_client_quit_reason
|
|
|
|
{
|
|
|
|
sid_t sid;
|
|
|
|
sid_t initator; // 0 = default/hub.
|
|
|
|
char message[128]; // optional
|
|
|
|
int flags;
|
2009-10-06 10:39:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-08-28 16:05:58 +00:00
|
|
|
struct ADC_client_callback_data
|
|
|
|
{
|
|
|
|
union {
|
|
|
|
struct ADC_hub_info* hubinfo;
|
|
|
|
struct ADC_chat_message* chat;
|
2009-10-06 10:39:31 +00:00
|
|
|
struct ADC_user* user;
|
2012-09-28 13:51:39 +00:00
|
|
|
struct ADC_client_quit_reason* quit;
|
2009-08-28 16:05:58 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2012-10-02 21:59:11 +00:00
|
|
|
sid_t ADC_client_get_sid(const struct ADC_client* client);
|
|
|
|
const char* ADC_client_get_nick(const struct ADC_client* client);
|
|
|
|
const char* ADC_client_get_description(const struct ADC_client* client);
|
|
|
|
void* ADC_client_get_ptr(const struct ADC_client* client);
|
|
|
|
|
2009-08-28 16:05:58 +00:00
|
|
|
typedef int (*adc_client_cb)(struct ADC_client*, enum ADC_client_callback_type, struct ADC_client_callback_data* data);
|
|
|
|
|
2012-10-02 21:59:11 +00:00
|
|
|
struct ADC_client* ADC_client_create(const char* nickname, const char* description, void* ptr);
|
2009-08-28 16:05:58 +00:00
|
|
|
void ADC_client_set_callback(struct ADC_client* client, adc_client_cb);
|
2009-08-28 14:04:45 +00:00
|
|
|
void ADC_client_destroy(struct ADC_client* client);
|
|
|
|
int ADC_client_connect(struct ADC_client* client, const char* address);
|
|
|
|
void ADC_client_disconnect(struct ADC_client* client);
|
2012-10-02 21:59:11 +00:00
|
|
|
void ADC_client_send(struct ADC_client* client, struct adc_message* msg);
|
2009-08-28 12:29:19 +00:00
|
|
|
|
|
|
|
#endif /* HAVE_UHUB_ADC_CLIENT_H */
|
|
|
|
|
|
|
|
|