Misc ADC client fixes.

This commit is contained in:
Jan Vidar Krey 2012-09-28 15:51:39 +02:00
parent a599b29b9d
commit ff2e2a3d4c
2 changed files with 70 additions and 22 deletions

View File

@ -23,7 +23,9 @@
#define ADC_CID_SIZE 39 #define ADC_CID_SIZE 39
#define BIG_BUFSIZE 32768 #define BIG_BUFSIZE 32768
#define TIGERSIZE 24 #define TIGERSIZE 24
// #define ADCC_DEBUG // #define ADCC_DEBUG
// #define ADC_CLIENT_DEBUG_PROTO
static ssize_t ADC_client_recv(struct ADC_client* client); static ssize_t ADC_client_recv(struct ADC_client* client);
static void ADC_client_send_info(struct ADC_client* client); static void ADC_client_send_info(struct ADC_client* client);
@ -156,12 +158,25 @@ static void event_callback(struct net_connection* con, int events, void *arg)
TARGET = NULL; \ TARGET = NULL; \
hub_free(TMP); hub_free(TMP);
#define UNESCAPE_ARG_X(TMP, TARGET, SIZE) \
if (TMP) \
adc_msg_unescape_to_target(TMP, TARGET, SIZE); \
else \
TARGET[0] = '\0'; \
hub_free(TMP);
#define EXTRACT_NAMED_ARG(MSG, NAME, TARGET) \ #define EXTRACT_NAMED_ARG(MSG, NAME, TARGET) \
do { \ do { \
char* tmp = adc_msg_get_named_argument(MSG, NAME); \ char* tmp = adc_msg_get_named_argument(MSG, NAME); \
UNESCAPE_ARG(tmp, TARGET); \ UNESCAPE_ARG(tmp, TARGET); \
} while (0) } while (0)
#define EXTRACT_NAMED_ARG_X(MSG, NAME, TARGET, SIZE) \
do { \
char* tmp = adc_msg_get_named_argument(MSG, NAME); \
UNESCAPE_ARG_X(tmp, TARGET, SIZE); \
} while(0)
#define EXTRACT_POS_ARG(MSG, POS, TARGET) \ #define EXTRACT_POS_ARG(MSG, POS, TARGET) \
do { \ do { \
char* tmp = adc_msg_get_argument(MSG, POS); \ char* tmp = adc_msg_get_argument(MSG, POS); \
@ -171,9 +186,12 @@ static void event_callback(struct net_connection* con, int events, void *arg)
static void ADC_client_on_recv_line(struct ADC_client* client, const char* line, size_t length) static void ADC_client_on_recv_line(struct ADC_client* client, const char* line, size_t length)
{ {
struct ADC_chat_message chat;
struct ADC_client_callback_data data;
ADC_TRACE; ADC_TRACE;
#ifdef ADC_CLIENT_DEBUG_PROTO #ifdef ADC_CLIENT_DEBUG_PROTO
ADC_client_debug(client, "- LINE: '%s'", start); ADC_client_debug(client, "- LINE: '%s'", line);
#endif #endif
/* Parse message */ /* Parse message */
@ -210,12 +228,18 @@ static void ADC_client_on_recv_line(struct ADC_client* client, const char* line,
case ADC_CMD_DMSG: case ADC_CMD_DMSG:
case ADC_CMD_IMSG: case ADC_CMD_IMSG:
{ {
struct ADC_chat_message chat;
struct ADC_client_callback_data data;
chat.from_sid = msg->source; chat.from_sid = msg->source;
chat.to_sid = msg->target; chat.to_sid = msg->target;
data.chat = &chat; data.chat = &chat;
EXTRACT_POS_ARG(msg, 0, chat.message); EXTRACT_POS_ARG(msg, 0, chat.message);
chat.flags = 0;
if (adc_msg_has_named_argument(msg, ADC_MSG_FLAG_ACTION))
chat.flags |= chat_flags_action;
if (adc_msg_has_named_argument(msg, ADC_MSG_FLAG_PRIVATE))
chat.flags |= chat_flags_private;
client->callback(client, ADC_CLIENT_MESSAGE, &data); client->callback(client, ADC_CLIENT_MESSAGE, &data);
hub_free(chat.message); hub_free(chat.message);
break; break;
@ -259,23 +283,32 @@ static void ADC_client_on_recv_line(struct ADC_client* client, const char* line,
{ {
struct ADC_user user; struct ADC_user user;
user.sid = msg->source; user.sid = msg->source;
EXTRACT_NAMED_ARG(msg, "NI", user.name); EXTRACT_NAMED_ARG_X(msg, "NI", user.name, sizeof(user.name));
EXTRACT_NAMED_ARG(msg, "DE", user.description); EXTRACT_NAMED_ARG_X(msg, "DE", user.description, sizeof(user.description));
EXTRACT_NAMED_ARG(msg, "VE", user.version); EXTRACT_NAMED_ARG_X(msg, "VE", user.version, sizeof(user.version));
EXTRACT_NAMED_ARG(msg, "ID", user.cid); EXTRACT_NAMED_ARG_X(msg, "ID", user.cid, sizeof(user.cid));
EXTRACT_NAMED_ARG(msg, "I4", user.address); EXTRACT_NAMED_ARG_X(msg, "I4", user.address, sizeof(user.address));
struct ADC_client_callback_data data; struct ADC_client_callback_data data;
data.user = &user; data.user = &user;
client->callback(client, ADC_CLIENT_USER_JOIN, &data); client->callback(client, ADC_CLIENT_USER_JOIN, &data);
}
}
}
break;
hub_free(user.name); case ADC_CMD_IQUI:
hub_free(user.description); {
hub_free(user.version); struct ADC_client_quit_reason reason;
hub_free(user.cid); memset(&reason, 0, sizeof(reason));
hub_free(user.address); reason.sid = string_to_sid(&line[5]);
}
} if (adc_msg_has_named_argument(msg, ADC_QUI_FLAG_DISCONNECT))
reason.flags |= 1;
data.quit = &reason;
client->callback(client, ADC_CLIENT_USER_QUIT, &data);
break;
} }
case ADC_CMD_ISTA: case ADC_CMD_ISTA:
@ -360,9 +393,7 @@ void ADC_client_send(struct ADC_client* client, char* msg)
void ADC_client_send_info(struct ADC_client* client) void ADC_client_send_info(struct ADC_client* client)
{ {
ADC_TRACE; ADC_TRACE;
char binf[11]; client->info = adc_msg_construct_source(ADC_CMD_BINF, client->sid, 64);
snprintf(binf, 11, "BINF %s\n", sid_to_string(client->sid));
client->info = adc_msg_create(binf);
adc_msg_add_named_argument_string(client->info, ADC_INF_FLAG_NICK, client->nick); adc_msg_add_named_argument_string(client->info, ADC_INF_FLAG_NICK, client->nick);

View File

@ -71,6 +71,13 @@ struct ADC_hub_info
char* version; char* version;
}; };
enum ADC_chat_message_flags
{
chat_flags_none = 0,
chat_flags_action = 1,
chat_flags_private = 2
};
struct ADC_chat_message struct ADC_chat_message
{ {
sid_t from_sid; sid_t from_sid;
@ -79,14 +86,23 @@ struct ADC_chat_message
int flags; int flags;
}; };
#define MAX_DESC_LEN 128
struct ADC_user struct ADC_user
{ {
sid_t sid; sid_t sid;
char* cid; char cid[MAX_CID_LEN+1];
char* name; char name[MAX_NICK_LEN+1];
char* description; char description[MAX_DESC_LEN+1];
char* address; char address[INET6_ADDRSTRLEN+1];
char* version; 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;
}; };
@ -96,6 +112,7 @@ struct ADC_client_callback_data
struct ADC_hub_info* hubinfo; struct ADC_hub_info* hubinfo;
struct ADC_chat_message* chat; struct ADC_chat_message* chat;
struct ADC_user* user; struct ADC_user* user;
struct ADC_client_quit_reason* quit;
}; };
}; };