1 /*======================================================================*
2 * Copyright (C) 2008 Light Weight Event System *
3 * All rights reserved. *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
18 * Boston, MA 02110-1301 USA. *
19 *======================================================================*/
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
23 #include <arpa/inet.h>
27 #include "lwes_event.h"
28 #include "lwes_hash.h"
29 #include "lwes_marshall_functions.h"
31 /*************************************************************************
32 PRIVATE API prototypes, shouldn't be called by a user of the library.
33 *************************************************************************/
35 /* Create the memory for an event attribute */
36 static struct lwes_event_attribute
*
37 lwes_event_attribute_create
43 (struct lwes_event
* event
,
44 LWES_CONST_SHORT_STRING attrNameIn
,
49 lwes_INT_64_from_hex_string
51 LWES_INT_64
* an_int64
);
54 lwes_U_INT_64_from_hex_string
56 LWES_U_INT_64
* a_uint64
);
58 /*************************************************************************
60 *************************************************************************/
62 lwes_event_create_no_name
63 (struct lwes_event_type_db
*db
)
65 struct lwes_event
*event
=
66 (struct lwes_event
*)malloc (sizeof (struct lwes_event
));
73 event
->eventName
= NULL
;
74 event
->number_of_attributes
= 0;
76 event
->attributes
= lwes_hash_create ();
77 if (event
->attributes
== NULL
)
86 /* PUBLIC : Create the memory for an event */
89 (struct lwes_event_type_db
*db
,
90 LWES_CONST_SHORT_STRING name
)
92 struct lwes_event
*event
;
99 event
= (struct lwes_event
*)malloc (sizeof (struct lwes_event
));
106 event
->eventName
= NULL
;
107 event
->number_of_attributes
= 0;
109 event
->attributes
= lwes_hash_create ();
110 if (event
->attributes
== NULL
)
116 if (lwes_event_set_name (event
,name
) < 0)
118 /* Having problems, bail and return NULL */
119 lwes_hash_destroy (event
->attributes
);
128 lwes_event_create_with_encoding
129 (struct lwes_event_type_db
*db
,
130 LWES_CONST_SHORT_STRING name
,
131 LWES_INT_16 encoding
)
133 struct lwes_event
*event
;
140 event
= (struct lwes_event
*)malloc(sizeof(struct lwes_event
));
147 event
->eventName
= NULL
;
148 event
->number_of_attributes
= 0;
150 event
->attributes
= lwes_hash_create ();
152 if (event
->attributes
== NULL
)
158 if (lwes_event_set_name(event
,name
) < 0)
160 /* Having memory problems, bail */
161 lwes_hash_destroy (event
->attributes
);
166 if (lwes_event_set_encoding (event
,encoding
) < 0)
168 /* problem setting encoding, free up memory and bail */
169 lwes_hash_destroy (event
->attributes
);
170 if (event
->eventName
!= NULL
)
172 free (event
->eventName
);
183 (struct lwes_event
*event
,
184 LWES_CONST_SHORT_STRING name
)
186 if (event
== NULL
|| name
== NULL
|| event
->eventName
!= NULL
)
192 (LWES_SHORT_STRING
) malloc (sizeof (LWES_CHAR
)*(strlen (name
)+1));
194 if (event
->eventName
== NULL
)
199 strcpy (event
->eventName
,name
);
205 lwes_event_set_encoding
206 (struct lwes_event
*event
,
207 LWES_INT_16 encoding
)
209 LWES_INT_16 tmp_encoding
;
216 if ( lwes_event_get_INT_16 (event
, LWES_ENCODING
, &tmp_encoding
) == -1 )
218 return lwes_event_set_INT_16 (event
, LWES_ENCODING
, encoding
);
226 (struct lwes_event
*event
, LWES_SHORT_STRING
*name
)
228 if (event
== NULL
|| name
== NULL
)
232 *name
= event
->eventName
;
237 lwes_event_get_number_of_attributes
238 (struct lwes_event
*event
,
239 LWES_U_INT_16
*number
)
241 if (event
== NULL
|| number
== NULL
)
245 *number
= event
->number_of_attributes
;
250 lwes_event_get_encoding
251 (struct lwes_event
*event
,
252 LWES_INT_16
*encoding
)
254 if (event
== NULL
|| encoding
== NULL
)
259 return lwes_event_get_INT_16 (event
,
260 (LWES_SHORT_STRING
)LWES_ENCODING
,
264 /* PUBLIC : Cleanup the memory for an event */
267 (struct lwes_event
*event
)
269 struct lwes_event_attribute
*tmp
= NULL
;
270 struct lwes_hash_enumeration e
;
277 /* free the parts of the event */
278 if (event
->eventName
!= NULL
)
280 free(event
->eventName
);
283 /* clear out the hash */
284 if (lwes_hash_keys (event
->attributes
, &e
))
286 while (lwes_hash_enumeration_has_more_elements (&e
))
288 LWES_SHORT_STRING tmpAttrName
=
289 lwes_hash_enumeration_next_element (&e
);
291 (struct lwes_event_attribute
*)lwes_hash_remove (event
->attributes
,
293 /* free the attribute name and value*/
294 if (tmpAttrName
!= NULL
)
298 if (tmp
->value
!= NULL
)
302 /* free the attribute itself*/
310 /* free the now empty hash */
311 lwes_hash_destroy (event
->attributes
);
313 /* finally free the event structure */
319 /* PUBLIC : serialize the event and put it into a byte array */
322 (struct lwes_event
*event
,
327 struct lwes_event_attribute
*tmp
;
328 struct lwes_event_attribute
*encodingAttr
;
329 size_t tmpOffset
= offset
;
330 struct lwes_hash_enumeration e
;
336 || offset
>= num_bytes
)
341 /* start with the event name */
342 if (marshall_SHORT_STRING (event
->eventName
,
347 /* then the number of attributes */
348 if (marshall_U_INT_16 (event
->number_of_attributes
,
353 /* handle encoding first if it is set */
355 (struct lwes_event_attribute
*)
356 lwes_hash_get (event
->attributes
,
357 (LWES_SHORT_STRING
)LWES_ENCODING
);
361 void* encodingValue
= encodingAttr
->value
;
362 LWES_BYTE encodingType
= encodingAttr
->type
;
365 if (encodingType
== LWES_INT_16_TOKEN
)
367 if (marshall_SHORT_STRING
368 ((LWES_SHORT_STRING
)LWES_ENCODING
,
380 (*((LWES_INT_16
*)encodingValue
),
399 /* now iterate over all the other values in the hash */
400 if (lwes_hash_keys (event
->attributes
, &e
))
402 while (lwes_hash_enumeration_has_more_elements (&e
) && ret
== 0)
404 LWES_SHORT_STRING tmpAttrName
=
405 lwes_hash_enumeration_next_element (&e
);
407 /* skip encoding as we've dealt with it above */
408 if (! strcmp(tmpAttrName
, LWES_ENCODING
))
414 (struct lwes_event_attribute
*)
415 lwes_hash_get (event
->attributes
, tmpAttrName
);
417 if (marshall_SHORT_STRING (tmpAttrName
,
426 if (marshall_BYTE (tmp
->type
,
435 if (tmp
->type
== LWES_U_INT_16_TOKEN
)
437 if (marshall_U_INT_16 (*((LWES_U_INT_16
*)tmp
->value
),
445 else if (tmp
->type
== LWES_INT_16_TOKEN
)
447 if (marshall_INT_16 (*((LWES_INT_16
*)tmp
->value
),
455 else if (tmp
->type
== LWES_U_INT_32_TOKEN
)
457 if (marshall_U_INT_32 (*((LWES_U_INT_32
*)tmp
->value
),
465 else if (tmp
->type
== LWES_INT_32_TOKEN
)
467 if (marshall_INT_32 (*((LWES_INT_32
*)tmp
->value
),
475 else if (tmp
->type
== LWES_U_INT_64_TOKEN
)
477 if (marshall_U_INT_64 (*((LWES_U_INT_64
*)tmp
->value
),
485 else if (tmp
->type
== LWES_INT_64_TOKEN
)
487 if (marshall_INT_64 (*((LWES_INT_64
*)tmp
->value
),
495 else if (tmp
->type
== LWES_BOOLEAN_TOKEN
)
497 if (marshall_BOOLEAN (*((LWES_BOOLEAN
*)tmp
->value
),
505 else if (tmp
->type
== LWES_IP_ADDR_TOKEN
)
507 if (marshall_IP_ADDR (*((LWES_IP_ADDR
*)tmp
->value
),
515 else if (tmp
->type
== LWES_STRING_TOKEN
)
517 if (marshall_LONG_STRING ((LWES_LONG_STRING
)tmp
->value
,
527 /* should never be reached, but if it does,
528 * there's some sort of corruption with this
529 * attribute of the event, so skip it */
546 return ((ret
< 0) ? ret
: (int)(tmpOffset
-offset
));
549 /* PUBLIC : deserialize the event from a byte array and into an event */
551 lwes_event_from_bytes
552 (struct lwes_event
*event
,
556 struct lwes_event_deserialize_tmp
*dtmp
)
559 LWES_U_INT_16 tmp_number_of_attributes
= 0;
560 size_t tmpOffset
= offset
;
563 LWES_U_INT_16 tmp_uint16
;
564 LWES_INT_16 tmp_int16
;
565 LWES_U_INT_32 tmp_uint32
;
566 LWES_INT_32 tmp_int32
;
567 LWES_U_INT_64 tmp_uint64
;
568 LWES_INT_64 tmp_int64
;
569 LWES_BOOLEAN tmp_boolean
;
570 LWES_IP_ADDR tmp_ip_addr
;
571 LWES_SHORT_STRING tmp_short_str
;
572 LWES_LONG_STRING tmp_long_str
;
577 || offset
>= num_bytes
583 tmp_short_str
= dtmp
->tmp_string
;
584 tmp_long_str
= dtmp
->tmp_string_long
;
586 /* unmarshall the event name */
587 if (unmarshall_SHORT_STRING (tmp_short_str
,
588 (SHORT_STRING_MAX
+1),
593 /* copies the data out of tmp_short_str */
594 if (lwes_event_set_name (event
, tmp_short_str
) == 0)
596 /* unmarshall the number of elements */
597 if (unmarshall_U_INT_16 (&tmp_uint16
,bytes
,num_bytes
,&tmpOffset
))
599 tmp_number_of_attributes
= tmp_uint16
;
601 for (i
= 0; i
< tmp_number_of_attributes
; i
++)
603 /* unmarshall the attribute name */
604 if (unmarshall_SHORT_STRING (tmp_short_str
,
605 (SHORT_STRING_MAX
+1),
610 /* unmarshall the type id */
611 if (unmarshall_BYTE (&tmp_byte
,
616 if (tmp_byte
== LWES_U_INT_16_TOKEN
)
618 if (unmarshall_U_INT_16 (&tmp_uint16
,
623 if (lwes_event_set_U_INT_16 (event
,
636 else if (tmp_byte
== LWES_INT_16_TOKEN
)
638 if (unmarshall_INT_16 (&tmp_int16
,
643 if (lwes_event_set_INT_16 (event
,
656 else if (tmp_byte
== LWES_U_INT_32_TOKEN
)
658 if (unmarshall_U_INT_32 (&tmp_uint32
,
663 if (lwes_event_set_U_INT_32 (event
,
676 else if (tmp_byte
== LWES_INT_32_TOKEN
)
678 if (unmarshall_INT_32 (&tmp_int32
,
683 if (lwes_event_set_INT_32 (event
,
696 else if (tmp_byte
== LWES_U_INT_64_TOKEN
)
698 if (unmarshall_U_INT_64 (&tmp_uint64
,
703 if (lwes_event_set_U_INT_64 (event
,
716 else if (tmp_byte
== LWES_INT_64_TOKEN
)
718 if (unmarshall_INT_64 (&tmp_int64
,
723 if (lwes_event_set_INT_64 (event
,
736 else if (tmp_byte
== LWES_BOOLEAN_TOKEN
)
738 if (unmarshall_BOOLEAN (&tmp_boolean
,
743 if (lwes_event_set_BOOLEAN (event
,
756 else if (tmp_byte
== LWES_IP_ADDR_TOKEN
)
758 if (unmarshall_IP_ADDR (&tmp_ip_addr
,
763 if (lwes_event_set_IP_ADDR (event
,
776 else if (tmp_byte
== LWES_STRING_TOKEN
)
778 if (unmarshall_LONG_STRING (tmp_long_str
,
784 if (lwes_event_set_STRING (event
,
828 return (int)(tmpOffset
-offset
);
831 int lwes_event_set_U_INT_16 (struct lwes_event
* event
,
832 LWES_CONST_SHORT_STRING attrName
,
836 LWES_U_INT_16
*attrValue
;
838 if (event
== NULL
|| attrName
== NULL
)
843 attrValue
= (LWES_U_INT_16
*)malloc (sizeof (LWES_U_INT_16
));
845 if (attrValue
== NULL
)
851 ret
= lwes_event_add (event
, attrName
, LWES_U_INT_16_TOKEN
, attrValue
);
859 int lwes_event_set_INT_16 (struct lwes_event
* event
,
860 LWES_CONST_SHORT_STRING attrName
,
864 LWES_INT_16
*attrValue
;
866 if (event
== NULL
|| attrName
== NULL
)
871 attrValue
= (LWES_INT_16
*)malloc (sizeof (LWES_INT_16
));
873 if (attrValue
== NULL
)
879 ret
= lwes_event_add (event
, attrName
, LWES_INT_16_TOKEN
, attrValue
);
887 int lwes_event_set_U_INT_32 (struct lwes_event
* event
,
888 LWES_CONST_SHORT_STRING attrName
,
892 LWES_U_INT_32
*attrValue
;
894 if (event
== NULL
|| attrName
== NULL
)
899 attrValue
= (LWES_U_INT_32
*)malloc(sizeof(LWES_U_INT_32
));
901 if (attrValue
== NULL
)
907 ret
= lwes_event_add (event
, attrName
, LWES_U_INT_32_TOKEN
, attrValue
);
915 int lwes_event_set_INT_32 (struct lwes_event
* event
,
916 LWES_CONST_SHORT_STRING attrName
,
920 LWES_INT_32
*attrValue
;
922 if (event
== NULL
|| attrName
== NULL
)
927 attrValue
= (LWES_INT_32
*)malloc (sizeof (LWES_INT_32
));
929 if (attrValue
== NULL
)
935 ret
= lwes_event_add (event
, attrName
, LWES_INT_32_TOKEN
, attrValue
);
943 int lwes_event_set_U_INT_64 (struct lwes_event
* event
,
944 LWES_CONST_SHORT_STRING attrName
,
948 LWES_U_INT_64
*attrValue
;
950 if (event
== NULL
|| attrName
== NULL
)
955 attrValue
= (LWES_U_INT_64
*)malloc (sizeof (LWES_U_INT_64
));
957 if (attrValue
== NULL
)
963 ret
= lwes_event_add (event
, attrName
, LWES_U_INT_64_TOKEN
, attrValue
);
971 int lwes_event_set_U_INT_64_w_string (struct lwes_event
* event
,
972 LWES_CONST_SHORT_STRING attrName
,
973 LWES_CONST_SHORT_STRING uint64_string
)
975 LWES_INT_64 u_int_64
;
976 if (event
== NULL
|| attrName
== NULL
|| uint64_string
== NULL
)
980 if (lwes_INT_64_from_hex_string (uint64_string
, &u_int_64
) < 0)
984 return lwes_event_set_U_INT_64 (event
, attrName
, u_int_64
);
987 int lwes_event_set_INT_64 (struct lwes_event
* event
,
988 LWES_CONST_SHORT_STRING attrName
,
992 LWES_INT_64
*attrValue
;
994 if (event
== NULL
|| attrName
== NULL
)
999 attrValue
= (LWES_INT_64
*)malloc (sizeof (LWES_INT_64
));
1001 if (attrValue
== NULL
)
1007 ret
= lwes_event_add (event
, attrName
, LWES_INT_64_TOKEN
, attrValue
);
1015 int lwes_event_set_INT_64_w_string (struct lwes_event
*event
,
1016 LWES_CONST_SHORT_STRING attrName
,
1017 LWES_CONST_SHORT_STRING int64_string
)
1021 if (event
== NULL
|| attrName
== NULL
|| int64_string
== NULL
)
1026 if (lwes_INT_64_from_hex_string (int64_string
,&int_64
) < 0)
1030 return lwes_event_set_INT_64 (event
, attrName
, int_64
);
1033 int lwes_event_set_STRING (struct lwes_event
* event
,
1034 LWES_CONST_SHORT_STRING attrName
,
1035 LWES_CONST_LONG_STRING value
)
1038 LWES_LONG_STRING attrValue
;
1040 if (event
== NULL
|| attrName
== NULL
|| value
== NULL
)
1045 attrValue
= (LWES_LONG_STRING
)malloc (sizeof (LWES_CHAR
)*(strlen (value
)+1));
1046 if (attrValue
== NULL
)
1050 strcpy(attrValue
,value
);
1052 ret
= lwes_event_add (event
, attrName
, LWES_STRING_TOKEN
, (void*)attrValue
);
1060 int lwes_event_set_IP_ADDR (struct lwes_event
* event
,
1061 LWES_CONST_SHORT_STRING attrName
,
1065 LWES_IP_ADDR
*attrValue
;
1067 if (event
== NULL
|| attrName
== NULL
)
1072 attrValue
= (LWES_IP_ADDR
*)malloc (sizeof (LWES_IP_ADDR
));
1074 if (attrValue
== NULL
)
1080 ret
= lwes_event_add (event
, attrName
, LWES_IP_ADDR_TOKEN
, attrValue
);
1088 int lwes_event_set_IP_ADDR_w_string (struct lwes_event
* event
,
1089 LWES_CONST_SHORT_STRING attrName
,
1090 LWES_CONST_SHORT_STRING value
)
1093 struct in_addr
*attrValue
;
1095 if (event
== NULL
|| attrName
== NULL
|| value
== NULL
)
1100 attrValue
= (LWES_IP_ADDR
*)malloc (sizeof (LWES_IP_ADDR
));
1101 if (attrValue
== NULL
)
1105 attrValue
->s_addr
= inet_addr (value
);
1107 ret
= lwes_event_add (event
, attrName
, LWES_IP_ADDR_TOKEN
, attrValue
);
1115 int lwes_event_set_BOOLEAN (struct lwes_event
* event
,
1116 LWES_CONST_SHORT_STRING attrName
,
1120 LWES_BOOLEAN
*attrValue
;
1122 if (event
== NULL
|| attrName
== NULL
)
1127 attrValue
= (LWES_BOOLEAN
*)malloc (sizeof (LWES_BOOLEAN
));
1128 if (attrValue
== NULL
)
1134 ret
= lwes_event_add (event
, attrName
, LWES_BOOLEAN_TOKEN
, attrValue
);
1143 /* ACCESSOR METHODS */
1145 int lwes_event_get_U_INT_16 (struct lwes_event
*event
,
1146 LWES_CONST_SHORT_STRING name
,
1147 LWES_U_INT_16
*value
)
1149 struct lwes_event_attribute
*tmp
;
1151 if (event
== NULL
|| name
== NULL
|| value
== NULL
)
1156 tmp
= (struct lwes_event_attribute
*)lwes_hash_get (event
->attributes
, name
);
1160 *value
= (*((LWES_U_INT_16
*)tmp
->value
));
1167 int lwes_event_get_INT_16 (struct lwes_event
*event
,
1168 LWES_CONST_SHORT_STRING name
,
1171 struct lwes_event_attribute
*tmp
;
1173 if (event
== NULL
|| name
== NULL
|| value
== NULL
)
1178 tmp
= (struct lwes_event_attribute
*)lwes_hash_get (event
->attributes
, name
);
1182 *value
= (*((LWES_INT_16
*)tmp
->value
));
1188 int lwes_event_get_U_INT_32 (struct lwes_event
*event
,
1189 LWES_CONST_SHORT_STRING name
,
1190 LWES_U_INT_32
*value
)
1192 struct lwes_event_attribute
*tmp
;
1194 if (event
== NULL
|| name
== NULL
|| value
== NULL
)
1199 tmp
= (struct lwes_event_attribute
*)lwes_hash_get (event
->attributes
, name
);
1203 *value
= (*((LWES_U_INT_32
*)tmp
->value
));
1210 int lwes_event_get_INT_32 (struct lwes_event
*event
,
1211 LWES_CONST_SHORT_STRING name
,
1214 struct lwes_event_attribute
*tmp
;
1216 if (event
== NULL
|| name
== NULL
|| value
== NULL
)
1221 tmp
= (struct lwes_event_attribute
*)lwes_hash_get (event
->attributes
, name
);
1225 *value
= (*((LWES_INT_32
*)tmp
->value
));
1232 int lwes_event_get_U_INT_64 (struct lwes_event
*event
,
1233 LWES_CONST_SHORT_STRING name
,
1234 LWES_U_INT_64
*value
)
1236 struct lwes_event_attribute
*tmp
;
1238 if (event
== NULL
|| name
== NULL
|| value
== NULL
)
1243 tmp
= (struct lwes_event_attribute
*)lwes_hash_get (event
->attributes
, name
);
1247 *value
= (*((LWES_U_INT_64
*)tmp
->value
));
1254 int lwes_event_get_INT_64 (struct lwes_event
*event
,
1255 LWES_CONST_SHORT_STRING name
,
1258 struct lwes_event_attribute
*tmp
;
1260 if (event
== NULL
|| name
== NULL
|| value
== NULL
)
1265 tmp
= (struct lwes_event_attribute
*)lwes_hash_get (event
->attributes
, name
);
1269 *value
= (*((LWES_INT_64
*)tmp
->value
));
1276 int lwes_event_get_STRING (struct lwes_event
*event
,
1277 LWES_CONST_SHORT_STRING name
,
1278 LWES_LONG_STRING
*value
)
1280 struct lwes_event_attribute
*tmp
;
1282 if (event
== NULL
|| name
== NULL
|| value
== NULL
)
1287 tmp
= (struct lwes_event_attribute
*)lwes_hash_get (event
->attributes
, name
);
1291 *value
= (((LWES_LONG_STRING
)tmp
->value
));
1297 int lwes_event_get_IP_ADDR (struct lwes_event
*event
,
1298 LWES_CONST_SHORT_STRING name
,
1299 LWES_IP_ADDR
*value
)
1301 struct lwes_event_attribute
*tmp
;
1303 if (event
== NULL
|| name
== NULL
|| value
== NULL
)
1308 tmp
= (struct lwes_event_attribute
*)lwes_hash_get (event
->attributes
, name
);
1312 *value
= (*((LWES_IP_ADDR
*)tmp
->value
));
1318 int lwes_event_get_BOOLEAN (struct lwes_event
*event
,
1319 LWES_CONST_SHORT_STRING name
,
1320 LWES_BOOLEAN
*value
)
1322 struct lwes_event_attribute
*tmp
;
1324 if (event
== NULL
|| name
== NULL
|| value
== NULL
)
1329 tmp
= (struct lwes_event_attribute
*)lwes_hash_get(event
->attributes
, name
);
1333 *value
= (*((LWES_BOOLEAN
*)tmp
->value
));
1339 /*************************************************************************
1341 *************************************************************************/
1342 /* Create the memory for an attribute */
1343 static struct lwes_event_attribute
*
1344 lwes_event_attribute_create (LWES_BYTE attrType
, void *attrValue
)
1346 struct lwes_event_attribute
*attribute
=
1347 (struct lwes_event_attribute
*)
1348 malloc (sizeof (struct lwes_event_attribute
));
1350 if (attribute
== NULL
)
1355 attribute
->type
= attrType
;
1356 attribute
->value
= attrValue
;
1361 /* add an attribute to an event */
1363 lwes_event_add (struct lwes_event
* event
,
1364 LWES_CONST_SHORT_STRING attrNameIn
,
1368 struct lwes_event_attribute
* attribute
= NULL
;
1369 LWES_SHORT_STRING attrName
= NULL
;
1372 /* check against the event db */
1373 if (event
->type_db
!= NULL
1374 && lwes_event_type_db_check_for_attribute (event
->type_db
,
1376 event
->eventName
) == 0)
1380 if (event
->type_db
!= NULL
1381 && lwes_event_type_db_check_for_type (event
->type_db
,
1384 event
->eventName
) == 0)
1389 /* copy the attribute name */
1391 (LWES_SHORT_STRING
) malloc( sizeof(LWES_CHAR
)*(strlen (attrNameIn
)+1));
1392 if (attrName
== NULL
)
1397 strcat (attrName
,attrNameIn
);
1399 /* create the attribute */
1400 attribute
= lwes_event_attribute_create (attrType
, attrValue
);
1401 if (attribute
== NULL
)
1407 /* Try and put something into the hash */
1408 ret
= lwes_hash_put (event
->attributes
, attrName
, attribute
);
1410 /* return code greater than or equal to 0 is okay, so increment the
1411 * number_of_attributes, otherwise, send out the failure value
1419 event
->number_of_attributes
++;
1421 return event
->number_of_attributes
;
1425 lwes_U_INT_64_from_hex_string
1426 (const char *buffer
,
1427 LWES_U_INT_64
* a_uint64
)
1431 /* manpage for strtoull suggests setting errno to zero then checking
1432 * for error afterwards
1435 *a_uint64
= strtoull (buffer
, &endptr
, 16);
1437 /* it's considered an error if it overflows (ie, errno is ERANGE)
1438 * or if the entire string is not used (ie, in_length is greater than
1442 || ((int)strlen (buffer
) > (int)(endptr
- buffer
)))
1451 lwes_INT_64_from_hex_string
1452 (const char *buffer
,
1453 LWES_INT_64
* an_int64
)
1456 * totally bogus, but on freebsd strtoll for hex can not reach the
1457 * maximum hex value of 0xffffffffffffffff, so instead I use
1458 * strtoull which does reach the upper range, and then cast
1460 LWES_U_INT_64 a_uint64
;
1463 ret
= lwes_U_INT_64_from_hex_string (buffer
, &a_uint64
);
1470 *an_int64
= (LWES_INT_64
)a_uint64
;
1477 (struct lwes_event
* event
,
1478 struct lwes_event_enumeration
*enumeration
)
1480 return lwes_hash_keys (event
->attributes
, &(enumeration
->hash_enum
));
1484 lwes_event_enumeration_next_element
1485 (struct lwes_event_enumeration
*enumeration
,
1486 LWES_CONST_SHORT_STRING
*key
,
1489 LWES_SHORT_STRING tmpAttrName
=
1490 lwes_hash_enumeration_next_element (&(enumeration
->hash_enum
));
1492 (*type
) = LWES_TYPE_UNDEFINED
;
1494 if ( tmpAttrName
!= NULL
)
1496 struct lwes_event_attribute
*tmp
=
1497 (struct lwes_event_attribute
*)
1498 lwes_hash_get (enumeration
->hash_enum
.enum_hash
, (tmpAttrName
));
1501 (*type
) = (LWES_TYPE
) (tmp
->type
);
1502 (*key
) = tmpAttrName
;