From 1cbc2783b692029af18c1b046b9c9480572b2f72 Mon Sep 17 00:00:00 2001 From: Alexander Vdolainen Date: Tue, 16 Mar 2021 01:32:33 +0200 Subject: [PATCH] types and miscs for ejabberd message are done. --- include/ejabbermsg.h | 48 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/include/ejabbermsg.h b/include/ejabbermsg.h index 09a9451..ec654f7 100644 --- a/include/ejabbermsg.h +++ b/include/ejabbermsg.h @@ -21,15 +21,55 @@ #ifndef __EJABBERDMSG_H__ #define __EJABBERDMSG_H__ +/* + * in order to avoid extensive strncmps + * that's a way faster to precalculate + * djb hash for each action. + * according to documentation there are the few ones: + * = auth:user:server:password (authentication itself) + * = isuser:user:server (check is user exist) + * = setpass:user:server:password (set new password) + * = tryregister:user:server:password (try to register a new account) + * = removeuser:user:server (remove user's account) + * = removeuser3:user:server:password (the same as above, but works with + * right password only) + */ +#define AUTH_HASH 0x000000017C944157 +#define ISUSER_HASH 0x00000653052FCFC0 +#define SETPASS_HASH 0x0000D0B68C342068 +#define TRYREGISTER_HASH 0xC0D7C0FAC0ED2809 +#define REMOVEUSER_HASH 0x7272BF5C0AA994F2 +#define REMOVEUSER3_HASH 0xC0CAAADD5FDC3365 + +/* type used for ejabberd action */ +typedef enum { + EJA_AUTH = 1, + EJA_ISUSER = 2, + EJA_SETPASS = 3, + EJA_TRYREGISTER = 4, + EJA_REMOVEUSER = 5, + EJA_REMOVEUSER3 = 6, + EJA_UNKNOWN = 7, +} ejabber_action_t; + +/* limits for allocation */ #define MAX_USER_LEN 256 #define MAX_DOMAIN_LEN 128 #define MAX_PASSWORD_LEN 128 struct ejabber_msg { - int action; - char user[MAX_USER_LEN]; - char domain[MAX_DOMAIN_LEN]; - char password[MAX_PASSWORD_LEN]; + ejabber_action_t aev; /* message action */ + char *msg_data; /* all data from the message */ + char *user; /* pointer to the user part */ + char *domain; /* pointer to the domain/server part of the message */ + char *password; /* pointer to the password part of the message */ }; +/* little helpers to avoid structure's names hunting */ +#define ejabber_msg_event(c) (c)->aev +#define ejabber_msg_data(c) (c)->msg_data +#define ejabber_msg_user(c) (c)->user +#define ejabber_msg_domain(c) (c)->domain +#define ejabber_msg_password(c) (c)->password + #endif /* __EJABBERDMSG_H__ */