ejabberd auth message function;
This commit is contained in:
parent
4b99ad0b7b
commit
25575475bf
52
src/eport.c
52
src/eport.c
@ -23,6 +23,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <ejabbermsg.h>
|
#include <ejabbermsg.h>
|
||||||
|
|
||||||
@ -77,5 +78,54 @@ ssize_t eport_write(FILE *stream, char *buffer, size_t buffer_size)
|
|||||||
int eport_ejabberd_msgread(char *buffer, size_t buffer_size,
|
int eport_ejabberd_msgread(char *buffer, size_t buffer_size,
|
||||||
struct ejabber_msg *m)
|
struct ejabber_msg *m)
|
||||||
{
|
{
|
||||||
return 0;
|
char *orig_buffer = buffer;
|
||||||
|
unsigned long hash = 5381;
|
||||||
|
int c, t = 0;
|
||||||
|
|
||||||
|
if(!buffer || buffer_size <= 0) {
|
||||||
|
ieinval:
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(!m) goto ieinval;
|
||||||
|
|
||||||
|
/* calc hash for first message word till the end or till the ':' */
|
||||||
|
while(((c = *buffer++) != '\0') || (*buffer == ':'))
|
||||||
|
hash = ((hash << 5) + hash) + c;
|
||||||
|
|
||||||
|
switch(hash) {
|
||||||
|
case AUTH_HASH: m->aev = EJA_AUTH; break;
|
||||||
|
case ISUSER_HASH: m->aev = EJA_ISUSER; break;
|
||||||
|
case SETPASS_HASH: m->aev = EJA_SETPASS; break;
|
||||||
|
case TRYREGISTER_HASH: m->aev = EJA_TRYREGISTER; break;
|
||||||
|
case REMOVEUSER_HASH: m->aev = EJA_REMOVEUSER; break;
|
||||||
|
case REMOVEUSER3_HASH: m->aev = EJA_REMOVEUSER3; break;
|
||||||
|
default:
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* initialize other things in message */
|
||||||
|
m->msg_data = orig_buffer;
|
||||||
|
m->user = m->domain = m->password = NULL;
|
||||||
|
/* shift a pointer */
|
||||||
|
c = *buffer++; orig_buffer = buffer;
|
||||||
|
|
||||||
|
while((buffer = strchr(buffer, ':')) != NULL) {
|
||||||
|
switch(t) {
|
||||||
|
case 0: m->user = orig_buffer; break;
|
||||||
|
case 1: m->domain = orig_buffer; break;
|
||||||
|
default:
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*buffer = '\0'; c = *buffer++;
|
||||||
|
orig_buffer = buffer; t++;
|
||||||
|
}
|
||||||
|
if(*orig_buffer != '\0') {
|
||||||
|
if(t > 1) m->password = orig_buffer;
|
||||||
|
else m->domain = orig_buffer;
|
||||||
|
t++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return t;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user