unfinished HandleCapabilities, moved the IRC structs to another headerfile
This commit is contained in:
@@ -1,64 +1,7 @@
|
||||
#ifndef IRC_H
|
||||
#define IRC_H
|
||||
|
||||
#include <stdbool.h>
|
||||
typedef enum
|
||||
{
|
||||
PLAIN,
|
||||
EXTERNAL
|
||||
} irc_sasl_method_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *nickname;
|
||||
int nicklen;
|
||||
char *ident;
|
||||
int identlen;
|
||||
char *hostname;
|
||||
int hostlen;
|
||||
} irc_hostmask_t;
|
||||
|
||||
typedef struct {
|
||||
char line[513];
|
||||
char *source;
|
||||
char *command;
|
||||
char *argv[16];
|
||||
int argc;
|
||||
} irc_message_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
irc_hostmask_t hostmask;
|
||||
char prefix;
|
||||
} irc_chanuser_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char name[64];
|
||||
char topic[512];
|
||||
irc_chanuser_t* users;
|
||||
} irc_channel_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char capLine[96]; // A place for name and args to point to.
|
||||
char *name;
|
||||
char *args;
|
||||
} irc_capability_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int sockfd;
|
||||
irc_hostmask_t ownHostmask;
|
||||
char supportedCapabilities[512];
|
||||
char* requestedCapabilities;
|
||||
} irc_client_t;
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
void (*handler)(irc_message_t *msg, irc_client_t *irc);
|
||||
} command_t;
|
||||
#include "IRC_structs.h"
|
||||
|
||||
void IRC_ParseMessage(char* line, irc_message_t *msg);
|
||||
void IRC_ProcessMessage(irc_message_t *msg, irc_client_t *irc);
|
||||
@@ -70,13 +13,15 @@ void IRC_NICK(char *nick, irc_client_t *irc);
|
||||
void IRC_USER(char *ident, char* realname, irc_client_t *irc);
|
||||
|
||||
// registration
|
||||
void IRC_Register(char *nick, char* ident, char *realname, bool saslEnabled, irc_sasl_method_t saslMethod, char *saslUsername, char *saslPassword, irc_client_t *irc);
|
||||
void IRC_Register(char *nick, char* ident, char *realname, bool saslEnabled, irc_sasl_mechanism_t saslMethod, char *saslUsername, char *saslPassword, irc_client_t *irc);
|
||||
|
||||
// Capability negotiation block
|
||||
void IRC_StartCapabilityNegotiation(irc_client_t *irc);
|
||||
void IRC_RequestCapabilities(char* caps, irc_client_t *irc);
|
||||
void IRC_EndCapabilityNegotiation(irc_client_t *irc);
|
||||
|
||||
void IRC_NeedCapabilities(char* caps, irc_client_t *irc);
|
||||
|
||||
int IRC_ParseCapabilities(char* caps, irc_capability_t *capabilities, int capsLength);
|
||||
|
||||
#endif
|
||||
97
include/IRC_structs.h
Normal file
97
include/IRC_structs.h
Normal file
@@ -0,0 +1,97 @@
|
||||
#ifndef IRC_STRUCTS_H
|
||||
#define IRC_STRUCTS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SASL_MECHANISM_NONE,
|
||||
SASL_MECHANISM_PLAIN,
|
||||
SASL_MECHANISM_EXTERNAL
|
||||
} irc_sasl_mechanism_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char nickname[32];
|
||||
char ident[16];
|
||||
char hostname;
|
||||
} irc_hostmask_t;
|
||||
|
||||
typedef struct {
|
||||
char line[513];
|
||||
char *source;
|
||||
char *command;
|
||||
char *argv[16];
|
||||
int argc;
|
||||
} irc_message_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
irc_hostmask_t hostmask;
|
||||
char prefix;
|
||||
} irc_chanuser_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char name[64];
|
||||
char topic[512];
|
||||
irc_chanuser_t* users;
|
||||
} irc_channel_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char capLine[96]; // A place for name and args to point to.
|
||||
char *name;
|
||||
char *args;
|
||||
} irc_capability_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char username[32];
|
||||
char password[64];
|
||||
} irc_sasl_plain_credentials_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char nickname[32];
|
||||
unsigned char fingerprint[20];
|
||||
} irc_sasl_external_credentials_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
irc_sasl_mechanism_t mechanism;
|
||||
union {
|
||||
irc_sasl_plain_credentials_t plain_credentials;
|
||||
irc_sasl_external_credentials_t external_credentials;
|
||||
};
|
||||
} irc_auth_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int sockfd;
|
||||
irc_hostmask_t ownHostmask;
|
||||
char supportedCapabilities[512];
|
||||
char requestedCapabilities[512];
|
||||
irc_capability_t acked[24];
|
||||
struct
|
||||
{
|
||||
bool saslWorks;
|
||||
} capabilities;
|
||||
|
||||
/* Authentication parameters */
|
||||
irc_auth_t sasl_auth;
|
||||
} irc_client_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char nick[32];
|
||||
char ident[16];
|
||||
char realname[64];
|
||||
} irc_identity_t;
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
void (*handler)(irc_message_t *msg, irc_client_t *irc);
|
||||
} command_t;
|
||||
|
||||
#endif
|
||||
43
src/IRC.c
43
src/IRC.c
@@ -130,10 +130,42 @@ static void handlePing(irc_message_t *msg, irc_client_t *irc)
|
||||
static void handleCapabilities(irc_message_t *msg, irc_client_t *irc)
|
||||
{
|
||||
// we are willing to tolerate some spaghetti...
|
||||
if(strncmp(msg->argv[1], "LS", 4) == 0)
|
||||
if(strcmp(msg->argv[2], "LS") == 0)
|
||||
{
|
||||
// parse the caps
|
||||
snprintf(irc->supportedCapabilities, sizeof irc->supportedCapabilities, "%s", msg->argv[3]);
|
||||
|
||||
// parse the caps
|
||||
irc_capability_t caps[24];
|
||||
int capCount = IRC_ParseCapabilities(irc->supportedCapabilities, caps, sizeof(caps) / sizeof(irc_capability_t));
|
||||
|
||||
irc_capability_t reqCaps[24];
|
||||
|
||||
int reqCapCount = IRC_ParseCapabilities(irc->requestedCapabilities, reqCaps, sizeof(reqCaps) / sizeof(irc_capability_t));
|
||||
|
||||
char buf[512];
|
||||
int bytesWritten = 0;
|
||||
|
||||
for(int i = 0; i < capCount; i++)
|
||||
{
|
||||
for(int j = 0; j < reqCapCount; j++)
|
||||
{
|
||||
if(strcmp(caps[i].name, reqCaps[j].name) == 0 == 0)
|
||||
{
|
||||
bytesWritten += snprintf(buf + bytesWritten, sizeof(buf) - bytesWritten, "%s ", reqCaps[j].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IRC_RequestCapabilities(buf, irc);
|
||||
}
|
||||
else if (strcmp(msg->argv[2], "ACK"))
|
||||
{
|
||||
int ackedCount = IRC_ParseCapabilities(msg->argv[3], irc->acked, sizeof(irc->acked) / sizeof(irc_capability_t));
|
||||
|
||||
for(int i = 0; i < ackedCount; i++)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +219,7 @@ void IRC_USER(char *ident, char *realname, irc_client_t *irc)
|
||||
NET_Send(irc->sockfd, buf);
|
||||
}
|
||||
|
||||
void IRC_REGISTER(char *nick, char *ident, char *realname, bool saslEnabled, irc_sasl_method_t saslMethod, char *saslUsername, char *saslPassword, irc_client_t *irc)
|
||||
void IRC_REGISTER(char *nick, char *ident, char *realname, irc_client_t *irc)
|
||||
{
|
||||
IRC_StartCapabilityNegotiation(irc);
|
||||
IRC_NICK(nick, irc);
|
||||
@@ -206,6 +238,11 @@ void IRC_RequestCapabilities(char *caps, irc_client_t *irc)
|
||||
NET_Send(irc->sockfd, buf);
|
||||
}
|
||||
|
||||
void IRC_NeedCapabilities(char *caps, irc_client_t *irc)
|
||||
{
|
||||
snprintf(irc->requestedCapabilities, sizeof irc->requestedCapabilities, "%s", caps);
|
||||
}
|
||||
|
||||
void IRC_EndCapabilityNegotiation(irc_client_t *irc)
|
||||
{
|
||||
NET_Send(irc->sockfd, "CAP END");
|
||||
|
||||
Reference in New Issue
Block a user