Nilorea Library
C utilities for networking, threading, graphics
n_network_msg.c
Go to the documentation of this file.
1
8#include "nilorea/n_common.h"
9#include "nilorea/n_log.h"
10#include "nilorea/n_network.h"
12
18double double_swap( double value )
19{
20 double swaped = 0 ;
21 unsigned char *src = (unsigned char *)&value ;
22 unsigned char *dst = (unsigned char *)&swaped ;
23
24 /* swap bytes */
25 dst[0] = src[7];
26 dst[1] = src[6];
27 dst[2] = src[5];
28 dst[3] = src[4];
29 dst[4] = src[3];
30 dst[5] = src[2];
31 dst[6] = src[1];
32 dst[7] = src[0];
33
34 return swaped ;
35} /* double_swap() */
36
37
38
44double htond( double value )
45{
46 double ret = value ;
47 /* if byte order is little like x86, PC, ... we swap to network notation */
48#if( BYTEORDER_ENDIAN == BYTEORDER_LITTLE_ENDIAN )
49 ret = double_swap( value );
50#endif
51 return ret ;
52} /* htond() */
53
54
55
61double ntohd( double value )
62{
63 double ret = value ;
64 /* if byte order is little like x86, PC, ... we swap to network notation */
65#if( BYTEORDER_ENDIAN == BYTEORDER_LITTLE_ENDIAN )
66 ret = double_swap( value );
67#endif
68 return ret ;
69} /* ntohd() */
70
71
72
78int create_msg( NETW_MSG **msg )
79{
80 if( (*msg) )
81 {
82 n_log( LOG_ERR, "create_msg destination is valid and should be NULL !" );
83 return FALSE;
84 }
85
86 Malloc( (*msg), NETW_MSG, 1 );
87 __n_assert( msg&&(*msg), return FALSE );
88
89 (*msg) -> tabstr = new_generic_list( -1 );
90 __n_assert( (*msg) -> tabstr, return FALSE );
91 (*msg) -> tabint = new_generic_list( -1 );
92 __n_assert( (*msg) -> tabint, return FALSE );
93 (*msg) -> tabflt = new_generic_list( -1 );
94 __n_assert( (*msg) -> tabflt, return FALSE );
95
96 return TRUE;
97} /* create_msg( ... ) */
98
99
100
107{
108 if( (*msg) )
109 {
110 if( (*msg) -> tabint )
111 {
112 list_destroy( &(*msg) -> tabint );
113 }
114 if( (*msg) -> tabflt )
115 {
116 list_destroy( &(*msg) -> tabflt );
117 }
118 if( (*msg) -> tabstr )
119 {
120 list_destroy( &(*msg) -> tabstr );
121 }
122 Free( (*msg) );
123 }
124 else
125 {
126 n_log( LOG_ERR, "(*msg) already NULL" );
127 return FALSE ;
128 }
129 return TRUE;
130} /* delete_msg */
131
132
133
139int empty_msg( NETW_MSG **msg )
140{
141 __n_assert( msg&&(*msg), return FALSE );
142
143 list_empty( (*msg) -> tabint );
144 list_empty( (*msg) -> tabflt );
145 list_empty( (*msg) -> tabstr );
146
147 return TRUE;
148} /* empty_msg(...) */
149
150
151
159int add_nb_to_msg( NETW_MSG *msg, double value )
160{
161 double *new_val = NULL ;
162
163 __n_assert( msg, return FALSE );
164
165 Malloc( new_val, double, 1 );
166 __n_assert( new_val, return FALSE );
167
168 new_val[ 0 ] = value ;
169
170 return list_push( msg -> tabflt, new_val, free );
171} /* add_nb_to_msg( ... ) */
172
173
174
181int add_int_to_msg( NETW_MSG *msg, int value )
182{
183 int *new_val = NULL ;
184
185 __n_assert( msg, return FALSE );
186
187 Malloc( new_val, int, 1 );
188 __n_assert( new_val, return FALSE );
189
190 new_val[ 0 ] = value ;
191
192 return list_push( msg -> tabint, new_val, free );
193} /* add_int_to_msg( ... ) */
194
195
196
204{
205 __n_assert( msg, return FALSE );
206 __n_assert( str, return FALSE );
207 __n_assert( str -> data, return FALSE );
208 return list_push( msg -> tabstr, str, free_nstr_ptr );
209} /* add_nstrptr_to_msg(...) */
210
211
212
220{
221 __n_assert( msg, return FALSE );
222 __n_assert( str, return FALSE );
223 __n_assert( str -> data, return FALSE );
224
225 return list_push( msg -> tabstr, nstrdup( str ), free_nstr_ptr );
226} /* add_nstrdup_to_msg(...) */
227
228
229
230
237int add_strdup_to_msg( NETW_MSG *msg, const char *str )
238{
239 __n_assert( msg, return FALSE );
240 __n_assert( str, return FALSE );
241
242 N_STR *dup = char_to_nstr( str );
243 __n_assert( dup, return FALSE );
244
245 return list_push( msg -> tabstr, dup, free_nstr_ptr );
246} /* add_strdup_to_msg(...) */
247
248
249
250
257int get_nb_from_msg( NETW_MSG *msg, double *value )
258{
259 double *val = NULL ;
260
261 __n_assert( msg, return FALSE );
262
263 val = list_shift( msg -> tabflt, double );
264 if( val )
265 {
266 (*value) = val[ 0 ] ;
267 Free( val );
268 return TRUE;
269 }
270 return FALSE;
271} /* get_nb_from_msg(...) */
272
273
274
281int get_int_from_msg( NETW_MSG *msg, int *value )
282{
283 int *val = NULL ;
284
285 __n_assert( msg, return FALSE );
286
287 val = list_shift( msg -> tabint, int );
288 if( val )
289 {
290 (*value) = val[ 0 ];
291 Free( val );
292 return TRUE;
293 }
294 return FALSE;
295
296} /* get_int_from_msg(...) */
297
298
299
306int get_nstr_from_msg( NETW_MSG *msg, N_STR **value )
307{
308 N_STR *val = NULL ;
309
310 __n_assert( msg, return FALSE );
311
312 val = list_shift( msg -> tabstr, N_STR );
313 if( val )
314 {
315 if( (*value) )
316 {
317 n_log( LOG_ERR, "Previous pointer value %p overriden by pointer %p", (*value), val );
318 }
319 (*value) = val ;
320 return TRUE;
321 }
322 return FALSE;
323} /* get_nstr_from_msg(...) */
324
325
326
333int get_str_from_msg( NETW_MSG *msg, char **value )
334{
335 N_STR *val = NULL ;
336
337 __n_assert( msg, return FALSE );
338
339 val = list_shift( msg -> tabstr, N_STR );
340 if( val )
341 {
342 if( (*value) )
343 {
344 n_log( LOG_ERR, "Previous pointer value %p overriden by pointer %p", (*value), val );
345 }
346
347 (*value) = val -> data ;
348 Free( val );
349 return TRUE;
350 }
351 return FALSE;
352} /* get_str_from_msg(...) */
353
354
355
362{
363 int str_length = 0 ;
364 LIST_NODE *node = NULL ;
365
366 N_STR *strptr = NULL,
367 *generated_str = NULL ;
368
369 char *charptr = NULL ;
370
371 __n_assert( msg, return NULL );
372
373 /* the first thing to do is to computer the resulting string size
374 the first 12 octets are for the number of ints , floats, strings in the message
375 */
376 str_length = 3 * sizeof( int32_t ) + ( msg -> tabint -> nb_items * sizeof( int32_t ) ) + ( msg -> tabflt -> nb_items * sizeof( double ) ) ;
377
378 /* let's count the eventual string blocks */
379 node = msg -> tabstr -> start ;
380 while( node )
381 {
382 strptr = (N_STR *)node -> ptr ;
383 str_length += sizeof( int32_t ) + sizeof( int32_t ) + strptr -> written ;
384 node = node -> next ;
385 }
386
387 /* preparing the new string */
388 Malloc( generated_str, N_STR, 1 );
389 __n_assert( generated_str, return NULL );
390 Malloc( generated_str -> data, char, str_length + 1 );
391 __n_assert( generated_str -> data, return NULL );
392
393 generated_str -> length = str_length + 1 ;
394 generated_str -> written = str_length ;
395
396
397 /* copying header */
398 charptr = generated_str -> data ;
399
400 /* byte order */
401 msg -> tabint -> nb_items = htonl( msg -> tabint -> nb_items );
402 msg -> tabflt -> nb_items = htonl( msg -> tabflt -> nb_items );
403 msg -> tabstr -> nb_items = htonl( msg -> tabstr -> nb_items );
404
405 /* number of ints inside the message */
406 memcpy ( charptr, &msg -> tabint -> nb_items, sizeof( int32_t ) );
407 charptr += sizeof( int32_t ) ;
408 /* number of doubles inside the message */
409 memcpy ( charptr, &msg -> tabflt -> nb_items, sizeof( int32_t ) );
410 charptr += sizeof( int32_t ) ;
411 /* number of string inside the message */
412 memcpy ( charptr, &msg -> tabstr -> nb_items, sizeof( int32_t ) );
413 charptr += sizeof( int32_t ) ;
414
415 /*reversing byte order to default host order */
416 msg -> tabint -> nb_items = ntohl( msg -> tabint -> nb_items );
417 msg -> tabflt -> nb_items = ntohl( msg -> tabflt -> nb_items );
418 msg -> tabstr -> nb_items = ntohl( msg -> tabstr -> nb_items );
419
420 /* if there are numbers, copy all them ! */
421 node = msg -> tabint -> start ;
422 while( node )
423 {
424 int32_t *nbptr = (int32_t *)node -> ptr ;
425 int32_t val = htonl( nbptr[ 0 ] );
426 memcpy( charptr, &val, sizeof( int32_t ) );
427 charptr += sizeof( int32_t ) ;
428 node = node -> next ;
429 }
430
431 /* if there are numbers, copy all them ! */
432 node = msg -> tabflt -> start ;
433 while( node )
434 {
435 double *nbptr = (double *)node -> ptr ;
436 double val = htond( nbptr[ 0 ] );
437 memcpy( charptr, &val, sizeof( double ) );
438 charptr += sizeof( double ) ;
439 node = node -> next ;
440 }
441
442 /* if there are strings, copy all them ! */
443 if( msg -> tabstr -> nb_items > 0 )
444 {
445 node = msg -> tabstr -> start ;
446 while( node )
447 {
448 strptr = (N_STR *)node -> ptr ;
449
450 int32_t var = htonl( strptr -> length );
451 memcpy( charptr, &var, sizeof( int32_t ) );
452 charptr += sizeof( int32_t );
453
454 var = htonl( strptr -> written );
455 memcpy( charptr, &var, sizeof( int32_t ) );
456 charptr += sizeof( int32_t );
457
458 memcpy( charptr, strptr -> data, strptr -> written );
459 charptr += strptr -> written ;
460 node = node -> next ;
461 }
462
463 }
464
465 return generated_str;
466} /* make_str_from_msg(...) */
467
468
469
476{
477 NETW_MSG *generated_msg = NULL ;
478 N_STR *tmpstr = NULL;
479
480 char *charptr = NULL;
481
482 int32_t it,
483 nb_int = 0,
484 nb_flt = 0,
485 nb_str = 0,
486 tmpnb = 0 ;
487
488 double tmpflt = 0 ;
489
490 __n_assert( str, return NULL );
491
492 charptr = str -> data;
493
494 create_msg( &generated_msg );
495
496 __n_assert( generated_msg, return NULL );
497
498 memcpy( &nb_int, charptr, sizeof( int32_t ) );
499 charptr += sizeof( int32_t ) ;
500 nb_int = ntohl( nb_int );
501
502 memcpy( &nb_flt, charptr, sizeof( int32_t ) );
503 charptr += sizeof( int32_t ) ;
504 nb_flt = ntohl( nb_flt );
505
506 memcpy( &nb_str, charptr, sizeof( int32_t ) );
507 charptr += sizeof( int32_t ) ;
508 nb_str = ntohl( nb_str );
509
510 if( nb_int > 0 )
511 {
512 for( it = 0 ; it < nb_int ; it ++ )
513 {
514 memcpy( &tmpnb, charptr, sizeof( int32_t ) ) ;
515 tmpnb = ntohl( tmpnb );
516 charptr += sizeof( int32_t ) ;
517 add_int_to_msg( generated_msg, tmpnb );
518 }
519 }
520
521 if( nb_flt > 0 )
522 {
523 for( it = 0 ; it < nb_flt ; it ++ )
524 {
525 memcpy( &tmpflt, charptr, sizeof( double ) ) ;
526 tmpflt = ntohd( tmpflt );
527 charptr += sizeof( double ) ;
528 add_nb_to_msg( generated_msg, tmpflt );
529 }
530 }
531
532
533 if( nb_str > 0 )
534 {
535 for( it = 0 ; it < nb_str ; it ++ )
536 {
537
538 Malloc( tmpstr, N_STR, 1 );
539 __n_assert( tmpstr, return NULL );
540 int32_t var = 0 ;
541 memcpy( &var, charptr, sizeof( int32_t ) );
542 charptr += sizeof( int32_t ) ;
543 tmpstr -> length = ntohl( var );
544
545 memcpy( &var, charptr, sizeof( int32_t ) );
546 charptr += sizeof( int32_t ) ;
547 tmpstr -> written = ntohl( var );
548
549 Malloc( tmpstr -> data, char, tmpstr -> length );
550 __n_assert( tmpstr -> data, return NULL );
551
552 memcpy( tmpstr -> data, charptr, tmpstr -> written );
553 charptr += tmpstr -> written ;
554
555 add_nstrptr_to_msg( generated_msg, tmpstr );
556 }
557 }
558 return generated_msg ;
559} /* make_msg_from_str(...) */
560
561
562
563#ifndef NO_NETMSG_API
564
573N_STR *netmsg_make_ping( int type, int id_from, int id_to, int time )
574{
575 NETW_MSG *msg = NULL ;
576
577 N_STR *tmpstr = NULL ;
578
579 create_msg( &msg );
580
581 __n_assert( msg, return NULL );
582
583 if( add_int_to_msg( msg, type ) == FALSE )
584 {
585 delete_msg( &msg );
586 return NULL;
587 }
588 if( add_int_to_msg( msg, id_from ) == FALSE )
589 {
590 delete_msg( &msg );
591 return NULL;
592 }
593 if( add_int_to_msg( msg, id_to ) == FALSE )
594 {
595 delete_msg( &msg );
596 return NULL;
597 }
598 if( add_int_to_msg( msg, time ) == FALSE )
599 {
600 delete_msg( &msg );
601 return NULL;
602 }
603
604 tmpstr = make_str_from_msg( msg );
605 delete_msg( &msg );
606
607 return tmpstr ;
608} /* netmsg_make_ping() */
609
610
611
620N_STR *netmsg_make_ident( int type, int id, N_STR *name, N_STR *passwd )
621{
622 NETW_MSG *msg = NULL ;
623 N_STR *tmpstr = NULL ;
624
625 create_msg( &msg );
626 __n_assert( msg, return FALSE );
627
628 if( add_int_to_msg( msg, type ) == FALSE )
629 {
630 delete_msg( &msg );
631 return NULL;
632 }
633 if( add_int_to_msg( msg, id ) == FALSE )
634 {
635 delete_msg( &msg );
636 return NULL;
637 }
638
639 if( add_nstrdup_to_msg( msg, name ) == FALSE )
640 {
641 delete_msg( &msg );
642 return NULL;
643 }
644 if( add_nstrdup_to_msg( msg, passwd ) == FALSE )
645 {
646 delete_msg( &msg );
647 return NULL;
648 }
649
650 tmpstr = make_str_from_msg( msg );
651 delete_msg( &msg );
652
653 return tmpstr ;
654} /* netmsg_make_ident() */
655
656
657
670N_STR *netmsg_make_position_msg( int id, double X, double Y, double vx, double vy, double acc_x, double acc_y, int time_stamp )
671{
672
673 NETW_MSG *msg = NULL ;
674 N_STR *tmpstr = NULL ;
675
676 create_msg( &msg );
677
678 __n_assert( msg, return NULL );
679
681 add_int_to_msg( msg, id );
682 add_nb_to_msg( msg, X );
683 add_nb_to_msg( msg, Y );
684 add_nb_to_msg( msg, vx );
685 add_nb_to_msg( msg, vy );
686 add_nb_to_msg( msg, acc_x );
687 add_nb_to_msg( msg, acc_y );
688 add_int_to_msg( msg, time_stamp );
689
690 tmpstr = make_str_from_msg( msg );
691 delete_msg( &msg );
692 return tmpstr ;
693} /* netmsg_make_position_msg() */
694
695
696
697
708N_STR *netmsg_make_string_msg( int id_from, int id_to, N_STR *name, N_STR *chan, N_STR *txt, int color )
709{
710 NETW_MSG *msg = NULL ;
711
712 N_STR *tmpstr = NULL ;
713
714 create_msg( &msg );
715
716 __n_assert( msg, return NULL );
717
719 add_int_to_msg( msg, id_from );
720 add_int_to_msg( msg, id_to );
721 add_int_to_msg( msg, color );
722
723
724 add_nstrdup_to_msg( msg, nstrdup( name ) );
725 add_nstrdup_to_msg( msg, nstrdup( chan ) );
726 add_nstrdup_to_msg( msg, nstrdup( txt ) );
727
728 tmpstr = make_str_from_msg( msg );
729 delete_msg( &msg );
730 __n_assert( tmpstr, return NULL );
731
732 return tmpstr ;
733
734} /* netmsg_make_string_msg */
735
736
737
743{
744 NETW_MSG *msg = NULL ;
745 N_STR *tmpstr = NULL ;
746
747 create_msg( &msg );
748 __n_assert( msg, return FALSE );
749
751 tmpstr = make_str_from_msg( msg );
752 delete_msg( &msg );
753 __n_assert( tmpstr, return NULL );
754
755 return tmpstr ;
756} /* netmsg_make_quit_msg() */
757
758
759
766{
767 int32_t tmpnb = 0 ;
768 char *charptr = NULL ;
769
770 __n_assert( msg, return FALSE );
771
772 charptr = msg -> data ;
773
774 /* here we bypass the number of int, numebr of flt, number of str, (4+4+4) to get the
775 * first number which should be type */
776 charptr += 3 * sizeof( int32_t );
777 memcpy( &tmpnb, charptr, sizeof( int32_t ) ) ;
778 tmpnb = ntohl( tmpnb );
779
780 return tmpnb;
781} /* netw_msg_get_type(...) */
782
783
784
794int netw_get_ident( N_STR *msg, int *type,int *ident, N_STR **name, N_STR **passwd )
795{
796 NETW_MSG *netmsg = NULL ;
797
798 __n_assert( msg, return FALSE);
799
800 netmsg = make_msg_from_str( msg );
801
802 __n_assert( netmsg, return FALSE);
803
804 get_int_from_msg( netmsg, &(*type) );
805 get_int_from_msg( netmsg, &(*ident) );
806
807 if( (*type) != NETMSG_IDENT_REQUEST && (*type) != NETMSG_IDENT_REPLY_OK && (*type) != NETMSG_IDENT_REPLY_NOK )
808 {
809 n_log( LOG_ERR, "unknow (*type) %d", (*type) );
810 delete_msg( &netmsg );
811 return FALSE;
812 }
813
814 get_nstr_from_msg( netmsg, &(*name) );
815 get_nstr_from_msg( netmsg, &(*passwd) );
816
817 delete_msg( &netmsg );
818
819 return TRUE;
820} /* netw_get_ident( ... ) */
821
822
823
837int 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 )
838{
839 NETW_MSG *netmsg = NULL ;
840
841 int type = 0 ;
842
843 __n_assert( msg, return FALSE );
844
845 netmsg = make_msg_from_str( msg );
846
847 __n_assert( netmsg, return FALSE );
848
849 get_int_from_msg( netmsg, &type );
850
851 if( type != NETMSG_POSITION )
852 {
853 delete_msg( &netmsg );
854 return FALSE;
855 }
856
857 get_int_from_msg( netmsg, &(*id) );
858 get_nb_from_msg( netmsg, &(*X) );
859 get_nb_from_msg( netmsg, &(*Y) );
860 get_nb_from_msg( netmsg, &(*vx) );
861 get_nb_from_msg( netmsg, &(*vy) );
862 get_nb_from_msg( netmsg, &(*acc_x) );
863 get_nb_from_msg( netmsg, &(*acc_y) );
864 get_int_from_msg( netmsg, &(*time_stamp) );
865
866 delete_msg( &netmsg );
867
868 return TRUE;
869} /* netw_get_position( ... ) */
870
871
872
884int netw_get_string( N_STR *msg, int *id, N_STR **name, N_STR **chan, N_STR **txt, int *color )
885{
886 NETW_MSG *netmsg = NULL;
887
888 int type = 0 ;
889
890 __n_assert( msg, return FALSE );
891
892 netmsg = make_msg_from_str( msg );
893
894 __n_assert( netmsg, return FALSE );
895
896 get_int_from_msg( netmsg, &type );
897
898 if( type != NETMSG_STRING )
899 {
900 delete_msg( &netmsg );
901 return FALSE;
902 }
903
904 get_int_from_msg( netmsg, id );
905 get_int_from_msg( netmsg, color );
906
907 get_nstr_from_msg( netmsg, &(*name) );
908 get_nstr_from_msg( netmsg, &(*chan) );
909 get_nstr_from_msg( netmsg, &(*txt) );
910
911 delete_msg( &netmsg );
912
913 return TRUE;
914
915} /* netw_get_string( ... ) */
916
917
918
928int netw_get_ping( N_STR *msg, int *type, int *from, int *to, int *time )
929{
930 NETW_MSG *netmsg;
931
932 __n_assert( msg, return FALSE );
933
934 netmsg = make_msg_from_str( msg );
935
936 __n_assert( netmsg, return FALSE );
937
938 get_int_from_msg( netmsg, &(*type) );
939
940 if( (*type) != NETMSG_PING_REQUEST && (*type) != NETMSG_PING_REPLY )
941 {
942 delete_msg( &netmsg );
943 return FALSE;
944 }
945
946 get_int_from_msg( netmsg, &(*from) );
947 get_int_from_msg( netmsg, &(*to) );
948 get_int_from_msg( netmsg, &(*time) );
949
950
951 delete_msg( &netmsg );
952
953 return TRUE;
954} /* netw_get_ping( ... ) */
955
956
957
964{
965 __n_assert( msg, return FALSE );
966
967 NETW_MSG *netmsg = NULL ;
968 netmsg = make_msg_from_str( msg );
969 __n_assert( netmsg, return FALSE );
970
971 int type = -1 ;
972 get_int_from_msg( netmsg, &type );
973 if( type != NETMSG_QUIT )
974 {
975 delete_msg( &netmsg );
976 return FALSE;
977 }
978 delete_msg( &netmsg );
979 return TRUE;
980} /* netw_get_quit( ... ) */
981
982
983#endif // NO_NETMSG_API
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
Definition: n_common.h:183
#define __n_assert(__ptr, __ret)
macro to assert things
Definition: n_common.h:276
#define Free(__ptr)
Free Handler to get errors.
Definition: n_common.h:256
#define list_shift(__LIST_, __TYPE_)
Shift macro helper for void pointer casting.
Definition: n_list.h:81
int list_empty(LIST *list)
Empty a LIST list of pointers.
Definition: n_list.c:547
int list_push(LIST *list, void *ptr, void(*destructor)(void *ptr))
Add a pointer to the end of the list.
Definition: n_list.c:244
int list_destroy(LIST **list)
Empty and Free a list container.
Definition: n_list.c:603
LIST * new_generic_list(int max_items)
Initialiaze a generic list container to max_items pointers.
Definition: n_list.c:20
Structure of a generic list node.
Definition: n_list.h:27
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
Definition: n_log.h:74
#define LOG_ERR
error conditions
Definition: n_log.h:58
void free_nstr_ptr(void *ptr)
Free a N_STR pointer structure.
Definition: n_str.c:55
N_STR * nstrdup(N_STR *str)
Duplicate a N_STR.
Definition: n_str.c:795
N_STR * char_to_nstr(const char *src)
Convert a char into a N_STR, short version.
Definition: n_str.c:273
A box including a string and his lenght.
Definition: n_str.h:173
#define NETMSG_IDENT_REQUEST
Network Message is identification request: (int)type , (int)id , (N_STR *)name , (N_STR *)password.
Definition: n_network_msg.h:27
double htond(double value)
If needed swap bytes for a double.
Definition: n_network_msg.c:44
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.
Definition: n_network_msg.h:37
#define NETMSG_IDENT_REPLY_NOK
Network Message is identification reply NON OK: (int)type , (int)id , (N_STR *)name ,...
Definition: n_network_msg.h:31
#define NETMSG_STRING
Network Message is string: (int)type , (int)id , (N_STR *)name , (N_STR *)chan , (N_STR *)text ,...
Definition: n_network_msg.h:33
#define NETMSG_PING_REPLY
Network Message is ping reply: (int)type , (int)id_from , (int)id_to.
Definition: n_network_msg.h:39
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.
Definition: n_network_msg.c:18
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.
Definition: n_network_msg.h:45
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.
Definition: n_network_msg.c:78
#define NETMSG_POSITION
Network Message position: (int)type , (int)id , (int)X , (int)Y , (int)x_shift , (int)y_shift ,...
Definition: n_network_msg.h:35
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.
Definition: n_network_msg.c:61
#define NETMSG_IDENT_REPLY_OK
Network Message is identification reply OK : (int)type , (int)id , (N_STR *)name ,...
Definition: n_network_msg.h:29
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
Definition: n_network_msg.h:49
Common headers and low-level hugly functions & define.
Generic log system.
Network Engine.
Network messages , serialization tools.