20 unsigned char* src = (
unsigned char*)&value;
21 unsigned char* dst = (
unsigned char*)&swaped;
44#if (BYTEORDER_ENDIAN == BYTEORDER_LITTLE_ENDIAN)
58#if (BYTEORDER_ENDIAN == BYTEORDER_LITTLE_ENDIAN)
71 n_log(
LOG_ERR,
"create_msg destination is valid and should be NULL !");
101 if ((*msg)->tabstr) {
135 double* new_val = NULL;
139 Malloc(new_val,
double, 1);
265 n_log(
LOG_ERR,
"Previous pointer value %p overriden by pointer %p", (*value), val);
287 n_log(
LOG_ERR,
"Previous pointer value %p overriden by pointer %p", (*value), val);
290 (*value) = val->
data;
303 size_t str_length = 0;
306 N_STR *strptr = NULL,
307 *generated_str = NULL;
309 char* charptr = NULL;
322 str_length +=
sizeof(int32_t) +
sizeof(int32_t) + strptr->
written;
329 Malloc(generated_str->data,
char, str_length + 1);
330 __n_assert(generated_str->data,
Free(generated_str);
return NULL);
332 generated_str->length = str_length + 1;
333 generated_str->written = str_length;
336 charptr = generated_str->data;
340 n_log(
LOG_ERR,
"too much items (>=UINT32_MAX) in int list of message %p", msg);
345 n_log(
LOG_ERR,
"too much items (>=UINT32_MAX) in float list of message %p", msg);
350 n_log(
LOG_ERR,
"too much items (>=UINT32_MAX) in string list of message %p", msg);
361 memcpy(charptr, &nb_int_items,
sizeof(uint32_t));
362 charptr +=
sizeof(uint32_t);
364 memcpy(charptr, &nb_float_items,
sizeof(uint32_t));
365 charptr +=
sizeof(uint32_t);
367 memcpy(charptr, &nb_str_items,
sizeof(uint32_t));
368 charptr +=
sizeof(uint32_t);
373 uint32_t* nbptr = (uint32_t*)node->
ptr;
374 uint32_t val = htonl(nbptr[0]);
375 memcpy(charptr, &val,
sizeof(uint32_t));
376 charptr +=
sizeof(uint32_t);
383 double* nbptr = (
double*)node->
ptr;
384 double val =
htond(nbptr[0]);
385 memcpy(charptr, &val,
sizeof(
double));
386 charptr +=
sizeof(double);
395 if (strptr->
length >= UINT32_MAX) {
396 n_log(
LOG_ERR,
"string too long (>=UINT32_MAX) in string list of message %p", msg);
400 uint32_t var = htonl((uint32_t)strptr->
length);
401 memcpy(charptr, &var,
sizeof(uint32_t));
402 charptr +=
sizeof(uint32_t);
404 if (strptr->
written >= UINT32_MAX) {
405 n_log(
LOG_ERR,
"string too long (>=UINT32_MAX) in string list of message %p", msg);
409 var = htonl((uint32_t)strptr->
written);
410 memcpy(charptr, &var,
sizeof(uint32_t));
411 charptr +=
sizeof(uint32_t);
419 return generated_str;
429 N_STR* tmpstr = NULL;
431 char* charptr = NULL;
449 memcpy(&nb_int, charptr,
sizeof(uint32_t));
450 charptr +=
sizeof(uint32_t);
451 nb_int = ntohl(nb_int);
453 memcpy(&nb_flt, charptr,
sizeof(uint32_t));
454 charptr +=
sizeof(uint32_t);
455 nb_flt = ntohl(nb_flt);
457 memcpy(&nb_str, charptr,
sizeof(uint32_t));
458 charptr +=
sizeof(uint32_t);
459 nb_str = ntohl(nb_str);
462 for (it = 0; it < nb_int; it++) {
463 memcpy(&tmpnb, charptr,
sizeof(uint32_t));
464 tmpnb = (int32_t)ntohl((uint32_t)tmpnb);
465 charptr +=
sizeof(uint32_t);
471 for (it = 0; it < nb_flt; it++) {
472 memcpy(&tmpflt, charptr,
sizeof(
double));
473 tmpflt =
ntohd(tmpflt);
474 charptr +=
sizeof(double);
480 for (it = 0; it < nb_str; it++) {
484 memcpy(&var, charptr,
sizeof(uint32_t));
485 charptr +=
sizeof(uint32_t);
486 tmpstr->
length = ntohl(var);
488 memcpy(&var, charptr,
sizeof(uint32_t));
489 charptr +=
sizeof(uint32_t);
501 return generated_msg;
517 N_STR* tmpstr = NULL;
556 N_STR* tmpstr = NULL;
599 N_STR* tmpstr = NULL;
660 N_STR* tmpstr = NULL;
710 N_STR* tmpstr = NULL;
733 char* charptr = NULL;
741 charptr += 3 *
sizeof(uint32_t);
742 memcpy(&tmpnb, charptr,
sizeof(uint32_t));
743 tmpnb = (int32_t)ntohl((uint32_t)tmpnb);
796int netw_get_position(
N_STR* msg,
int*
id,
double* X,
double* Y,
double* vx,
double* vy,
double* acc_x,
double* acc_y,
int* time_stamp) {
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define __n_assert(__ptr, __ret)
macro to assert things
#define Free(__ptr)
Free Handler to get errors.
void * ptr
void pointer to store
LIST_NODE * start
pointer to the start of the list
size_t nb_items
number of item currently in the list
struct LIST_NODE * next
pointer to the next node
#define list_shift(__LIST_, __TYPE_)
Shift macro helper for void pointer casting.
int list_empty(LIST *list)
Empty a LIST list of pointers.
int list_push(LIST *list, void *ptr, void(*destructor)(void *ptr))
Add a pointer to the end of the list.
int list_destroy(LIST **list)
Empty and Free a list container.
#define MAX_LIST_ITEMS
flag to pass to new_generic_list for the maximum possible number of item in a list
Structure of a generic list node.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_ERR
error conditions
size_t written
size of the written data inside the string
size_t length
length of string (in case we wanna keep information after the 0 end of string value)
void free_nstr_ptr(void *ptr)
Free a N_STR pointer structure.
#define free_nstr(__ptr)
free a N_STR structure and set the pointer to NULL
N_STR * nstrdup(N_STR *str)
Duplicate a N_STR.
N_STR * char_to_nstr(const char *src)
Convert a char into a N_STR, short version.
A box including a string and his lenght.
LIST * tabflt
array of casted double value
LIST * tabstr
array of N_STR
LIST * tabint
array of int
#define NETMSG_IDENT_REQUEST
Network Message is identification request: (int)type , (int)id , (N_STR *)name , (N_STR *)password.
double htond(double value)
If needed swap bytes for a double.
int get_str_from_msg(NETW_MSG *msg, char **value)
Get a string from a message string list.
int add_strdup_to_msg(NETW_MSG *msg, const char *str)
Add a copy of char *str to the string list in the message.
int netw_get_position(N_STR *msg, int *id, double *X, double *Y, double *vx, double *vy, double *acc_x, double *acc_y, int *time_stamp)
Retrieves position from netwmsg.
#define NETMSG_PING_REQUEST
Network Message is ping request: (int)type , (int)id_from , (int)id_to.
#define NETMSG_IDENT_REPLY_NOK
Network Message is identification reply NON OK: (int)type , (int)id , (N_STR *)name ,...
#define NETMSG_STRING
Network Message is string: (int)type , (int)id , (N_STR *)name , (N_STR *)chan , (N_STR *)text ,...
#define NETMSG_PING_REPLY
Network Message is ping reply: (int)type , (int)id_from , (int)id_to.
NETW_MSG * make_msg_from_str(N_STR *str)
Make a single message of the string.
int empty_msg(NETW_MSG **msg)
Empty a NETW_MSG *object.
double double_swap(double value)
Swap bytes endiannes for a double.
N_STR * make_str_from_msg(NETW_MSG *msg)
Make a single string of the message.
int netw_get_ping(N_STR *msg, int *type, int *from, int *to, int *time)
Retrieves a ping travel elapsed time.
int add_nstrptr_to_msg(NETW_MSG *msg, N_STR *str)
Add a string to the string list in the message.
int get_nb_from_msg(NETW_MSG *msg, double *value)
Get a number from a message number list.
#define NETMSG_QUIT
Network asking for exit.
int netw_get_quit(N_STR *msg)
get a formatted NETWMSG_QUIT message from the specified network
int create_msg(NETW_MSG **msg)
Create a NETW_MSG *object.
#define NETMSG_POSITION
Network Message position: (int)type , (int)id , (int)X , (int)Y , (int)x_shift , (int)y_shift ,...
N_STR * netmsg_make_position_msg(int id, double X, double Y, double vx, double vy, double acc_x, double acc_y, int time_stamp)
make a network NETMSG_POSITION message with given parameters
int netw_msg_get_type(N_STR *msg)
Get the type of message without killing the first number. Use with netw_get_XXX.
int get_nstr_from_msg(NETW_MSG *msg, N_STR **value)
Get a string from a message string list.
N_STR * netmsg_make_ident(int type, int id, N_STR *name, N_STR *passwd)
Add a formatted NETWMSG_IDENT message to the specified network.
int add_nstrdup_to_msg(NETW_MSG *msg, N_STR *str)
Add a copy of str to the string list in the message.
int add_int_to_msg(NETW_MSG *msg, int value)
Add an int to the int list int the message.
double ntohd(double value)
If needed swap bytes for a double.
#define NETMSG_IDENT_REPLY_OK
Network Message is identification reply OK : (int)type , (int)id , (N_STR *)name ,...
int netw_get_string(N_STR *msg, int *id, N_STR **name, N_STR **chan, N_STR **txt, int *color)
Retrieves string from netwmsg.
int delete_msg(NETW_MSG **msg)
Delete a NETW_MSG *object.
int add_nb_to_msg(NETW_MSG *msg, double value)
Add an float to the message.
N_STR * netmsg_make_quit_msg(void)
make a generic network NETMSG_QUIT message
N_STR * netmsg_make_ping(int type, int id_from, int id_to, int time)
Make a ping message to send to a network.
int netw_get_ident(N_STR *msg, int *type, int *ident, N_STR **name, N_STR **passwd)
Retrieves identification from netwmsg.
N_STR * netmsg_make_string_msg(int id_from, int id_to, N_STR *name, N_STR *chan, N_STR *txt, int color)
make a network NETMSG_STRING message with given parameters
int get_int_from_msg(NETW_MSG *msg, int *value)
Get a number from a message number list.
network message, array of char and int
Common headers and low-level functions & define.
Network messages , serialization tools.