eport read function;

master
Alexander Vdolainen 4 years ago
parent e3f4f84c02
commit 4220890af6

@ -20,17 +20,39 @@
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <unistd.h>
#include <errno.h>
#include <ejabbermsg.h> #include <ejabbermsg.h>
size_t eport_read(FILE *stream, char *buffer, size_t buffer_size) ssize_t eport_read(FILE *stream, char *buffer, size_t buffer_size)
{ {
return 0; int fd = fileno(stream);
int16_t port_msg_len = 0;
ssize_t pr = 0;
if(fd < 0) return -1;
/* firstly the size of plain text message is required.
* it has a short size and is going in bigendian order.
*/
pr = read(fd, &port_msg_len, sizeof(int16_t));
if(pr < 0) return -1;
port_msg_len = (port_msg_len << 8) | ((port_msg_len >> 8) & 0xFF);
/* check if a buffer has required amount of bytes */
if(port_msg_len > buffer_size) {
errno = EMSGSIZE; /* message is too long */
return -1;
} else
pr = read(fd, buffer, port_msg_len);
return pr;
} }
size_t eport_write(FILE *stream, char *buffer, size_t buffer_size) ssize_t eport_write(FILE *stream, char *buffer, size_t buffer_size)
{ {
return 0; return -1;
} }
int eport_ejabberd_msgread(char *buffer, size_t buffer_size, int eport_ejabberd_msgread(char *buffer, size_t buffer_size,

Loading…
Cancel
Save