1
2 /*****
3 *
4 * Copyright (C) 2001-2015 CS-SI. All Rights Reserved.
5 * Author: Yoann Vandoorselaere <yoann.v@prelude-ids.com>
6 * Author: Nicolas Delon <nicolas.delon@prelude-ids.com>
7 *
8 * This file is part of the Prelude library.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 *
24 *****/
25
26 /* Auto-generated by the GenerateIDMEFTreeWrapC package */
27
28 #include "config.h"
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <strings.h>
34 #include <sys/types.h>
35
36 #include "prelude-inttypes.h"
37 #include "prelude-list.h"
38 #include "prelude-msg.h"
39 #include "prelude-string.h"
40
41 #define PRELUDE_ERROR_SOURCE_DEFAULT PRELUDE_ERROR_SOURCE_IDMEF_TREE_WRAP
42 #include "prelude-error.h"
43
44 #include "idmef-time.h"
45 #include "idmef-data.h"
46 #include "idmef-class.h"
47 #include "idmef-value.h"
48 #include "idmef-object-prv.h"
49
50 #include "idmef-tree-wrap.h"
51 #include "libmissing.h"
52 #include "common.h"
53
54 #ifdef WIN32
55 # undef interface
56 #endif
57
58
59 #define LISTED_OBJECT(name, type) prelude_list_t name
60 #define KEYLISTED_OBJECT(name, type) prelude_list_t name
61
62 #define IS_KEY_LISTED(keyfield) IDMEF_LINKED_OBJECT; prelude_string_t *keyfield
63
64 #define UNION(type, var) type var; union
65
66 #define UNION_MEMBER(value, type, name) type name
67
68 #define ENUM(...) typedef enum
69
70 #define PRE_DECLARE(type, class)
71
72 #define TYPE_ID(type, id) type
73
74 #define PRIMITIVE_TYPE(type)
75 #define PRIMITIVE_TYPE_STRUCT(type)
76
77 #define HIDE(type, name) type name
78
79 #define REFCOUNT int refcount
80 #define REQUIRED(type, name) type name
81 #define IGNORED(type, name) type name
82
83 #define DYNAMIC_IDENT(x) uint64_t x
84
85 #define OPTIONAL_INT(type, name) type name; unsigned int name ## _is_set:1
86
87 #define IDENT(name) uint64_t name
88
89
90 #define idmef_data_copy idmef_data_copy_dup
91
92 #ifndef ABS
93 # define ABS(x) (((x) < 0) ? -(x) : (x))
94 #endif
95
96
97 /*
98 * If we subtract the integer representations of two floats then that
99 * will tell us how close they are. If the difference is zero, they are
100 * identical. If the difference is one, they are adjacent floats.
101 * In general, if the difference is n then there are n-1 floats between
102 * them.
103 *
104 * http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
105 */
float_compare(float a,float b)106 static int float_compare(float a, float b)
107 {
108 union {
109 float fval;
110 int32_t ival;
111 } au, bu;
112
113 au.fval = a;
114 bu.fval = b;
115
116 /* Make aInt lexicographically ordered as a twos-complement int */
117 if ( au.ival < 0 )
118 au.ival = 0x80000000 - au.ival;
119
120 /* Make bInt lexicographically ordered as a twos-complement int */
121 if ( bu.ival < 0 )
122 bu.ival = 0x80000000 - bu.ival;
123
124 return (ABS(au.ival - bu.ival) <= 0) ? 0 : -1;
125 }
126
127
128
prelude_string_copy(const prelude_string_t * src,prelude_string_t * dst)129 static int prelude_string_copy(const prelude_string_t *src, prelude_string_t *dst)
130 {
131 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
132 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
133
134 if ( ! prelude_string_is_empty(src) )
135 return prelude_string_copy_dup(src, dst);
136
137 return 0;
138 }
139
140
141
get_value_from_string(idmef_value_t ** value,prelude_string_t * str,prelude_bool_t is_ptr)142 static int get_value_from_string(idmef_value_t **value, prelude_string_t *str, prelude_bool_t is_ptr)
143 {
144 int ret;
145
146 if ( ! str ) {
147 *value = NULL;
148 return 0;
149 }
150
151 if ( ! is_ptr ) {
152 ret = prelude_string_clone(str, &str);
153 if ( ret < 0 )
154 return ret;
155 }
156
157 ret = idmef_value_new_string(value, str);
158 if ( ret < 0 ) {
159 prelude_string_destroy(str);
160 return ret;
161 }
162
163 if ( is_ptr )
164 prelude_string_ref(str);
165
166 return 0;
167 }
168
169
170
get_value_from_data(idmef_value_t ** value,idmef_data_t * data,prelude_bool_t is_ptr)171 static int get_value_from_data(idmef_value_t **value, idmef_data_t *data, prelude_bool_t is_ptr)
172 {
173 int ret;
174
175 if ( ! data ) {
176 *value = NULL;
177 return 0;
178 }
179
180 if ( ! is_ptr ) {
181 ret = idmef_data_clone(data, &data);
182 if ( ret < 0 )
183 return ret;
184 }
185
186 ret = idmef_value_new_data(value, data);
187 if ( ret < 0 ) {
188 idmef_data_destroy(data);
189 return ret;
190 }
191
192 if ( is_ptr )
193 idmef_data_ref(data);
194
195 return 0;
196 }
197
198
get_value_from_time(idmef_value_t ** value,idmef_time_t * time,prelude_bool_t is_ptr)199 static int get_value_from_time(idmef_value_t **value, idmef_time_t *time, prelude_bool_t is_ptr)
200 {
201 int ret;
202
203 if ( ! time ) {
204 *value = NULL;
205 return 0;
206 }
207
208 if ( ! is_ptr ) {
209 ret = idmef_time_clone(time, &time);
210 if ( ret < 0 )
211 return ret;
212 }
213
214 ret = idmef_value_new_time(value, time);
215 if ( ret < 0 ) {
216 idmef_time_destroy(time);
217 return ret;
218 }
219
220 if ( is_ptr )
221 idmef_time_ref(time);
222
223 return 0;
224 }
225
226
list_insert(prelude_list_t * head,prelude_list_t * item,int pos)227 static void list_insert(prelude_list_t *head, prelude_list_t *item, int pos)
228 {
229 int i = 0;
230 prelude_list_t *tmp;
231
232 if ( pos == IDMEF_LIST_APPEND )
233 prelude_list_add_tail(head, item);
234
235 else if ( pos == IDMEF_LIST_PREPEND )
236 prelude_list_add(head, item);
237
238 else if ( pos >= 0 ) {
239 prelude_list_for_each(head, tmp) {
240 if ( i == pos )
241 break;
242 i++;
243 }
244
245 prelude_list_add_tail(tmp, item);
246 }
247
248 else if ( pos < 0 ) {
249 pos = -pos;
250 pos--;
251
252 prelude_list_for_each_reversed(head, tmp) {
253 if ( i == pos )
254 break;
255 i++;
256 }
257
258 prelude_list_add(tmp, item);
259 }
260 }
261
262
263 /**
264 * idmef_additional_data_type_to_numeric:
265 * @name: pointer to an IDMEF string representation of a #idmef_additional_data_type_t value.
266 *
267 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
268 */
idmef_additional_data_type_to_numeric(const char * name)269 idmef_additional_data_type_t idmef_additional_data_type_to_numeric(const char *name)
270 {
271 size_t i;
272 const struct {
273 idmef_additional_data_type_t val;
274 const char *name;
275 } tbl[] = {
276 { IDMEF_ADDITIONAL_DATA_TYPE_STRING, "string" },
277 { IDMEF_ADDITIONAL_DATA_TYPE_BYTE, "byte" },
278 { IDMEF_ADDITIONAL_DATA_TYPE_CHARACTER, "character" },
279 { IDMEF_ADDITIONAL_DATA_TYPE_DATE_TIME, "date-time" },
280 { IDMEF_ADDITIONAL_DATA_TYPE_INTEGER, "integer" },
281 { IDMEF_ADDITIONAL_DATA_TYPE_NTPSTAMP, "ntpstamp" },
282 { IDMEF_ADDITIONAL_DATA_TYPE_PORTLIST, "portlist" },
283 { IDMEF_ADDITIONAL_DATA_TYPE_REAL, "real" },
284 { IDMEF_ADDITIONAL_DATA_TYPE_BOOLEAN, "boolean" },
285 { IDMEF_ADDITIONAL_DATA_TYPE_BYTE_STRING, "byte-string" },
286 { IDMEF_ADDITIONAL_DATA_TYPE_XML, "xml" },
287 };
288
289 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
290
291 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
292 if ( strcasecmp(name, tbl[i].name) == 0 )
293 return tbl[i].val;
294 }
295
296 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for additional_data_type", name);
297 }
298
299 /**
300 * idmef_additional_data_type_to_string:
301 * @val: an enumeration value for #idmef_additional_data_type_t.
302 *
303 * Return the IDMEF string equivalent of @val provided #idmef_additional_data_type_t value.
304 *
305 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
306 */
idmef_additional_data_type_to_string(idmef_additional_data_type_t val)307 const char *idmef_additional_data_type_to_string(idmef_additional_data_type_t val)
308 {
309 const struct {
310 idmef_additional_data_type_t val;
311 const char *name;
312 } tbl[] = {
313 { IDMEF_ADDITIONAL_DATA_TYPE_STRING, "string" },
314 { IDMEF_ADDITIONAL_DATA_TYPE_BYTE, "byte" },
315 { IDMEF_ADDITIONAL_DATA_TYPE_CHARACTER, "character" },
316 { IDMEF_ADDITIONAL_DATA_TYPE_DATE_TIME, "date-time" },
317 { IDMEF_ADDITIONAL_DATA_TYPE_INTEGER, "integer" },
318 { IDMEF_ADDITIONAL_DATA_TYPE_NTPSTAMP, "ntpstamp" },
319 { IDMEF_ADDITIONAL_DATA_TYPE_PORTLIST, "portlist" },
320 { IDMEF_ADDITIONAL_DATA_TYPE_REAL, "real" },
321 { IDMEF_ADDITIONAL_DATA_TYPE_BOOLEAN, "boolean" },
322 { IDMEF_ADDITIONAL_DATA_TYPE_BYTE_STRING, "byte-string" },
323 { IDMEF_ADDITIONAL_DATA_TYPE_XML, "xml" },
324 };
325
326 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
327 return NULL;
328
329 return tbl[val].name;
330 }
331
332
333 struct idmef_additional_data {
334
335 IS_KEY_LISTED(meaning);
336 REFCOUNT;
337 IGNORED(prelude_bool_t, _type_is_set);
338 idmef_additional_data_type_t type;
339 REQUIRED(idmef_data_t, *data);
340
341 };
342
343
344 /**
345 * idmef_reference_origin_to_numeric:
346 * @name: pointer to an IDMEF string representation of a #idmef_reference_origin_t value.
347 *
348 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
349 */
idmef_reference_origin_to_numeric(const char * name)350 idmef_reference_origin_t idmef_reference_origin_to_numeric(const char *name)
351 {
352 size_t i;
353 const struct {
354 idmef_reference_origin_t val;
355 const char *name;
356 } tbl[] = {
357 { IDMEF_REFERENCE_ORIGIN_UNKNOWN, "unknown" },
358 { IDMEF_REFERENCE_ORIGIN_VENDOR_SPECIFIC, "vendor-specific" },
359 { IDMEF_REFERENCE_ORIGIN_USER_SPECIFIC, "user-specific" },
360 { IDMEF_REFERENCE_ORIGIN_BUGTRAQID, "bugtraqid" },
361 { IDMEF_REFERENCE_ORIGIN_CVE, "cve" },
362 { IDMEF_REFERENCE_ORIGIN_OSVDB, "osvdb" },
363 };
364
365 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
366
367 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
368 if ( strcasecmp(name, tbl[i].name) == 0 )
369 return tbl[i].val;
370 }
371
372 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for reference_origin", name);
373 }
374
375 /**
376 * idmef_reference_origin_to_string:
377 * @val: an enumeration value for #idmef_reference_origin_t.
378 *
379 * Return the IDMEF string equivalent of @val provided #idmef_reference_origin_t value.
380 *
381 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
382 */
idmef_reference_origin_to_string(idmef_reference_origin_t val)383 const char *idmef_reference_origin_to_string(idmef_reference_origin_t val)
384 {
385 const struct {
386 idmef_reference_origin_t val;
387 const char *name;
388 } tbl[] = {
389 { IDMEF_REFERENCE_ORIGIN_UNKNOWN, "unknown" },
390 { IDMEF_REFERENCE_ORIGIN_VENDOR_SPECIFIC, "vendor-specific" },
391 { IDMEF_REFERENCE_ORIGIN_USER_SPECIFIC, "user-specific" },
392 { IDMEF_REFERENCE_ORIGIN_BUGTRAQID, "bugtraqid" },
393 { IDMEF_REFERENCE_ORIGIN_CVE, "cve" },
394 { IDMEF_REFERENCE_ORIGIN_OSVDB, "osvdb" },
395 };
396
397 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
398 return NULL;
399
400 return tbl[val].name;
401 }
402
403
404 struct idmef_reference {
405
406 IDMEF_LINKED_OBJECT;
407 REFCOUNT;
408 idmef_reference_origin_t origin;
409
410 REQUIRED(prelude_string_t, *name);
411 REQUIRED(prelude_string_t, *url);
412 prelude_string_t *meaning;
413
414 };
415
416
417
418 struct idmef_classification {
419
420 IDMEF_OBJECT;
421 REFCOUNT;
422 prelude_string_t *ident;
423 REQUIRED(prelude_string_t, *text);
424 LISTED_OBJECT(reference_list, idmef_reference_t);
425
426
427 };
428
429
430 /**
431 * idmef_user_id_type_to_numeric:
432 * @name: pointer to an IDMEF string representation of a #idmef_user_id_type_t value.
433 *
434 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
435 */
idmef_user_id_type_to_numeric(const char * name)436 idmef_user_id_type_t idmef_user_id_type_to_numeric(const char *name)
437 {
438 size_t i;
439 const struct {
440 idmef_user_id_type_t val;
441 const char *name;
442 } tbl[] = {
443 { IDMEF_USER_ID_TYPE_ORIGINAL_USER, "original-user" },
444 { IDMEF_USER_ID_TYPE_CURRENT_USER, "current-user" },
445 { IDMEF_USER_ID_TYPE_TARGET_USER, "target-user" },
446 { IDMEF_USER_ID_TYPE_USER_PRIVS, "user-privs" },
447 { IDMEF_USER_ID_TYPE_CURRENT_GROUP, "current-group" },
448 { IDMEF_USER_ID_TYPE_GROUP_PRIVS, "group-privs" },
449 { IDMEF_USER_ID_TYPE_OTHER_PRIVS, "other-privs" },
450 };
451
452 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
453
454 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
455 if ( strcasecmp(name, tbl[i].name) == 0 )
456 return tbl[i].val;
457 }
458
459 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for user_id_type", name);
460 }
461
462 /**
463 * idmef_user_id_type_to_string:
464 * @val: an enumeration value for #idmef_user_id_type_t.
465 *
466 * Return the IDMEF string equivalent of @val provided #idmef_user_id_type_t value.
467 *
468 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
469 */
idmef_user_id_type_to_string(idmef_user_id_type_t val)470 const char *idmef_user_id_type_to_string(idmef_user_id_type_t val)
471 {
472 const struct {
473 idmef_user_id_type_t val;
474 const char *name;
475 } tbl[] = {
476 { IDMEF_USER_ID_TYPE_ORIGINAL_USER, "original-user" },
477 { IDMEF_USER_ID_TYPE_CURRENT_USER, "current-user" },
478 { IDMEF_USER_ID_TYPE_TARGET_USER, "target-user" },
479 { IDMEF_USER_ID_TYPE_USER_PRIVS, "user-privs" },
480 { IDMEF_USER_ID_TYPE_CURRENT_GROUP, "current-group" },
481 { IDMEF_USER_ID_TYPE_GROUP_PRIVS, "group-privs" },
482 { IDMEF_USER_ID_TYPE_OTHER_PRIVS, "other-privs" },
483 };
484
485 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
486 return NULL;
487
488 return tbl[val].name;
489 }
490
491
492 struct idmef_user_id {
493
494 IDMEF_LINKED_OBJECT;
495 REFCOUNT;
496 prelude_string_t *ident;
497 idmef_user_id_type_t type;
498 prelude_string_t *tty;
499 prelude_string_t *name;
500 OPTIONAL_INT(uint32_t, number);
501
502 };
503
504
505 /**
506 * idmef_user_category_to_numeric:
507 * @name: pointer to an IDMEF string representation of a #idmef_user_category_t value.
508 *
509 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
510 */
idmef_user_category_to_numeric(const char * name)511 idmef_user_category_t idmef_user_category_to_numeric(const char *name)
512 {
513 size_t i;
514 const struct {
515 idmef_user_category_t val;
516 const char *name;
517 } tbl[] = {
518 { IDMEF_USER_CATEGORY_UNKNOWN, "unknown" },
519 { IDMEF_USER_CATEGORY_APPLICATION, "application" },
520 { IDMEF_USER_CATEGORY_OS_DEVICE, "os-device" },
521 };
522
523 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
524
525 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
526 if ( strcasecmp(name, tbl[i].name) == 0 )
527 return tbl[i].val;
528 }
529
530 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for user_category", name);
531 }
532
533 /**
534 * idmef_user_category_to_string:
535 * @val: an enumeration value for #idmef_user_category_t.
536 *
537 * Return the IDMEF string equivalent of @val provided #idmef_user_category_t value.
538 *
539 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
540 */
idmef_user_category_to_string(idmef_user_category_t val)541 const char *idmef_user_category_to_string(idmef_user_category_t val)
542 {
543 const struct {
544 idmef_user_category_t val;
545 const char *name;
546 } tbl[] = {
547 { IDMEF_USER_CATEGORY_UNKNOWN, "unknown" },
548 { IDMEF_USER_CATEGORY_APPLICATION, "application" },
549 { IDMEF_USER_CATEGORY_OS_DEVICE, "os-device" },
550 };
551
552 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
553 return NULL;
554
555 return tbl[val].name;
556 }
557
558
559 struct idmef_user {
560
561 IDMEF_OBJECT;
562 REFCOUNT;
563 prelude_string_t *ident;
564 idmef_user_category_t category;
565 LISTED_OBJECT(user_id_list, idmef_user_id_t);
566
567 };
568
569
570 /**
571 * idmef_address_category_to_numeric:
572 * @name: pointer to an IDMEF string representation of a #idmef_address_category_t value.
573 *
574 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
575 */
idmef_address_category_to_numeric(const char * name)576 idmef_address_category_t idmef_address_category_to_numeric(const char *name)
577 {
578 size_t i;
579 const struct {
580 idmef_address_category_t val;
581 const char *name;
582 } tbl[] = {
583 { IDMEF_ADDRESS_CATEGORY_UNKNOWN, "unknown" },
584 { IDMEF_ADDRESS_CATEGORY_ATM, "atm" },
585 { IDMEF_ADDRESS_CATEGORY_E_MAIL, "e-mail" },
586 { IDMEF_ADDRESS_CATEGORY_LOTUS_NOTES, "lotus-notes" },
587 { IDMEF_ADDRESS_CATEGORY_MAC, "mac" },
588 { IDMEF_ADDRESS_CATEGORY_SNA, "sna" },
589 { IDMEF_ADDRESS_CATEGORY_VM, "vm" },
590 { IDMEF_ADDRESS_CATEGORY_IPV4_ADDR, "ipv4-addr" },
591 { IDMEF_ADDRESS_CATEGORY_IPV4_ADDR_HEX, "ipv4-addr-hex" },
592 { IDMEF_ADDRESS_CATEGORY_IPV4_NET, "ipv4-net" },
593 { IDMEF_ADDRESS_CATEGORY_IPV4_NET_MASK, "ipv4-net-mask" },
594 { IDMEF_ADDRESS_CATEGORY_IPV6_ADDR, "ipv6-addr" },
595 { IDMEF_ADDRESS_CATEGORY_IPV6_ADDR_HEX, "ipv6-addr-hex" },
596 { IDMEF_ADDRESS_CATEGORY_IPV6_NET, "ipv6-net" },
597 { IDMEF_ADDRESS_CATEGORY_IPV6_NET_MASK, "ipv6-net-mask" },
598 };
599
600 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
601
602 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
603 if ( strcasecmp(name, tbl[i].name) == 0 )
604 return tbl[i].val;
605 }
606
607 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for address_category", name);
608 }
609
610 /**
611 * idmef_address_category_to_string:
612 * @val: an enumeration value for #idmef_address_category_t.
613 *
614 * Return the IDMEF string equivalent of @val provided #idmef_address_category_t value.
615 *
616 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
617 */
idmef_address_category_to_string(idmef_address_category_t val)618 const char *idmef_address_category_to_string(idmef_address_category_t val)
619 {
620 const struct {
621 idmef_address_category_t val;
622 const char *name;
623 } tbl[] = {
624 { IDMEF_ADDRESS_CATEGORY_UNKNOWN, "unknown" },
625 { IDMEF_ADDRESS_CATEGORY_ATM, "atm" },
626 { IDMEF_ADDRESS_CATEGORY_E_MAIL, "e-mail" },
627 { IDMEF_ADDRESS_CATEGORY_LOTUS_NOTES, "lotus-notes" },
628 { IDMEF_ADDRESS_CATEGORY_MAC, "mac" },
629 { IDMEF_ADDRESS_CATEGORY_SNA, "sna" },
630 { IDMEF_ADDRESS_CATEGORY_VM, "vm" },
631 { IDMEF_ADDRESS_CATEGORY_IPV4_ADDR, "ipv4-addr" },
632 { IDMEF_ADDRESS_CATEGORY_IPV4_ADDR_HEX, "ipv4-addr-hex" },
633 { IDMEF_ADDRESS_CATEGORY_IPV4_NET, "ipv4-net" },
634 { IDMEF_ADDRESS_CATEGORY_IPV4_NET_MASK, "ipv4-net-mask" },
635 { IDMEF_ADDRESS_CATEGORY_IPV6_ADDR, "ipv6-addr" },
636 { IDMEF_ADDRESS_CATEGORY_IPV6_ADDR_HEX, "ipv6-addr-hex" },
637 { IDMEF_ADDRESS_CATEGORY_IPV6_NET, "ipv6-net" },
638 { IDMEF_ADDRESS_CATEGORY_IPV6_NET_MASK, "ipv6-net-mask" },
639 };
640
641 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
642 return NULL;
643
644 return tbl[val].name;
645 }
646
647
648 struct idmef_address {
649
650 IDMEF_LINKED_OBJECT;
651 REFCOUNT;
652 prelude_string_t *ident;
653 idmef_address_category_t category;
654 prelude_string_t *vlan_name;
655 OPTIONAL_INT(int32_t, vlan_num);
656 REQUIRED(prelude_string_t, *address);
657 prelude_string_t *netmask;
658
659 };
660
661
662
663 struct idmef_process {
664
665 IDMEF_OBJECT;
666 REFCOUNT;
667 prelude_string_t *ident;
668 REQUIRED(prelude_string_t, *name);
669 OPTIONAL_INT(uint32_t, pid);
670 prelude_string_t *path;
671
672 LISTED_OBJECT(arg_list, prelude_string_t);
673 LISTED_OBJECT(env_list, prelude_string_t);
674
675 };
676
677
678
679 struct idmef_web_service {
680
681 IDMEF_OBJECT;
682 REFCOUNT;
683 REQUIRED(prelude_string_t, *url);
684 prelude_string_t *cgi;
685 prelude_string_t *http_method;
686 LISTED_OBJECT(arg_list, prelude_string_t);
687
688 };
689
690
691
692 struct idmef_snmp_service {
693
694 IDMEF_OBJECT;
695 REFCOUNT;
696 prelude_string_t *oid;
697 OPTIONAL_INT(uint32_t, message_processing_model);
698 OPTIONAL_INT(uint32_t, security_model);
699 prelude_string_t *security_name;
700 OPTIONAL_INT(uint32_t, security_level);
701 prelude_string_t *context_name;
702 prelude_string_t *context_engine_id;
703 prelude_string_t *command;
704
705
706
707
708 prelude_string_t *community;
709
710 };
711
712
713 /**
714 * idmef_service_type_to_numeric:
715 * @name: pointer to an IDMEF string representation of a #idmef_service_type_t value.
716 *
717 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
718 */
idmef_service_type_to_numeric(const char * name)719 idmef_service_type_t idmef_service_type_to_numeric(const char *name)
720 {
721 size_t i;
722 const struct {
723 idmef_service_type_t val;
724 const char *name;
725 } tbl[] = {
726 { IDMEF_SERVICE_TYPE_DEFAULT, "default" },
727 { IDMEF_SERVICE_TYPE_WEB, "web" },
728 { IDMEF_SERVICE_TYPE_SNMP, "snmp" },
729 };
730
731 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
732
733 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
734 if ( strcasecmp(name, tbl[i].name) == 0 )
735 return tbl[i].val;
736 }
737
738 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for service_type", name);
739 }
740
741 /**
742 * idmef_service_type_to_string:
743 * @val: an enumeration value for #idmef_service_type_t.
744 *
745 * Return the IDMEF string equivalent of @val provided #idmef_service_type_t value.
746 *
747 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
748 */
idmef_service_type_to_string(idmef_service_type_t val)749 const char *idmef_service_type_to_string(idmef_service_type_t val)
750 {
751 const struct {
752 idmef_service_type_t val;
753 const char *name;
754 } tbl[] = {
755 { IDMEF_SERVICE_TYPE_DEFAULT, "default" },
756 { IDMEF_SERVICE_TYPE_WEB, "web" },
757 { IDMEF_SERVICE_TYPE_SNMP, "snmp" },
758 };
759
760 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
761 return NULL;
762
763 return tbl[val].name;
764 }
765
766
767 struct idmef_service {
768
769 IDMEF_OBJECT;
770 REFCOUNT;
771 prelude_string_t *ident;
772
773 OPTIONAL_INT(uint8_t, ip_version);
774 OPTIONAL_INT(uint8_t, iana_protocol_number);
775 prelude_string_t *iana_protocol_name;
776
777 prelude_string_t *name;
778 OPTIONAL_INT(uint16_t, port);
779 prelude_string_t *portlist;
780 prelude_string_t *protocol;
781
UNIONidmef_service782 UNION(idmef_service_type_t, type) {
783 UNION_MEMBER(IDMEF_SERVICE_TYPE_WEB, idmef_web_service_t, *web_service);
784 UNION_MEMBER(IDMEF_SERVICE_TYPE_SNMP, idmef_snmp_service_t, *snmp_service);
785 } specific;
786
787
788 };
789
790
791 /**
792 * idmef_node_category_to_numeric:
793 * @name: pointer to an IDMEF string representation of a #idmef_node_category_t value.
794 *
795 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
796 */
idmef_node_category_to_numeric(const char * name)797 idmef_node_category_t idmef_node_category_to_numeric(const char *name)
798 {
799 size_t i;
800 const struct {
801 idmef_node_category_t val;
802 const char *name;
803 } tbl[] = {
804 { IDMEF_NODE_CATEGORY_UNKNOWN, "unknown" },
805 { IDMEF_NODE_CATEGORY_ADS, "ads" },
806 { IDMEF_NODE_CATEGORY_AFS, "afs" },
807 { IDMEF_NODE_CATEGORY_CODA, "coda" },
808 { IDMEF_NODE_CATEGORY_DFS, "dfs" },
809 { IDMEF_NODE_CATEGORY_DNS, "dns" },
810 { IDMEF_NODE_CATEGORY_HOSTS, "hosts" },
811 { IDMEF_NODE_CATEGORY_KERBEROS, "kerberos" },
812 { IDMEF_NODE_CATEGORY_NDS, "nds" },
813 { IDMEF_NODE_CATEGORY_NIS, "nis" },
814 { IDMEF_NODE_CATEGORY_NISPLUS, "nisplus" },
815 { IDMEF_NODE_CATEGORY_NT, "nt" },
816 { IDMEF_NODE_CATEGORY_WFW, "wfw" },
817 };
818
819 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
820
821 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
822 if ( strcasecmp(name, tbl[i].name) == 0 )
823 return tbl[i].val;
824 }
825
826 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for node_category", name);
827 }
828
829 /**
830 * idmef_node_category_to_string:
831 * @val: an enumeration value for #idmef_node_category_t.
832 *
833 * Return the IDMEF string equivalent of @val provided #idmef_node_category_t value.
834 *
835 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
836 */
idmef_node_category_to_string(idmef_node_category_t val)837 const char *idmef_node_category_to_string(idmef_node_category_t val)
838 {
839 const struct {
840 idmef_node_category_t val;
841 const char *name;
842 } tbl[] = {
843 { IDMEF_NODE_CATEGORY_UNKNOWN, "unknown" },
844 { IDMEF_NODE_CATEGORY_ADS, "ads" },
845 { IDMEF_NODE_CATEGORY_AFS, "afs" },
846 { IDMEF_NODE_CATEGORY_CODA, "coda" },
847 { IDMEF_NODE_CATEGORY_DFS, "dfs" },
848 { IDMEF_NODE_CATEGORY_DNS, "dns" },
849 { IDMEF_NODE_CATEGORY_HOSTS, "hosts" },
850 { IDMEF_NODE_CATEGORY_KERBEROS, "kerberos" },
851 { IDMEF_NODE_CATEGORY_NDS, "nds" },
852 { IDMEF_NODE_CATEGORY_NIS, "nis" },
853 { IDMEF_NODE_CATEGORY_NISPLUS, "nisplus" },
854 { IDMEF_NODE_CATEGORY_NT, "nt" },
855 { IDMEF_NODE_CATEGORY_WFW, "wfw" },
856 };
857
858 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
859 return NULL;
860
861 return tbl[val].name;
862 }
863
864
865 struct idmef_node {
866
867 IDMEF_OBJECT;
868 REFCOUNT;
869 prelude_string_t *ident;
870 idmef_node_category_t category;
871 prelude_string_t *location;
872 prelude_string_t *name;
873 LISTED_OBJECT(address_list, idmef_address_t);
874
875 };
876
877
878 /**
879 * idmef_source_spoofed_to_numeric:
880 * @name: pointer to an IDMEF string representation of a #idmef_source_spoofed_t value.
881 *
882 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
883 */
idmef_source_spoofed_to_numeric(const char * name)884 idmef_source_spoofed_t idmef_source_spoofed_to_numeric(const char *name)
885 {
886 size_t i;
887 const struct {
888 idmef_source_spoofed_t val;
889 const char *name;
890 } tbl[] = {
891 { IDMEF_SOURCE_SPOOFED_UNKNOWN, "unknown" },
892 { IDMEF_SOURCE_SPOOFED_YES, "yes" },
893 { IDMEF_SOURCE_SPOOFED_NO, "no" },
894 };
895
896 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
897
898 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
899 if ( strcasecmp(name, tbl[i].name) == 0 )
900 return tbl[i].val;
901 }
902
903 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for source_spoofed", name);
904 }
905
906 /**
907 * idmef_source_spoofed_to_string:
908 * @val: an enumeration value for #idmef_source_spoofed_t.
909 *
910 * Return the IDMEF string equivalent of @val provided #idmef_source_spoofed_t value.
911 *
912 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
913 */
idmef_source_spoofed_to_string(idmef_source_spoofed_t val)914 const char *idmef_source_spoofed_to_string(idmef_source_spoofed_t val)
915 {
916 const struct {
917 idmef_source_spoofed_t val;
918 const char *name;
919 } tbl[] = {
920 { IDMEF_SOURCE_SPOOFED_UNKNOWN, "unknown" },
921 { IDMEF_SOURCE_SPOOFED_YES, "yes" },
922 { IDMEF_SOURCE_SPOOFED_NO, "no" },
923 };
924
925 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
926 return NULL;
927
928 return tbl[val].name;
929 }
930
931
932 struct idmef_source {
933
934 IDMEF_LINKED_OBJECT;
935 REFCOUNT;
936 prelude_string_t *ident;
937
938 idmef_source_spoofed_t spoofed;
939 prelude_string_t *interface;
940
941 idmef_node_t *node;
942 idmef_user_t *user;
943 idmef_process_t *process;
944 idmef_service_t *service;
945
946
947 };
948
949
950
951 struct idmef_file_access {
952
953 IDMEF_LINKED_OBJECT;
954 REFCOUNT;
955
956 REQUIRED(idmef_user_id_t, *user_id);
957 LISTED_OBJECT(permission_list, prelude_string_t);
958
959 };
960
961
962
963 struct idmef_inode {
964
965 IDMEF_OBJECT;
966 REFCOUNT;
967 idmef_time_t *change_time;
968 OPTIONAL_INT(uint32_t, number);
969 OPTIONAL_INT(uint32_t, major_device);
970 OPTIONAL_INT(uint32_t, minor_device);
971 OPTIONAL_INT(uint32_t, c_major_device);
972 OPTIONAL_INT(uint32_t, c_minor_device);
973
974 };
975
976
977 /**
978 * idmef_checksum_algorithm_to_numeric:
979 * @name: pointer to an IDMEF string representation of a #idmef_checksum_algorithm_t value.
980 *
981 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
982 */
idmef_checksum_algorithm_to_numeric(const char * name)983 idmef_checksum_algorithm_t idmef_checksum_algorithm_to_numeric(const char *name)
984 {
985 size_t i;
986 const struct {
987 idmef_checksum_algorithm_t val;
988 const char *name;
989 } tbl[] = {
990 { IDMEF_CHECKSUM_ALGORITHM_MD4, "MD4" },
991 { IDMEF_CHECKSUM_ALGORITHM_MD5, "MD5" },
992 { IDMEF_CHECKSUM_ALGORITHM_SHA1, "SHA1" },
993 { IDMEF_CHECKSUM_ALGORITHM_SHA2_256, "SHA2-256" },
994 { IDMEF_CHECKSUM_ALGORITHM_SHA2_384, "SHA2-384" },
995 { IDMEF_CHECKSUM_ALGORITHM_SHA2_512, "SHA2-512" },
996 { IDMEF_CHECKSUM_ALGORITHM_CRC_32, "CRC-32" },
997 { IDMEF_CHECKSUM_ALGORITHM_HAVAL, "Haval" },
998 { IDMEF_CHECKSUM_ALGORITHM_TIGER, "Tiger" },
999 { IDMEF_CHECKSUM_ALGORITHM_GOST, "Gost" },
1000 };
1001
1002 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
1003
1004 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
1005 if ( strcasecmp(name, tbl[i].name) == 0 )
1006 return tbl[i].val;
1007 }
1008
1009 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for checksum_algorithm", name);
1010 }
1011
1012 /**
1013 * idmef_checksum_algorithm_to_string:
1014 * @val: an enumeration value for #idmef_checksum_algorithm_t.
1015 *
1016 * Return the IDMEF string equivalent of @val provided #idmef_checksum_algorithm_t value.
1017 *
1018 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
1019 */
idmef_checksum_algorithm_to_string(idmef_checksum_algorithm_t val)1020 const char *idmef_checksum_algorithm_to_string(idmef_checksum_algorithm_t val)
1021 {
1022 const struct {
1023 idmef_checksum_algorithm_t val;
1024 const char *name;
1025 } tbl[] = {{ 0, NULL },
1026 { IDMEF_CHECKSUM_ALGORITHM_MD4, "MD4" },
1027 { IDMEF_CHECKSUM_ALGORITHM_MD5, "MD5" },
1028 { IDMEF_CHECKSUM_ALGORITHM_SHA1, "SHA1" },
1029 { IDMEF_CHECKSUM_ALGORITHM_SHA2_256, "SHA2-256" },
1030 { IDMEF_CHECKSUM_ALGORITHM_SHA2_384, "SHA2-384" },
1031 { IDMEF_CHECKSUM_ALGORITHM_SHA2_512, "SHA2-512" },
1032 { IDMEF_CHECKSUM_ALGORITHM_CRC_32, "CRC-32" },
1033 { IDMEF_CHECKSUM_ALGORITHM_HAVAL, "Haval" },
1034 { IDMEF_CHECKSUM_ALGORITHM_TIGER, "Tiger" },
1035 { IDMEF_CHECKSUM_ALGORITHM_GOST, "Gost" },
1036 };
1037
1038 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
1039 return NULL;
1040
1041 return tbl[val].name;
1042 }
1043
1044
1045 struct idmef_checksum {
1046
1047 IDMEF_LINKED_OBJECT;
1048 REFCOUNT;
1049 REQUIRED(prelude_string_t, *value);
1050 prelude_string_t *key;
1051 idmef_checksum_algorithm_t algorithm;
1052
1053 };
1054
1055
1056 /**
1057 * idmef_file_category_to_numeric:
1058 * @name: pointer to an IDMEF string representation of a #idmef_file_category_t value.
1059 *
1060 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
1061 */
idmef_file_category_to_numeric(const char * name)1062 idmef_file_category_t idmef_file_category_to_numeric(const char *name)
1063 {
1064 size_t i;
1065 const struct {
1066 idmef_file_category_t val;
1067 const char *name;
1068 } tbl[] = {
1069 { IDMEF_FILE_CATEGORY_CURRENT, "current" },
1070 { IDMEF_FILE_CATEGORY_ORIGINAL, "original" },
1071 };
1072
1073 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
1074
1075 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
1076 if ( strcasecmp(name, tbl[i].name) == 0 )
1077 return tbl[i].val;
1078 }
1079
1080 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for file_category", name);
1081 }
1082
1083 /**
1084 * idmef_file_category_to_string:
1085 * @val: an enumeration value for #idmef_file_category_t.
1086 *
1087 * Return the IDMEF string equivalent of @val provided #idmef_file_category_t value.
1088 *
1089 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
1090 */
idmef_file_category_to_string(idmef_file_category_t val)1091 const char *idmef_file_category_to_string(idmef_file_category_t val)
1092 {
1093 const struct {
1094 idmef_file_category_t val;
1095 const char *name;
1096 } tbl[] = {{ 0, NULL },
1097 { IDMEF_FILE_CATEGORY_CURRENT, "current" },
1098 { IDMEF_FILE_CATEGORY_ORIGINAL, "original" },
1099 };
1100
1101 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
1102 return NULL;
1103
1104 return tbl[val].name;
1105 }
1106
1107 /**
1108 * idmef_file_fstype_to_numeric:
1109 * @name: pointer to an IDMEF string representation of a #idmef_file_fstype_t value.
1110 *
1111 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
1112 */
idmef_file_fstype_to_numeric(const char * name)1113 idmef_file_fstype_t idmef_file_fstype_to_numeric(const char *name)
1114 {
1115 size_t i;
1116 const struct {
1117 idmef_file_fstype_t val;
1118 const char *name;
1119 } tbl[] = {
1120 { IDMEF_FILE_FSTYPE_UFS, "ufs" },
1121 { IDMEF_FILE_FSTYPE_EFS, "efs" },
1122 { IDMEF_FILE_FSTYPE_NFS, "nfs" },
1123 { IDMEF_FILE_FSTYPE_AFS, "afs" },
1124 { IDMEF_FILE_FSTYPE_NTFS, "ntfs" },
1125 { IDMEF_FILE_FSTYPE_FAT16, "fat16" },
1126 { IDMEF_FILE_FSTYPE_FAT32, "fat32" },
1127 { IDMEF_FILE_FSTYPE_PCFS, "pcfs" },
1128 { IDMEF_FILE_FSTYPE_JOLIET, "joliet" },
1129 { IDMEF_FILE_FSTYPE_ISO9660, "iso9660" },
1130 };
1131
1132 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
1133
1134 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
1135 if ( strcasecmp(name, tbl[i].name) == 0 )
1136 return tbl[i].val;
1137 }
1138
1139 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for file_fstype", name);
1140 }
1141
1142 /**
1143 * idmef_file_fstype_to_string:
1144 * @val: an enumeration value for #idmef_file_fstype_t.
1145 *
1146 * Return the IDMEF string equivalent of @val provided #idmef_file_fstype_t value.
1147 *
1148 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
1149 */
idmef_file_fstype_to_string(idmef_file_fstype_t val)1150 const char *idmef_file_fstype_to_string(idmef_file_fstype_t val)
1151 {
1152 const struct {
1153 idmef_file_fstype_t val;
1154 const char *name;
1155 } tbl[] = {{ 0, NULL },
1156 { IDMEF_FILE_FSTYPE_UFS, "ufs" },
1157 { IDMEF_FILE_FSTYPE_EFS, "efs" },
1158 { IDMEF_FILE_FSTYPE_NFS, "nfs" },
1159 { IDMEF_FILE_FSTYPE_AFS, "afs" },
1160 { IDMEF_FILE_FSTYPE_NTFS, "ntfs" },
1161 { IDMEF_FILE_FSTYPE_FAT16, "fat16" },
1162 { IDMEF_FILE_FSTYPE_FAT32, "fat32" },
1163 { IDMEF_FILE_FSTYPE_PCFS, "pcfs" },
1164 { IDMEF_FILE_FSTYPE_JOLIET, "joliet" },
1165 { IDMEF_FILE_FSTYPE_ISO9660, "iso9660" },
1166 };
1167
1168 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
1169 return NULL;
1170
1171 return tbl[val].name;
1172 }
1173
1174
1175 struct idmef_file {
1176
1177 IDMEF_LINKED_OBJECT;
1178 REFCOUNT;
1179 prelude_string_t *ident;
1180
1181 REQUIRED(prelude_string_t, *name);
1182 REQUIRED(prelude_string_t, *path);
1183
1184 idmef_time_t *create_time;
1185 idmef_time_t *modify_time;
1186 idmef_time_t *access_time;
1187
1188
1189 OPTIONAL_INT(uint64_t, data_size);
1190 OPTIONAL_INT(uint64_t, disk_size);
1191
1192 LISTED_OBJECT(file_access_list, idmef_file_access_t);
1193 LISTED_OBJECT(linkage_list, idmef_linkage_t);
1194
1195 idmef_inode_t *inode;
1196 LISTED_OBJECT(checksum_list, idmef_checksum_t);
1197
1198 idmef_file_category_t category;
1199 OPTIONAL_INT(idmef_file_fstype_t, fstype);
1200 prelude_string_t *file_type;
1201
1202
1203 };
1204
1205
1206 /**
1207 * idmef_linkage_category_to_numeric:
1208 * @name: pointer to an IDMEF string representation of a #idmef_linkage_category_t value.
1209 *
1210 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
1211 */
idmef_linkage_category_to_numeric(const char * name)1212 idmef_linkage_category_t idmef_linkage_category_to_numeric(const char *name)
1213 {
1214 size_t i;
1215 const struct {
1216 idmef_linkage_category_t val;
1217 const char *name;
1218 } tbl[] = {
1219 { IDMEF_LINKAGE_CATEGORY_HARD_LINK, "hard-link" },
1220 { IDMEF_LINKAGE_CATEGORY_MOUNT_POINT, "mount-point" },
1221 { IDMEF_LINKAGE_CATEGORY_REPARSE_POINT, "reparse-point" },
1222 { IDMEF_LINKAGE_CATEGORY_SHORTCUT, "shortcut" },
1223 { IDMEF_LINKAGE_CATEGORY_STREAM, "stream" },
1224 { IDMEF_LINKAGE_CATEGORY_SYMBOLIC_LINK, "symbolic-link" },
1225 };
1226
1227 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
1228
1229 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
1230 if ( strcasecmp(name, tbl[i].name) == 0 )
1231 return tbl[i].val;
1232 }
1233
1234 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for linkage_category", name);
1235 }
1236
1237 /**
1238 * idmef_linkage_category_to_string:
1239 * @val: an enumeration value for #idmef_linkage_category_t.
1240 *
1241 * Return the IDMEF string equivalent of @val provided #idmef_linkage_category_t value.
1242 *
1243 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
1244 */
idmef_linkage_category_to_string(idmef_linkage_category_t val)1245 const char *idmef_linkage_category_to_string(idmef_linkage_category_t val)
1246 {
1247 const struct {
1248 idmef_linkage_category_t val;
1249 const char *name;
1250 } tbl[] = {{ 0, NULL },
1251 { IDMEF_LINKAGE_CATEGORY_HARD_LINK, "hard-link" },
1252 { IDMEF_LINKAGE_CATEGORY_MOUNT_POINT, "mount-point" },
1253 { IDMEF_LINKAGE_CATEGORY_REPARSE_POINT, "reparse-point" },
1254 { IDMEF_LINKAGE_CATEGORY_SHORTCUT, "shortcut" },
1255 { IDMEF_LINKAGE_CATEGORY_STREAM, "stream" },
1256 { IDMEF_LINKAGE_CATEGORY_SYMBOLIC_LINK, "symbolic-link" },
1257 };
1258
1259 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
1260 return NULL;
1261
1262 return tbl[val].name;
1263 }
1264
1265
1266 struct idmef_linkage {
1267
1268 IDMEF_LINKED_OBJECT;
1269 REFCOUNT;
1270
1271 idmef_linkage_category_t category;
1272 REQUIRED(prelude_string_t, *name);
1273 REQUIRED(prelude_string_t, *path);
1274 REQUIRED(idmef_file_t, *file);
1275
1276 };
1277
1278
1279 /**
1280 * idmef_target_decoy_to_numeric:
1281 * @name: pointer to an IDMEF string representation of a #idmef_target_decoy_t value.
1282 *
1283 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
1284 */
idmef_target_decoy_to_numeric(const char * name)1285 idmef_target_decoy_t idmef_target_decoy_to_numeric(const char *name)
1286 {
1287 size_t i;
1288 const struct {
1289 idmef_target_decoy_t val;
1290 const char *name;
1291 } tbl[] = {
1292 { IDMEF_TARGET_DECOY_UNKNOWN, "unknown" },
1293 { IDMEF_TARGET_DECOY_YES, "yes" },
1294 { IDMEF_TARGET_DECOY_NO, "no" },
1295 };
1296
1297 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
1298
1299 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
1300 if ( strcasecmp(name, tbl[i].name) == 0 )
1301 return tbl[i].val;
1302 }
1303
1304 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for target_decoy", name);
1305 }
1306
1307 /**
1308 * idmef_target_decoy_to_string:
1309 * @val: an enumeration value for #idmef_target_decoy_t.
1310 *
1311 * Return the IDMEF string equivalent of @val provided #idmef_target_decoy_t value.
1312 *
1313 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
1314 */
idmef_target_decoy_to_string(idmef_target_decoy_t val)1315 const char *idmef_target_decoy_to_string(idmef_target_decoy_t val)
1316 {
1317 const struct {
1318 idmef_target_decoy_t val;
1319 const char *name;
1320 } tbl[] = {
1321 { IDMEF_TARGET_DECOY_UNKNOWN, "unknown" },
1322 { IDMEF_TARGET_DECOY_YES, "yes" },
1323 { IDMEF_TARGET_DECOY_NO, "no" },
1324 };
1325
1326 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
1327 return NULL;
1328
1329 return tbl[val].name;
1330 }
1331
1332
1333 struct idmef_target {
1334
1335 IDMEF_LINKED_OBJECT;
1336 REFCOUNT;
1337 prelude_string_t *ident;
1338
1339 idmef_target_decoy_t decoy;
1340 prelude_string_t *interface;
1341
1342 idmef_node_t *node;
1343 idmef_user_t *user;
1344 idmef_process_t *process;
1345 idmef_service_t *service;
1346 LISTED_OBJECT(file_list, idmef_file_t);
1347
1348 };
1349
1350
1351
1352 struct idmef_analyzer {
1353
1354 IDMEF_LINKED_OBJECT;
1355 REFCOUNT;
1356 prelude_string_t *analyzerid;
1357
1358 prelude_string_t *name;
1359 prelude_string_t *manufacturer;
1360 prelude_string_t *model;
1361 prelude_string_t *version;
1362 prelude_string_t *class;
1363 prelude_string_t *ostype;
1364 prelude_string_t *osversion;
1365
1366 idmef_node_t *node;
1367 idmef_process_t *process;
1368
1369
1370 };
1371
1372
1373
1374 struct idmef_alertident {
1375
1376 IDMEF_LINKED_OBJECT;
1377 REFCOUNT;
1378
1379 REQUIRED(prelude_string_t, *alertident);
1380 prelude_string_t *analyzerid;
1381
1382
1383 };
1384
1385
1386 /**
1387 * idmef_impact_severity_to_numeric:
1388 * @name: pointer to an IDMEF string representation of a #idmef_impact_severity_t value.
1389 *
1390 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
1391 */
idmef_impact_severity_to_numeric(const char * name)1392 idmef_impact_severity_t idmef_impact_severity_to_numeric(const char *name)
1393 {
1394 size_t i;
1395 const struct {
1396 idmef_impact_severity_t val;
1397 const char *name;
1398 } tbl[] = {
1399 { IDMEF_IMPACT_SEVERITY_INFO, "info" },
1400 { IDMEF_IMPACT_SEVERITY_LOW, "low" },
1401 { IDMEF_IMPACT_SEVERITY_MEDIUM, "medium" },
1402 { IDMEF_IMPACT_SEVERITY_HIGH, "high" },
1403 };
1404
1405 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
1406
1407 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
1408 if ( strcasecmp(name, tbl[i].name) == 0 )
1409 return tbl[i].val;
1410 }
1411
1412 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for impact_severity", name);
1413 }
1414
1415 /**
1416 * idmef_impact_severity_to_string:
1417 * @val: an enumeration value for #idmef_impact_severity_t.
1418 *
1419 * Return the IDMEF string equivalent of @val provided #idmef_impact_severity_t value.
1420 *
1421 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
1422 */
idmef_impact_severity_to_string(idmef_impact_severity_t val)1423 const char *idmef_impact_severity_to_string(idmef_impact_severity_t val)
1424 {
1425 const struct {
1426 idmef_impact_severity_t val;
1427 const char *name;
1428 } tbl[] = {{ 0, NULL },
1429 { IDMEF_IMPACT_SEVERITY_INFO, "info" },
1430 { IDMEF_IMPACT_SEVERITY_LOW, "low" },
1431 { IDMEF_IMPACT_SEVERITY_MEDIUM, "medium" },
1432 { IDMEF_IMPACT_SEVERITY_HIGH, "high" },
1433 };
1434
1435 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
1436 return NULL;
1437
1438 return tbl[val].name;
1439 }
1440
1441 /**
1442 * idmef_impact_completion_to_numeric:
1443 * @name: pointer to an IDMEF string representation of a #idmef_impact_completion_t value.
1444 *
1445 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
1446 */
idmef_impact_completion_to_numeric(const char * name)1447 idmef_impact_completion_t idmef_impact_completion_to_numeric(const char *name)
1448 {
1449 size_t i;
1450 const struct {
1451 idmef_impact_completion_t val;
1452 const char *name;
1453 } tbl[] = {
1454 { IDMEF_IMPACT_COMPLETION_FAILED, "failed" },
1455 { IDMEF_IMPACT_COMPLETION_SUCCEEDED, "succeeded" },
1456 };
1457
1458 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
1459
1460 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
1461 if ( strcasecmp(name, tbl[i].name) == 0 )
1462 return tbl[i].val;
1463 }
1464
1465 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for impact_completion", name);
1466 }
1467
1468 /**
1469 * idmef_impact_completion_to_string:
1470 * @val: an enumeration value for #idmef_impact_completion_t.
1471 *
1472 * Return the IDMEF string equivalent of @val provided #idmef_impact_completion_t value.
1473 *
1474 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
1475 */
idmef_impact_completion_to_string(idmef_impact_completion_t val)1476 const char *idmef_impact_completion_to_string(idmef_impact_completion_t val)
1477 {
1478 const struct {
1479 idmef_impact_completion_t val;
1480 const char *name;
1481 } tbl[] = {{ 0, NULL },
1482 { IDMEF_IMPACT_COMPLETION_FAILED, "failed" },
1483 { IDMEF_IMPACT_COMPLETION_SUCCEEDED, "succeeded" },
1484 };
1485
1486 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
1487 return NULL;
1488
1489 return tbl[val].name;
1490 }
1491
1492 /**
1493 * idmef_impact_type_to_numeric:
1494 * @name: pointer to an IDMEF string representation of a #idmef_impact_type_t value.
1495 *
1496 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
1497 */
idmef_impact_type_to_numeric(const char * name)1498 idmef_impact_type_t idmef_impact_type_to_numeric(const char *name)
1499 {
1500 size_t i;
1501 const struct {
1502 idmef_impact_type_t val;
1503 const char *name;
1504 } tbl[] = {
1505 { IDMEF_IMPACT_TYPE_OTHER, "other" },
1506 { IDMEF_IMPACT_TYPE_ADMIN, "admin" },
1507 { IDMEF_IMPACT_TYPE_DOS, "dos" },
1508 { IDMEF_IMPACT_TYPE_FILE, "file" },
1509 { IDMEF_IMPACT_TYPE_RECON, "recon" },
1510 { IDMEF_IMPACT_TYPE_USER, "user" },
1511 };
1512
1513 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
1514
1515 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
1516 if ( strcasecmp(name, tbl[i].name) == 0 )
1517 return tbl[i].val;
1518 }
1519
1520 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for impact_type", name);
1521 }
1522
1523 /**
1524 * idmef_impact_type_to_string:
1525 * @val: an enumeration value for #idmef_impact_type_t.
1526 *
1527 * Return the IDMEF string equivalent of @val provided #idmef_impact_type_t value.
1528 *
1529 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
1530 */
idmef_impact_type_to_string(idmef_impact_type_t val)1531 const char *idmef_impact_type_to_string(idmef_impact_type_t val)
1532 {
1533 const struct {
1534 idmef_impact_type_t val;
1535 const char *name;
1536 } tbl[] = {
1537 { IDMEF_IMPACT_TYPE_OTHER, "other" },
1538 { IDMEF_IMPACT_TYPE_ADMIN, "admin" },
1539 { IDMEF_IMPACT_TYPE_DOS, "dos" },
1540 { IDMEF_IMPACT_TYPE_FILE, "file" },
1541 { IDMEF_IMPACT_TYPE_RECON, "recon" },
1542 { IDMEF_IMPACT_TYPE_USER, "user" },
1543 };
1544
1545 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
1546 return NULL;
1547
1548 return tbl[val].name;
1549 }
1550
1551
1552 struct idmef_impact {
1553
1554 IDMEF_OBJECT;
1555 REFCOUNT;
1556
1557 OPTIONAL_INT(idmef_impact_severity_t, severity);
1558 OPTIONAL_INT(idmef_impact_completion_t, completion);
1559 idmef_impact_type_t type;
1560 prelude_string_t *description;
1561
1562 };
1563
1564
1565 /**
1566 * idmef_action_category_to_numeric:
1567 * @name: pointer to an IDMEF string representation of a #idmef_action_category_t value.
1568 *
1569 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
1570 */
idmef_action_category_to_numeric(const char * name)1571 idmef_action_category_t idmef_action_category_to_numeric(const char *name)
1572 {
1573 size_t i;
1574 const struct {
1575 idmef_action_category_t val;
1576 const char *name;
1577 } tbl[] = {
1578 { IDMEF_ACTION_CATEGORY_OTHER, "other" },
1579 { IDMEF_ACTION_CATEGORY_BLOCK_INSTALLED, "block-installed" },
1580 { IDMEF_ACTION_CATEGORY_NOTIFICATION_SENT, "notification-sent" },
1581 { IDMEF_ACTION_CATEGORY_TAKEN_OFFLINE, "taken-offline" },
1582 };
1583
1584 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
1585
1586 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
1587 if ( strcasecmp(name, tbl[i].name) == 0 )
1588 return tbl[i].val;
1589 }
1590
1591 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for action_category", name);
1592 }
1593
1594 /**
1595 * idmef_action_category_to_string:
1596 * @val: an enumeration value for #idmef_action_category_t.
1597 *
1598 * Return the IDMEF string equivalent of @val provided #idmef_action_category_t value.
1599 *
1600 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
1601 */
idmef_action_category_to_string(idmef_action_category_t val)1602 const char *idmef_action_category_to_string(idmef_action_category_t val)
1603 {
1604 const struct {
1605 idmef_action_category_t val;
1606 const char *name;
1607 } tbl[] = {
1608 { IDMEF_ACTION_CATEGORY_OTHER, "other" },
1609 { IDMEF_ACTION_CATEGORY_BLOCK_INSTALLED, "block-installed" },
1610 { IDMEF_ACTION_CATEGORY_NOTIFICATION_SENT, "notification-sent" },
1611 { IDMEF_ACTION_CATEGORY_TAKEN_OFFLINE, "taken-offline" },
1612 };
1613
1614 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
1615 return NULL;
1616
1617 return tbl[val].name;
1618 }
1619
1620
1621 struct idmef_action {
1622
1623 IDMEF_LINKED_OBJECT;
1624 REFCOUNT;
1625
1626 idmef_action_category_t category;
1627 prelude_string_t *description;
1628
1629 };
1630
1631
1632 /**
1633 * idmef_confidence_rating_to_numeric:
1634 * @name: pointer to an IDMEF string representation of a #idmef_confidence_rating_t value.
1635 *
1636 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
1637 */
idmef_confidence_rating_to_numeric(const char * name)1638 idmef_confidence_rating_t idmef_confidence_rating_to_numeric(const char *name)
1639 {
1640 size_t i;
1641 const struct {
1642 idmef_confidence_rating_t val;
1643 const char *name;
1644 } tbl[] = {
1645 { IDMEF_CONFIDENCE_RATING_NUMERIC, "numeric" },
1646 { IDMEF_CONFIDENCE_RATING_LOW, "low" },
1647 { IDMEF_CONFIDENCE_RATING_MEDIUM, "medium" },
1648 { IDMEF_CONFIDENCE_RATING_HIGH, "high" },
1649 };
1650
1651 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
1652
1653 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
1654 if ( strcasecmp(name, tbl[i].name) == 0 )
1655 return tbl[i].val;
1656 }
1657
1658 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for confidence_rating", name);
1659 }
1660
1661 /**
1662 * idmef_confidence_rating_to_string:
1663 * @val: an enumeration value for #idmef_confidence_rating_t.
1664 *
1665 * Return the IDMEF string equivalent of @val provided #idmef_confidence_rating_t value.
1666 *
1667 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
1668 */
idmef_confidence_rating_to_string(idmef_confidence_rating_t val)1669 const char *idmef_confidence_rating_to_string(idmef_confidence_rating_t val)
1670 {
1671 const struct {
1672 idmef_confidence_rating_t val;
1673 const char *name;
1674 } tbl[] = {
1675 { IDMEF_CONFIDENCE_RATING_NUMERIC, "numeric" },
1676 { IDMEF_CONFIDENCE_RATING_LOW, "low" },
1677 { IDMEF_CONFIDENCE_RATING_MEDIUM, "medium" },
1678 { IDMEF_CONFIDENCE_RATING_HIGH, "high" },
1679 };
1680
1681 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
1682 return NULL;
1683
1684 return tbl[val].name;
1685 }
1686
1687
1688 struct idmef_confidence {
1689
1690 IDMEF_OBJECT;
1691 REFCOUNT;
1692
1693 idmef_confidence_rating_t rating;
1694 float confidence;
1695
1696 };
1697
1698
1699
1700 struct idmef_assessment {
1701
1702 IDMEF_OBJECT;
1703 REFCOUNT;
1704
1705 idmef_impact_t *impact;
1706 LISTED_OBJECT(action_list, idmef_action_t);
1707 idmef_confidence_t *confidence;
1708
1709 };
1710
1711
1712
1713 struct idmef_tool_alert {
1714
1715 IDMEF_OBJECT;
1716 REFCOUNT;
1717
1718 REQUIRED(prelude_string_t, *name);
1719 prelude_string_t *command;
1720 LISTED_OBJECT(alertident_list, idmef_alertident_t);
1721
1722 };
1723
1724
1725
1726 struct idmef_correlation_alert {
1727
1728 IDMEF_OBJECT;
1729 REFCOUNT;
1730
1731 REQUIRED(prelude_string_t, *name);
1732 LISTED_OBJECT(alertident_list, idmef_alertident_t);
1733
1734 };
1735
1736
1737
1738 struct idmef_overflow_alert {
1739
1740 IDMEF_OBJECT;
1741 REFCOUNT;
1742
1743 REQUIRED(prelude_string_t, *program);
1744 OPTIONAL_INT(uint32_t, size);
1745 idmef_data_t *buffer;
1746
1747 };
1748
1749
1750 /**
1751 * idmef_alert_type_to_numeric:
1752 * @name: pointer to an IDMEF string representation of a #idmef_alert_type_t value.
1753 *
1754 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
1755 */
idmef_alert_type_to_numeric(const char * name)1756 idmef_alert_type_t idmef_alert_type_to_numeric(const char *name)
1757 {
1758 size_t i;
1759 const struct {
1760 idmef_alert_type_t val;
1761 const char *name;
1762 } tbl[] = {
1763 { IDMEF_ALERT_TYPE_DEFAULT, "default" },
1764 { IDMEF_ALERT_TYPE_TOOL, "tool" },
1765 { IDMEF_ALERT_TYPE_CORRELATION, "correlation" },
1766 { IDMEF_ALERT_TYPE_OVERFLOW, "overflow" },
1767 };
1768
1769 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
1770
1771 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
1772 if ( strcasecmp(name, tbl[i].name) == 0 )
1773 return tbl[i].val;
1774 }
1775
1776 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for alert_type", name);
1777 }
1778
1779 /**
1780 * idmef_alert_type_to_string:
1781 * @val: an enumeration value for #idmef_alert_type_t.
1782 *
1783 * Return the IDMEF string equivalent of @val provided #idmef_alert_type_t value.
1784 *
1785 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
1786 */
idmef_alert_type_to_string(idmef_alert_type_t val)1787 const char *idmef_alert_type_to_string(idmef_alert_type_t val)
1788 {
1789 const struct {
1790 idmef_alert_type_t val;
1791 const char *name;
1792 } tbl[] = {
1793 { IDMEF_ALERT_TYPE_DEFAULT, "default" },
1794 { IDMEF_ALERT_TYPE_TOOL, "tool" },
1795 { IDMEF_ALERT_TYPE_CORRELATION, "correlation" },
1796 { IDMEF_ALERT_TYPE_OVERFLOW, "overflow" },
1797 };
1798
1799 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
1800 return NULL;
1801
1802 return tbl[val].name;
1803 }
1804
1805
1806 struct idmef_alert {
1807
1808 IDMEF_OBJECT;
1809 REFCOUNT;
1810 prelude_string_t *messageid;
1811
1812 LISTED_OBJECT(analyzer_list, idmef_analyzer_t);
1813
1814 REQUIRED(idmef_time_t, *create_time);
1815 REQUIRED(idmef_classification_t, *classification);
1816 idmef_time_t *detect_time;
1817 idmef_time_t *analyzer_time;
1818
1819 LISTED_OBJECT(source_list, idmef_source_t);
1820 LISTED_OBJECT(target_list, idmef_target_t);
1821
1822 idmef_assessment_t *assessment;
1823
1824 KEYLISTED_OBJECT(additional_data_list, idmef_additional_data_t);
1825
UNIONidmef_alert1826 UNION(idmef_alert_type_t, type) {
1827 UNION_MEMBER(IDMEF_ALERT_TYPE_TOOL, idmef_tool_alert_t, *tool_alert);
1828 UNION_MEMBER(IDMEF_ALERT_TYPE_CORRELATION, idmef_correlation_alert_t, *correlation_alert);
1829 UNION_MEMBER(IDMEF_ALERT_TYPE_OVERFLOW, idmef_overflow_alert_t, *overflow_alert);
1830 } detail;
1831
1832
1833 };
1834
1835
1836
1837 struct idmef_heartbeat {
1838
1839 IDMEF_OBJECT;
1840 REFCOUNT;
1841
1842 prelude_string_t *messageid;
1843 LISTED_OBJECT(analyzer_list, idmef_analyzer_t);
1844
1845 REQUIRED(idmef_time_t, *create_time);
1846 idmef_time_t *analyzer_time;
1847
1848 OPTIONAL_INT(uint32_t, heartbeat_interval);
1849 KEYLISTED_OBJECT(additional_data_list, idmef_additional_data_t);
1850
1851 };
1852
1853
1854 /**
1855 * idmef_message_type_to_numeric:
1856 * @name: pointer to an IDMEF string representation of a #idmef_message_type_t value.
1857 *
1858 * Returns: the numeric equivalent of @name, or -1 if @name is not valid.
1859 */
idmef_message_type_to_numeric(const char * name)1860 idmef_message_type_t idmef_message_type_to_numeric(const char *name)
1861 {
1862 size_t i;
1863 const struct {
1864 idmef_message_type_t val;
1865 const char *name;
1866 } tbl[] = {
1867 { IDMEF_MESSAGE_TYPE_ALERT, "alert" },
1868 { IDMEF_MESSAGE_TYPE_HEARTBEAT, "heartbeat" },
1869 };
1870
1871 prelude_return_val_if_fail(name, prelude_error(PRELUDE_ERROR_ASSERTION));
1872
1873 for ( i = 0; i < sizeof(tbl) / sizeof(*tbl); i++ ) {
1874 if ( strcasecmp(name, tbl[i].name) == 0 )
1875 return tbl[i].val;
1876 }
1877
1878 return prelude_error_verbose(PRELUDE_ERROR_IDMEF_UNKNOWN_ENUM_STRING, "Unknown enumeration value '%s' for message_type", name);
1879 }
1880
1881 /**
1882 * idmef_message_type_to_string:
1883 * @val: an enumeration value for #idmef_message_type_t.
1884 *
1885 * Return the IDMEF string equivalent of @val provided #idmef_message_type_t value.
1886 *
1887 * Returns: a pointer to the string describing @val, or NULL if @val is invalid.
1888 */
idmef_message_type_to_string(idmef_message_type_t val)1889 const char *idmef_message_type_to_string(idmef_message_type_t val)
1890 {
1891 const struct {
1892 idmef_message_type_t val;
1893 const char *name;
1894 } tbl[] = {{ 0, NULL },
1895 { IDMEF_MESSAGE_TYPE_ALERT, "alert" },
1896 { IDMEF_MESSAGE_TYPE_HEARTBEAT, "heartbeat" },
1897 };
1898
1899 if ( val < 0 || (size_t) val >= (sizeof(tbl) / sizeof(*tbl)) )
1900 return NULL;
1901
1902 return tbl[val].name;
1903 }
1904
1905
1906 struct idmef_message {
1907
1908 IDMEF_OBJECT;
1909 REFCOUNT;
1910
1911 REQUIRED(prelude_string_t, *version);
1912
UNIONidmef_message1913 UNION(idmef_message_type_t, type) {
1914 UNION_MEMBER(IDMEF_MESSAGE_TYPE_ALERT, idmef_alert_t, *alert);
1915 UNION_MEMBER(IDMEF_MESSAGE_TYPE_HEARTBEAT, idmef_heartbeat_t, *heartbeat);
1916 } message;
1917
1918 HIDE(prelude_msg_t *, pmsg);
1919
1920
1921 };
1922
1923
1924 /**
1925 * idmef_additional_data_new:
1926 * @ret: Pointer where to store the created #idmef_additional_data_t object.
1927 *
1928 * Create a new #idmef_additional_data_t object.
1929 *
1930 * Returns: 0 on success, a negative value if an error occured.
1931 */
idmef_additional_data_new(idmef_additional_data_t ** ret)1932 int idmef_additional_data_new(idmef_additional_data_t **ret)
1933 {
1934 *ret = calloc(1, sizeof(**ret));
1935 if ( ! *ret )
1936 return prelude_error_from_errno(errno);
1937
1938 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_ADDITIONAL_DATA;
1939
1940 prelude_list_init(&((prelude_linked_object_t *) (*ret))->_list);
1941
1942 (*ret)->refcount = 1;
1943
1944 {
1945 int retval = idmef_data_new(&(*ret)->data);
1946
1947 if ( retval < 0 ) {
1948 idmef_additional_data_destroy(*ret);
1949 *ret = NULL;
1950 return retval;
1951 }
1952 }
1953
1954 return 0;
1955
1956 }
1957
1958 /**
1959 * idmef_additional_data_ref:
1960 * @additional_data: pointer to a #idmef_additional_data_t object.
1961 *
1962 * Increase @additional_data reference count, so that it can be referenced
1963 * multiple time.
1964 *
1965 * Returns: a pointer to @additional_data.
1966 */
idmef_additional_data_ref(idmef_additional_data_t * additional_data)1967 idmef_additional_data_t *idmef_additional_data_ref(idmef_additional_data_t *additional_data)
1968 {
1969 prelude_return_val_if_fail(additional_data, NULL);
1970 additional_data->refcount++;
1971
1972 return additional_data;
1973 }
1974
_idmef_additional_data_get_child(void * p,idmef_class_child_id_t child,void ** childptr)1975 int _idmef_additional_data_get_child(void *p, idmef_class_child_id_t child, void **childptr)
1976 {
1977 idmef_additional_data_t *ptr = p;
1978
1979 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
1980 *childptr = NULL;
1981
1982 switch ( child ) {
1983
1984 case 0:
1985 return get_value_from_string((idmef_value_t **) childptr, ptr->meaning, TRUE);
1986 case 1:
1987 return idmef_value_new_enum_from_numeric((idmef_value_t **) childptr,
1988 IDMEF_CLASS_ID_ADDITIONAL_DATA_TYPE, ptr->type);
1989
1990 case 2:
1991 return get_value_from_data((idmef_value_t **) childptr, ptr->data, TRUE);
1992 default:
1993 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
1994 }
1995 }
1996
_idmef_additional_data_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)1997 int _idmef_additional_data_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
1998 {
1999 idmef_additional_data_t *ptr = p;
2000
2001 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
2002
2003 switch ( child ) {
2004
2005 case 0:
2006 return idmef_additional_data_new_meaning(ptr, (prelude_string_t **) ret);
2007
2008 case 1:
2009 return idmef_additional_data_new_type(ptr, (idmef_additional_data_type_t **) ret);
2010
2011 case 2:
2012 return idmef_additional_data_new_data(ptr, (idmef_data_t **) ret);
2013
2014 default:
2015 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
2016 }
2017 }
2018
_idmef_additional_data_destroy_child(void * p,idmef_class_child_id_t child,int n)2019 int _idmef_additional_data_destroy_child(void *p, idmef_class_child_id_t child, int n)
2020 {
2021 idmef_additional_data_t *ptr = p;
2022
2023 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
2024
2025 switch ( child ) {
2026
2027 case 0:
2028 if ( ptr->meaning ) {
2029 prelude_string_destroy(ptr->meaning);
2030 ptr->meaning = NULL;
2031 }
2032
2033 return 0;
2034
2035 case 1:
2036 ptr->type = 0;
2037 return 0;
2038
2039 case 2:
2040 if ( ptr->data ) {
2041 idmef_data_destroy(ptr->data);
2042 ptr->data = NULL;
2043 }
2044
2045 return 0;
2046
2047 default:
2048 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
2049 }
2050 }
2051
idmef_additional_data_destroy_internal(idmef_additional_data_t * ptr)2052 static void idmef_additional_data_destroy_internal(idmef_additional_data_t *ptr)
2053 {
2054 prelude_return_if_fail(ptr);
2055
2056 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *)ptr)->_list) )
2057 prelude_list_del_init(&((prelude_linked_object_t *)ptr)->_list);
2058
2059 if ( ptr->meaning ) {
2060 prelude_string_destroy(ptr->meaning);
2061 ptr->meaning = NULL;
2062 }
2063
2064 if ( ptr->data ) {
2065 idmef_data_destroy(ptr->data);
2066 ptr->data = NULL;
2067 }
2068
2069
2070 /* free() should be done by the caller */
2071 }
2072
2073 /**
2074 * idmef_additional_data_destroy:
2075 * @ptr: pointer to a #idmef_additional_data_t object.
2076 *
2077 * Destroy @ptr and all of it's children.
2078 * The objects are only destroyed if their reference count reach zero.
2079 */
2080
idmef_additional_data_destroy(idmef_additional_data_t * ptr)2081 void idmef_additional_data_destroy(idmef_additional_data_t *ptr)
2082 {
2083 prelude_return_if_fail(ptr);
2084
2085 if ( --ptr->refcount )
2086 return;
2087
2088 idmef_additional_data_destroy_internal(ptr);
2089 free(ptr);
2090 }
2091
2092 /**
2093 * idmef_additional_data_get_meaning:
2094 * @ptr: pointer to a #idmef_additional_data_t object.
2095 *
2096 * Get meaning children of the #idmef_additional_data_t object.
2097 *
2098 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
2099 */
idmef_additional_data_get_meaning(idmef_additional_data_t * ptr)2100 prelude_string_t *idmef_additional_data_get_meaning(idmef_additional_data_t *ptr)
2101 {
2102 prelude_return_val_if_fail(ptr, 0); /* FIXME */
2103
2104 return ptr->meaning;
2105 }
2106
2107 /**
2108 * idmef_additional_data_set_meaning:
2109 * @ptr: pointer to a #idmef_additional_data_t object.
2110 * @meaning: pointer to a #prelude_string_t object.
2111 *
2112 * Set @meaning object as a children of @ptr.
2113 * if @ptr already contain an @meaning object, then it is destroyed,
2114 * and updated to point to the provided @meaning object.
2115 */
2116
idmef_additional_data_set_meaning(idmef_additional_data_t * ptr,prelude_string_t * meaning)2117 void idmef_additional_data_set_meaning(idmef_additional_data_t *ptr, prelude_string_t *meaning)
2118 {
2119 prelude_return_if_fail(ptr);
2120
2121 if ( ptr->meaning )
2122 prelude_string_destroy(ptr->meaning);
2123
2124 ptr->meaning = meaning;
2125 }
2126
2127 /**
2128 * idmef_additional_data_new_meaning:
2129 * @ptr: pointer to a #idmef_additional_data_t object.
2130 * @ret: pointer to an address where to store the created #prelude_string_t object.
2131 *
2132 * Create a new meaning object, children of #idmef_additional_data_t.
2133 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
2134 *
2135 * Returns: 0 on success, or a negative value if an error occured.
2136 */
idmef_additional_data_new_meaning(idmef_additional_data_t * ptr,prelude_string_t ** ret)2137 int idmef_additional_data_new_meaning(idmef_additional_data_t *ptr, prelude_string_t **ret)
2138 {
2139 int retval;
2140
2141 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
2142
2143 if ( ! ptr->meaning ) {
2144 retval = prelude_string_new(&ptr->meaning);
2145 if ( retval < 0 )
2146 return retval;
2147 }
2148
2149 *ret = ptr->meaning;
2150 return 0;
2151 }
2152
2153 /**
2154 * idmef_additional_data_get_type:
2155 * @ptr: pointer to a #idmef_additional_data_t object.
2156 *
2157 * Get type children of the #idmef_additional_data_t object.
2158 *
2159 * Returns: a pointer to a idmef_additional_data_type_t object, or NULL if the children object is not set.
2160 */
idmef_additional_data_get_type(idmef_additional_data_t * ptr)2161 idmef_additional_data_type_t idmef_additional_data_get_type(idmef_additional_data_t *ptr)
2162 {
2163 prelude_return_val_if_fail(ptr, 0); /* FIXME */
2164
2165 return ptr->type;
2166 }
2167
2168 /**
2169 * idmef_additional_data_set_type:
2170 * @ptr: pointer to a #idmef_additional_data_t object.
2171 * @type: pointer to a #idmef_additional_data_type_t object.
2172 *
2173 * Set @type object as a children of @ptr.
2174 * if @ptr already contain an @type object, then it is destroyed,
2175 * and updated to point to the provided @type object.
2176 */
2177
idmef_additional_data_set_type(idmef_additional_data_t * ptr,idmef_additional_data_type_t type)2178 void idmef_additional_data_set_type(idmef_additional_data_t *ptr, idmef_additional_data_type_t type)
2179 {
2180 prelude_return_if_fail(ptr);
2181 ptr->type = type;
2182
2183 ptr->_type_is_set = TRUE;
2184
2185 }
2186
2187 /**
2188 * idmef_additional_data_new_type:
2189 * @ptr: pointer to a #idmef_additional_data_t object.
2190 * @ret: pointer to an address where to store the created #idmef_additional_data_type_t object.
2191 *
2192 * Create a new type object, children of #idmef_additional_data_t.
2193 * If @ptr already contain a #idmef_additional_data_type_t object, then it is destroyed.
2194 *
2195 * Returns: 0 on success, or a negative value if an error occured.
2196 */
idmef_additional_data_new_type(idmef_additional_data_t * ptr,idmef_additional_data_type_t ** ret)2197 int idmef_additional_data_new_type(idmef_additional_data_t *ptr, idmef_additional_data_type_t **ret)
2198 {
2199 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
2200 ptr->_type_is_set = TRUE;
2201 *ret = &ptr->type;
2202 return 0;
2203 }
2204
2205 /**
2206 * idmef_additional_data_get_data:
2207 * @ptr: pointer to a #idmef_additional_data_t object.
2208 *
2209 * Get data children of the #idmef_additional_data_t object.
2210 *
2211 * Returns: a pointer to a idmef_data_t object, or NULL if the children object is not set.
2212 */
idmef_additional_data_get_data(idmef_additional_data_t * ptr)2213 idmef_data_t *idmef_additional_data_get_data(idmef_additional_data_t *ptr)
2214 {
2215 prelude_return_val_if_fail(ptr, 0); /* FIXME */
2216
2217 return ptr->data;
2218 }
2219
2220 /**
2221 * idmef_additional_data_set_data:
2222 * @ptr: pointer to a #idmef_additional_data_t object.
2223 * @data: pointer to a #idmef_data_t object.
2224 *
2225 * Set @data object as a children of @ptr.
2226 * if @ptr already contain an @data object, then it is destroyed,
2227 * and updated to point to the provided @data object.
2228 */
2229
idmef_additional_data_set_data(idmef_additional_data_t * ptr,idmef_data_t * data)2230 void idmef_additional_data_set_data(idmef_additional_data_t *ptr, idmef_data_t *data)
2231 {
2232 prelude_return_if_fail(ptr);
2233
2234 if ( ptr->data )
2235 idmef_data_destroy(ptr->data);
2236
2237 ptr->data = data;
2238 }
2239
2240 /**
2241 * idmef_additional_data_new_data:
2242 * @ptr: pointer to a #idmef_additional_data_t object.
2243 * @ret: pointer to an address where to store the created #idmef_data_t object.
2244 *
2245 * Create a new data object, children of #idmef_additional_data_t.
2246 * If @ptr already contain a #idmef_data_t object, then it is destroyed.
2247 *
2248 * Returns: 0 on success, or a negative value if an error occured.
2249 */
idmef_additional_data_new_data(idmef_additional_data_t * ptr,idmef_data_t ** ret)2250 int idmef_additional_data_new_data(idmef_additional_data_t *ptr, idmef_data_t **ret)
2251 {
2252 int retval;
2253
2254 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
2255
2256 if ( ! ptr->data ) {
2257 retval = idmef_data_new(&ptr->data);
2258 if ( retval < 0 )
2259 return retval;
2260 }
2261
2262 *ret = ptr->data;
2263 return 0;
2264 }
2265
2266 /**
2267 * idmef_additional_data_copy:
2268 * @src: Source of the copy.
2269 * @dst: Where to copy the object.
2270 *
2271 * Copy a new #idmef_additional_data_t object from @src to @dst.
2272 *
2273 * Returns: 0 on success, a negative value if an error occured.
2274 */
idmef_additional_data_copy(const idmef_additional_data_t * src,idmef_additional_data_t * dst)2275 int idmef_additional_data_copy(const idmef_additional_data_t *src, idmef_additional_data_t *dst)
2276 {
2277 int ret;
2278
2279 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
2280 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
2281
2282 ret = 0;
2283
2284 if ( src->meaning ) {
2285 ret = prelude_string_clone(src->meaning, &dst->meaning);
2286 if ( ret < 0 )
2287 return ret;
2288 }
2289
2290 dst->type = src->type;
2291
2292 if ( src->data ) {
2293 ret = idmef_data_copy(src->data, dst->data);
2294 if ( ret < 0 )
2295 return ret;
2296 }
2297
2298 return 0;
2299 }
2300
2301 /**
2302 * idmef_additional_data_clone:
2303 * @src: Object to be cloned.
2304 * @dst: Address where to store the pointer to the cloned object.
2305 *
2306 * Create a copy of @src, and store it in @dst.
2307 *
2308 * Returns: 0 on success, a negative value if an error occured.
2309 */
idmef_additional_data_clone(idmef_additional_data_t * src,idmef_additional_data_t ** dst)2310 int idmef_additional_data_clone(idmef_additional_data_t *src, idmef_additional_data_t **dst)
2311 {
2312 int ret;
2313
2314 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
2315
2316 ret = idmef_additional_data_new(dst);
2317 if ( ret < 0 )
2318 return ret;
2319
2320 return idmef_additional_data_copy(src, *dst);
2321 }
2322
2323 /**
2324 * idmef_additional_data_compare:
2325 * @obj1: Object to compare with @obj2.
2326 * @obj2: Object to compare with @obj1.
2327 *
2328 * Compare @obj1 with @obj2.
2329 *
2330 * Returns: 0 on match, a negative value on comparison failure.
2331 */
idmef_additional_data_compare(const idmef_additional_data_t * obj1,const idmef_additional_data_t * obj2)2332 int idmef_additional_data_compare(const idmef_additional_data_t *obj1, const idmef_additional_data_t *obj2)
2333 {
2334 int ret = 0;
2335
2336 if ( obj1 == NULL && obj2 == NULL )
2337 return 0;
2338
2339 else if ( obj1 == NULL || obj2 == NULL )
2340 return -1;
2341
2342 ret = prelude_string_compare(obj1->meaning, obj2->meaning);
2343 if ( ret != 0 )
2344 return ret;
2345
2346 if ( obj1->type != obj2->type )
2347 return -1;
2348
2349 ret = idmef_data_compare(obj1->data, obj2->data);
2350 if ( ret != 0 )
2351 return ret;
2352
2353 return ret;
2354 }
2355
2356 /**
2357 * idmef_reference_new:
2358 * @ret: Pointer where to store the created #idmef_reference_t object.
2359 *
2360 * Create a new #idmef_reference_t object.
2361 *
2362 * Returns: 0 on success, a negative value if an error occured.
2363 */
idmef_reference_new(idmef_reference_t ** ret)2364 int idmef_reference_new(idmef_reference_t **ret)
2365 {
2366 *ret = calloc(1, sizeof(**ret));
2367 if ( ! *ret )
2368 return prelude_error_from_errno(errno);
2369
2370 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_REFERENCE;
2371
2372 prelude_list_init(&((prelude_linked_object_t *) (*ret))->_list);
2373
2374 (*ret)->refcount = 1;
2375
2376 {
2377 int retval = prelude_string_new(&(*ret)->name);
2378
2379 if ( retval < 0 ) {
2380 idmef_reference_destroy(*ret);
2381 *ret = NULL;
2382 return retval;
2383 }
2384 }
2385
2386 {
2387 int retval = prelude_string_new(&(*ret)->url);
2388
2389 if ( retval < 0 ) {
2390 idmef_reference_destroy(*ret);
2391 *ret = NULL;
2392 return retval;
2393 }
2394 }
2395
2396 return 0;
2397
2398 }
2399
2400 /**
2401 * idmef_reference_ref:
2402 * @reference: pointer to a #idmef_reference_t object.
2403 *
2404 * Increase @reference reference count, so that it can be referenced
2405 * multiple time.
2406 *
2407 * Returns: a pointer to @reference.
2408 */
idmef_reference_ref(idmef_reference_t * reference)2409 idmef_reference_t *idmef_reference_ref(idmef_reference_t *reference)
2410 {
2411 prelude_return_val_if_fail(reference, NULL);
2412 reference->refcount++;
2413
2414 return reference;
2415 }
2416
_idmef_reference_get_child(void * p,idmef_class_child_id_t child,void ** childptr)2417 int _idmef_reference_get_child(void *p, idmef_class_child_id_t child, void **childptr)
2418 {
2419 idmef_reference_t *ptr = p;
2420
2421 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
2422 *childptr = NULL;
2423
2424 switch ( child ) {
2425
2426 case 0:
2427 return idmef_value_new_enum_from_numeric((idmef_value_t **) childptr,
2428 IDMEF_CLASS_ID_REFERENCE_ORIGIN, ptr->origin);
2429
2430 case 1:
2431 return get_value_from_string((idmef_value_t **) childptr, ptr->name, TRUE);
2432 case 2:
2433 return get_value_from_string((idmef_value_t **) childptr, ptr->url, TRUE);
2434 case 3:
2435 return get_value_from_string((idmef_value_t **) childptr, ptr->meaning, TRUE);
2436 default:
2437 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
2438 }
2439 }
2440
_idmef_reference_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)2441 int _idmef_reference_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
2442 {
2443 idmef_reference_t *ptr = p;
2444
2445 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
2446
2447 switch ( child ) {
2448
2449 case 0:
2450 return idmef_reference_new_origin(ptr, (idmef_reference_origin_t **) ret);
2451
2452 case 1:
2453 return idmef_reference_new_name(ptr, (prelude_string_t **) ret);
2454
2455 case 2:
2456 return idmef_reference_new_url(ptr, (prelude_string_t **) ret);
2457
2458 case 3:
2459 return idmef_reference_new_meaning(ptr, (prelude_string_t **) ret);
2460
2461 default:
2462 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
2463 }
2464 }
2465
_idmef_reference_destroy_child(void * p,idmef_class_child_id_t child,int n)2466 int _idmef_reference_destroy_child(void *p, idmef_class_child_id_t child, int n)
2467 {
2468 idmef_reference_t *ptr = p;
2469
2470 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
2471
2472 switch ( child ) {
2473
2474 case 0:
2475 ptr->origin = 0;
2476 return 0;
2477
2478 case 1:
2479 if ( ptr->name ) {
2480 prelude_string_destroy(ptr->name);
2481 ptr->name = NULL;
2482 }
2483
2484 return 0;
2485
2486 case 2:
2487 if ( ptr->url ) {
2488 prelude_string_destroy(ptr->url);
2489 ptr->url = NULL;
2490 }
2491
2492 return 0;
2493
2494 case 3:
2495 if ( ptr->meaning ) {
2496 prelude_string_destroy(ptr->meaning);
2497 ptr->meaning = NULL;
2498 }
2499
2500 return 0;
2501
2502 default:
2503 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
2504 }
2505 }
2506
idmef_reference_destroy_internal(idmef_reference_t * ptr)2507 static void idmef_reference_destroy_internal(idmef_reference_t *ptr)
2508 {
2509 prelude_return_if_fail(ptr);
2510
2511 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *)ptr)->_list) )
2512 prelude_list_del_init(&((prelude_linked_object_t *)ptr)->_list);
2513
2514 if ( ptr->name ) {
2515 prelude_string_destroy(ptr->name);
2516 ptr->name = NULL;
2517 }
2518
2519 if ( ptr->url ) {
2520 prelude_string_destroy(ptr->url);
2521 ptr->url = NULL;
2522 }
2523
2524 if ( ptr->meaning ) {
2525 prelude_string_destroy(ptr->meaning);
2526 ptr->meaning = NULL;
2527 }
2528
2529
2530 /* free() should be done by the caller */
2531 }
2532
2533 /**
2534 * idmef_reference_destroy:
2535 * @ptr: pointer to a #idmef_reference_t object.
2536 *
2537 * Destroy @ptr and all of it's children.
2538 * The objects are only destroyed if their reference count reach zero.
2539 */
2540
idmef_reference_destroy(idmef_reference_t * ptr)2541 void idmef_reference_destroy(idmef_reference_t *ptr)
2542 {
2543 prelude_return_if_fail(ptr);
2544
2545 if ( --ptr->refcount )
2546 return;
2547
2548 idmef_reference_destroy_internal(ptr);
2549 free(ptr);
2550 }
2551
2552 /**
2553 * idmef_reference_get_origin:
2554 * @ptr: pointer to a #idmef_reference_t object.
2555 *
2556 * Get origin children of the #idmef_reference_t object.
2557 *
2558 * Returns: a pointer to a idmef_reference_origin_t object, or NULL if the children object is not set.
2559 */
idmef_reference_get_origin(idmef_reference_t * ptr)2560 idmef_reference_origin_t idmef_reference_get_origin(idmef_reference_t *ptr)
2561 {
2562 prelude_return_val_if_fail(ptr, 0); /* FIXME */
2563
2564 return ptr->origin;
2565 }
2566
2567 /**
2568 * idmef_reference_set_origin:
2569 * @ptr: pointer to a #idmef_reference_t object.
2570 * @origin: pointer to a #idmef_reference_origin_t object.
2571 *
2572 * Set @origin object as a children of @ptr.
2573 * if @ptr already contain an @origin object, then it is destroyed,
2574 * and updated to point to the provided @origin object.
2575 */
2576
idmef_reference_set_origin(idmef_reference_t * ptr,idmef_reference_origin_t origin)2577 void idmef_reference_set_origin(idmef_reference_t *ptr, idmef_reference_origin_t origin)
2578 {
2579 prelude_return_if_fail(ptr);
2580 ptr->origin = origin;
2581 }
2582
2583 /**
2584 * idmef_reference_new_origin:
2585 * @ptr: pointer to a #idmef_reference_t object.
2586 * @ret: pointer to an address where to store the created #idmef_reference_origin_t object.
2587 *
2588 * Create a new origin object, children of #idmef_reference_t.
2589 * If @ptr already contain a #idmef_reference_origin_t object, then it is destroyed.
2590 *
2591 * Returns: 0 on success, or a negative value if an error occured.
2592 */
idmef_reference_new_origin(idmef_reference_t * ptr,idmef_reference_origin_t ** ret)2593 int idmef_reference_new_origin(idmef_reference_t *ptr, idmef_reference_origin_t **ret)
2594 {
2595 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
2596
2597 *ret = &ptr->origin;
2598 return 0;
2599 }
2600
2601 /**
2602 * idmef_reference_get_name:
2603 * @ptr: pointer to a #idmef_reference_t object.
2604 *
2605 * Get name children of the #idmef_reference_t object.
2606 *
2607 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
2608 */
idmef_reference_get_name(idmef_reference_t * ptr)2609 prelude_string_t *idmef_reference_get_name(idmef_reference_t *ptr)
2610 {
2611 prelude_return_val_if_fail(ptr, 0); /* FIXME */
2612
2613 return ptr->name;
2614 }
2615
2616 /**
2617 * idmef_reference_set_name:
2618 * @ptr: pointer to a #idmef_reference_t object.
2619 * @name: pointer to a #prelude_string_t object.
2620 *
2621 * Set @name object as a children of @ptr.
2622 * if @ptr already contain an @name object, then it is destroyed,
2623 * and updated to point to the provided @name object.
2624 */
2625
idmef_reference_set_name(idmef_reference_t * ptr,prelude_string_t * name)2626 void idmef_reference_set_name(idmef_reference_t *ptr, prelude_string_t *name)
2627 {
2628 prelude_return_if_fail(ptr);
2629
2630 if ( ptr->name )
2631 prelude_string_destroy(ptr->name);
2632
2633 ptr->name = name;
2634 }
2635
2636 /**
2637 * idmef_reference_new_name:
2638 * @ptr: pointer to a #idmef_reference_t object.
2639 * @ret: pointer to an address where to store the created #prelude_string_t object.
2640 *
2641 * Create a new name object, children of #idmef_reference_t.
2642 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
2643 *
2644 * Returns: 0 on success, or a negative value if an error occured.
2645 */
idmef_reference_new_name(idmef_reference_t * ptr,prelude_string_t ** ret)2646 int idmef_reference_new_name(idmef_reference_t *ptr, prelude_string_t **ret)
2647 {
2648 int retval;
2649
2650 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
2651
2652 if ( ! ptr->name ) {
2653 retval = prelude_string_new(&ptr->name);
2654 if ( retval < 0 )
2655 return retval;
2656 }
2657
2658 *ret = ptr->name;
2659 return 0;
2660 }
2661
2662 /**
2663 * idmef_reference_get_url:
2664 * @ptr: pointer to a #idmef_reference_t object.
2665 *
2666 * Get url children of the #idmef_reference_t object.
2667 *
2668 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
2669 */
idmef_reference_get_url(idmef_reference_t * ptr)2670 prelude_string_t *idmef_reference_get_url(idmef_reference_t *ptr)
2671 {
2672 prelude_return_val_if_fail(ptr, 0); /* FIXME */
2673
2674 return ptr->url;
2675 }
2676
2677 /**
2678 * idmef_reference_set_url:
2679 * @ptr: pointer to a #idmef_reference_t object.
2680 * @url: pointer to a #prelude_string_t object.
2681 *
2682 * Set @url object as a children of @ptr.
2683 * if @ptr already contain an @url object, then it is destroyed,
2684 * and updated to point to the provided @url object.
2685 */
2686
idmef_reference_set_url(idmef_reference_t * ptr,prelude_string_t * url)2687 void idmef_reference_set_url(idmef_reference_t *ptr, prelude_string_t *url)
2688 {
2689 prelude_return_if_fail(ptr);
2690
2691 if ( ptr->url )
2692 prelude_string_destroy(ptr->url);
2693
2694 ptr->url = url;
2695 }
2696
2697 /**
2698 * idmef_reference_new_url:
2699 * @ptr: pointer to a #idmef_reference_t object.
2700 * @ret: pointer to an address where to store the created #prelude_string_t object.
2701 *
2702 * Create a new url object, children of #idmef_reference_t.
2703 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
2704 *
2705 * Returns: 0 on success, or a negative value if an error occured.
2706 */
idmef_reference_new_url(idmef_reference_t * ptr,prelude_string_t ** ret)2707 int idmef_reference_new_url(idmef_reference_t *ptr, prelude_string_t **ret)
2708 {
2709 int retval;
2710
2711 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
2712
2713 if ( ! ptr->url ) {
2714 retval = prelude_string_new(&ptr->url);
2715 if ( retval < 0 )
2716 return retval;
2717 }
2718
2719 *ret = ptr->url;
2720 return 0;
2721 }
2722
2723 /**
2724 * idmef_reference_get_meaning:
2725 * @ptr: pointer to a #idmef_reference_t object.
2726 *
2727 * Get meaning children of the #idmef_reference_t object.
2728 *
2729 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
2730 */
idmef_reference_get_meaning(idmef_reference_t * ptr)2731 prelude_string_t *idmef_reference_get_meaning(idmef_reference_t *ptr)
2732 {
2733 prelude_return_val_if_fail(ptr, 0); /* FIXME */
2734
2735 return ptr->meaning;
2736 }
2737
2738 /**
2739 * idmef_reference_set_meaning:
2740 * @ptr: pointer to a #idmef_reference_t object.
2741 * @meaning: pointer to a #prelude_string_t object.
2742 *
2743 * Set @meaning object as a children of @ptr.
2744 * if @ptr already contain an @meaning object, then it is destroyed,
2745 * and updated to point to the provided @meaning object.
2746 */
2747
idmef_reference_set_meaning(idmef_reference_t * ptr,prelude_string_t * meaning)2748 void idmef_reference_set_meaning(idmef_reference_t *ptr, prelude_string_t *meaning)
2749 {
2750 prelude_return_if_fail(ptr);
2751
2752 if ( ptr->meaning )
2753 prelude_string_destroy(ptr->meaning);
2754
2755 ptr->meaning = meaning;
2756 }
2757
2758 /**
2759 * idmef_reference_new_meaning:
2760 * @ptr: pointer to a #idmef_reference_t object.
2761 * @ret: pointer to an address where to store the created #prelude_string_t object.
2762 *
2763 * Create a new meaning object, children of #idmef_reference_t.
2764 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
2765 *
2766 * Returns: 0 on success, or a negative value if an error occured.
2767 */
idmef_reference_new_meaning(idmef_reference_t * ptr,prelude_string_t ** ret)2768 int idmef_reference_new_meaning(idmef_reference_t *ptr, prelude_string_t **ret)
2769 {
2770 int retval;
2771
2772 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
2773
2774 if ( ! ptr->meaning ) {
2775 retval = prelude_string_new(&ptr->meaning);
2776 if ( retval < 0 )
2777 return retval;
2778 }
2779
2780 *ret = ptr->meaning;
2781 return 0;
2782 }
2783
2784 /**
2785 * idmef_reference_copy:
2786 * @src: Source of the copy.
2787 * @dst: Where to copy the object.
2788 *
2789 * Copy a new #idmef_reference_t object from @src to @dst.
2790 *
2791 * Returns: 0 on success, a negative value if an error occured.
2792 */
idmef_reference_copy(const idmef_reference_t * src,idmef_reference_t * dst)2793 int idmef_reference_copy(const idmef_reference_t *src, idmef_reference_t *dst)
2794 {
2795 int ret;
2796
2797 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
2798 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
2799
2800 ret = 0;
2801
2802 dst->origin = src->origin;
2803
2804 if ( src->name ) {
2805 ret = prelude_string_copy(src->name, dst->name);
2806 if ( ret < 0 )
2807 return ret;
2808 }
2809
2810 if ( src->url ) {
2811 ret = prelude_string_copy(src->url, dst->url);
2812 if ( ret < 0 )
2813 return ret;
2814 }
2815
2816 if ( src->meaning ) {
2817 ret = prelude_string_clone(src->meaning, &dst->meaning);
2818 if ( ret < 0 )
2819 return ret;
2820 }
2821
2822 return 0;
2823 }
2824
2825 /**
2826 * idmef_reference_clone:
2827 * @src: Object to be cloned.
2828 * @dst: Address where to store the pointer to the cloned object.
2829 *
2830 * Create a copy of @src, and store it in @dst.
2831 *
2832 * Returns: 0 on success, a negative value if an error occured.
2833 */
idmef_reference_clone(idmef_reference_t * src,idmef_reference_t ** dst)2834 int idmef_reference_clone(idmef_reference_t *src, idmef_reference_t **dst)
2835 {
2836 int ret;
2837
2838 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
2839
2840 ret = idmef_reference_new(dst);
2841 if ( ret < 0 )
2842 return ret;
2843
2844 return idmef_reference_copy(src, *dst);
2845 }
2846
2847 /**
2848 * idmef_reference_compare:
2849 * @obj1: Object to compare with @obj2.
2850 * @obj2: Object to compare with @obj1.
2851 *
2852 * Compare @obj1 with @obj2.
2853 *
2854 * Returns: 0 on match, a negative value on comparison failure.
2855 */
idmef_reference_compare(const idmef_reference_t * obj1,const idmef_reference_t * obj2)2856 int idmef_reference_compare(const idmef_reference_t *obj1, const idmef_reference_t *obj2)
2857 {
2858 int ret = 0;
2859
2860 if ( obj1 == NULL && obj2 == NULL )
2861 return 0;
2862
2863 else if ( obj1 == NULL || obj2 == NULL )
2864 return -1;
2865
2866 if ( obj1->origin != obj2->origin )
2867 return -1;
2868
2869 ret = prelude_string_compare(obj1->name, obj2->name);
2870 if ( ret != 0 )
2871 return ret;
2872
2873 ret = prelude_string_compare(obj1->url, obj2->url);
2874 if ( ret != 0 )
2875 return ret;
2876
2877 ret = prelude_string_compare(obj1->meaning, obj2->meaning);
2878 if ( ret != 0 )
2879 return ret;
2880
2881 return ret;
2882 }
2883
2884 /**
2885 * idmef_classification_new:
2886 * @ret: Pointer where to store the created #idmef_classification_t object.
2887 *
2888 * Create a new #idmef_classification_t object.
2889 *
2890 * Returns: 0 on success, a negative value if an error occured.
2891 */
idmef_classification_new(idmef_classification_t ** ret)2892 int idmef_classification_new(idmef_classification_t **ret)
2893 {
2894 *ret = calloc(1, sizeof(**ret));
2895 if ( ! *ret )
2896 return prelude_error_from_errno(errno);
2897
2898 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_CLASSIFICATION;
2899
2900 (*ret)->refcount = 1;
2901
2902 prelude_list_init(&(*ret)->reference_list);
2903
2904
2905 {
2906 int retval = prelude_string_new(&(*ret)->text);
2907
2908 if ( retval < 0 ) {
2909 idmef_classification_destroy(*ret);
2910 *ret = NULL;
2911 return retval;
2912 }
2913 }
2914
2915 return 0;
2916
2917 }
2918
2919 /**
2920 * idmef_classification_ref:
2921 * @classification: pointer to a #idmef_classification_t object.
2922 *
2923 * Increase @classification reference count, so that it can be referenced
2924 * multiple time.
2925 *
2926 * Returns: a pointer to @classification.
2927 */
idmef_classification_ref(idmef_classification_t * classification)2928 idmef_classification_t *idmef_classification_ref(idmef_classification_t *classification)
2929 {
2930 prelude_return_val_if_fail(classification, NULL);
2931 classification->refcount++;
2932
2933 return classification;
2934 }
2935
_idmef_classification_get_child(void * p,idmef_class_child_id_t child,void ** childptr)2936 int _idmef_classification_get_child(void *p, idmef_class_child_id_t child, void **childptr)
2937 {
2938 idmef_classification_t *ptr = p;
2939
2940 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
2941 *childptr = NULL;
2942
2943 switch ( child ) {
2944
2945 case 0:
2946 return get_value_from_string((idmef_value_t **) childptr, ptr->ident, TRUE);
2947 case 1:
2948 return get_value_from_string((idmef_value_t **) childptr, ptr->text, TRUE);
2949 case 2:
2950 *childptr = &ptr->reference_list;
2951 return 0;
2952
2953 default:
2954 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
2955 }
2956 }
2957
_idmef_classification_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)2958 int _idmef_classification_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
2959 {
2960 idmef_classification_t *ptr = p;
2961
2962 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
2963
2964 switch ( child ) {
2965
2966 case 0:
2967 return idmef_classification_new_ident(ptr, (prelude_string_t **) ret);
2968
2969 case 1:
2970 return idmef_classification_new_text(ptr, (prelude_string_t **) ret);
2971
2972 case 2: {
2973 int i = 0;
2974 prelude_list_t *tmp;
2975
2976 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
2977 return idmef_classification_new_reference(ptr, (idmef_reference_t **) ret, n);
2978
2979 if ( n >= 0 ) {
2980 prelude_list_for_each(&ptr->reference_list, tmp) {
2981 if ( i++ == n ) {
2982 *ret = prelude_linked_object_get_object(tmp);
2983 return 0;
2984 }
2985 }
2986
2987 if ( i != n )
2988 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
2989 } else {
2990 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
2991
2992 prelude_list_for_each_reversed(&ptr->reference_list, tmp) {
2993 if ( i++ == pos ) {
2994 *ret = prelude_linked_object_get_object(tmp);
2995 return 0;
2996 }
2997 }
2998
2999 if ( i != pos )
3000 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
3001 }
3002
3003 return idmef_classification_new_reference(ptr, (idmef_reference_t **) ret, n);
3004 }
3005
3006 default:
3007 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
3008 }
3009 }
3010
_idmef_classification_destroy_child(void * p,idmef_class_child_id_t child,int n)3011 int _idmef_classification_destroy_child(void *p, idmef_class_child_id_t child, int n)
3012 {
3013 idmef_classification_t *ptr = p;
3014
3015 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
3016
3017 switch ( child ) {
3018
3019 case 0:
3020 if ( ptr->ident ) {
3021 prelude_string_destroy(ptr->ident);
3022 ptr->ident = NULL;
3023 }
3024
3025 return 0;
3026
3027 case 1:
3028 if ( ptr->text ) {
3029 prelude_string_destroy(ptr->text);
3030 ptr->text = NULL;
3031 }
3032
3033 return 0;
3034
3035 case 2: {
3036 int i = 0;
3037 prelude_list_t *tmp;
3038
3039 if ( n >= 0 ) {
3040 prelude_list_for_each(&ptr->reference_list, tmp) {
3041 if ( i++ == n ) {
3042 void *b = prelude_linked_object_get_object(tmp);
3043 idmef_reference_destroy(b);
3044 return 0;
3045 }
3046 }
3047
3048 if ( i != n )
3049 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
3050 } else {
3051 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
3052
3053 prelude_list_for_each_reversed(&ptr->reference_list, tmp) {
3054 if ( i++ == pos ) {
3055 void *b = prelude_linked_object_get_object(tmp);
3056 idmef_reference_destroy(b);
3057 return 0;
3058 }
3059 }
3060
3061 if ( i != pos )
3062 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
3063 }
3064 }
3065
3066 default:
3067 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
3068 }
3069 }
3070
idmef_classification_destroy_internal(idmef_classification_t * ptr)3071 static void idmef_classification_destroy_internal(idmef_classification_t *ptr)
3072 {
3073 prelude_return_if_fail(ptr);
3074
3075 if ( ptr->ident ) {
3076 prelude_string_destroy(ptr->ident);
3077 ptr->ident = NULL;
3078 }
3079
3080 if ( ptr->text ) {
3081 prelude_string_destroy(ptr->text);
3082 ptr->text = NULL;
3083 }
3084
3085 {
3086 prelude_list_t *n, *tmp;
3087 idmef_reference_t *entry;
3088
3089 prelude_list_for_each_safe(&ptr->reference_list, tmp, n) {
3090 entry = prelude_linked_object_get_object(tmp);
3091 prelude_list_del_init(tmp);
3092 idmef_reference_destroy(entry);
3093 }
3094 }
3095
3096
3097 /* free() should be done by the caller */
3098 }
3099
3100 /**
3101 * idmef_classification_destroy:
3102 * @ptr: pointer to a #idmef_classification_t object.
3103 *
3104 * Destroy @ptr and all of it's children.
3105 * The objects are only destroyed if their reference count reach zero.
3106 */
3107
idmef_classification_destroy(idmef_classification_t * ptr)3108 void idmef_classification_destroy(idmef_classification_t *ptr)
3109 {
3110 prelude_return_if_fail(ptr);
3111
3112 if ( --ptr->refcount )
3113 return;
3114
3115 idmef_classification_destroy_internal(ptr);
3116 free(ptr);
3117 }
3118
3119 /**
3120 * idmef_classification_get_ident:
3121 * @ptr: pointer to a #idmef_classification_t object.
3122 *
3123 * Get ident children of the #idmef_classification_t object.
3124 *
3125 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
3126 */
idmef_classification_get_ident(idmef_classification_t * ptr)3127 prelude_string_t *idmef_classification_get_ident(idmef_classification_t *ptr)
3128 {
3129 prelude_return_val_if_fail(ptr, 0); /* FIXME */
3130
3131 return ptr->ident;
3132 }
3133
3134 /**
3135 * idmef_classification_set_ident:
3136 * @ptr: pointer to a #idmef_classification_t object.
3137 * @ident: pointer to a #prelude_string_t object.
3138 *
3139 * Set @ident object as a children of @ptr.
3140 * if @ptr already contain an @ident object, then it is destroyed,
3141 * and updated to point to the provided @ident object.
3142 */
3143
idmef_classification_set_ident(idmef_classification_t * ptr,prelude_string_t * ident)3144 void idmef_classification_set_ident(idmef_classification_t *ptr, prelude_string_t *ident)
3145 {
3146 prelude_return_if_fail(ptr);
3147
3148 if ( ptr->ident )
3149 prelude_string_destroy(ptr->ident);
3150
3151 ptr->ident = ident;
3152 }
3153
3154 /**
3155 * idmef_classification_new_ident:
3156 * @ptr: pointer to a #idmef_classification_t object.
3157 * @ret: pointer to an address where to store the created #prelude_string_t object.
3158 *
3159 * Create a new ident object, children of #idmef_classification_t.
3160 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
3161 *
3162 * Returns: 0 on success, or a negative value if an error occured.
3163 */
idmef_classification_new_ident(idmef_classification_t * ptr,prelude_string_t ** ret)3164 int idmef_classification_new_ident(idmef_classification_t *ptr, prelude_string_t **ret)
3165 {
3166 int retval;
3167
3168 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
3169
3170 if ( ! ptr->ident ) {
3171 retval = prelude_string_new(&ptr->ident);
3172 if ( retval < 0 )
3173 return retval;
3174 }
3175
3176 *ret = ptr->ident;
3177 return 0;
3178 }
3179
3180 /**
3181 * idmef_classification_get_text:
3182 * @ptr: pointer to a #idmef_classification_t object.
3183 *
3184 * Get text children of the #idmef_classification_t object.
3185 *
3186 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
3187 */
idmef_classification_get_text(idmef_classification_t * ptr)3188 prelude_string_t *idmef_classification_get_text(idmef_classification_t *ptr)
3189 {
3190 prelude_return_val_if_fail(ptr, 0); /* FIXME */
3191
3192 return ptr->text;
3193 }
3194
3195 /**
3196 * idmef_classification_set_text:
3197 * @ptr: pointer to a #idmef_classification_t object.
3198 * @text: pointer to a #prelude_string_t object.
3199 *
3200 * Set @text object as a children of @ptr.
3201 * if @ptr already contain an @text object, then it is destroyed,
3202 * and updated to point to the provided @text object.
3203 */
3204
idmef_classification_set_text(idmef_classification_t * ptr,prelude_string_t * text)3205 void idmef_classification_set_text(idmef_classification_t *ptr, prelude_string_t *text)
3206 {
3207 prelude_return_if_fail(ptr);
3208
3209 if ( ptr->text )
3210 prelude_string_destroy(ptr->text);
3211
3212 ptr->text = text;
3213 }
3214
3215 /**
3216 * idmef_classification_new_text:
3217 * @ptr: pointer to a #idmef_classification_t object.
3218 * @ret: pointer to an address where to store the created #prelude_string_t object.
3219 *
3220 * Create a new text object, children of #idmef_classification_t.
3221 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
3222 *
3223 * Returns: 0 on success, or a negative value if an error occured.
3224 */
idmef_classification_new_text(idmef_classification_t * ptr,prelude_string_t ** ret)3225 int idmef_classification_new_text(idmef_classification_t *ptr, prelude_string_t **ret)
3226 {
3227 int retval;
3228
3229 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
3230
3231 if ( ! ptr->text ) {
3232 retval = prelude_string_new(&ptr->text);
3233 if ( retval < 0 )
3234 return retval;
3235 }
3236
3237 *ret = ptr->text;
3238 return 0;
3239 }
3240
3241 /**
3242 * idmef_classification_get_next_reference:
3243 * @classification: pointer to a #idmef_classification_t object.
3244 * @reference_cur: pointer to a #idmef_reference_t object.
3245 *
3246 * Get the next #idmef_reference_t object listed in @ptr.
3247 * When iterating over the idmef_reference_t object listed in @ptr,
3248 * @object should be set to the latest returned #idmef_reference_t object.
3249 *
3250 * Returns: the next #idmef_reference_t in the list.
3251 */
idmef_classification_get_next_reference(idmef_classification_t * classification,idmef_reference_t * reference_cur)3252 idmef_reference_t *idmef_classification_get_next_reference(idmef_classification_t *classification, idmef_reference_t *reference_cur)
3253 {
3254 prelude_list_t *tmp = (reference_cur) ? &((prelude_linked_object_t *) reference_cur)->_list : NULL;
3255
3256 prelude_return_val_if_fail(classification, NULL);
3257
3258 prelude_list_for_each_continue(&classification->reference_list, tmp)
3259 return prelude_linked_object_get_object(tmp);
3260
3261 return NULL;
3262 }
3263
3264
3265 /**
3266 * idmef_classification_set_reference:
3267 * @ptr: pointer to a #idmef_classification_t object.
3268 * @object: pointer to a #idmef_reference_t object.
3269 * @pos: Position in the list.
3270 *
3271 * Add @object to position @pos of @ptr list of #idmef_reference_t object.
3272 *
3273 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
3274 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
3275 */
idmef_classification_set_reference(idmef_classification_t * ptr,idmef_reference_t * object,int pos)3276 void idmef_classification_set_reference(idmef_classification_t *ptr, idmef_reference_t *object, int pos)
3277 {
3278 prelude_return_if_fail(ptr);
3279 prelude_return_if_fail(object);
3280
3281 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
3282 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
3283
3284 list_insert(&ptr->reference_list, &((prelude_linked_object_t *) object)->_list, pos);
3285 }
3286
3287
3288 /**
3289 * idmef_classification_new_reference:
3290 * @ptr: pointer to a #idmef_classification_t object.
3291 * @ret: pointer to an address where to store the created #idmef_reference_t object.
3292 * @pos: position in the list.
3293 *
3294 * Create a new #idmef_reference_t children of @ptr, and add it to position @pos of
3295 * @ptr list of #idmef_reference_t object. The created #idmef_reference_t object is
3296 * stored in @ret.
3297 *
3298 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
3299 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
3300 *
3301 * Returns: 0 on success, or a negative value if an error occured.
3302 */
idmef_classification_new_reference(idmef_classification_t * ptr,idmef_reference_t ** ret,int pos)3303 int idmef_classification_new_reference(idmef_classification_t *ptr, idmef_reference_t **ret, int pos)
3304 {
3305 int retval;
3306
3307 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
3308
3309 retval = idmef_reference_new(ret);
3310 if ( retval < 0 )
3311 return retval;
3312
3313 list_insert(&ptr->reference_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
3314
3315 return 0;
3316 }
3317
3318
3319 /**
3320 * idmef_classification_copy:
3321 * @src: Source of the copy.
3322 * @dst: Where to copy the object.
3323 *
3324 * Copy a new #idmef_classification_t object from @src to @dst.
3325 *
3326 * Returns: 0 on success, a negative value if an error occured.
3327 */
idmef_classification_copy(const idmef_classification_t * src,idmef_classification_t * dst)3328 int idmef_classification_copy(const idmef_classification_t *src, idmef_classification_t *dst)
3329 {
3330 int ret;
3331
3332 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
3333 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
3334
3335 ret = 0;
3336
3337 if ( src->ident ) {
3338 ret = prelude_string_clone(src->ident, &dst->ident);
3339 if ( ret < 0 )
3340 return ret;
3341 }
3342
3343 if ( src->text ) {
3344 ret = prelude_string_copy(src->text, dst->text);
3345 if ( ret < 0 )
3346 return ret;
3347 }
3348
3349 {
3350 prelude_list_t *n, *tmp;
3351 idmef_reference_t *entry, *new;
3352
3353 prelude_list_for_each_safe(&src->reference_list, tmp, n) {
3354 entry = prelude_linked_object_get_object(tmp);
3355 idmef_reference_clone(entry, &new);
3356 prelude_list_add_tail(&dst->reference_list, &((prelude_linked_object_t *) new)->_list);
3357 }
3358 }
3359
3360 return 0;
3361 }
3362
3363 /**
3364 * idmef_classification_clone:
3365 * @src: Object to be cloned.
3366 * @dst: Address where to store the pointer to the cloned object.
3367 *
3368 * Create a copy of @src, and store it in @dst.
3369 *
3370 * Returns: 0 on success, a negative value if an error occured.
3371 */
idmef_classification_clone(idmef_classification_t * src,idmef_classification_t ** dst)3372 int idmef_classification_clone(idmef_classification_t *src, idmef_classification_t **dst)
3373 {
3374 int ret;
3375
3376 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
3377
3378 ret = idmef_classification_new(dst);
3379 if ( ret < 0 )
3380 return ret;
3381
3382 return idmef_classification_copy(src, *dst);
3383 }
3384
3385 /**
3386 * idmef_classification_compare:
3387 * @obj1: Object to compare with @obj2.
3388 * @obj2: Object to compare with @obj1.
3389 *
3390 * Compare @obj1 with @obj2.
3391 *
3392 * Returns: 0 on match, a negative value on comparison failure.
3393 */
idmef_classification_compare(const idmef_classification_t * obj1,const idmef_classification_t * obj2)3394 int idmef_classification_compare(const idmef_classification_t *obj1, const idmef_classification_t *obj2)
3395 {
3396 int ret = 0;
3397
3398 if ( obj1 == NULL && obj2 == NULL )
3399 return 0;
3400
3401 else if ( obj1 == NULL || obj2 == NULL )
3402 return -1;
3403
3404 ret = prelude_string_compare(obj1->ident, obj2->ident);
3405 if ( ret != 0 )
3406 return ret;
3407
3408 ret = prelude_string_compare(obj1->text, obj2->text);
3409 if ( ret != 0 )
3410 return ret;
3411
3412 {
3413 prelude_list_t *tmp1, *tmp2;
3414 idmef_reference_t *entry1, *entry2;
3415
3416 tmp1 = tmp2 = NULL;
3417 do {
3418 entry1 = entry2 = NULL;
3419
3420 prelude_list_for_each_continue(&obj1->reference_list, tmp1) {
3421 entry1 = prelude_linked_object_get_object(tmp1);
3422 break;
3423 }
3424
3425 prelude_list_for_each_continue(&obj2->reference_list, tmp2) {
3426 entry2 = prelude_linked_object_get_object(tmp2);
3427 break;
3428 }
3429
3430 ret = idmef_reference_compare(entry1, entry2);
3431 if ( ret != 0 )
3432 return ret;
3433
3434 } while ( entry1 && entry2 );
3435 }
3436
3437 return ret;
3438 }
3439
3440 /**
3441 * idmef_user_id_new:
3442 * @ret: Pointer where to store the created #idmef_user_id_t object.
3443 *
3444 * Create a new #idmef_user_id_t object.
3445 *
3446 * Returns: 0 on success, a negative value if an error occured.
3447 */
idmef_user_id_new(idmef_user_id_t ** ret)3448 int idmef_user_id_new(idmef_user_id_t **ret)
3449 {
3450 *ret = calloc(1, sizeof(**ret));
3451 if ( ! *ret )
3452 return prelude_error_from_errno(errno);
3453
3454 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_USER_ID;
3455
3456 prelude_list_init(&((prelude_linked_object_t *) (*ret))->_list);
3457
3458 (*ret)->refcount = 1;
3459
3460 return 0;
3461
3462 }
3463
3464 /**
3465 * idmef_user_id_ref:
3466 * @user_id: pointer to a #idmef_user_id_t object.
3467 *
3468 * Increase @user_id reference count, so that it can be referenced
3469 * multiple time.
3470 *
3471 * Returns: a pointer to @user_id.
3472 */
idmef_user_id_ref(idmef_user_id_t * user_id)3473 idmef_user_id_t *idmef_user_id_ref(idmef_user_id_t *user_id)
3474 {
3475 prelude_return_val_if_fail(user_id, NULL);
3476 user_id->refcount++;
3477
3478 return user_id;
3479 }
3480
_idmef_user_id_get_child(void * p,idmef_class_child_id_t child,void ** childptr)3481 int _idmef_user_id_get_child(void *p, idmef_class_child_id_t child, void **childptr)
3482 {
3483 idmef_user_id_t *ptr = p;
3484
3485 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
3486 *childptr = NULL;
3487
3488 switch ( child ) {
3489
3490 case 0:
3491 return get_value_from_string((idmef_value_t **) childptr, ptr->ident, TRUE);
3492 case 1:
3493 return idmef_value_new_enum_from_numeric((idmef_value_t **) childptr,
3494 IDMEF_CLASS_ID_USER_ID_TYPE, ptr->type);
3495
3496 case 2:
3497 return get_value_from_string((idmef_value_t **) childptr, ptr->tty, TRUE);
3498 case 3:
3499 return get_value_from_string((idmef_value_t **) childptr, ptr->name, TRUE);
3500 case 4:
3501 return (ptr->number_is_set) ? idmef_value_new_uint32((idmef_value_t **) childptr, ptr->number) : 0;
3502
3503 default:
3504 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
3505 }
3506 }
3507
_idmef_user_id_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)3508 int _idmef_user_id_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
3509 {
3510 idmef_user_id_t *ptr = p;
3511
3512 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
3513
3514 switch ( child ) {
3515
3516 case 0:
3517 return idmef_user_id_new_ident(ptr, (prelude_string_t **) ret);
3518
3519 case 1:
3520 return idmef_user_id_new_type(ptr, (idmef_user_id_type_t **) ret);
3521
3522 case 2:
3523 return idmef_user_id_new_tty(ptr, (prelude_string_t **) ret);
3524
3525 case 3:
3526 return idmef_user_id_new_name(ptr, (prelude_string_t **) ret);
3527
3528 case 4:
3529 return idmef_user_id_new_number(ptr, (uint32_t **) ret);
3530
3531 default:
3532 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
3533 }
3534 }
3535
_idmef_user_id_destroy_child(void * p,idmef_class_child_id_t child,int n)3536 int _idmef_user_id_destroy_child(void *p, idmef_class_child_id_t child, int n)
3537 {
3538 idmef_user_id_t *ptr = p;
3539
3540 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
3541
3542 switch ( child ) {
3543
3544 case 0:
3545 if ( ptr->ident ) {
3546 prelude_string_destroy(ptr->ident);
3547 ptr->ident = NULL;
3548 }
3549
3550 return 0;
3551
3552 case 1:
3553 ptr->type = 0;
3554 return 0;
3555
3556 case 2:
3557 if ( ptr->tty ) {
3558 prelude_string_destroy(ptr->tty);
3559 ptr->tty = NULL;
3560 }
3561
3562 return 0;
3563
3564 case 3:
3565 if ( ptr->name ) {
3566 prelude_string_destroy(ptr->name);
3567 ptr->name = NULL;
3568 }
3569
3570 return 0;
3571
3572 case 4:
3573 ptr->number_is_set = 0;
3574 return 0;
3575
3576 default:
3577 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
3578 }
3579 }
3580
idmef_user_id_destroy_internal(idmef_user_id_t * ptr)3581 static void idmef_user_id_destroy_internal(idmef_user_id_t *ptr)
3582 {
3583 prelude_return_if_fail(ptr);
3584
3585 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *)ptr)->_list) )
3586 prelude_list_del_init(&((prelude_linked_object_t *)ptr)->_list);
3587
3588 if ( ptr->ident ) {
3589 prelude_string_destroy(ptr->ident);
3590 ptr->ident = NULL;
3591 }
3592
3593 if ( ptr->tty ) {
3594 prelude_string_destroy(ptr->tty);
3595 ptr->tty = NULL;
3596 }
3597
3598 if ( ptr->name ) {
3599 prelude_string_destroy(ptr->name);
3600 ptr->name = NULL;
3601 }
3602
3603
3604 /* free() should be done by the caller */
3605 }
3606
3607 /**
3608 * idmef_user_id_destroy:
3609 * @ptr: pointer to a #idmef_user_id_t object.
3610 *
3611 * Destroy @ptr and all of it's children.
3612 * The objects are only destroyed if their reference count reach zero.
3613 */
3614
idmef_user_id_destroy(idmef_user_id_t * ptr)3615 void idmef_user_id_destroy(idmef_user_id_t *ptr)
3616 {
3617 prelude_return_if_fail(ptr);
3618
3619 if ( --ptr->refcount )
3620 return;
3621
3622 idmef_user_id_destroy_internal(ptr);
3623 free(ptr);
3624 }
3625
3626 /**
3627 * idmef_user_id_get_ident:
3628 * @ptr: pointer to a #idmef_user_id_t object.
3629 *
3630 * Get ident children of the #idmef_user_id_t object.
3631 *
3632 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
3633 */
idmef_user_id_get_ident(idmef_user_id_t * ptr)3634 prelude_string_t *idmef_user_id_get_ident(idmef_user_id_t *ptr)
3635 {
3636 prelude_return_val_if_fail(ptr, 0); /* FIXME */
3637
3638 return ptr->ident;
3639 }
3640
3641 /**
3642 * idmef_user_id_set_ident:
3643 * @ptr: pointer to a #idmef_user_id_t object.
3644 * @ident: pointer to a #prelude_string_t object.
3645 *
3646 * Set @ident object as a children of @ptr.
3647 * if @ptr already contain an @ident object, then it is destroyed,
3648 * and updated to point to the provided @ident object.
3649 */
3650
idmef_user_id_set_ident(idmef_user_id_t * ptr,prelude_string_t * ident)3651 void idmef_user_id_set_ident(idmef_user_id_t *ptr, prelude_string_t *ident)
3652 {
3653 prelude_return_if_fail(ptr);
3654
3655 if ( ptr->ident )
3656 prelude_string_destroy(ptr->ident);
3657
3658 ptr->ident = ident;
3659 }
3660
3661 /**
3662 * idmef_user_id_new_ident:
3663 * @ptr: pointer to a #idmef_user_id_t object.
3664 * @ret: pointer to an address where to store the created #prelude_string_t object.
3665 *
3666 * Create a new ident object, children of #idmef_user_id_t.
3667 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
3668 *
3669 * Returns: 0 on success, or a negative value if an error occured.
3670 */
idmef_user_id_new_ident(idmef_user_id_t * ptr,prelude_string_t ** ret)3671 int idmef_user_id_new_ident(idmef_user_id_t *ptr, prelude_string_t **ret)
3672 {
3673 int retval;
3674
3675 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
3676
3677 if ( ! ptr->ident ) {
3678 retval = prelude_string_new(&ptr->ident);
3679 if ( retval < 0 )
3680 return retval;
3681 }
3682
3683 *ret = ptr->ident;
3684 return 0;
3685 }
3686
3687 /**
3688 * idmef_user_id_get_type:
3689 * @ptr: pointer to a #idmef_user_id_t object.
3690 *
3691 * Get type children of the #idmef_user_id_t object.
3692 *
3693 * Returns: a pointer to a idmef_user_id_type_t object, or NULL if the children object is not set.
3694 */
idmef_user_id_get_type(idmef_user_id_t * ptr)3695 idmef_user_id_type_t idmef_user_id_get_type(idmef_user_id_t *ptr)
3696 {
3697 prelude_return_val_if_fail(ptr, 0); /* FIXME */
3698
3699 return ptr->type;
3700 }
3701
3702 /**
3703 * idmef_user_id_set_type:
3704 * @ptr: pointer to a #idmef_user_id_t object.
3705 * @type: pointer to a #idmef_user_id_type_t object.
3706 *
3707 * Set @type object as a children of @ptr.
3708 * if @ptr already contain an @type object, then it is destroyed,
3709 * and updated to point to the provided @type object.
3710 */
3711
idmef_user_id_set_type(idmef_user_id_t * ptr,idmef_user_id_type_t type)3712 void idmef_user_id_set_type(idmef_user_id_t *ptr, idmef_user_id_type_t type)
3713 {
3714 prelude_return_if_fail(ptr);
3715 ptr->type = type;
3716 }
3717
3718 /**
3719 * idmef_user_id_new_type:
3720 * @ptr: pointer to a #idmef_user_id_t object.
3721 * @ret: pointer to an address where to store the created #idmef_user_id_type_t object.
3722 *
3723 * Create a new type object, children of #idmef_user_id_t.
3724 * If @ptr already contain a #idmef_user_id_type_t object, then it is destroyed.
3725 *
3726 * Returns: 0 on success, or a negative value if an error occured.
3727 */
idmef_user_id_new_type(idmef_user_id_t * ptr,idmef_user_id_type_t ** ret)3728 int idmef_user_id_new_type(idmef_user_id_t *ptr, idmef_user_id_type_t **ret)
3729 {
3730 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
3731
3732 *ret = &ptr->type;
3733 return 0;
3734 }
3735
3736 /**
3737 * idmef_user_id_get_tty:
3738 * @ptr: pointer to a #idmef_user_id_t object.
3739 *
3740 * Get tty children of the #idmef_user_id_t object.
3741 *
3742 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
3743 */
idmef_user_id_get_tty(idmef_user_id_t * ptr)3744 prelude_string_t *idmef_user_id_get_tty(idmef_user_id_t *ptr)
3745 {
3746 prelude_return_val_if_fail(ptr, 0); /* FIXME */
3747
3748 return ptr->tty;
3749 }
3750
3751 /**
3752 * idmef_user_id_set_tty:
3753 * @ptr: pointer to a #idmef_user_id_t object.
3754 * @tty: pointer to a #prelude_string_t object.
3755 *
3756 * Set @tty object as a children of @ptr.
3757 * if @ptr already contain an @tty object, then it is destroyed,
3758 * and updated to point to the provided @tty object.
3759 */
3760
idmef_user_id_set_tty(idmef_user_id_t * ptr,prelude_string_t * tty)3761 void idmef_user_id_set_tty(idmef_user_id_t *ptr, prelude_string_t *tty)
3762 {
3763 prelude_return_if_fail(ptr);
3764
3765 if ( ptr->tty )
3766 prelude_string_destroy(ptr->tty);
3767
3768 ptr->tty = tty;
3769 }
3770
3771 /**
3772 * idmef_user_id_new_tty:
3773 * @ptr: pointer to a #idmef_user_id_t object.
3774 * @ret: pointer to an address where to store the created #prelude_string_t object.
3775 *
3776 * Create a new tty object, children of #idmef_user_id_t.
3777 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
3778 *
3779 * Returns: 0 on success, or a negative value if an error occured.
3780 */
idmef_user_id_new_tty(idmef_user_id_t * ptr,prelude_string_t ** ret)3781 int idmef_user_id_new_tty(idmef_user_id_t *ptr, prelude_string_t **ret)
3782 {
3783 int retval;
3784
3785 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
3786
3787 if ( ! ptr->tty ) {
3788 retval = prelude_string_new(&ptr->tty);
3789 if ( retval < 0 )
3790 return retval;
3791 }
3792
3793 *ret = ptr->tty;
3794 return 0;
3795 }
3796
3797 /**
3798 * idmef_user_id_get_name:
3799 * @ptr: pointer to a #idmef_user_id_t object.
3800 *
3801 * Get name children of the #idmef_user_id_t object.
3802 *
3803 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
3804 */
idmef_user_id_get_name(idmef_user_id_t * ptr)3805 prelude_string_t *idmef_user_id_get_name(idmef_user_id_t *ptr)
3806 {
3807 prelude_return_val_if_fail(ptr, 0); /* FIXME */
3808
3809 return ptr->name;
3810 }
3811
3812 /**
3813 * idmef_user_id_set_name:
3814 * @ptr: pointer to a #idmef_user_id_t object.
3815 * @name: pointer to a #prelude_string_t object.
3816 *
3817 * Set @name object as a children of @ptr.
3818 * if @ptr already contain an @name object, then it is destroyed,
3819 * and updated to point to the provided @name object.
3820 */
3821
idmef_user_id_set_name(idmef_user_id_t * ptr,prelude_string_t * name)3822 void idmef_user_id_set_name(idmef_user_id_t *ptr, prelude_string_t *name)
3823 {
3824 prelude_return_if_fail(ptr);
3825
3826 if ( ptr->name )
3827 prelude_string_destroy(ptr->name);
3828
3829 ptr->name = name;
3830 }
3831
3832 /**
3833 * idmef_user_id_new_name:
3834 * @ptr: pointer to a #idmef_user_id_t object.
3835 * @ret: pointer to an address where to store the created #prelude_string_t object.
3836 *
3837 * Create a new name object, children of #idmef_user_id_t.
3838 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
3839 *
3840 * Returns: 0 on success, or a negative value if an error occured.
3841 */
idmef_user_id_new_name(idmef_user_id_t * ptr,prelude_string_t ** ret)3842 int idmef_user_id_new_name(idmef_user_id_t *ptr, prelude_string_t **ret)
3843 {
3844 int retval;
3845
3846 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
3847
3848 if ( ! ptr->name ) {
3849 retval = prelude_string_new(&ptr->name);
3850 if ( retval < 0 )
3851 return retval;
3852 }
3853
3854 *ret = ptr->name;
3855 return 0;
3856 }
3857
3858 /**
3859 * idmef_user_id_get_number:
3860 * @ptr: pointer to a #idmef_user_id_t object.
3861 *
3862 * Get number children of the #idmef_user_id_t object.
3863 *
3864 * Returns: a pointer to a uint32_t object, or NULL if the children object is not set.
3865 */
idmef_user_id_get_number(idmef_user_id_t * ptr)3866 uint32_t *idmef_user_id_get_number(idmef_user_id_t *ptr)
3867 {
3868 prelude_return_val_if_fail(ptr, 0); /* FIXME */
3869
3870 return ptr->number_is_set ? &ptr->number : NULL;
3871 }
3872
3873 /**
3874 * idmef_user_id_set_number:
3875 * @ptr: pointer to a #idmef_user_id_t object.
3876 * @number: pointer to a #uint32_t object.
3877 *
3878 * Set @number object as a children of @ptr.
3879 * if @ptr already contain an @number object, then it is destroyed,
3880 * and updated to point to the provided @number object.
3881 */
3882
idmef_user_id_set_number(idmef_user_id_t * ptr,uint32_t number)3883 void idmef_user_id_set_number(idmef_user_id_t *ptr, uint32_t number)
3884 {
3885 prelude_return_if_fail(ptr);
3886 ptr->number = number;
3887 ptr->number_is_set = 1;
3888 }
3889
3890
idmef_user_id_unset_number(idmef_user_id_t * ptr)3891 void idmef_user_id_unset_number(idmef_user_id_t *ptr)
3892 {
3893 prelude_return_if_fail(ptr);
3894 ptr->number_is_set = 0;
3895 }
3896
3897
3898 /**
3899 * idmef_user_id_new_number:
3900 * @ptr: pointer to a #idmef_user_id_t object.
3901 * @ret: pointer to an address where to store the created #uint32_t object.
3902 *
3903 * Create a new number object, children of #idmef_user_id_t.
3904 * If @ptr already contain a #uint32_t object, then it is destroyed.
3905 *
3906 * Returns: 0 on success, or a negative value if an error occured.
3907 */
idmef_user_id_new_number(idmef_user_id_t * ptr,uint32_t ** ret)3908 int idmef_user_id_new_number(idmef_user_id_t *ptr, uint32_t **ret)
3909 {
3910 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
3911 ptr->number_is_set = 1;
3912
3913 *ret = &ptr->number;
3914 return 0;
3915 }
3916
3917 /**
3918 * idmef_user_id_copy:
3919 * @src: Source of the copy.
3920 * @dst: Where to copy the object.
3921 *
3922 * Copy a new #idmef_user_id_t object from @src to @dst.
3923 *
3924 * Returns: 0 on success, a negative value if an error occured.
3925 */
idmef_user_id_copy(const idmef_user_id_t * src,idmef_user_id_t * dst)3926 int idmef_user_id_copy(const idmef_user_id_t *src, idmef_user_id_t *dst)
3927 {
3928 int ret;
3929
3930 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
3931 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
3932
3933 ret = 0;
3934
3935 if ( src->ident ) {
3936 ret = prelude_string_clone(src->ident, &dst->ident);
3937 if ( ret < 0 )
3938 return ret;
3939 }
3940
3941 dst->type = src->type;
3942
3943 if ( src->tty ) {
3944 ret = prelude_string_clone(src->tty, &dst->tty);
3945 if ( ret < 0 )
3946 return ret;
3947 }
3948
3949 if ( src->name ) {
3950 ret = prelude_string_clone(src->name, &dst->name);
3951 if ( ret < 0 )
3952 return ret;
3953 }
3954
3955 dst->number_is_set = src->number_is_set;
3956
3957 dst->number = src->number;
3958
3959 return 0;
3960 }
3961
3962 /**
3963 * idmef_user_id_clone:
3964 * @src: Object to be cloned.
3965 * @dst: Address where to store the pointer to the cloned object.
3966 *
3967 * Create a copy of @src, and store it in @dst.
3968 *
3969 * Returns: 0 on success, a negative value if an error occured.
3970 */
idmef_user_id_clone(idmef_user_id_t * src,idmef_user_id_t ** dst)3971 int idmef_user_id_clone(idmef_user_id_t *src, idmef_user_id_t **dst)
3972 {
3973 int ret;
3974
3975 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
3976
3977 ret = idmef_user_id_new(dst);
3978 if ( ret < 0 )
3979 return ret;
3980
3981 return idmef_user_id_copy(src, *dst);
3982 }
3983
3984 /**
3985 * idmef_user_id_compare:
3986 * @obj1: Object to compare with @obj2.
3987 * @obj2: Object to compare with @obj1.
3988 *
3989 * Compare @obj1 with @obj2.
3990 *
3991 * Returns: 0 on match, a negative value on comparison failure.
3992 */
idmef_user_id_compare(const idmef_user_id_t * obj1,const idmef_user_id_t * obj2)3993 int idmef_user_id_compare(const idmef_user_id_t *obj1, const idmef_user_id_t *obj2)
3994 {
3995 int ret = 0;
3996
3997 if ( obj1 == NULL && obj2 == NULL )
3998 return 0;
3999
4000 else if ( obj1 == NULL || obj2 == NULL )
4001 return -1;
4002
4003 ret = prelude_string_compare(obj1->ident, obj2->ident);
4004 if ( ret != 0 )
4005 return ret;
4006
4007 if ( obj1->type != obj2->type )
4008 return -1;
4009
4010 ret = prelude_string_compare(obj1->tty, obj2->tty);
4011 if ( ret != 0 )
4012 return ret;
4013
4014 ret = prelude_string_compare(obj1->name, obj2->name);
4015 if ( ret != 0 )
4016 return ret;
4017
4018 if ( obj1->number_is_set != obj2->number_is_set )
4019 return -1;
4020
4021 if ( obj1->number_is_set && obj1->number != obj2->number )
4022 return -1;
4023
4024 return ret;
4025 }
4026
4027 /**
4028 * idmef_user_new:
4029 * @ret: Pointer where to store the created #idmef_user_t object.
4030 *
4031 * Create a new #idmef_user_t object.
4032 *
4033 * Returns: 0 on success, a negative value if an error occured.
4034 */
idmef_user_new(idmef_user_t ** ret)4035 int idmef_user_new(idmef_user_t **ret)
4036 {
4037 *ret = calloc(1, sizeof(**ret));
4038 if ( ! *ret )
4039 return prelude_error_from_errno(errno);
4040
4041 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_USER;
4042
4043 (*ret)->refcount = 1;
4044
4045 prelude_list_init(&(*ret)->user_id_list);
4046
4047
4048 return 0;
4049
4050 }
4051
4052 /**
4053 * idmef_user_ref:
4054 * @user: pointer to a #idmef_user_t object.
4055 *
4056 * Increase @user reference count, so that it can be referenced
4057 * multiple time.
4058 *
4059 * Returns: a pointer to @user.
4060 */
idmef_user_ref(idmef_user_t * user)4061 idmef_user_t *idmef_user_ref(idmef_user_t *user)
4062 {
4063 prelude_return_val_if_fail(user, NULL);
4064 user->refcount++;
4065
4066 return user;
4067 }
4068
_idmef_user_get_child(void * p,idmef_class_child_id_t child,void ** childptr)4069 int _idmef_user_get_child(void *p, idmef_class_child_id_t child, void **childptr)
4070 {
4071 idmef_user_t *ptr = p;
4072
4073 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
4074 *childptr = NULL;
4075
4076 switch ( child ) {
4077
4078 case 0:
4079 return get_value_from_string((idmef_value_t **) childptr, ptr->ident, TRUE);
4080 case 1:
4081 return idmef_value_new_enum_from_numeric((idmef_value_t **) childptr,
4082 IDMEF_CLASS_ID_USER_CATEGORY, ptr->category);
4083
4084 case 2:
4085 *childptr = &ptr->user_id_list;
4086 return 0;
4087
4088 default:
4089 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
4090 }
4091 }
4092
_idmef_user_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)4093 int _idmef_user_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
4094 {
4095 idmef_user_t *ptr = p;
4096
4097 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
4098
4099 switch ( child ) {
4100
4101 case 0:
4102 return idmef_user_new_ident(ptr, (prelude_string_t **) ret);
4103
4104 case 1:
4105 return idmef_user_new_category(ptr, (idmef_user_category_t **) ret);
4106
4107 case 2: {
4108 int i = 0;
4109 prelude_list_t *tmp;
4110
4111 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
4112 return idmef_user_new_user_id(ptr, (idmef_user_id_t **) ret, n);
4113
4114 if ( n >= 0 ) {
4115 prelude_list_for_each(&ptr->user_id_list, tmp) {
4116 if ( i++ == n ) {
4117 *ret = prelude_linked_object_get_object(tmp);
4118 return 0;
4119 }
4120 }
4121
4122 if ( i != n )
4123 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
4124 } else {
4125 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
4126
4127 prelude_list_for_each_reversed(&ptr->user_id_list, tmp) {
4128 if ( i++ == pos ) {
4129 *ret = prelude_linked_object_get_object(tmp);
4130 return 0;
4131 }
4132 }
4133
4134 if ( i != pos )
4135 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
4136 }
4137
4138 return idmef_user_new_user_id(ptr, (idmef_user_id_t **) ret, n);
4139 }
4140
4141 default:
4142 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
4143 }
4144 }
4145
_idmef_user_destroy_child(void * p,idmef_class_child_id_t child,int n)4146 int _idmef_user_destroy_child(void *p, idmef_class_child_id_t child, int n)
4147 {
4148 idmef_user_t *ptr = p;
4149
4150 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
4151
4152 switch ( child ) {
4153
4154 case 0:
4155 if ( ptr->ident ) {
4156 prelude_string_destroy(ptr->ident);
4157 ptr->ident = NULL;
4158 }
4159
4160 return 0;
4161
4162 case 1:
4163 ptr->category = 0;
4164 return 0;
4165
4166 case 2: {
4167 int i = 0;
4168 prelude_list_t *tmp;
4169
4170 if ( n >= 0 ) {
4171 prelude_list_for_each(&ptr->user_id_list, tmp) {
4172 if ( i++ == n ) {
4173 void *b = prelude_linked_object_get_object(tmp);
4174 idmef_user_id_destroy(b);
4175 return 0;
4176 }
4177 }
4178
4179 if ( i != n )
4180 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
4181 } else {
4182 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
4183
4184 prelude_list_for_each_reversed(&ptr->user_id_list, tmp) {
4185 if ( i++ == pos ) {
4186 void *b = prelude_linked_object_get_object(tmp);
4187 idmef_user_id_destroy(b);
4188 return 0;
4189 }
4190 }
4191
4192 if ( i != pos )
4193 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
4194 }
4195 }
4196
4197 default:
4198 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
4199 }
4200 }
4201
idmef_user_destroy_internal(idmef_user_t * ptr)4202 static void idmef_user_destroy_internal(idmef_user_t *ptr)
4203 {
4204 prelude_return_if_fail(ptr);
4205
4206 if ( ptr->ident ) {
4207 prelude_string_destroy(ptr->ident);
4208 ptr->ident = NULL;
4209 }
4210
4211 {
4212 prelude_list_t *n, *tmp;
4213 idmef_user_id_t *entry;
4214
4215 prelude_list_for_each_safe(&ptr->user_id_list, tmp, n) {
4216 entry = prelude_linked_object_get_object(tmp);
4217 prelude_list_del_init(tmp);
4218 idmef_user_id_destroy(entry);
4219 }
4220 }
4221
4222
4223 /* free() should be done by the caller */
4224 }
4225
4226 /**
4227 * idmef_user_destroy:
4228 * @ptr: pointer to a #idmef_user_t object.
4229 *
4230 * Destroy @ptr and all of it's children.
4231 * The objects are only destroyed if their reference count reach zero.
4232 */
4233
idmef_user_destroy(idmef_user_t * ptr)4234 void idmef_user_destroy(idmef_user_t *ptr)
4235 {
4236 prelude_return_if_fail(ptr);
4237
4238 if ( --ptr->refcount )
4239 return;
4240
4241 idmef_user_destroy_internal(ptr);
4242 free(ptr);
4243 }
4244
4245 /**
4246 * idmef_user_get_ident:
4247 * @ptr: pointer to a #idmef_user_t object.
4248 *
4249 * Get ident children of the #idmef_user_t object.
4250 *
4251 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
4252 */
idmef_user_get_ident(idmef_user_t * ptr)4253 prelude_string_t *idmef_user_get_ident(idmef_user_t *ptr)
4254 {
4255 prelude_return_val_if_fail(ptr, 0); /* FIXME */
4256
4257 return ptr->ident;
4258 }
4259
4260 /**
4261 * idmef_user_set_ident:
4262 * @ptr: pointer to a #idmef_user_t object.
4263 * @ident: pointer to a #prelude_string_t object.
4264 *
4265 * Set @ident object as a children of @ptr.
4266 * if @ptr already contain an @ident object, then it is destroyed,
4267 * and updated to point to the provided @ident object.
4268 */
4269
idmef_user_set_ident(idmef_user_t * ptr,prelude_string_t * ident)4270 void idmef_user_set_ident(idmef_user_t *ptr, prelude_string_t *ident)
4271 {
4272 prelude_return_if_fail(ptr);
4273
4274 if ( ptr->ident )
4275 prelude_string_destroy(ptr->ident);
4276
4277 ptr->ident = ident;
4278 }
4279
4280 /**
4281 * idmef_user_new_ident:
4282 * @ptr: pointer to a #idmef_user_t object.
4283 * @ret: pointer to an address where to store the created #prelude_string_t object.
4284 *
4285 * Create a new ident object, children of #idmef_user_t.
4286 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
4287 *
4288 * Returns: 0 on success, or a negative value if an error occured.
4289 */
idmef_user_new_ident(idmef_user_t * ptr,prelude_string_t ** ret)4290 int idmef_user_new_ident(idmef_user_t *ptr, prelude_string_t **ret)
4291 {
4292 int retval;
4293
4294 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
4295
4296 if ( ! ptr->ident ) {
4297 retval = prelude_string_new(&ptr->ident);
4298 if ( retval < 0 )
4299 return retval;
4300 }
4301
4302 *ret = ptr->ident;
4303 return 0;
4304 }
4305
4306 /**
4307 * idmef_user_get_category:
4308 * @ptr: pointer to a #idmef_user_t object.
4309 *
4310 * Get category children of the #idmef_user_t object.
4311 *
4312 * Returns: a pointer to a idmef_user_category_t object, or NULL if the children object is not set.
4313 */
idmef_user_get_category(idmef_user_t * ptr)4314 idmef_user_category_t idmef_user_get_category(idmef_user_t *ptr)
4315 {
4316 prelude_return_val_if_fail(ptr, 0); /* FIXME */
4317
4318 return ptr->category;
4319 }
4320
4321 /**
4322 * idmef_user_set_category:
4323 * @ptr: pointer to a #idmef_user_t object.
4324 * @category: pointer to a #idmef_user_category_t object.
4325 *
4326 * Set @category object as a children of @ptr.
4327 * if @ptr already contain an @category object, then it is destroyed,
4328 * and updated to point to the provided @category object.
4329 */
4330
idmef_user_set_category(idmef_user_t * ptr,idmef_user_category_t category)4331 void idmef_user_set_category(idmef_user_t *ptr, idmef_user_category_t category)
4332 {
4333 prelude_return_if_fail(ptr);
4334 ptr->category = category;
4335 }
4336
4337 /**
4338 * idmef_user_new_category:
4339 * @ptr: pointer to a #idmef_user_t object.
4340 * @ret: pointer to an address where to store the created #idmef_user_category_t object.
4341 *
4342 * Create a new category object, children of #idmef_user_t.
4343 * If @ptr already contain a #idmef_user_category_t object, then it is destroyed.
4344 *
4345 * Returns: 0 on success, or a negative value if an error occured.
4346 */
idmef_user_new_category(idmef_user_t * ptr,idmef_user_category_t ** ret)4347 int idmef_user_new_category(idmef_user_t *ptr, idmef_user_category_t **ret)
4348 {
4349 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
4350
4351 *ret = &ptr->category;
4352 return 0;
4353 }
4354
4355 /**
4356 * idmef_user_get_next_user_id:
4357 * @user: pointer to a #idmef_user_t object.
4358 * @user_id_cur: pointer to a #idmef_user_id_t object.
4359 *
4360 * Get the next #idmef_user_id_t object listed in @ptr.
4361 * When iterating over the idmef_user_id_t object listed in @ptr,
4362 * @object should be set to the latest returned #idmef_user_id_t object.
4363 *
4364 * Returns: the next #idmef_user_id_t in the list.
4365 */
idmef_user_get_next_user_id(idmef_user_t * user,idmef_user_id_t * user_id_cur)4366 idmef_user_id_t *idmef_user_get_next_user_id(idmef_user_t *user, idmef_user_id_t *user_id_cur)
4367 {
4368 prelude_list_t *tmp = (user_id_cur) ? &((prelude_linked_object_t *) user_id_cur)->_list : NULL;
4369
4370 prelude_return_val_if_fail(user, NULL);
4371
4372 prelude_list_for_each_continue(&user->user_id_list, tmp)
4373 return prelude_linked_object_get_object(tmp);
4374
4375 return NULL;
4376 }
4377
4378
4379 /**
4380 * idmef_user_set_user_id:
4381 * @ptr: pointer to a #idmef_user_t object.
4382 * @object: pointer to a #idmef_user_id_t object.
4383 * @pos: Position in the list.
4384 *
4385 * Add @object to position @pos of @ptr list of #idmef_user_id_t object.
4386 *
4387 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
4388 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
4389 */
idmef_user_set_user_id(idmef_user_t * ptr,idmef_user_id_t * object,int pos)4390 void idmef_user_set_user_id(idmef_user_t *ptr, idmef_user_id_t *object, int pos)
4391 {
4392 prelude_return_if_fail(ptr);
4393 prelude_return_if_fail(object);
4394
4395 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
4396 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
4397
4398 list_insert(&ptr->user_id_list, &((prelude_linked_object_t *) object)->_list, pos);
4399 }
4400
4401
4402 /**
4403 * idmef_user_new_user_id:
4404 * @ptr: pointer to a #idmef_user_t object.
4405 * @ret: pointer to an address where to store the created #idmef_user_id_t object.
4406 * @pos: position in the list.
4407 *
4408 * Create a new #idmef_user_id_t children of @ptr, and add it to position @pos of
4409 * @ptr list of #idmef_user_id_t object. The created #idmef_user_id_t object is
4410 * stored in @ret.
4411 *
4412 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
4413 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
4414 *
4415 * Returns: 0 on success, or a negative value if an error occured.
4416 */
idmef_user_new_user_id(idmef_user_t * ptr,idmef_user_id_t ** ret,int pos)4417 int idmef_user_new_user_id(idmef_user_t *ptr, idmef_user_id_t **ret, int pos)
4418 {
4419 int retval;
4420
4421 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
4422
4423 retval = idmef_user_id_new(ret);
4424 if ( retval < 0 )
4425 return retval;
4426
4427 list_insert(&ptr->user_id_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
4428
4429 return 0;
4430 }
4431
4432
4433 /**
4434 * idmef_user_copy:
4435 * @src: Source of the copy.
4436 * @dst: Where to copy the object.
4437 *
4438 * Copy a new #idmef_user_t object from @src to @dst.
4439 *
4440 * Returns: 0 on success, a negative value if an error occured.
4441 */
idmef_user_copy(const idmef_user_t * src,idmef_user_t * dst)4442 int idmef_user_copy(const idmef_user_t *src, idmef_user_t *dst)
4443 {
4444 int ret;
4445
4446 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
4447 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
4448
4449 ret = 0;
4450
4451 if ( src->ident ) {
4452 ret = prelude_string_clone(src->ident, &dst->ident);
4453 if ( ret < 0 )
4454 return ret;
4455 }
4456
4457 dst->category = src->category;
4458
4459 {
4460 prelude_list_t *n, *tmp;
4461 idmef_user_id_t *entry, *new;
4462
4463 prelude_list_for_each_safe(&src->user_id_list, tmp, n) {
4464 entry = prelude_linked_object_get_object(tmp);
4465 idmef_user_id_clone(entry, &new);
4466 prelude_list_add_tail(&dst->user_id_list, &((prelude_linked_object_t *) new)->_list);
4467 }
4468 }
4469
4470 return 0;
4471 }
4472
4473 /**
4474 * idmef_user_clone:
4475 * @src: Object to be cloned.
4476 * @dst: Address where to store the pointer to the cloned object.
4477 *
4478 * Create a copy of @src, and store it in @dst.
4479 *
4480 * Returns: 0 on success, a negative value if an error occured.
4481 */
idmef_user_clone(idmef_user_t * src,idmef_user_t ** dst)4482 int idmef_user_clone(idmef_user_t *src, idmef_user_t **dst)
4483 {
4484 int ret;
4485
4486 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
4487
4488 ret = idmef_user_new(dst);
4489 if ( ret < 0 )
4490 return ret;
4491
4492 return idmef_user_copy(src, *dst);
4493 }
4494
4495 /**
4496 * idmef_user_compare:
4497 * @obj1: Object to compare with @obj2.
4498 * @obj2: Object to compare with @obj1.
4499 *
4500 * Compare @obj1 with @obj2.
4501 *
4502 * Returns: 0 on match, a negative value on comparison failure.
4503 */
idmef_user_compare(const idmef_user_t * obj1,const idmef_user_t * obj2)4504 int idmef_user_compare(const idmef_user_t *obj1, const idmef_user_t *obj2)
4505 {
4506 int ret = 0;
4507
4508 if ( obj1 == NULL && obj2 == NULL )
4509 return 0;
4510
4511 else if ( obj1 == NULL || obj2 == NULL )
4512 return -1;
4513
4514 ret = prelude_string_compare(obj1->ident, obj2->ident);
4515 if ( ret != 0 )
4516 return ret;
4517
4518 if ( obj1->category != obj2->category )
4519 return -1;
4520
4521 {
4522 prelude_list_t *tmp1, *tmp2;
4523 idmef_user_id_t *entry1, *entry2;
4524
4525 tmp1 = tmp2 = NULL;
4526 do {
4527 entry1 = entry2 = NULL;
4528
4529 prelude_list_for_each_continue(&obj1->user_id_list, tmp1) {
4530 entry1 = prelude_linked_object_get_object(tmp1);
4531 break;
4532 }
4533
4534 prelude_list_for_each_continue(&obj2->user_id_list, tmp2) {
4535 entry2 = prelude_linked_object_get_object(tmp2);
4536 break;
4537 }
4538
4539 ret = idmef_user_id_compare(entry1, entry2);
4540 if ( ret != 0 )
4541 return ret;
4542
4543 } while ( entry1 && entry2 );
4544 }
4545
4546 return ret;
4547 }
4548
4549 /**
4550 * idmef_address_new:
4551 * @ret: Pointer where to store the created #idmef_address_t object.
4552 *
4553 * Create a new #idmef_address_t object.
4554 *
4555 * Returns: 0 on success, a negative value if an error occured.
4556 */
idmef_address_new(idmef_address_t ** ret)4557 int idmef_address_new(idmef_address_t **ret)
4558 {
4559 *ret = calloc(1, sizeof(**ret));
4560 if ( ! *ret )
4561 return prelude_error_from_errno(errno);
4562
4563 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_ADDRESS;
4564
4565 prelude_list_init(&((prelude_linked_object_t *) (*ret))->_list);
4566
4567 (*ret)->refcount = 1;
4568
4569 {
4570 int retval = prelude_string_new(&(*ret)->address);
4571
4572 if ( retval < 0 ) {
4573 idmef_address_destroy(*ret);
4574 *ret = NULL;
4575 return retval;
4576 }
4577 }
4578
4579 return 0;
4580
4581 }
4582
4583 /**
4584 * idmef_address_ref:
4585 * @address: pointer to a #idmef_address_t object.
4586 *
4587 * Increase @address reference count, so that it can be referenced
4588 * multiple time.
4589 *
4590 * Returns: a pointer to @address.
4591 */
idmef_address_ref(idmef_address_t * address)4592 idmef_address_t *idmef_address_ref(idmef_address_t *address)
4593 {
4594 prelude_return_val_if_fail(address, NULL);
4595 address->refcount++;
4596
4597 return address;
4598 }
4599
_idmef_address_get_child(void * p,idmef_class_child_id_t child,void ** childptr)4600 int _idmef_address_get_child(void *p, idmef_class_child_id_t child, void **childptr)
4601 {
4602 idmef_address_t *ptr = p;
4603
4604 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
4605 *childptr = NULL;
4606
4607 switch ( child ) {
4608
4609 case 0:
4610 return get_value_from_string((idmef_value_t **) childptr, ptr->ident, TRUE);
4611 case 1:
4612 return idmef_value_new_enum_from_numeric((idmef_value_t **) childptr,
4613 IDMEF_CLASS_ID_ADDRESS_CATEGORY, ptr->category);
4614
4615 case 2:
4616 return get_value_from_string((idmef_value_t **) childptr, ptr->vlan_name, TRUE);
4617 case 3:
4618 return (ptr->vlan_num_is_set) ? idmef_value_new_int32((idmef_value_t **) childptr, ptr->vlan_num) : 0;
4619
4620 case 4:
4621 return get_value_from_string((idmef_value_t **) childptr, ptr->address, TRUE);
4622 case 5:
4623 return get_value_from_string((idmef_value_t **) childptr, ptr->netmask, TRUE);
4624 default:
4625 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
4626 }
4627 }
4628
_idmef_address_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)4629 int _idmef_address_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
4630 {
4631 idmef_address_t *ptr = p;
4632
4633 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
4634
4635 switch ( child ) {
4636
4637 case 0:
4638 return idmef_address_new_ident(ptr, (prelude_string_t **) ret);
4639
4640 case 1:
4641 return idmef_address_new_category(ptr, (idmef_address_category_t **) ret);
4642
4643 case 2:
4644 return idmef_address_new_vlan_name(ptr, (prelude_string_t **) ret);
4645
4646 case 3:
4647 return idmef_address_new_vlan_num(ptr, (int32_t **) ret);
4648
4649 case 4:
4650 return idmef_address_new_address(ptr, (prelude_string_t **) ret);
4651
4652 case 5:
4653 return idmef_address_new_netmask(ptr, (prelude_string_t **) ret);
4654
4655 default:
4656 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
4657 }
4658 }
4659
_idmef_address_destroy_child(void * p,idmef_class_child_id_t child,int n)4660 int _idmef_address_destroy_child(void *p, idmef_class_child_id_t child, int n)
4661 {
4662 idmef_address_t *ptr = p;
4663
4664 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
4665
4666 switch ( child ) {
4667
4668 case 0:
4669 if ( ptr->ident ) {
4670 prelude_string_destroy(ptr->ident);
4671 ptr->ident = NULL;
4672 }
4673
4674 return 0;
4675
4676 case 1:
4677 ptr->category = 0;
4678 return 0;
4679
4680 case 2:
4681 if ( ptr->vlan_name ) {
4682 prelude_string_destroy(ptr->vlan_name);
4683 ptr->vlan_name = NULL;
4684 }
4685
4686 return 0;
4687
4688 case 3:
4689 ptr->vlan_num_is_set = 0;
4690 return 0;
4691
4692 case 4:
4693 if ( ptr->address ) {
4694 prelude_string_destroy(ptr->address);
4695 ptr->address = NULL;
4696 }
4697
4698 return 0;
4699
4700 case 5:
4701 if ( ptr->netmask ) {
4702 prelude_string_destroy(ptr->netmask);
4703 ptr->netmask = NULL;
4704 }
4705
4706 return 0;
4707
4708 default:
4709 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
4710 }
4711 }
4712
idmef_address_destroy_internal(idmef_address_t * ptr)4713 static void idmef_address_destroy_internal(idmef_address_t *ptr)
4714 {
4715 prelude_return_if_fail(ptr);
4716
4717 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *)ptr)->_list) )
4718 prelude_list_del_init(&((prelude_linked_object_t *)ptr)->_list);
4719
4720 if ( ptr->ident ) {
4721 prelude_string_destroy(ptr->ident);
4722 ptr->ident = NULL;
4723 }
4724
4725 if ( ptr->vlan_name ) {
4726 prelude_string_destroy(ptr->vlan_name);
4727 ptr->vlan_name = NULL;
4728 }
4729
4730 if ( ptr->address ) {
4731 prelude_string_destroy(ptr->address);
4732 ptr->address = NULL;
4733 }
4734
4735 if ( ptr->netmask ) {
4736 prelude_string_destroy(ptr->netmask);
4737 ptr->netmask = NULL;
4738 }
4739
4740
4741 /* free() should be done by the caller */
4742 }
4743
4744 /**
4745 * idmef_address_destroy:
4746 * @ptr: pointer to a #idmef_address_t object.
4747 *
4748 * Destroy @ptr and all of it's children.
4749 * The objects are only destroyed if their reference count reach zero.
4750 */
4751
idmef_address_destroy(idmef_address_t * ptr)4752 void idmef_address_destroy(idmef_address_t *ptr)
4753 {
4754 prelude_return_if_fail(ptr);
4755
4756 if ( --ptr->refcount )
4757 return;
4758
4759 idmef_address_destroy_internal(ptr);
4760 free(ptr);
4761 }
4762
4763 /**
4764 * idmef_address_get_ident:
4765 * @ptr: pointer to a #idmef_address_t object.
4766 *
4767 * Get ident children of the #idmef_address_t object.
4768 *
4769 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
4770 */
idmef_address_get_ident(idmef_address_t * ptr)4771 prelude_string_t *idmef_address_get_ident(idmef_address_t *ptr)
4772 {
4773 prelude_return_val_if_fail(ptr, 0); /* FIXME */
4774
4775 return ptr->ident;
4776 }
4777
4778 /**
4779 * idmef_address_set_ident:
4780 * @ptr: pointer to a #idmef_address_t object.
4781 * @ident: pointer to a #prelude_string_t object.
4782 *
4783 * Set @ident object as a children of @ptr.
4784 * if @ptr already contain an @ident object, then it is destroyed,
4785 * and updated to point to the provided @ident object.
4786 */
4787
idmef_address_set_ident(idmef_address_t * ptr,prelude_string_t * ident)4788 void idmef_address_set_ident(idmef_address_t *ptr, prelude_string_t *ident)
4789 {
4790 prelude_return_if_fail(ptr);
4791
4792 if ( ptr->ident )
4793 prelude_string_destroy(ptr->ident);
4794
4795 ptr->ident = ident;
4796 }
4797
4798 /**
4799 * idmef_address_new_ident:
4800 * @ptr: pointer to a #idmef_address_t object.
4801 * @ret: pointer to an address where to store the created #prelude_string_t object.
4802 *
4803 * Create a new ident object, children of #idmef_address_t.
4804 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
4805 *
4806 * Returns: 0 on success, or a negative value if an error occured.
4807 */
idmef_address_new_ident(idmef_address_t * ptr,prelude_string_t ** ret)4808 int idmef_address_new_ident(idmef_address_t *ptr, prelude_string_t **ret)
4809 {
4810 int retval;
4811
4812 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
4813
4814 if ( ! ptr->ident ) {
4815 retval = prelude_string_new(&ptr->ident);
4816 if ( retval < 0 )
4817 return retval;
4818 }
4819
4820 *ret = ptr->ident;
4821 return 0;
4822 }
4823
4824 /**
4825 * idmef_address_get_category:
4826 * @ptr: pointer to a #idmef_address_t object.
4827 *
4828 * Get category children of the #idmef_address_t object.
4829 *
4830 * Returns: a pointer to a idmef_address_category_t object, or NULL if the children object is not set.
4831 */
idmef_address_get_category(idmef_address_t * ptr)4832 idmef_address_category_t idmef_address_get_category(idmef_address_t *ptr)
4833 {
4834 prelude_return_val_if_fail(ptr, 0); /* FIXME */
4835
4836 return ptr->category;
4837 }
4838
4839 /**
4840 * idmef_address_set_category:
4841 * @ptr: pointer to a #idmef_address_t object.
4842 * @category: pointer to a #idmef_address_category_t object.
4843 *
4844 * Set @category object as a children of @ptr.
4845 * if @ptr already contain an @category object, then it is destroyed,
4846 * and updated to point to the provided @category object.
4847 */
4848
idmef_address_set_category(idmef_address_t * ptr,idmef_address_category_t category)4849 void idmef_address_set_category(idmef_address_t *ptr, idmef_address_category_t category)
4850 {
4851 prelude_return_if_fail(ptr);
4852 ptr->category = category;
4853 }
4854
4855 /**
4856 * idmef_address_new_category:
4857 * @ptr: pointer to a #idmef_address_t object.
4858 * @ret: pointer to an address where to store the created #idmef_address_category_t object.
4859 *
4860 * Create a new category object, children of #idmef_address_t.
4861 * If @ptr already contain a #idmef_address_category_t object, then it is destroyed.
4862 *
4863 * Returns: 0 on success, or a negative value if an error occured.
4864 */
idmef_address_new_category(idmef_address_t * ptr,idmef_address_category_t ** ret)4865 int idmef_address_new_category(idmef_address_t *ptr, idmef_address_category_t **ret)
4866 {
4867 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
4868
4869 *ret = &ptr->category;
4870 return 0;
4871 }
4872
4873 /**
4874 * idmef_address_get_vlan_name:
4875 * @ptr: pointer to a #idmef_address_t object.
4876 *
4877 * Get vlan_name children of the #idmef_address_t object.
4878 *
4879 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
4880 */
idmef_address_get_vlan_name(idmef_address_t * ptr)4881 prelude_string_t *idmef_address_get_vlan_name(idmef_address_t *ptr)
4882 {
4883 prelude_return_val_if_fail(ptr, 0); /* FIXME */
4884
4885 return ptr->vlan_name;
4886 }
4887
4888 /**
4889 * idmef_address_set_vlan_name:
4890 * @ptr: pointer to a #idmef_address_t object.
4891 * @vlan_name: pointer to a #prelude_string_t object.
4892 *
4893 * Set @vlan_name object as a children of @ptr.
4894 * if @ptr already contain an @vlan_name object, then it is destroyed,
4895 * and updated to point to the provided @vlan_name object.
4896 */
4897
idmef_address_set_vlan_name(idmef_address_t * ptr,prelude_string_t * vlan_name)4898 void idmef_address_set_vlan_name(idmef_address_t *ptr, prelude_string_t *vlan_name)
4899 {
4900 prelude_return_if_fail(ptr);
4901
4902 if ( ptr->vlan_name )
4903 prelude_string_destroy(ptr->vlan_name);
4904
4905 ptr->vlan_name = vlan_name;
4906 }
4907
4908 /**
4909 * idmef_address_new_vlan_name:
4910 * @ptr: pointer to a #idmef_address_t object.
4911 * @ret: pointer to an address where to store the created #prelude_string_t object.
4912 *
4913 * Create a new vlan_name object, children of #idmef_address_t.
4914 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
4915 *
4916 * Returns: 0 on success, or a negative value if an error occured.
4917 */
idmef_address_new_vlan_name(idmef_address_t * ptr,prelude_string_t ** ret)4918 int idmef_address_new_vlan_name(idmef_address_t *ptr, prelude_string_t **ret)
4919 {
4920 int retval;
4921
4922 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
4923
4924 if ( ! ptr->vlan_name ) {
4925 retval = prelude_string_new(&ptr->vlan_name);
4926 if ( retval < 0 )
4927 return retval;
4928 }
4929
4930 *ret = ptr->vlan_name;
4931 return 0;
4932 }
4933
4934 /**
4935 * idmef_address_get_vlan_num:
4936 * @ptr: pointer to a #idmef_address_t object.
4937 *
4938 * Get vlan_num children of the #idmef_address_t object.
4939 *
4940 * Returns: a pointer to a int32_t object, or NULL if the children object is not set.
4941 */
idmef_address_get_vlan_num(idmef_address_t * ptr)4942 int32_t *idmef_address_get_vlan_num(idmef_address_t *ptr)
4943 {
4944 prelude_return_val_if_fail(ptr, 0); /* FIXME */
4945
4946 return ptr->vlan_num_is_set ? &ptr->vlan_num : NULL;
4947 }
4948
4949 /**
4950 * idmef_address_set_vlan_num:
4951 * @ptr: pointer to a #idmef_address_t object.
4952 * @vlan_num: pointer to a #int32_t object.
4953 *
4954 * Set @vlan_num object as a children of @ptr.
4955 * if @ptr already contain an @vlan_num object, then it is destroyed,
4956 * and updated to point to the provided @vlan_num object.
4957 */
4958
idmef_address_set_vlan_num(idmef_address_t * ptr,int32_t vlan_num)4959 void idmef_address_set_vlan_num(idmef_address_t *ptr, int32_t vlan_num)
4960 {
4961 prelude_return_if_fail(ptr);
4962 ptr->vlan_num = vlan_num;
4963 ptr->vlan_num_is_set = 1;
4964 }
4965
4966
idmef_address_unset_vlan_num(idmef_address_t * ptr)4967 void idmef_address_unset_vlan_num(idmef_address_t *ptr)
4968 {
4969 prelude_return_if_fail(ptr);
4970 ptr->vlan_num_is_set = 0;
4971 }
4972
4973
4974 /**
4975 * idmef_address_new_vlan_num:
4976 * @ptr: pointer to a #idmef_address_t object.
4977 * @ret: pointer to an address where to store the created #int32_t object.
4978 *
4979 * Create a new vlan_num object, children of #idmef_address_t.
4980 * If @ptr already contain a #int32_t object, then it is destroyed.
4981 *
4982 * Returns: 0 on success, or a negative value if an error occured.
4983 */
idmef_address_new_vlan_num(idmef_address_t * ptr,int32_t ** ret)4984 int idmef_address_new_vlan_num(idmef_address_t *ptr, int32_t **ret)
4985 {
4986 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
4987 ptr->vlan_num_is_set = 1;
4988
4989 *ret = &ptr->vlan_num;
4990 return 0;
4991 }
4992
4993 /**
4994 * idmef_address_get_address:
4995 * @ptr: pointer to a #idmef_address_t object.
4996 *
4997 * Get address children of the #idmef_address_t object.
4998 *
4999 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
5000 */
idmef_address_get_address(idmef_address_t * ptr)5001 prelude_string_t *idmef_address_get_address(idmef_address_t *ptr)
5002 {
5003 prelude_return_val_if_fail(ptr, 0); /* FIXME */
5004
5005 return ptr->address;
5006 }
5007
5008 /**
5009 * idmef_address_set_address:
5010 * @ptr: pointer to a #idmef_address_t object.
5011 * @address: pointer to a #prelude_string_t object.
5012 *
5013 * Set @address object as a children of @ptr.
5014 * if @ptr already contain an @address object, then it is destroyed,
5015 * and updated to point to the provided @address object.
5016 */
5017
idmef_address_set_address(idmef_address_t * ptr,prelude_string_t * address)5018 void idmef_address_set_address(idmef_address_t *ptr, prelude_string_t *address)
5019 {
5020 prelude_return_if_fail(ptr);
5021
5022 if ( ptr->address )
5023 prelude_string_destroy(ptr->address);
5024
5025 ptr->address = address;
5026 }
5027
5028 /**
5029 * idmef_address_new_address:
5030 * @ptr: pointer to a #idmef_address_t object.
5031 * @ret: pointer to an address where to store the created #prelude_string_t object.
5032 *
5033 * Create a new address object, children of #idmef_address_t.
5034 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
5035 *
5036 * Returns: 0 on success, or a negative value if an error occured.
5037 */
idmef_address_new_address(idmef_address_t * ptr,prelude_string_t ** ret)5038 int idmef_address_new_address(idmef_address_t *ptr, prelude_string_t **ret)
5039 {
5040 int retval;
5041
5042 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
5043
5044 if ( ! ptr->address ) {
5045 retval = prelude_string_new(&ptr->address);
5046 if ( retval < 0 )
5047 return retval;
5048 }
5049
5050 *ret = ptr->address;
5051 return 0;
5052 }
5053
5054 /**
5055 * idmef_address_get_netmask:
5056 * @ptr: pointer to a #idmef_address_t object.
5057 *
5058 * Get netmask children of the #idmef_address_t object.
5059 *
5060 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
5061 */
idmef_address_get_netmask(idmef_address_t * ptr)5062 prelude_string_t *idmef_address_get_netmask(idmef_address_t *ptr)
5063 {
5064 prelude_return_val_if_fail(ptr, 0); /* FIXME */
5065
5066 return ptr->netmask;
5067 }
5068
5069 /**
5070 * idmef_address_set_netmask:
5071 * @ptr: pointer to a #idmef_address_t object.
5072 * @netmask: pointer to a #prelude_string_t object.
5073 *
5074 * Set @netmask object as a children of @ptr.
5075 * if @ptr already contain an @netmask object, then it is destroyed,
5076 * and updated to point to the provided @netmask object.
5077 */
5078
idmef_address_set_netmask(idmef_address_t * ptr,prelude_string_t * netmask)5079 void idmef_address_set_netmask(idmef_address_t *ptr, prelude_string_t *netmask)
5080 {
5081 prelude_return_if_fail(ptr);
5082
5083 if ( ptr->netmask )
5084 prelude_string_destroy(ptr->netmask);
5085
5086 ptr->netmask = netmask;
5087 }
5088
5089 /**
5090 * idmef_address_new_netmask:
5091 * @ptr: pointer to a #idmef_address_t object.
5092 * @ret: pointer to an address where to store the created #prelude_string_t object.
5093 *
5094 * Create a new netmask object, children of #idmef_address_t.
5095 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
5096 *
5097 * Returns: 0 on success, or a negative value if an error occured.
5098 */
idmef_address_new_netmask(idmef_address_t * ptr,prelude_string_t ** ret)5099 int idmef_address_new_netmask(idmef_address_t *ptr, prelude_string_t **ret)
5100 {
5101 int retval;
5102
5103 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
5104
5105 if ( ! ptr->netmask ) {
5106 retval = prelude_string_new(&ptr->netmask);
5107 if ( retval < 0 )
5108 return retval;
5109 }
5110
5111 *ret = ptr->netmask;
5112 return 0;
5113 }
5114
5115 /**
5116 * idmef_address_copy:
5117 * @src: Source of the copy.
5118 * @dst: Where to copy the object.
5119 *
5120 * Copy a new #idmef_address_t object from @src to @dst.
5121 *
5122 * Returns: 0 on success, a negative value if an error occured.
5123 */
idmef_address_copy(const idmef_address_t * src,idmef_address_t * dst)5124 int idmef_address_copy(const idmef_address_t *src, idmef_address_t *dst)
5125 {
5126 int ret;
5127
5128 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
5129 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
5130
5131 ret = 0;
5132
5133 if ( src->ident ) {
5134 ret = prelude_string_clone(src->ident, &dst->ident);
5135 if ( ret < 0 )
5136 return ret;
5137 }
5138
5139 dst->category = src->category;
5140
5141 if ( src->vlan_name ) {
5142 ret = prelude_string_clone(src->vlan_name, &dst->vlan_name);
5143 if ( ret < 0 )
5144 return ret;
5145 }
5146
5147 dst->vlan_num_is_set = src->vlan_num_is_set;
5148
5149 dst->vlan_num = src->vlan_num;
5150
5151 if ( src->address ) {
5152 ret = prelude_string_copy(src->address, dst->address);
5153 if ( ret < 0 )
5154 return ret;
5155 }
5156
5157 if ( src->netmask ) {
5158 ret = prelude_string_clone(src->netmask, &dst->netmask);
5159 if ( ret < 0 )
5160 return ret;
5161 }
5162
5163 return 0;
5164 }
5165
5166 /**
5167 * idmef_address_clone:
5168 * @src: Object to be cloned.
5169 * @dst: Address where to store the pointer to the cloned object.
5170 *
5171 * Create a copy of @src, and store it in @dst.
5172 *
5173 * Returns: 0 on success, a negative value if an error occured.
5174 */
idmef_address_clone(idmef_address_t * src,idmef_address_t ** dst)5175 int idmef_address_clone(idmef_address_t *src, idmef_address_t **dst)
5176 {
5177 int ret;
5178
5179 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
5180
5181 ret = idmef_address_new(dst);
5182 if ( ret < 0 )
5183 return ret;
5184
5185 return idmef_address_copy(src, *dst);
5186 }
5187
5188 /**
5189 * idmef_address_compare:
5190 * @obj1: Object to compare with @obj2.
5191 * @obj2: Object to compare with @obj1.
5192 *
5193 * Compare @obj1 with @obj2.
5194 *
5195 * Returns: 0 on match, a negative value on comparison failure.
5196 */
idmef_address_compare(const idmef_address_t * obj1,const idmef_address_t * obj2)5197 int idmef_address_compare(const idmef_address_t *obj1, const idmef_address_t *obj2)
5198 {
5199 int ret = 0;
5200
5201 if ( obj1 == NULL && obj2 == NULL )
5202 return 0;
5203
5204 else if ( obj1 == NULL || obj2 == NULL )
5205 return -1;
5206
5207 ret = prelude_string_compare(obj1->ident, obj2->ident);
5208 if ( ret != 0 )
5209 return ret;
5210
5211 if ( obj1->category != obj2->category )
5212 return -1;
5213
5214 ret = prelude_string_compare(obj1->vlan_name, obj2->vlan_name);
5215 if ( ret != 0 )
5216 return ret;
5217
5218 if ( obj1->vlan_num_is_set != obj2->vlan_num_is_set )
5219 return -1;
5220
5221 if ( obj1->vlan_num_is_set && obj1->vlan_num != obj2->vlan_num )
5222 return -1;
5223
5224 ret = prelude_string_compare(obj1->address, obj2->address);
5225 if ( ret != 0 )
5226 return ret;
5227
5228 ret = prelude_string_compare(obj1->netmask, obj2->netmask);
5229 if ( ret != 0 )
5230 return ret;
5231
5232 return ret;
5233 }
5234
5235 /**
5236 * idmef_process_new:
5237 * @ret: Pointer where to store the created #idmef_process_t object.
5238 *
5239 * Create a new #idmef_process_t object.
5240 *
5241 * Returns: 0 on success, a negative value if an error occured.
5242 */
idmef_process_new(idmef_process_t ** ret)5243 int idmef_process_new(idmef_process_t **ret)
5244 {
5245 *ret = calloc(1, sizeof(**ret));
5246 if ( ! *ret )
5247 return prelude_error_from_errno(errno);
5248
5249 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_PROCESS;
5250
5251 (*ret)->refcount = 1;
5252
5253 prelude_list_init(&(*ret)->arg_list);
5254
5255
5256 prelude_list_init(&(*ret)->env_list);
5257
5258
5259 {
5260 int retval = prelude_string_new(&(*ret)->name);
5261
5262 if ( retval < 0 ) {
5263 idmef_process_destroy(*ret);
5264 *ret = NULL;
5265 return retval;
5266 }
5267 }
5268
5269 return 0;
5270
5271 }
5272
5273 /**
5274 * idmef_process_ref:
5275 * @process: pointer to a #idmef_process_t object.
5276 *
5277 * Increase @process reference count, so that it can be referenced
5278 * multiple time.
5279 *
5280 * Returns: a pointer to @process.
5281 */
idmef_process_ref(idmef_process_t * process)5282 idmef_process_t *idmef_process_ref(idmef_process_t *process)
5283 {
5284 prelude_return_val_if_fail(process, NULL);
5285 process->refcount++;
5286
5287 return process;
5288 }
5289
_idmef_process_get_child(void * p,idmef_class_child_id_t child,void ** childptr)5290 int _idmef_process_get_child(void *p, idmef_class_child_id_t child, void **childptr)
5291 {
5292 idmef_process_t *ptr = p;
5293
5294 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
5295 *childptr = NULL;
5296
5297 switch ( child ) {
5298
5299 case 0:
5300 return get_value_from_string((idmef_value_t **) childptr, ptr->ident, TRUE);
5301 case 1:
5302 return get_value_from_string((idmef_value_t **) childptr, ptr->name, TRUE);
5303 case 2:
5304 return (ptr->pid_is_set) ? idmef_value_new_uint32((idmef_value_t **) childptr, ptr->pid) : 0;
5305
5306 case 3:
5307 return get_value_from_string((idmef_value_t **) childptr, ptr->path, TRUE);
5308 case 4:
5309 *childptr = &ptr->arg_list;
5310 return 0;
5311
5312 case 5:
5313 *childptr = &ptr->env_list;
5314 return 0;
5315
5316 default:
5317 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
5318 }
5319 }
5320
_idmef_process_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)5321 int _idmef_process_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
5322 {
5323 idmef_process_t *ptr = p;
5324
5325 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
5326
5327 switch ( child ) {
5328
5329 case 0:
5330 return idmef_process_new_ident(ptr, (prelude_string_t **) ret);
5331
5332 case 1:
5333 return idmef_process_new_name(ptr, (prelude_string_t **) ret);
5334
5335 case 2:
5336 return idmef_process_new_pid(ptr, (uint32_t **) ret);
5337
5338 case 3:
5339 return idmef_process_new_path(ptr, (prelude_string_t **) ret);
5340
5341 case 4: {
5342 int i = 0;
5343 prelude_list_t *tmp;
5344
5345 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
5346 return idmef_process_new_arg(ptr, (prelude_string_t **) ret, n);
5347
5348 if ( n >= 0 ) {
5349 prelude_list_for_each(&ptr->arg_list, tmp) {
5350 if ( i++ == n ) {
5351 *ret = prelude_linked_object_get_object(tmp);
5352 return 0;
5353 }
5354 }
5355
5356 if ( i != n )
5357 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
5358 } else {
5359 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
5360
5361 prelude_list_for_each_reversed(&ptr->arg_list, tmp) {
5362 if ( i++ == pos ) {
5363 *ret = prelude_linked_object_get_object(tmp);
5364 return 0;
5365 }
5366 }
5367
5368 if ( i != pos )
5369 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
5370 }
5371
5372 return idmef_process_new_arg(ptr, (prelude_string_t **) ret, n);
5373 }
5374
5375 case 5: {
5376 int i = 0;
5377 prelude_list_t *tmp;
5378
5379 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
5380 return idmef_process_new_env(ptr, (prelude_string_t **) ret, n);
5381
5382 if ( n >= 0 ) {
5383 prelude_list_for_each(&ptr->env_list, tmp) {
5384 if ( i++ == n ) {
5385 *ret = prelude_linked_object_get_object(tmp);
5386 return 0;
5387 }
5388 }
5389
5390 if ( i != n )
5391 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
5392 } else {
5393 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
5394
5395 prelude_list_for_each_reversed(&ptr->env_list, tmp) {
5396 if ( i++ == pos ) {
5397 *ret = prelude_linked_object_get_object(tmp);
5398 return 0;
5399 }
5400 }
5401
5402 if ( i != pos )
5403 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
5404 }
5405
5406 return idmef_process_new_env(ptr, (prelude_string_t **) ret, n);
5407 }
5408
5409 default:
5410 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
5411 }
5412 }
5413
_idmef_process_destroy_child(void * p,idmef_class_child_id_t child,int n)5414 int _idmef_process_destroy_child(void *p, idmef_class_child_id_t child, int n)
5415 {
5416 idmef_process_t *ptr = p;
5417
5418 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
5419
5420 switch ( child ) {
5421
5422 case 0:
5423 if ( ptr->ident ) {
5424 prelude_string_destroy(ptr->ident);
5425 ptr->ident = NULL;
5426 }
5427
5428 return 0;
5429
5430 case 1:
5431 if ( ptr->name ) {
5432 prelude_string_destroy(ptr->name);
5433 ptr->name = NULL;
5434 }
5435
5436 return 0;
5437
5438 case 2:
5439 ptr->pid_is_set = 0;
5440 return 0;
5441
5442 case 3:
5443 if ( ptr->path ) {
5444 prelude_string_destroy(ptr->path);
5445 ptr->path = NULL;
5446 }
5447
5448 return 0;
5449
5450 case 4: {
5451 int i = 0;
5452 prelude_list_t *tmp;
5453
5454 if ( n >= 0 ) {
5455 prelude_list_for_each(&ptr->arg_list, tmp) {
5456 if ( i++ == n ) {
5457 void *b = prelude_linked_object_get_object(tmp);
5458 prelude_string_destroy(b);
5459 return 0;
5460 }
5461 }
5462
5463 if ( i != n )
5464 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
5465 } else {
5466 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
5467
5468 prelude_list_for_each_reversed(&ptr->arg_list, tmp) {
5469 if ( i++ == pos ) {
5470 void *b = prelude_linked_object_get_object(tmp);
5471 prelude_string_destroy(b);
5472 return 0;
5473 }
5474 }
5475
5476 if ( i != pos )
5477 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
5478 }
5479 }
5480
5481 case 5: {
5482 int i = 0;
5483 prelude_list_t *tmp;
5484
5485 if ( n >= 0 ) {
5486 prelude_list_for_each(&ptr->env_list, tmp) {
5487 if ( i++ == n ) {
5488 void *b = prelude_linked_object_get_object(tmp);
5489 prelude_string_destroy(b);
5490 return 0;
5491 }
5492 }
5493
5494 if ( i != n )
5495 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
5496 } else {
5497 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
5498
5499 prelude_list_for_each_reversed(&ptr->env_list, tmp) {
5500 if ( i++ == pos ) {
5501 void *b = prelude_linked_object_get_object(tmp);
5502 prelude_string_destroy(b);
5503 return 0;
5504 }
5505 }
5506
5507 if ( i != pos )
5508 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
5509 }
5510 }
5511
5512 default:
5513 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
5514 }
5515 }
5516
idmef_process_destroy_internal(idmef_process_t * ptr)5517 static void idmef_process_destroy_internal(idmef_process_t *ptr)
5518 {
5519 prelude_return_if_fail(ptr);
5520
5521 if ( ptr->ident ) {
5522 prelude_string_destroy(ptr->ident);
5523 ptr->ident = NULL;
5524 }
5525
5526 if ( ptr->name ) {
5527 prelude_string_destroy(ptr->name);
5528 ptr->name = NULL;
5529 }
5530
5531 if ( ptr->path ) {
5532 prelude_string_destroy(ptr->path);
5533 ptr->path = NULL;
5534 }
5535
5536 {
5537 prelude_list_t *n, *tmp;
5538 prelude_string_t *entry;
5539
5540 prelude_list_for_each_safe(&ptr->arg_list, tmp, n) {
5541 entry = prelude_linked_object_get_object(tmp);
5542 prelude_list_del_init(tmp);
5543 prelude_string_destroy(entry);
5544 }
5545 }
5546
5547 {
5548 prelude_list_t *n, *tmp;
5549 prelude_string_t *entry;
5550
5551 prelude_list_for_each_safe(&ptr->env_list, tmp, n) {
5552 entry = prelude_linked_object_get_object(tmp);
5553 prelude_list_del_init(tmp);
5554 prelude_string_destroy(entry);
5555 }
5556 }
5557
5558
5559 /* free() should be done by the caller */
5560 }
5561
5562 /**
5563 * idmef_process_destroy:
5564 * @ptr: pointer to a #idmef_process_t object.
5565 *
5566 * Destroy @ptr and all of it's children.
5567 * The objects are only destroyed if their reference count reach zero.
5568 */
5569
idmef_process_destroy(idmef_process_t * ptr)5570 void idmef_process_destroy(idmef_process_t *ptr)
5571 {
5572 prelude_return_if_fail(ptr);
5573
5574 if ( --ptr->refcount )
5575 return;
5576
5577 idmef_process_destroy_internal(ptr);
5578 free(ptr);
5579 }
5580
5581 /**
5582 * idmef_process_get_ident:
5583 * @ptr: pointer to a #idmef_process_t object.
5584 *
5585 * Get ident children of the #idmef_process_t object.
5586 *
5587 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
5588 */
idmef_process_get_ident(idmef_process_t * ptr)5589 prelude_string_t *idmef_process_get_ident(idmef_process_t *ptr)
5590 {
5591 prelude_return_val_if_fail(ptr, 0); /* FIXME */
5592
5593 return ptr->ident;
5594 }
5595
5596 /**
5597 * idmef_process_set_ident:
5598 * @ptr: pointer to a #idmef_process_t object.
5599 * @ident: pointer to a #prelude_string_t object.
5600 *
5601 * Set @ident object as a children of @ptr.
5602 * if @ptr already contain an @ident object, then it is destroyed,
5603 * and updated to point to the provided @ident object.
5604 */
5605
idmef_process_set_ident(idmef_process_t * ptr,prelude_string_t * ident)5606 void idmef_process_set_ident(idmef_process_t *ptr, prelude_string_t *ident)
5607 {
5608 prelude_return_if_fail(ptr);
5609
5610 if ( ptr->ident )
5611 prelude_string_destroy(ptr->ident);
5612
5613 ptr->ident = ident;
5614 }
5615
5616 /**
5617 * idmef_process_new_ident:
5618 * @ptr: pointer to a #idmef_process_t object.
5619 * @ret: pointer to an address where to store the created #prelude_string_t object.
5620 *
5621 * Create a new ident object, children of #idmef_process_t.
5622 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
5623 *
5624 * Returns: 0 on success, or a negative value if an error occured.
5625 */
idmef_process_new_ident(idmef_process_t * ptr,prelude_string_t ** ret)5626 int idmef_process_new_ident(idmef_process_t *ptr, prelude_string_t **ret)
5627 {
5628 int retval;
5629
5630 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
5631
5632 if ( ! ptr->ident ) {
5633 retval = prelude_string_new(&ptr->ident);
5634 if ( retval < 0 )
5635 return retval;
5636 }
5637
5638 *ret = ptr->ident;
5639 return 0;
5640 }
5641
5642 /**
5643 * idmef_process_get_name:
5644 * @ptr: pointer to a #idmef_process_t object.
5645 *
5646 * Get name children of the #idmef_process_t object.
5647 *
5648 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
5649 */
idmef_process_get_name(idmef_process_t * ptr)5650 prelude_string_t *idmef_process_get_name(idmef_process_t *ptr)
5651 {
5652 prelude_return_val_if_fail(ptr, 0); /* FIXME */
5653
5654 return ptr->name;
5655 }
5656
5657 /**
5658 * idmef_process_set_name:
5659 * @ptr: pointer to a #idmef_process_t object.
5660 * @name: pointer to a #prelude_string_t object.
5661 *
5662 * Set @name object as a children of @ptr.
5663 * if @ptr already contain an @name object, then it is destroyed,
5664 * and updated to point to the provided @name object.
5665 */
5666
idmef_process_set_name(idmef_process_t * ptr,prelude_string_t * name)5667 void idmef_process_set_name(idmef_process_t *ptr, prelude_string_t *name)
5668 {
5669 prelude_return_if_fail(ptr);
5670
5671 if ( ptr->name )
5672 prelude_string_destroy(ptr->name);
5673
5674 ptr->name = name;
5675 }
5676
5677 /**
5678 * idmef_process_new_name:
5679 * @ptr: pointer to a #idmef_process_t object.
5680 * @ret: pointer to an address where to store the created #prelude_string_t object.
5681 *
5682 * Create a new name object, children of #idmef_process_t.
5683 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
5684 *
5685 * Returns: 0 on success, or a negative value if an error occured.
5686 */
idmef_process_new_name(idmef_process_t * ptr,prelude_string_t ** ret)5687 int idmef_process_new_name(idmef_process_t *ptr, prelude_string_t **ret)
5688 {
5689 int retval;
5690
5691 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
5692
5693 if ( ! ptr->name ) {
5694 retval = prelude_string_new(&ptr->name);
5695 if ( retval < 0 )
5696 return retval;
5697 }
5698
5699 *ret = ptr->name;
5700 return 0;
5701 }
5702
5703 /**
5704 * idmef_process_get_pid:
5705 * @ptr: pointer to a #idmef_process_t object.
5706 *
5707 * Get pid children of the #idmef_process_t object.
5708 *
5709 * Returns: a pointer to a uint32_t object, or NULL if the children object is not set.
5710 */
idmef_process_get_pid(idmef_process_t * ptr)5711 uint32_t *idmef_process_get_pid(idmef_process_t *ptr)
5712 {
5713 prelude_return_val_if_fail(ptr, 0); /* FIXME */
5714
5715 return ptr->pid_is_set ? &ptr->pid : NULL;
5716 }
5717
5718 /**
5719 * idmef_process_set_pid:
5720 * @ptr: pointer to a #idmef_process_t object.
5721 * @pid: pointer to a #uint32_t object.
5722 *
5723 * Set @pid object as a children of @ptr.
5724 * if @ptr already contain an @pid object, then it is destroyed,
5725 * and updated to point to the provided @pid object.
5726 */
5727
idmef_process_set_pid(idmef_process_t * ptr,uint32_t pid)5728 void idmef_process_set_pid(idmef_process_t *ptr, uint32_t pid)
5729 {
5730 prelude_return_if_fail(ptr);
5731 ptr->pid = pid;
5732 ptr->pid_is_set = 1;
5733 }
5734
5735
idmef_process_unset_pid(idmef_process_t * ptr)5736 void idmef_process_unset_pid(idmef_process_t *ptr)
5737 {
5738 prelude_return_if_fail(ptr);
5739 ptr->pid_is_set = 0;
5740 }
5741
5742
5743 /**
5744 * idmef_process_new_pid:
5745 * @ptr: pointer to a #idmef_process_t object.
5746 * @ret: pointer to an address where to store the created #uint32_t object.
5747 *
5748 * Create a new pid object, children of #idmef_process_t.
5749 * If @ptr already contain a #uint32_t object, then it is destroyed.
5750 *
5751 * Returns: 0 on success, or a negative value if an error occured.
5752 */
idmef_process_new_pid(idmef_process_t * ptr,uint32_t ** ret)5753 int idmef_process_new_pid(idmef_process_t *ptr, uint32_t **ret)
5754 {
5755 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
5756 ptr->pid_is_set = 1;
5757
5758 *ret = &ptr->pid;
5759 return 0;
5760 }
5761
5762 /**
5763 * idmef_process_get_path:
5764 * @ptr: pointer to a #idmef_process_t object.
5765 *
5766 * Get path children of the #idmef_process_t object.
5767 *
5768 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
5769 */
idmef_process_get_path(idmef_process_t * ptr)5770 prelude_string_t *idmef_process_get_path(idmef_process_t *ptr)
5771 {
5772 prelude_return_val_if_fail(ptr, 0); /* FIXME */
5773
5774 return ptr->path;
5775 }
5776
5777 /**
5778 * idmef_process_set_path:
5779 * @ptr: pointer to a #idmef_process_t object.
5780 * @path: pointer to a #prelude_string_t object.
5781 *
5782 * Set @path object as a children of @ptr.
5783 * if @ptr already contain an @path object, then it is destroyed,
5784 * and updated to point to the provided @path object.
5785 */
5786
idmef_process_set_path(idmef_process_t * ptr,prelude_string_t * path)5787 void idmef_process_set_path(idmef_process_t *ptr, prelude_string_t *path)
5788 {
5789 prelude_return_if_fail(ptr);
5790
5791 if ( ptr->path )
5792 prelude_string_destroy(ptr->path);
5793
5794 ptr->path = path;
5795 }
5796
5797 /**
5798 * idmef_process_new_path:
5799 * @ptr: pointer to a #idmef_process_t object.
5800 * @ret: pointer to an address where to store the created #prelude_string_t object.
5801 *
5802 * Create a new path object, children of #idmef_process_t.
5803 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
5804 *
5805 * Returns: 0 on success, or a negative value if an error occured.
5806 */
idmef_process_new_path(idmef_process_t * ptr,prelude_string_t ** ret)5807 int idmef_process_new_path(idmef_process_t *ptr, prelude_string_t **ret)
5808 {
5809 int retval;
5810
5811 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
5812
5813 if ( ! ptr->path ) {
5814 retval = prelude_string_new(&ptr->path);
5815 if ( retval < 0 )
5816 return retval;
5817 }
5818
5819 *ret = ptr->path;
5820 return 0;
5821 }
5822
5823 /**
5824 * idmef_process_get_next_arg:
5825 * @process: pointer to a #idmef_process_t object.
5826 * @prelude_string_cur: pointer to a #prelude_string_t object.
5827 *
5828 * Get the next #prelude_string_t object listed in @ptr.
5829 * When iterating over the prelude_string_t object listed in @ptr,
5830 * @object should be set to the latest returned #prelude_string_t object.
5831 *
5832 * Returns: the next #prelude_string_t in the list.
5833 */
idmef_process_get_next_arg(idmef_process_t * process,prelude_string_t * prelude_string_cur)5834 prelude_string_t *idmef_process_get_next_arg(idmef_process_t *process, prelude_string_t *prelude_string_cur)
5835 {
5836 prelude_list_t *tmp = (prelude_string_cur) ? &((prelude_linked_object_t *) prelude_string_cur)->_list : NULL;
5837
5838 prelude_return_val_if_fail(process, NULL);
5839
5840 prelude_list_for_each_continue(&process->arg_list, tmp)
5841 return prelude_linked_object_get_object(tmp);
5842
5843 return NULL;
5844 }
5845
5846
5847 /**
5848 * idmef_process_set_arg:
5849 * @ptr: pointer to a #idmef_process_t object.
5850 * @object: pointer to a #prelude_string_t object.
5851 * @pos: Position in the list.
5852 *
5853 * Add @object to position @pos of @ptr list of #prelude_string_t object.
5854 *
5855 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
5856 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
5857 */
idmef_process_set_arg(idmef_process_t * ptr,prelude_string_t * object,int pos)5858 void idmef_process_set_arg(idmef_process_t *ptr, prelude_string_t *object, int pos)
5859 {
5860 prelude_return_if_fail(ptr);
5861 prelude_return_if_fail(object);
5862
5863 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
5864 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
5865
5866 list_insert(&ptr->arg_list, &((prelude_linked_object_t *) object)->_list, pos);
5867 }
5868
5869
5870 /**
5871 * idmef_process_new_arg:
5872 * @ptr: pointer to a #idmef_process_t object.
5873 * @ret: pointer to an address where to store the created #prelude_string_t object.
5874 * @pos: position in the list.
5875 *
5876 * Create a new #prelude_string_t children of @ptr, and add it to position @pos of
5877 * @ptr list of #prelude_string_t object. The created #prelude_string_t object is
5878 * stored in @ret.
5879 *
5880 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
5881 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
5882 *
5883 * Returns: 0 on success, or a negative value if an error occured.
5884 */
idmef_process_new_arg(idmef_process_t * ptr,prelude_string_t ** ret,int pos)5885 int idmef_process_new_arg(idmef_process_t *ptr, prelude_string_t **ret, int pos)
5886 {
5887 int retval;
5888
5889 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
5890
5891 retval = prelude_string_new(ret);
5892 if ( retval < 0 )
5893 return retval;
5894
5895 list_insert(&ptr->arg_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
5896
5897 return 0;
5898 }
5899
5900
5901 /**
5902 * idmef_process_get_next_env:
5903 * @process: pointer to a #idmef_process_t object.
5904 * @prelude_string_cur: pointer to a #prelude_string_t object.
5905 *
5906 * Get the next #prelude_string_t object listed in @ptr.
5907 * When iterating over the prelude_string_t object listed in @ptr,
5908 * @object should be set to the latest returned #prelude_string_t object.
5909 *
5910 * Returns: the next #prelude_string_t in the list.
5911 */
idmef_process_get_next_env(idmef_process_t * process,prelude_string_t * prelude_string_cur)5912 prelude_string_t *idmef_process_get_next_env(idmef_process_t *process, prelude_string_t *prelude_string_cur)
5913 {
5914 prelude_list_t *tmp = (prelude_string_cur) ? &((prelude_linked_object_t *) prelude_string_cur)->_list : NULL;
5915
5916 prelude_return_val_if_fail(process, NULL);
5917
5918 prelude_list_for_each_continue(&process->env_list, tmp)
5919 return prelude_linked_object_get_object(tmp);
5920
5921 return NULL;
5922 }
5923
5924
5925 /**
5926 * idmef_process_set_env:
5927 * @ptr: pointer to a #idmef_process_t object.
5928 * @object: pointer to a #prelude_string_t object.
5929 * @pos: Position in the list.
5930 *
5931 * Add @object to position @pos of @ptr list of #prelude_string_t object.
5932 *
5933 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
5934 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
5935 */
idmef_process_set_env(idmef_process_t * ptr,prelude_string_t * object,int pos)5936 void idmef_process_set_env(idmef_process_t *ptr, prelude_string_t *object, int pos)
5937 {
5938 prelude_return_if_fail(ptr);
5939 prelude_return_if_fail(object);
5940
5941 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
5942 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
5943
5944 list_insert(&ptr->env_list, &((prelude_linked_object_t *) object)->_list, pos);
5945 }
5946
5947
5948 /**
5949 * idmef_process_new_env:
5950 * @ptr: pointer to a #idmef_process_t object.
5951 * @ret: pointer to an address where to store the created #prelude_string_t object.
5952 * @pos: position in the list.
5953 *
5954 * Create a new #prelude_string_t children of @ptr, and add it to position @pos of
5955 * @ptr list of #prelude_string_t object. The created #prelude_string_t object is
5956 * stored in @ret.
5957 *
5958 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
5959 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
5960 *
5961 * Returns: 0 on success, or a negative value if an error occured.
5962 */
idmef_process_new_env(idmef_process_t * ptr,prelude_string_t ** ret,int pos)5963 int idmef_process_new_env(idmef_process_t *ptr, prelude_string_t **ret, int pos)
5964 {
5965 int retval;
5966
5967 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
5968
5969 retval = prelude_string_new(ret);
5970 if ( retval < 0 )
5971 return retval;
5972
5973 list_insert(&ptr->env_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
5974
5975 return 0;
5976 }
5977
5978
5979 /**
5980 * idmef_process_copy:
5981 * @src: Source of the copy.
5982 * @dst: Where to copy the object.
5983 *
5984 * Copy a new #idmef_process_t object from @src to @dst.
5985 *
5986 * Returns: 0 on success, a negative value if an error occured.
5987 */
idmef_process_copy(const idmef_process_t * src,idmef_process_t * dst)5988 int idmef_process_copy(const idmef_process_t *src, idmef_process_t *dst)
5989 {
5990 int ret;
5991
5992 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
5993 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
5994
5995 ret = 0;
5996
5997 if ( src->ident ) {
5998 ret = prelude_string_clone(src->ident, &dst->ident);
5999 if ( ret < 0 )
6000 return ret;
6001 }
6002
6003 if ( src->name ) {
6004 ret = prelude_string_copy(src->name, dst->name);
6005 if ( ret < 0 )
6006 return ret;
6007 }
6008
6009 dst->pid_is_set = src->pid_is_set;
6010
6011 dst->pid = src->pid;
6012
6013 if ( src->path ) {
6014 ret = prelude_string_clone(src->path, &dst->path);
6015 if ( ret < 0 )
6016 return ret;
6017 }
6018
6019 {
6020 prelude_list_t *n, *tmp;
6021 prelude_string_t *entry, *new;
6022
6023 prelude_list_for_each_safe(&src->arg_list, tmp, n) {
6024 entry = prelude_linked_object_get_object(tmp);
6025 prelude_string_clone(entry, &new);
6026 prelude_list_add_tail(&dst->arg_list, &((prelude_linked_object_t *) new)->_list);
6027 }
6028 }
6029
6030 {
6031 prelude_list_t *n, *tmp;
6032 prelude_string_t *entry, *new;
6033
6034 prelude_list_for_each_safe(&src->env_list, tmp, n) {
6035 entry = prelude_linked_object_get_object(tmp);
6036 prelude_string_clone(entry, &new);
6037 prelude_list_add_tail(&dst->env_list, &((prelude_linked_object_t *) new)->_list);
6038 }
6039 }
6040
6041 return 0;
6042 }
6043
6044 /**
6045 * idmef_process_clone:
6046 * @src: Object to be cloned.
6047 * @dst: Address where to store the pointer to the cloned object.
6048 *
6049 * Create a copy of @src, and store it in @dst.
6050 *
6051 * Returns: 0 on success, a negative value if an error occured.
6052 */
idmef_process_clone(idmef_process_t * src,idmef_process_t ** dst)6053 int idmef_process_clone(idmef_process_t *src, idmef_process_t **dst)
6054 {
6055 int ret;
6056
6057 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
6058
6059 ret = idmef_process_new(dst);
6060 if ( ret < 0 )
6061 return ret;
6062
6063 return idmef_process_copy(src, *dst);
6064 }
6065
6066 /**
6067 * idmef_process_compare:
6068 * @obj1: Object to compare with @obj2.
6069 * @obj2: Object to compare with @obj1.
6070 *
6071 * Compare @obj1 with @obj2.
6072 *
6073 * Returns: 0 on match, a negative value on comparison failure.
6074 */
idmef_process_compare(const idmef_process_t * obj1,const idmef_process_t * obj2)6075 int idmef_process_compare(const idmef_process_t *obj1, const idmef_process_t *obj2)
6076 {
6077 int ret = 0;
6078
6079 if ( obj1 == NULL && obj2 == NULL )
6080 return 0;
6081
6082 else if ( obj1 == NULL || obj2 == NULL )
6083 return -1;
6084
6085 ret = prelude_string_compare(obj1->ident, obj2->ident);
6086 if ( ret != 0 )
6087 return ret;
6088
6089 ret = prelude_string_compare(obj1->name, obj2->name);
6090 if ( ret != 0 )
6091 return ret;
6092
6093 if ( obj1->pid_is_set != obj2->pid_is_set )
6094 return -1;
6095
6096 if ( obj1->pid_is_set && obj1->pid != obj2->pid )
6097 return -1;
6098
6099 ret = prelude_string_compare(obj1->path, obj2->path);
6100 if ( ret != 0 )
6101 return ret;
6102
6103 {
6104 prelude_list_t *tmp1, *tmp2;
6105 prelude_string_t *entry1, *entry2;
6106
6107 tmp1 = tmp2 = NULL;
6108 do {
6109 entry1 = entry2 = NULL;
6110
6111 prelude_list_for_each_continue(&obj1->arg_list, tmp1) {
6112 entry1 = prelude_linked_object_get_object(tmp1);
6113 break;
6114 }
6115
6116 prelude_list_for_each_continue(&obj2->arg_list, tmp2) {
6117 entry2 = prelude_linked_object_get_object(tmp2);
6118 break;
6119 }
6120
6121 ret = prelude_string_compare(entry1, entry2);
6122 if ( ret != 0 )
6123 return ret;
6124
6125 } while ( entry1 && entry2 );
6126 }
6127
6128 {
6129 prelude_list_t *tmp1, *tmp2;
6130 prelude_string_t *entry1, *entry2;
6131
6132 tmp1 = tmp2 = NULL;
6133 do {
6134 entry1 = entry2 = NULL;
6135
6136 prelude_list_for_each_continue(&obj1->env_list, tmp1) {
6137 entry1 = prelude_linked_object_get_object(tmp1);
6138 break;
6139 }
6140
6141 prelude_list_for_each_continue(&obj2->env_list, tmp2) {
6142 entry2 = prelude_linked_object_get_object(tmp2);
6143 break;
6144 }
6145
6146 ret = prelude_string_compare(entry1, entry2);
6147 if ( ret != 0 )
6148 return ret;
6149
6150 } while ( entry1 && entry2 );
6151 }
6152
6153 return ret;
6154 }
6155
6156 /**
6157 * idmef_web_service_new:
6158 * @ret: Pointer where to store the created #idmef_web_service_t object.
6159 *
6160 * Create a new #idmef_web_service_t object.
6161 *
6162 * Returns: 0 on success, a negative value if an error occured.
6163 */
idmef_web_service_new(idmef_web_service_t ** ret)6164 int idmef_web_service_new(idmef_web_service_t **ret)
6165 {
6166 *ret = calloc(1, sizeof(**ret));
6167 if ( ! *ret )
6168 return prelude_error_from_errno(errno);
6169
6170 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_WEB_SERVICE;
6171
6172 (*ret)->refcount = 1;
6173
6174 prelude_list_init(&(*ret)->arg_list);
6175
6176
6177 {
6178 int retval = prelude_string_new(&(*ret)->url);
6179
6180 if ( retval < 0 ) {
6181 idmef_web_service_destroy(*ret);
6182 *ret = NULL;
6183 return retval;
6184 }
6185 }
6186
6187 return 0;
6188
6189 }
6190
6191 /**
6192 * idmef_web_service_ref:
6193 * @web_service: pointer to a #idmef_web_service_t object.
6194 *
6195 * Increase @web_service reference count, so that it can be referenced
6196 * multiple time.
6197 *
6198 * Returns: a pointer to @web_service.
6199 */
idmef_web_service_ref(idmef_web_service_t * web_service)6200 idmef_web_service_t *idmef_web_service_ref(idmef_web_service_t *web_service)
6201 {
6202 prelude_return_val_if_fail(web_service, NULL);
6203 web_service->refcount++;
6204
6205 return web_service;
6206 }
6207
_idmef_web_service_get_child(void * p,idmef_class_child_id_t child,void ** childptr)6208 int _idmef_web_service_get_child(void *p, idmef_class_child_id_t child, void **childptr)
6209 {
6210 idmef_web_service_t *ptr = p;
6211
6212 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
6213 *childptr = NULL;
6214
6215 switch ( child ) {
6216
6217 case 0:
6218 return get_value_from_string((idmef_value_t **) childptr, ptr->url, TRUE);
6219 case 1:
6220 return get_value_from_string((idmef_value_t **) childptr, ptr->cgi, TRUE);
6221 case 2:
6222 return get_value_from_string((idmef_value_t **) childptr, ptr->http_method, TRUE);
6223 case 3:
6224 *childptr = &ptr->arg_list;
6225 return 0;
6226
6227 default:
6228 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
6229 }
6230 }
6231
_idmef_web_service_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)6232 int _idmef_web_service_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
6233 {
6234 idmef_web_service_t *ptr = p;
6235
6236 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
6237
6238 switch ( child ) {
6239
6240 case 0:
6241 return idmef_web_service_new_url(ptr, (prelude_string_t **) ret);
6242
6243 case 1:
6244 return idmef_web_service_new_cgi(ptr, (prelude_string_t **) ret);
6245
6246 case 2:
6247 return idmef_web_service_new_http_method(ptr, (prelude_string_t **) ret);
6248
6249 case 3: {
6250 int i = 0;
6251 prelude_list_t *tmp;
6252
6253 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
6254 return idmef_web_service_new_arg(ptr, (prelude_string_t **) ret, n);
6255
6256 if ( n >= 0 ) {
6257 prelude_list_for_each(&ptr->arg_list, tmp) {
6258 if ( i++ == n ) {
6259 *ret = prelude_linked_object_get_object(tmp);
6260 return 0;
6261 }
6262 }
6263
6264 if ( i != n )
6265 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
6266 } else {
6267 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
6268
6269 prelude_list_for_each_reversed(&ptr->arg_list, tmp) {
6270 if ( i++ == pos ) {
6271 *ret = prelude_linked_object_get_object(tmp);
6272 return 0;
6273 }
6274 }
6275
6276 if ( i != pos )
6277 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
6278 }
6279
6280 return idmef_web_service_new_arg(ptr, (prelude_string_t **) ret, n);
6281 }
6282
6283 default:
6284 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
6285 }
6286 }
6287
_idmef_web_service_destroy_child(void * p,idmef_class_child_id_t child,int n)6288 int _idmef_web_service_destroy_child(void *p, idmef_class_child_id_t child, int n)
6289 {
6290 idmef_web_service_t *ptr = p;
6291
6292 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
6293
6294 switch ( child ) {
6295
6296 case 0:
6297 if ( ptr->url ) {
6298 prelude_string_destroy(ptr->url);
6299 ptr->url = NULL;
6300 }
6301
6302 return 0;
6303
6304 case 1:
6305 if ( ptr->cgi ) {
6306 prelude_string_destroy(ptr->cgi);
6307 ptr->cgi = NULL;
6308 }
6309
6310 return 0;
6311
6312 case 2:
6313 if ( ptr->http_method ) {
6314 prelude_string_destroy(ptr->http_method);
6315 ptr->http_method = NULL;
6316 }
6317
6318 return 0;
6319
6320 case 3: {
6321 int i = 0;
6322 prelude_list_t *tmp;
6323
6324 if ( n >= 0 ) {
6325 prelude_list_for_each(&ptr->arg_list, tmp) {
6326 if ( i++ == n ) {
6327 void *b = prelude_linked_object_get_object(tmp);
6328 prelude_string_destroy(b);
6329 return 0;
6330 }
6331 }
6332
6333 if ( i != n )
6334 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
6335 } else {
6336 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
6337
6338 prelude_list_for_each_reversed(&ptr->arg_list, tmp) {
6339 if ( i++ == pos ) {
6340 void *b = prelude_linked_object_get_object(tmp);
6341 prelude_string_destroy(b);
6342 return 0;
6343 }
6344 }
6345
6346 if ( i != pos )
6347 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
6348 }
6349 }
6350
6351 default:
6352 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
6353 }
6354 }
6355
idmef_web_service_destroy_internal(idmef_web_service_t * ptr)6356 static void idmef_web_service_destroy_internal(idmef_web_service_t *ptr)
6357 {
6358 prelude_return_if_fail(ptr);
6359
6360 if ( ptr->url ) {
6361 prelude_string_destroy(ptr->url);
6362 ptr->url = NULL;
6363 }
6364
6365 if ( ptr->cgi ) {
6366 prelude_string_destroy(ptr->cgi);
6367 ptr->cgi = NULL;
6368 }
6369
6370 if ( ptr->http_method ) {
6371 prelude_string_destroy(ptr->http_method);
6372 ptr->http_method = NULL;
6373 }
6374
6375 {
6376 prelude_list_t *n, *tmp;
6377 prelude_string_t *entry;
6378
6379 prelude_list_for_each_safe(&ptr->arg_list, tmp, n) {
6380 entry = prelude_linked_object_get_object(tmp);
6381 prelude_list_del_init(tmp);
6382 prelude_string_destroy(entry);
6383 }
6384 }
6385
6386
6387 /* free() should be done by the caller */
6388 }
6389
6390 /**
6391 * idmef_web_service_destroy:
6392 * @ptr: pointer to a #idmef_web_service_t object.
6393 *
6394 * Destroy @ptr and all of it's children.
6395 * The objects are only destroyed if their reference count reach zero.
6396 */
6397
idmef_web_service_destroy(idmef_web_service_t * ptr)6398 void idmef_web_service_destroy(idmef_web_service_t *ptr)
6399 {
6400 prelude_return_if_fail(ptr);
6401
6402 if ( --ptr->refcount )
6403 return;
6404
6405 idmef_web_service_destroy_internal(ptr);
6406 free(ptr);
6407 }
6408
6409 /**
6410 * idmef_web_service_get_url:
6411 * @ptr: pointer to a #idmef_web_service_t object.
6412 *
6413 * Get url children of the #idmef_web_service_t object.
6414 *
6415 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
6416 */
idmef_web_service_get_url(idmef_web_service_t * ptr)6417 prelude_string_t *idmef_web_service_get_url(idmef_web_service_t *ptr)
6418 {
6419 prelude_return_val_if_fail(ptr, 0); /* FIXME */
6420
6421 return ptr->url;
6422 }
6423
6424 /**
6425 * idmef_web_service_set_url:
6426 * @ptr: pointer to a #idmef_web_service_t object.
6427 * @url: pointer to a #prelude_string_t object.
6428 *
6429 * Set @url object as a children of @ptr.
6430 * if @ptr already contain an @url object, then it is destroyed,
6431 * and updated to point to the provided @url object.
6432 */
6433
idmef_web_service_set_url(idmef_web_service_t * ptr,prelude_string_t * url)6434 void idmef_web_service_set_url(idmef_web_service_t *ptr, prelude_string_t *url)
6435 {
6436 prelude_return_if_fail(ptr);
6437
6438 if ( ptr->url )
6439 prelude_string_destroy(ptr->url);
6440
6441 ptr->url = url;
6442 }
6443
6444 /**
6445 * idmef_web_service_new_url:
6446 * @ptr: pointer to a #idmef_web_service_t object.
6447 * @ret: pointer to an address where to store the created #prelude_string_t object.
6448 *
6449 * Create a new url object, children of #idmef_web_service_t.
6450 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
6451 *
6452 * Returns: 0 on success, or a negative value if an error occured.
6453 */
idmef_web_service_new_url(idmef_web_service_t * ptr,prelude_string_t ** ret)6454 int idmef_web_service_new_url(idmef_web_service_t *ptr, prelude_string_t **ret)
6455 {
6456 int retval;
6457
6458 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
6459
6460 if ( ! ptr->url ) {
6461 retval = prelude_string_new(&ptr->url);
6462 if ( retval < 0 )
6463 return retval;
6464 }
6465
6466 *ret = ptr->url;
6467 return 0;
6468 }
6469
6470 /**
6471 * idmef_web_service_get_cgi:
6472 * @ptr: pointer to a #idmef_web_service_t object.
6473 *
6474 * Get cgi children of the #idmef_web_service_t object.
6475 *
6476 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
6477 */
idmef_web_service_get_cgi(idmef_web_service_t * ptr)6478 prelude_string_t *idmef_web_service_get_cgi(idmef_web_service_t *ptr)
6479 {
6480 prelude_return_val_if_fail(ptr, 0); /* FIXME */
6481
6482 return ptr->cgi;
6483 }
6484
6485 /**
6486 * idmef_web_service_set_cgi:
6487 * @ptr: pointer to a #idmef_web_service_t object.
6488 * @cgi: pointer to a #prelude_string_t object.
6489 *
6490 * Set @cgi object as a children of @ptr.
6491 * if @ptr already contain an @cgi object, then it is destroyed,
6492 * and updated to point to the provided @cgi object.
6493 */
6494
idmef_web_service_set_cgi(idmef_web_service_t * ptr,prelude_string_t * cgi)6495 void idmef_web_service_set_cgi(idmef_web_service_t *ptr, prelude_string_t *cgi)
6496 {
6497 prelude_return_if_fail(ptr);
6498
6499 if ( ptr->cgi )
6500 prelude_string_destroy(ptr->cgi);
6501
6502 ptr->cgi = cgi;
6503 }
6504
6505 /**
6506 * idmef_web_service_new_cgi:
6507 * @ptr: pointer to a #idmef_web_service_t object.
6508 * @ret: pointer to an address where to store the created #prelude_string_t object.
6509 *
6510 * Create a new cgi object, children of #idmef_web_service_t.
6511 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
6512 *
6513 * Returns: 0 on success, or a negative value if an error occured.
6514 */
idmef_web_service_new_cgi(idmef_web_service_t * ptr,prelude_string_t ** ret)6515 int idmef_web_service_new_cgi(idmef_web_service_t *ptr, prelude_string_t **ret)
6516 {
6517 int retval;
6518
6519 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
6520
6521 if ( ! ptr->cgi ) {
6522 retval = prelude_string_new(&ptr->cgi);
6523 if ( retval < 0 )
6524 return retval;
6525 }
6526
6527 *ret = ptr->cgi;
6528 return 0;
6529 }
6530
6531 /**
6532 * idmef_web_service_get_http_method:
6533 * @ptr: pointer to a #idmef_web_service_t object.
6534 *
6535 * Get http_method children of the #idmef_web_service_t object.
6536 *
6537 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
6538 */
idmef_web_service_get_http_method(idmef_web_service_t * ptr)6539 prelude_string_t *idmef_web_service_get_http_method(idmef_web_service_t *ptr)
6540 {
6541 prelude_return_val_if_fail(ptr, 0); /* FIXME */
6542
6543 return ptr->http_method;
6544 }
6545
6546 /**
6547 * idmef_web_service_set_http_method:
6548 * @ptr: pointer to a #idmef_web_service_t object.
6549 * @http_method: pointer to a #prelude_string_t object.
6550 *
6551 * Set @http_method object as a children of @ptr.
6552 * if @ptr already contain an @http_method object, then it is destroyed,
6553 * and updated to point to the provided @http_method object.
6554 */
6555
idmef_web_service_set_http_method(idmef_web_service_t * ptr,prelude_string_t * http_method)6556 void idmef_web_service_set_http_method(idmef_web_service_t *ptr, prelude_string_t *http_method)
6557 {
6558 prelude_return_if_fail(ptr);
6559
6560 if ( ptr->http_method )
6561 prelude_string_destroy(ptr->http_method);
6562
6563 ptr->http_method = http_method;
6564 }
6565
6566 /**
6567 * idmef_web_service_new_http_method:
6568 * @ptr: pointer to a #idmef_web_service_t object.
6569 * @ret: pointer to an address where to store the created #prelude_string_t object.
6570 *
6571 * Create a new http_method object, children of #idmef_web_service_t.
6572 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
6573 *
6574 * Returns: 0 on success, or a negative value if an error occured.
6575 */
idmef_web_service_new_http_method(idmef_web_service_t * ptr,prelude_string_t ** ret)6576 int idmef_web_service_new_http_method(idmef_web_service_t *ptr, prelude_string_t **ret)
6577 {
6578 int retval;
6579
6580 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
6581
6582 if ( ! ptr->http_method ) {
6583 retval = prelude_string_new(&ptr->http_method);
6584 if ( retval < 0 )
6585 return retval;
6586 }
6587
6588 *ret = ptr->http_method;
6589 return 0;
6590 }
6591
6592 /**
6593 * idmef_web_service_get_next_arg:
6594 * @web_service: pointer to a #idmef_web_service_t object.
6595 * @prelude_string_cur: pointer to a #prelude_string_t object.
6596 *
6597 * Get the next #prelude_string_t object listed in @ptr.
6598 * When iterating over the prelude_string_t object listed in @ptr,
6599 * @object should be set to the latest returned #prelude_string_t object.
6600 *
6601 * Returns: the next #prelude_string_t in the list.
6602 */
idmef_web_service_get_next_arg(idmef_web_service_t * web_service,prelude_string_t * prelude_string_cur)6603 prelude_string_t *idmef_web_service_get_next_arg(idmef_web_service_t *web_service, prelude_string_t *prelude_string_cur)
6604 {
6605 prelude_list_t *tmp = (prelude_string_cur) ? &((prelude_linked_object_t *) prelude_string_cur)->_list : NULL;
6606
6607 prelude_return_val_if_fail(web_service, NULL);
6608
6609 prelude_list_for_each_continue(&web_service->arg_list, tmp)
6610 return prelude_linked_object_get_object(tmp);
6611
6612 return NULL;
6613 }
6614
6615
6616 /**
6617 * idmef_web_service_set_arg:
6618 * @ptr: pointer to a #idmef_web_service_t object.
6619 * @object: pointer to a #prelude_string_t object.
6620 * @pos: Position in the list.
6621 *
6622 * Add @object to position @pos of @ptr list of #prelude_string_t object.
6623 *
6624 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
6625 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
6626 */
idmef_web_service_set_arg(idmef_web_service_t * ptr,prelude_string_t * object,int pos)6627 void idmef_web_service_set_arg(idmef_web_service_t *ptr, prelude_string_t *object, int pos)
6628 {
6629 prelude_return_if_fail(ptr);
6630 prelude_return_if_fail(object);
6631
6632 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
6633 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
6634
6635 list_insert(&ptr->arg_list, &((prelude_linked_object_t *) object)->_list, pos);
6636 }
6637
6638
6639 /**
6640 * idmef_web_service_new_arg:
6641 * @ptr: pointer to a #idmef_web_service_t object.
6642 * @ret: pointer to an address where to store the created #prelude_string_t object.
6643 * @pos: position in the list.
6644 *
6645 * Create a new #prelude_string_t children of @ptr, and add it to position @pos of
6646 * @ptr list of #prelude_string_t object. The created #prelude_string_t object is
6647 * stored in @ret.
6648 *
6649 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
6650 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
6651 *
6652 * Returns: 0 on success, or a negative value if an error occured.
6653 */
idmef_web_service_new_arg(idmef_web_service_t * ptr,prelude_string_t ** ret,int pos)6654 int idmef_web_service_new_arg(idmef_web_service_t *ptr, prelude_string_t **ret, int pos)
6655 {
6656 int retval;
6657
6658 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
6659
6660 retval = prelude_string_new(ret);
6661 if ( retval < 0 )
6662 return retval;
6663
6664 list_insert(&ptr->arg_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
6665
6666 return 0;
6667 }
6668
6669
6670 /**
6671 * idmef_web_service_copy:
6672 * @src: Source of the copy.
6673 * @dst: Where to copy the object.
6674 *
6675 * Copy a new #idmef_web_service_t object from @src to @dst.
6676 *
6677 * Returns: 0 on success, a negative value if an error occured.
6678 */
idmef_web_service_copy(const idmef_web_service_t * src,idmef_web_service_t * dst)6679 int idmef_web_service_copy(const idmef_web_service_t *src, idmef_web_service_t *dst)
6680 {
6681 int ret;
6682
6683 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
6684 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
6685
6686 ret = 0;
6687
6688 if ( src->url ) {
6689 ret = prelude_string_copy(src->url, dst->url);
6690 if ( ret < 0 )
6691 return ret;
6692 }
6693
6694 if ( src->cgi ) {
6695 ret = prelude_string_clone(src->cgi, &dst->cgi);
6696 if ( ret < 0 )
6697 return ret;
6698 }
6699
6700 if ( src->http_method ) {
6701 ret = prelude_string_clone(src->http_method, &dst->http_method);
6702 if ( ret < 0 )
6703 return ret;
6704 }
6705
6706 {
6707 prelude_list_t *n, *tmp;
6708 prelude_string_t *entry, *new;
6709
6710 prelude_list_for_each_safe(&src->arg_list, tmp, n) {
6711 entry = prelude_linked_object_get_object(tmp);
6712 prelude_string_clone(entry, &new);
6713 prelude_list_add_tail(&dst->arg_list, &((prelude_linked_object_t *) new)->_list);
6714 }
6715 }
6716
6717 return 0;
6718 }
6719
6720 /**
6721 * idmef_web_service_clone:
6722 * @src: Object to be cloned.
6723 * @dst: Address where to store the pointer to the cloned object.
6724 *
6725 * Create a copy of @src, and store it in @dst.
6726 *
6727 * Returns: 0 on success, a negative value if an error occured.
6728 */
idmef_web_service_clone(idmef_web_service_t * src,idmef_web_service_t ** dst)6729 int idmef_web_service_clone(idmef_web_service_t *src, idmef_web_service_t **dst)
6730 {
6731 int ret;
6732
6733 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
6734
6735 ret = idmef_web_service_new(dst);
6736 if ( ret < 0 )
6737 return ret;
6738
6739 return idmef_web_service_copy(src, *dst);
6740 }
6741
6742 /**
6743 * idmef_web_service_compare:
6744 * @obj1: Object to compare with @obj2.
6745 * @obj2: Object to compare with @obj1.
6746 *
6747 * Compare @obj1 with @obj2.
6748 *
6749 * Returns: 0 on match, a negative value on comparison failure.
6750 */
idmef_web_service_compare(const idmef_web_service_t * obj1,const idmef_web_service_t * obj2)6751 int idmef_web_service_compare(const idmef_web_service_t *obj1, const idmef_web_service_t *obj2)
6752 {
6753 int ret = 0;
6754
6755 if ( obj1 == NULL && obj2 == NULL )
6756 return 0;
6757
6758 else if ( obj1 == NULL || obj2 == NULL )
6759 return -1;
6760
6761 ret = prelude_string_compare(obj1->url, obj2->url);
6762 if ( ret != 0 )
6763 return ret;
6764
6765 ret = prelude_string_compare(obj1->cgi, obj2->cgi);
6766 if ( ret != 0 )
6767 return ret;
6768
6769 ret = prelude_string_compare(obj1->http_method, obj2->http_method);
6770 if ( ret != 0 )
6771 return ret;
6772
6773 {
6774 prelude_list_t *tmp1, *tmp2;
6775 prelude_string_t *entry1, *entry2;
6776
6777 tmp1 = tmp2 = NULL;
6778 do {
6779 entry1 = entry2 = NULL;
6780
6781 prelude_list_for_each_continue(&obj1->arg_list, tmp1) {
6782 entry1 = prelude_linked_object_get_object(tmp1);
6783 break;
6784 }
6785
6786 prelude_list_for_each_continue(&obj2->arg_list, tmp2) {
6787 entry2 = prelude_linked_object_get_object(tmp2);
6788 break;
6789 }
6790
6791 ret = prelude_string_compare(entry1, entry2);
6792 if ( ret != 0 )
6793 return ret;
6794
6795 } while ( entry1 && entry2 );
6796 }
6797
6798 return ret;
6799 }
6800
6801 /**
6802 * idmef_snmp_service_new:
6803 * @ret: Pointer where to store the created #idmef_snmp_service_t object.
6804 *
6805 * Create a new #idmef_snmp_service_t object.
6806 *
6807 * Returns: 0 on success, a negative value if an error occured.
6808 */
idmef_snmp_service_new(idmef_snmp_service_t ** ret)6809 int idmef_snmp_service_new(idmef_snmp_service_t **ret)
6810 {
6811 *ret = calloc(1, sizeof(**ret));
6812 if ( ! *ret )
6813 return prelude_error_from_errno(errno);
6814
6815 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_SNMP_SERVICE;
6816
6817 (*ret)->refcount = 1;
6818
6819 return 0;
6820
6821 }
6822
6823 /**
6824 * idmef_snmp_service_ref:
6825 * @snmp_service: pointer to a #idmef_snmp_service_t object.
6826 *
6827 * Increase @snmp_service reference count, so that it can be referenced
6828 * multiple time.
6829 *
6830 * Returns: a pointer to @snmp_service.
6831 */
idmef_snmp_service_ref(idmef_snmp_service_t * snmp_service)6832 idmef_snmp_service_t *idmef_snmp_service_ref(idmef_snmp_service_t *snmp_service)
6833 {
6834 prelude_return_val_if_fail(snmp_service, NULL);
6835 snmp_service->refcount++;
6836
6837 return snmp_service;
6838 }
6839
_idmef_snmp_service_get_child(void * p,idmef_class_child_id_t child,void ** childptr)6840 int _idmef_snmp_service_get_child(void *p, idmef_class_child_id_t child, void **childptr)
6841 {
6842 idmef_snmp_service_t *ptr = p;
6843
6844 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
6845 *childptr = NULL;
6846
6847 switch ( child ) {
6848
6849 case 0:
6850 return get_value_from_string((idmef_value_t **) childptr, ptr->oid, TRUE);
6851 case 1:
6852 return (ptr->message_processing_model_is_set) ? idmef_value_new_uint32((idmef_value_t **) childptr, ptr->message_processing_model) : 0;
6853
6854 case 2:
6855 return (ptr->security_model_is_set) ? idmef_value_new_uint32((idmef_value_t **) childptr, ptr->security_model) : 0;
6856
6857 case 3:
6858 return get_value_from_string((idmef_value_t **) childptr, ptr->security_name, TRUE);
6859 case 4:
6860 return (ptr->security_level_is_set) ? idmef_value_new_uint32((idmef_value_t **) childptr, ptr->security_level) : 0;
6861
6862 case 5:
6863 return get_value_from_string((idmef_value_t **) childptr, ptr->context_name, TRUE);
6864 case 6:
6865 return get_value_from_string((idmef_value_t **) childptr, ptr->context_engine_id, TRUE);
6866 case 7:
6867 return get_value_from_string((idmef_value_t **) childptr, ptr->command, TRUE);
6868 case 8:
6869 return get_value_from_string((idmef_value_t **) childptr, ptr->community, TRUE);
6870 default:
6871 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
6872 }
6873 }
6874
_idmef_snmp_service_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)6875 int _idmef_snmp_service_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
6876 {
6877 idmef_snmp_service_t *ptr = p;
6878
6879 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
6880
6881 switch ( child ) {
6882
6883 case 0:
6884 return idmef_snmp_service_new_oid(ptr, (prelude_string_t **) ret);
6885
6886 case 1:
6887 return idmef_snmp_service_new_message_processing_model(ptr, (uint32_t **) ret);
6888
6889 case 2:
6890 return idmef_snmp_service_new_security_model(ptr, (uint32_t **) ret);
6891
6892 case 3:
6893 return idmef_snmp_service_new_security_name(ptr, (prelude_string_t **) ret);
6894
6895 case 4:
6896 return idmef_snmp_service_new_security_level(ptr, (uint32_t **) ret);
6897
6898 case 5:
6899 return idmef_snmp_service_new_context_name(ptr, (prelude_string_t **) ret);
6900
6901 case 6:
6902 return idmef_snmp_service_new_context_engine_id(ptr, (prelude_string_t **) ret);
6903
6904 case 7:
6905 return idmef_snmp_service_new_command(ptr, (prelude_string_t **) ret);
6906
6907 case 8:
6908 return idmef_snmp_service_new_community(ptr, (prelude_string_t **) ret);
6909
6910 default:
6911 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
6912 }
6913 }
6914
_idmef_snmp_service_destroy_child(void * p,idmef_class_child_id_t child,int n)6915 int _idmef_snmp_service_destroy_child(void *p, idmef_class_child_id_t child, int n)
6916 {
6917 idmef_snmp_service_t *ptr = p;
6918
6919 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
6920
6921 switch ( child ) {
6922
6923 case 0:
6924 if ( ptr->oid ) {
6925 prelude_string_destroy(ptr->oid);
6926 ptr->oid = NULL;
6927 }
6928
6929 return 0;
6930
6931 case 1:
6932 ptr->message_processing_model_is_set = 0;
6933 return 0;
6934
6935 case 2:
6936 ptr->security_model_is_set = 0;
6937 return 0;
6938
6939 case 3:
6940 if ( ptr->security_name ) {
6941 prelude_string_destroy(ptr->security_name);
6942 ptr->security_name = NULL;
6943 }
6944
6945 return 0;
6946
6947 case 4:
6948 ptr->security_level_is_set = 0;
6949 return 0;
6950
6951 case 5:
6952 if ( ptr->context_name ) {
6953 prelude_string_destroy(ptr->context_name);
6954 ptr->context_name = NULL;
6955 }
6956
6957 return 0;
6958
6959 case 6:
6960 if ( ptr->context_engine_id ) {
6961 prelude_string_destroy(ptr->context_engine_id);
6962 ptr->context_engine_id = NULL;
6963 }
6964
6965 return 0;
6966
6967 case 7:
6968 if ( ptr->command ) {
6969 prelude_string_destroy(ptr->command);
6970 ptr->command = NULL;
6971 }
6972
6973 return 0;
6974
6975 case 8:
6976 if ( ptr->community ) {
6977 prelude_string_destroy(ptr->community);
6978 ptr->community = NULL;
6979 }
6980
6981 return 0;
6982
6983 default:
6984 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
6985 }
6986 }
6987
idmef_snmp_service_destroy_internal(idmef_snmp_service_t * ptr)6988 static void idmef_snmp_service_destroy_internal(idmef_snmp_service_t *ptr)
6989 {
6990 prelude_return_if_fail(ptr);
6991
6992 if ( ptr->oid ) {
6993 prelude_string_destroy(ptr->oid);
6994 ptr->oid = NULL;
6995 }
6996
6997 if ( ptr->security_name ) {
6998 prelude_string_destroy(ptr->security_name);
6999 ptr->security_name = NULL;
7000 }
7001
7002 if ( ptr->context_name ) {
7003 prelude_string_destroy(ptr->context_name);
7004 ptr->context_name = NULL;
7005 }
7006
7007 if ( ptr->context_engine_id ) {
7008 prelude_string_destroy(ptr->context_engine_id);
7009 ptr->context_engine_id = NULL;
7010 }
7011
7012 if ( ptr->command ) {
7013 prelude_string_destroy(ptr->command);
7014 ptr->command = NULL;
7015 }
7016
7017 if ( ptr->community ) {
7018 prelude_string_destroy(ptr->community);
7019 ptr->community = NULL;
7020 }
7021
7022
7023 /* free() should be done by the caller */
7024 }
7025
7026 /**
7027 * idmef_snmp_service_destroy:
7028 * @ptr: pointer to a #idmef_snmp_service_t object.
7029 *
7030 * Destroy @ptr and all of it's children.
7031 * The objects are only destroyed if their reference count reach zero.
7032 */
7033
idmef_snmp_service_destroy(idmef_snmp_service_t * ptr)7034 void idmef_snmp_service_destroy(idmef_snmp_service_t *ptr)
7035 {
7036 prelude_return_if_fail(ptr);
7037
7038 if ( --ptr->refcount )
7039 return;
7040
7041 idmef_snmp_service_destroy_internal(ptr);
7042 free(ptr);
7043 }
7044
7045 /**
7046 * idmef_snmp_service_get_oid:
7047 * @ptr: pointer to a #idmef_snmp_service_t object.
7048 *
7049 * Get oid children of the #idmef_snmp_service_t object.
7050 *
7051 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
7052 */
idmef_snmp_service_get_oid(idmef_snmp_service_t * ptr)7053 prelude_string_t *idmef_snmp_service_get_oid(idmef_snmp_service_t *ptr)
7054 {
7055 prelude_return_val_if_fail(ptr, 0); /* FIXME */
7056
7057 return ptr->oid;
7058 }
7059
7060 /**
7061 * idmef_snmp_service_set_oid:
7062 * @ptr: pointer to a #idmef_snmp_service_t object.
7063 * @oid: pointer to a #prelude_string_t object.
7064 *
7065 * Set @oid object as a children of @ptr.
7066 * if @ptr already contain an @oid object, then it is destroyed,
7067 * and updated to point to the provided @oid object.
7068 */
7069
idmef_snmp_service_set_oid(idmef_snmp_service_t * ptr,prelude_string_t * oid)7070 void idmef_snmp_service_set_oid(idmef_snmp_service_t *ptr, prelude_string_t *oid)
7071 {
7072 prelude_return_if_fail(ptr);
7073
7074 if ( ptr->oid )
7075 prelude_string_destroy(ptr->oid);
7076
7077 ptr->oid = oid;
7078 }
7079
7080 /**
7081 * idmef_snmp_service_new_oid:
7082 * @ptr: pointer to a #idmef_snmp_service_t object.
7083 * @ret: pointer to an address where to store the created #prelude_string_t object.
7084 *
7085 * Create a new oid object, children of #idmef_snmp_service_t.
7086 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
7087 *
7088 * Returns: 0 on success, or a negative value if an error occured.
7089 */
idmef_snmp_service_new_oid(idmef_snmp_service_t * ptr,prelude_string_t ** ret)7090 int idmef_snmp_service_new_oid(idmef_snmp_service_t *ptr, prelude_string_t **ret)
7091 {
7092 int retval;
7093
7094 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
7095
7096 if ( ! ptr->oid ) {
7097 retval = prelude_string_new(&ptr->oid);
7098 if ( retval < 0 )
7099 return retval;
7100 }
7101
7102 *ret = ptr->oid;
7103 return 0;
7104 }
7105
7106 /**
7107 * idmef_snmp_service_get_message_processing_model:
7108 * @ptr: pointer to a #idmef_snmp_service_t object.
7109 *
7110 * Get message_processing_model children of the #idmef_snmp_service_t object.
7111 *
7112 * Returns: a pointer to a uint32_t object, or NULL if the children object is not set.
7113 */
idmef_snmp_service_get_message_processing_model(idmef_snmp_service_t * ptr)7114 uint32_t *idmef_snmp_service_get_message_processing_model(idmef_snmp_service_t *ptr)
7115 {
7116 prelude_return_val_if_fail(ptr, 0); /* FIXME */
7117
7118 return ptr->message_processing_model_is_set ? &ptr->message_processing_model : NULL;
7119 }
7120
7121 /**
7122 * idmef_snmp_service_set_message_processing_model:
7123 * @ptr: pointer to a #idmef_snmp_service_t object.
7124 * @message_processing_model: pointer to a #uint32_t object.
7125 *
7126 * Set @message_processing_model object as a children of @ptr.
7127 * if @ptr already contain an @message_processing_model object, then it is destroyed,
7128 * and updated to point to the provided @message_processing_model object.
7129 */
7130
idmef_snmp_service_set_message_processing_model(idmef_snmp_service_t * ptr,uint32_t message_processing_model)7131 void idmef_snmp_service_set_message_processing_model(idmef_snmp_service_t *ptr, uint32_t message_processing_model)
7132 {
7133 prelude_return_if_fail(ptr);
7134 ptr->message_processing_model = message_processing_model;
7135 ptr->message_processing_model_is_set = 1;
7136 }
7137
7138
idmef_snmp_service_unset_message_processing_model(idmef_snmp_service_t * ptr)7139 void idmef_snmp_service_unset_message_processing_model(idmef_snmp_service_t *ptr)
7140 {
7141 prelude_return_if_fail(ptr);
7142 ptr->message_processing_model_is_set = 0;
7143 }
7144
7145
7146 /**
7147 * idmef_snmp_service_new_message_processing_model:
7148 * @ptr: pointer to a #idmef_snmp_service_t object.
7149 * @ret: pointer to an address where to store the created #uint32_t object.
7150 *
7151 * Create a new message_processing_model object, children of #idmef_snmp_service_t.
7152 * If @ptr already contain a #uint32_t object, then it is destroyed.
7153 *
7154 * Returns: 0 on success, or a negative value if an error occured.
7155 */
idmef_snmp_service_new_message_processing_model(idmef_snmp_service_t * ptr,uint32_t ** ret)7156 int idmef_snmp_service_new_message_processing_model(idmef_snmp_service_t *ptr, uint32_t **ret)
7157 {
7158 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
7159 ptr->message_processing_model_is_set = 1;
7160
7161 *ret = &ptr->message_processing_model;
7162 return 0;
7163 }
7164
7165 /**
7166 * idmef_snmp_service_get_security_model:
7167 * @ptr: pointer to a #idmef_snmp_service_t object.
7168 *
7169 * Get security_model children of the #idmef_snmp_service_t object.
7170 *
7171 * Returns: a pointer to a uint32_t object, or NULL if the children object is not set.
7172 */
idmef_snmp_service_get_security_model(idmef_snmp_service_t * ptr)7173 uint32_t *idmef_snmp_service_get_security_model(idmef_snmp_service_t *ptr)
7174 {
7175 prelude_return_val_if_fail(ptr, 0); /* FIXME */
7176
7177 return ptr->security_model_is_set ? &ptr->security_model : NULL;
7178 }
7179
7180 /**
7181 * idmef_snmp_service_set_security_model:
7182 * @ptr: pointer to a #idmef_snmp_service_t object.
7183 * @security_model: pointer to a #uint32_t object.
7184 *
7185 * Set @security_model object as a children of @ptr.
7186 * if @ptr already contain an @security_model object, then it is destroyed,
7187 * and updated to point to the provided @security_model object.
7188 */
7189
idmef_snmp_service_set_security_model(idmef_snmp_service_t * ptr,uint32_t security_model)7190 void idmef_snmp_service_set_security_model(idmef_snmp_service_t *ptr, uint32_t security_model)
7191 {
7192 prelude_return_if_fail(ptr);
7193 ptr->security_model = security_model;
7194 ptr->security_model_is_set = 1;
7195 }
7196
7197
idmef_snmp_service_unset_security_model(idmef_snmp_service_t * ptr)7198 void idmef_snmp_service_unset_security_model(idmef_snmp_service_t *ptr)
7199 {
7200 prelude_return_if_fail(ptr);
7201 ptr->security_model_is_set = 0;
7202 }
7203
7204
7205 /**
7206 * idmef_snmp_service_new_security_model:
7207 * @ptr: pointer to a #idmef_snmp_service_t object.
7208 * @ret: pointer to an address where to store the created #uint32_t object.
7209 *
7210 * Create a new security_model object, children of #idmef_snmp_service_t.
7211 * If @ptr already contain a #uint32_t object, then it is destroyed.
7212 *
7213 * Returns: 0 on success, or a negative value if an error occured.
7214 */
idmef_snmp_service_new_security_model(idmef_snmp_service_t * ptr,uint32_t ** ret)7215 int idmef_snmp_service_new_security_model(idmef_snmp_service_t *ptr, uint32_t **ret)
7216 {
7217 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
7218 ptr->security_model_is_set = 1;
7219
7220 *ret = &ptr->security_model;
7221 return 0;
7222 }
7223
7224 /**
7225 * idmef_snmp_service_get_security_name:
7226 * @ptr: pointer to a #idmef_snmp_service_t object.
7227 *
7228 * Get security_name children of the #idmef_snmp_service_t object.
7229 *
7230 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
7231 */
idmef_snmp_service_get_security_name(idmef_snmp_service_t * ptr)7232 prelude_string_t *idmef_snmp_service_get_security_name(idmef_snmp_service_t *ptr)
7233 {
7234 prelude_return_val_if_fail(ptr, 0); /* FIXME */
7235
7236 return ptr->security_name;
7237 }
7238
7239 /**
7240 * idmef_snmp_service_set_security_name:
7241 * @ptr: pointer to a #idmef_snmp_service_t object.
7242 * @security_name: pointer to a #prelude_string_t object.
7243 *
7244 * Set @security_name object as a children of @ptr.
7245 * if @ptr already contain an @security_name object, then it is destroyed,
7246 * and updated to point to the provided @security_name object.
7247 */
7248
idmef_snmp_service_set_security_name(idmef_snmp_service_t * ptr,prelude_string_t * security_name)7249 void idmef_snmp_service_set_security_name(idmef_snmp_service_t *ptr, prelude_string_t *security_name)
7250 {
7251 prelude_return_if_fail(ptr);
7252
7253 if ( ptr->security_name )
7254 prelude_string_destroy(ptr->security_name);
7255
7256 ptr->security_name = security_name;
7257 }
7258
7259 /**
7260 * idmef_snmp_service_new_security_name:
7261 * @ptr: pointer to a #idmef_snmp_service_t object.
7262 * @ret: pointer to an address where to store the created #prelude_string_t object.
7263 *
7264 * Create a new security_name object, children of #idmef_snmp_service_t.
7265 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
7266 *
7267 * Returns: 0 on success, or a negative value if an error occured.
7268 */
idmef_snmp_service_new_security_name(idmef_snmp_service_t * ptr,prelude_string_t ** ret)7269 int idmef_snmp_service_new_security_name(idmef_snmp_service_t *ptr, prelude_string_t **ret)
7270 {
7271 int retval;
7272
7273 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
7274
7275 if ( ! ptr->security_name ) {
7276 retval = prelude_string_new(&ptr->security_name);
7277 if ( retval < 0 )
7278 return retval;
7279 }
7280
7281 *ret = ptr->security_name;
7282 return 0;
7283 }
7284
7285 /**
7286 * idmef_snmp_service_get_security_level:
7287 * @ptr: pointer to a #idmef_snmp_service_t object.
7288 *
7289 * Get security_level children of the #idmef_snmp_service_t object.
7290 *
7291 * Returns: a pointer to a uint32_t object, or NULL if the children object is not set.
7292 */
idmef_snmp_service_get_security_level(idmef_snmp_service_t * ptr)7293 uint32_t *idmef_snmp_service_get_security_level(idmef_snmp_service_t *ptr)
7294 {
7295 prelude_return_val_if_fail(ptr, 0); /* FIXME */
7296
7297 return ptr->security_level_is_set ? &ptr->security_level : NULL;
7298 }
7299
7300 /**
7301 * idmef_snmp_service_set_security_level:
7302 * @ptr: pointer to a #idmef_snmp_service_t object.
7303 * @security_level: pointer to a #uint32_t object.
7304 *
7305 * Set @security_level object as a children of @ptr.
7306 * if @ptr already contain an @security_level object, then it is destroyed,
7307 * and updated to point to the provided @security_level object.
7308 */
7309
idmef_snmp_service_set_security_level(idmef_snmp_service_t * ptr,uint32_t security_level)7310 void idmef_snmp_service_set_security_level(idmef_snmp_service_t *ptr, uint32_t security_level)
7311 {
7312 prelude_return_if_fail(ptr);
7313 ptr->security_level = security_level;
7314 ptr->security_level_is_set = 1;
7315 }
7316
7317
idmef_snmp_service_unset_security_level(idmef_snmp_service_t * ptr)7318 void idmef_snmp_service_unset_security_level(idmef_snmp_service_t *ptr)
7319 {
7320 prelude_return_if_fail(ptr);
7321 ptr->security_level_is_set = 0;
7322 }
7323
7324
7325 /**
7326 * idmef_snmp_service_new_security_level:
7327 * @ptr: pointer to a #idmef_snmp_service_t object.
7328 * @ret: pointer to an address where to store the created #uint32_t object.
7329 *
7330 * Create a new security_level object, children of #idmef_snmp_service_t.
7331 * If @ptr already contain a #uint32_t object, then it is destroyed.
7332 *
7333 * Returns: 0 on success, or a negative value if an error occured.
7334 */
idmef_snmp_service_new_security_level(idmef_snmp_service_t * ptr,uint32_t ** ret)7335 int idmef_snmp_service_new_security_level(idmef_snmp_service_t *ptr, uint32_t **ret)
7336 {
7337 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
7338 ptr->security_level_is_set = 1;
7339
7340 *ret = &ptr->security_level;
7341 return 0;
7342 }
7343
7344 /**
7345 * idmef_snmp_service_get_context_name:
7346 * @ptr: pointer to a #idmef_snmp_service_t object.
7347 *
7348 * Get context_name children of the #idmef_snmp_service_t object.
7349 *
7350 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
7351 */
idmef_snmp_service_get_context_name(idmef_snmp_service_t * ptr)7352 prelude_string_t *idmef_snmp_service_get_context_name(idmef_snmp_service_t *ptr)
7353 {
7354 prelude_return_val_if_fail(ptr, 0); /* FIXME */
7355
7356 return ptr->context_name;
7357 }
7358
7359 /**
7360 * idmef_snmp_service_set_context_name:
7361 * @ptr: pointer to a #idmef_snmp_service_t object.
7362 * @context_name: pointer to a #prelude_string_t object.
7363 *
7364 * Set @context_name object as a children of @ptr.
7365 * if @ptr already contain an @context_name object, then it is destroyed,
7366 * and updated to point to the provided @context_name object.
7367 */
7368
idmef_snmp_service_set_context_name(idmef_snmp_service_t * ptr,prelude_string_t * context_name)7369 void idmef_snmp_service_set_context_name(idmef_snmp_service_t *ptr, prelude_string_t *context_name)
7370 {
7371 prelude_return_if_fail(ptr);
7372
7373 if ( ptr->context_name )
7374 prelude_string_destroy(ptr->context_name);
7375
7376 ptr->context_name = context_name;
7377 }
7378
7379 /**
7380 * idmef_snmp_service_new_context_name:
7381 * @ptr: pointer to a #idmef_snmp_service_t object.
7382 * @ret: pointer to an address where to store the created #prelude_string_t object.
7383 *
7384 * Create a new context_name object, children of #idmef_snmp_service_t.
7385 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
7386 *
7387 * Returns: 0 on success, or a negative value if an error occured.
7388 */
idmef_snmp_service_new_context_name(idmef_snmp_service_t * ptr,prelude_string_t ** ret)7389 int idmef_snmp_service_new_context_name(idmef_snmp_service_t *ptr, prelude_string_t **ret)
7390 {
7391 int retval;
7392
7393 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
7394
7395 if ( ! ptr->context_name ) {
7396 retval = prelude_string_new(&ptr->context_name);
7397 if ( retval < 0 )
7398 return retval;
7399 }
7400
7401 *ret = ptr->context_name;
7402 return 0;
7403 }
7404
7405 /**
7406 * idmef_snmp_service_get_context_engine_id:
7407 * @ptr: pointer to a #idmef_snmp_service_t object.
7408 *
7409 * Get context_engine_id children of the #idmef_snmp_service_t object.
7410 *
7411 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
7412 */
idmef_snmp_service_get_context_engine_id(idmef_snmp_service_t * ptr)7413 prelude_string_t *idmef_snmp_service_get_context_engine_id(idmef_snmp_service_t *ptr)
7414 {
7415 prelude_return_val_if_fail(ptr, 0); /* FIXME */
7416
7417 return ptr->context_engine_id;
7418 }
7419
7420 /**
7421 * idmef_snmp_service_set_context_engine_id:
7422 * @ptr: pointer to a #idmef_snmp_service_t object.
7423 * @context_engine_id: pointer to a #prelude_string_t object.
7424 *
7425 * Set @context_engine_id object as a children of @ptr.
7426 * if @ptr already contain an @context_engine_id object, then it is destroyed,
7427 * and updated to point to the provided @context_engine_id object.
7428 */
7429
idmef_snmp_service_set_context_engine_id(idmef_snmp_service_t * ptr,prelude_string_t * context_engine_id)7430 void idmef_snmp_service_set_context_engine_id(idmef_snmp_service_t *ptr, prelude_string_t *context_engine_id)
7431 {
7432 prelude_return_if_fail(ptr);
7433
7434 if ( ptr->context_engine_id )
7435 prelude_string_destroy(ptr->context_engine_id);
7436
7437 ptr->context_engine_id = context_engine_id;
7438 }
7439
7440 /**
7441 * idmef_snmp_service_new_context_engine_id:
7442 * @ptr: pointer to a #idmef_snmp_service_t object.
7443 * @ret: pointer to an address where to store the created #prelude_string_t object.
7444 *
7445 * Create a new context_engine_id object, children of #idmef_snmp_service_t.
7446 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
7447 *
7448 * Returns: 0 on success, or a negative value if an error occured.
7449 */
idmef_snmp_service_new_context_engine_id(idmef_snmp_service_t * ptr,prelude_string_t ** ret)7450 int idmef_snmp_service_new_context_engine_id(idmef_snmp_service_t *ptr, prelude_string_t **ret)
7451 {
7452 int retval;
7453
7454 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
7455
7456 if ( ! ptr->context_engine_id ) {
7457 retval = prelude_string_new(&ptr->context_engine_id);
7458 if ( retval < 0 )
7459 return retval;
7460 }
7461
7462 *ret = ptr->context_engine_id;
7463 return 0;
7464 }
7465
7466 /**
7467 * idmef_snmp_service_get_command:
7468 * @ptr: pointer to a #idmef_snmp_service_t object.
7469 *
7470 * Get command children of the #idmef_snmp_service_t object.
7471 *
7472 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
7473 */
idmef_snmp_service_get_command(idmef_snmp_service_t * ptr)7474 prelude_string_t *idmef_snmp_service_get_command(idmef_snmp_service_t *ptr)
7475 {
7476 prelude_return_val_if_fail(ptr, 0); /* FIXME */
7477
7478 return ptr->command;
7479 }
7480
7481 /**
7482 * idmef_snmp_service_set_command:
7483 * @ptr: pointer to a #idmef_snmp_service_t object.
7484 * @command: pointer to a #prelude_string_t object.
7485 *
7486 * Set @command object as a children of @ptr.
7487 * if @ptr already contain an @command object, then it is destroyed,
7488 * and updated to point to the provided @command object.
7489 */
7490
idmef_snmp_service_set_command(idmef_snmp_service_t * ptr,prelude_string_t * command)7491 void idmef_snmp_service_set_command(idmef_snmp_service_t *ptr, prelude_string_t *command)
7492 {
7493 prelude_return_if_fail(ptr);
7494
7495 if ( ptr->command )
7496 prelude_string_destroy(ptr->command);
7497
7498 ptr->command = command;
7499 }
7500
7501 /**
7502 * idmef_snmp_service_new_command:
7503 * @ptr: pointer to a #idmef_snmp_service_t object.
7504 * @ret: pointer to an address where to store the created #prelude_string_t object.
7505 *
7506 * Create a new command object, children of #idmef_snmp_service_t.
7507 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
7508 *
7509 * Returns: 0 on success, or a negative value if an error occured.
7510 */
idmef_snmp_service_new_command(idmef_snmp_service_t * ptr,prelude_string_t ** ret)7511 int idmef_snmp_service_new_command(idmef_snmp_service_t *ptr, prelude_string_t **ret)
7512 {
7513 int retval;
7514
7515 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
7516
7517 if ( ! ptr->command ) {
7518 retval = prelude_string_new(&ptr->command);
7519 if ( retval < 0 )
7520 return retval;
7521 }
7522
7523 *ret = ptr->command;
7524 return 0;
7525 }
7526
7527 /**
7528 * idmef_snmp_service_get_community:
7529 * @ptr: pointer to a #idmef_snmp_service_t object.
7530 *
7531 * Get community children of the #idmef_snmp_service_t object.
7532 *
7533 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
7534 */
idmef_snmp_service_get_community(idmef_snmp_service_t * ptr)7535 prelude_string_t *idmef_snmp_service_get_community(idmef_snmp_service_t *ptr)
7536 {
7537 prelude_return_val_if_fail(ptr, 0); /* FIXME */
7538
7539 return ptr->community;
7540 }
7541
7542 /**
7543 * idmef_snmp_service_set_community:
7544 * @ptr: pointer to a #idmef_snmp_service_t object.
7545 * @community: pointer to a #prelude_string_t object.
7546 *
7547 * Set @community object as a children of @ptr.
7548 * if @ptr already contain an @community object, then it is destroyed,
7549 * and updated to point to the provided @community object.
7550 */
7551
idmef_snmp_service_set_community(idmef_snmp_service_t * ptr,prelude_string_t * community)7552 void idmef_snmp_service_set_community(idmef_snmp_service_t *ptr, prelude_string_t *community)
7553 {
7554 prelude_return_if_fail(ptr);
7555
7556 if ( ptr->community )
7557 prelude_string_destroy(ptr->community);
7558
7559 ptr->community = community;
7560 }
7561
7562 /**
7563 * idmef_snmp_service_new_community:
7564 * @ptr: pointer to a #idmef_snmp_service_t object.
7565 * @ret: pointer to an address where to store the created #prelude_string_t object.
7566 *
7567 * Create a new community object, children of #idmef_snmp_service_t.
7568 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
7569 *
7570 * Returns: 0 on success, or a negative value if an error occured.
7571 */
idmef_snmp_service_new_community(idmef_snmp_service_t * ptr,prelude_string_t ** ret)7572 int idmef_snmp_service_new_community(idmef_snmp_service_t *ptr, prelude_string_t **ret)
7573 {
7574 int retval;
7575
7576 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
7577
7578 if ( ! ptr->community ) {
7579 retval = prelude_string_new(&ptr->community);
7580 if ( retval < 0 )
7581 return retval;
7582 }
7583
7584 *ret = ptr->community;
7585 return 0;
7586 }
7587
7588 /**
7589 * idmef_snmp_service_copy:
7590 * @src: Source of the copy.
7591 * @dst: Where to copy the object.
7592 *
7593 * Copy a new #idmef_snmp_service_t object from @src to @dst.
7594 *
7595 * Returns: 0 on success, a negative value if an error occured.
7596 */
idmef_snmp_service_copy(const idmef_snmp_service_t * src,idmef_snmp_service_t * dst)7597 int idmef_snmp_service_copy(const idmef_snmp_service_t *src, idmef_snmp_service_t *dst)
7598 {
7599 int ret;
7600
7601 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
7602 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
7603
7604 ret = 0;
7605
7606 if ( src->oid ) {
7607 ret = prelude_string_clone(src->oid, &dst->oid);
7608 if ( ret < 0 )
7609 return ret;
7610 }
7611
7612 dst->message_processing_model_is_set = src->message_processing_model_is_set;
7613
7614 dst->message_processing_model = src->message_processing_model;
7615
7616 dst->security_model_is_set = src->security_model_is_set;
7617
7618 dst->security_model = src->security_model;
7619
7620 if ( src->security_name ) {
7621 ret = prelude_string_clone(src->security_name, &dst->security_name);
7622 if ( ret < 0 )
7623 return ret;
7624 }
7625
7626 dst->security_level_is_set = src->security_level_is_set;
7627
7628 dst->security_level = src->security_level;
7629
7630 if ( src->context_name ) {
7631 ret = prelude_string_clone(src->context_name, &dst->context_name);
7632 if ( ret < 0 )
7633 return ret;
7634 }
7635
7636 if ( src->context_engine_id ) {
7637 ret = prelude_string_clone(src->context_engine_id, &dst->context_engine_id);
7638 if ( ret < 0 )
7639 return ret;
7640 }
7641
7642 if ( src->command ) {
7643 ret = prelude_string_clone(src->command, &dst->command);
7644 if ( ret < 0 )
7645 return ret;
7646 }
7647
7648 if ( src->community ) {
7649 ret = prelude_string_clone(src->community, &dst->community);
7650 if ( ret < 0 )
7651 return ret;
7652 }
7653
7654 return 0;
7655 }
7656
7657 /**
7658 * idmef_snmp_service_clone:
7659 * @src: Object to be cloned.
7660 * @dst: Address where to store the pointer to the cloned object.
7661 *
7662 * Create a copy of @src, and store it in @dst.
7663 *
7664 * Returns: 0 on success, a negative value if an error occured.
7665 */
idmef_snmp_service_clone(idmef_snmp_service_t * src,idmef_snmp_service_t ** dst)7666 int idmef_snmp_service_clone(idmef_snmp_service_t *src, idmef_snmp_service_t **dst)
7667 {
7668 int ret;
7669
7670 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
7671
7672 ret = idmef_snmp_service_new(dst);
7673 if ( ret < 0 )
7674 return ret;
7675
7676 return idmef_snmp_service_copy(src, *dst);
7677 }
7678
7679 /**
7680 * idmef_snmp_service_compare:
7681 * @obj1: Object to compare with @obj2.
7682 * @obj2: Object to compare with @obj1.
7683 *
7684 * Compare @obj1 with @obj2.
7685 *
7686 * Returns: 0 on match, a negative value on comparison failure.
7687 */
idmef_snmp_service_compare(const idmef_snmp_service_t * obj1,const idmef_snmp_service_t * obj2)7688 int idmef_snmp_service_compare(const idmef_snmp_service_t *obj1, const idmef_snmp_service_t *obj2)
7689 {
7690 int ret = 0;
7691
7692 if ( obj1 == NULL && obj2 == NULL )
7693 return 0;
7694
7695 else if ( obj1 == NULL || obj2 == NULL )
7696 return -1;
7697
7698 ret = prelude_string_compare(obj1->oid, obj2->oid);
7699 if ( ret != 0 )
7700 return ret;
7701
7702 if ( obj1->message_processing_model_is_set != obj2->message_processing_model_is_set )
7703 return -1;
7704
7705 if ( obj1->message_processing_model_is_set && obj1->message_processing_model != obj2->message_processing_model )
7706 return -1;
7707
7708 if ( obj1->security_model_is_set != obj2->security_model_is_set )
7709 return -1;
7710
7711 if ( obj1->security_model_is_set && obj1->security_model != obj2->security_model )
7712 return -1;
7713
7714 ret = prelude_string_compare(obj1->security_name, obj2->security_name);
7715 if ( ret != 0 )
7716 return ret;
7717
7718 if ( obj1->security_level_is_set != obj2->security_level_is_set )
7719 return -1;
7720
7721 if ( obj1->security_level_is_set && obj1->security_level != obj2->security_level )
7722 return -1;
7723
7724 ret = prelude_string_compare(obj1->context_name, obj2->context_name);
7725 if ( ret != 0 )
7726 return ret;
7727
7728 ret = prelude_string_compare(obj1->context_engine_id, obj2->context_engine_id);
7729 if ( ret != 0 )
7730 return ret;
7731
7732 ret = prelude_string_compare(obj1->command, obj2->command);
7733 if ( ret != 0 )
7734 return ret;
7735
7736 ret = prelude_string_compare(obj1->community, obj2->community);
7737 if ( ret != 0 )
7738 return ret;
7739
7740 return ret;
7741 }
7742
7743 /**
7744 * idmef_service_new:
7745 * @ret: Pointer where to store the created #idmef_service_t object.
7746 *
7747 * Create a new #idmef_service_t object.
7748 *
7749 * Returns: 0 on success, a negative value if an error occured.
7750 */
idmef_service_new(idmef_service_t ** ret)7751 int idmef_service_new(idmef_service_t **ret)
7752 {
7753 *ret = calloc(1, sizeof(**ret));
7754 if ( ! *ret )
7755 return prelude_error_from_errno(errno);
7756
7757 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_SERVICE;
7758
7759 (*ret)->refcount = 1;
7760
7761 return 0;
7762
7763 }
7764
7765 /**
7766 * idmef_service_ref:
7767 * @service: pointer to a #idmef_service_t object.
7768 *
7769 * Increase @service reference count, so that it can be referenced
7770 * multiple time.
7771 *
7772 * Returns: a pointer to @service.
7773 */
idmef_service_ref(idmef_service_t * service)7774 idmef_service_t *idmef_service_ref(idmef_service_t *service)
7775 {
7776 prelude_return_val_if_fail(service, NULL);
7777 service->refcount++;
7778
7779 return service;
7780 }
7781
_idmef_service_get_child(void * p,idmef_class_child_id_t child,void ** childptr)7782 int _idmef_service_get_child(void *p, idmef_class_child_id_t child, void **childptr)
7783 {
7784 idmef_service_t *ptr = p;
7785
7786 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
7787 *childptr = NULL;
7788
7789 switch ( child ) {
7790
7791 case 0:
7792 return get_value_from_string((idmef_value_t **) childptr, ptr->ident, TRUE);
7793 case 1:
7794 return (ptr->ip_version_is_set) ? idmef_value_new_uint8((idmef_value_t **) childptr, ptr->ip_version) : 0;
7795
7796 case 2:
7797 return (ptr->iana_protocol_number_is_set) ? idmef_value_new_uint8((idmef_value_t **) childptr, ptr->iana_protocol_number) : 0;
7798
7799 case 3:
7800 return get_value_from_string((idmef_value_t **) childptr, ptr->iana_protocol_name, TRUE);
7801 case 4:
7802 return get_value_from_string((idmef_value_t **) childptr, ptr->name, TRUE);
7803 case 5:
7804 return (ptr->port_is_set) ? idmef_value_new_uint16((idmef_value_t **) childptr, ptr->port) : 0;
7805
7806 case 6:
7807 return get_value_from_string((idmef_value_t **) childptr, ptr->portlist, TRUE);
7808 case 7:
7809 return get_value_from_string((idmef_value_t **) childptr, ptr->protocol, TRUE);
7810 case 8:
7811 *childptr = ( ptr->type == IDMEF_SERVICE_TYPE_WEB ) ? ptr->specific.web_service : NULL;
7812 return 0;
7813
7814 case 9:
7815 *childptr = ( ptr->type == IDMEF_SERVICE_TYPE_SNMP ) ? ptr->specific.snmp_service : NULL;
7816 return 0;
7817
7818 default:
7819 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
7820 }
7821 }
7822
_idmef_service_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)7823 int _idmef_service_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
7824 {
7825 idmef_service_t *ptr = p;
7826
7827 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
7828
7829 switch ( child ) {
7830
7831 case 0:
7832 return idmef_service_new_ident(ptr, (prelude_string_t **) ret);
7833
7834 case 1:
7835 return idmef_service_new_ip_version(ptr, (uint8_t **) ret);
7836
7837 case 2:
7838 return idmef_service_new_iana_protocol_number(ptr, (uint8_t **) ret);
7839
7840 case 3:
7841 return idmef_service_new_iana_protocol_name(ptr, (prelude_string_t **) ret);
7842
7843 case 4:
7844 return idmef_service_new_name(ptr, (prelude_string_t **) ret);
7845
7846 case 5:
7847 return idmef_service_new_port(ptr, (uint16_t **) ret);
7848
7849 case 6:
7850 return idmef_service_new_portlist(ptr, (prelude_string_t **) ret);
7851
7852 case 7:
7853 return idmef_service_new_protocol(ptr, (prelude_string_t **) ret);
7854
7855 case 8:
7856 return idmef_service_new_web_service(ptr, (idmef_web_service_t **) ret);
7857
7858 case 9:
7859 return idmef_service_new_snmp_service(ptr, (idmef_snmp_service_t **) ret);
7860
7861 default:
7862 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
7863 }
7864 }
7865
_idmef_service_destroy_child(void * p,idmef_class_child_id_t child,int n)7866 int _idmef_service_destroy_child(void *p, idmef_class_child_id_t child, int n)
7867 {
7868 idmef_service_t *ptr = p;
7869
7870 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
7871
7872 switch ( child ) {
7873
7874 case 0:
7875 if ( ptr->ident ) {
7876 prelude_string_destroy(ptr->ident);
7877 ptr->ident = NULL;
7878 }
7879
7880 return 0;
7881
7882 case 1:
7883 ptr->ip_version_is_set = 0;
7884 return 0;
7885
7886 case 2:
7887 ptr->iana_protocol_number_is_set = 0;
7888 return 0;
7889
7890 case 3:
7891 if ( ptr->iana_protocol_name ) {
7892 prelude_string_destroy(ptr->iana_protocol_name);
7893 ptr->iana_protocol_name = NULL;
7894 }
7895
7896 return 0;
7897
7898 case 4:
7899 if ( ptr->name ) {
7900 prelude_string_destroy(ptr->name);
7901 ptr->name = NULL;
7902 }
7903
7904 return 0;
7905
7906 case 5:
7907 ptr->port_is_set = 0;
7908 return 0;
7909
7910 case 6:
7911 if ( ptr->portlist ) {
7912 prelude_string_destroy(ptr->portlist);
7913 ptr->portlist = NULL;
7914 }
7915
7916 return 0;
7917
7918 case 7:
7919 if ( ptr->protocol ) {
7920 prelude_string_destroy(ptr->protocol);
7921 ptr->protocol = NULL;
7922 }
7923
7924 return 0;
7925
7926 case 8:
7927 if ( ptr->type != IDMEF_SERVICE_TYPE_WEB )
7928 return 0;
7929
7930 idmef_web_service_destroy(ptr->specific.web_service);
7931 ptr->specific.web_service = NULL;
7932 ptr->type = 0;
7933
7934 return 0;
7935
7936 case 9:
7937 if ( ptr->type != IDMEF_SERVICE_TYPE_SNMP )
7938 return 0;
7939
7940 idmef_snmp_service_destroy(ptr->specific.snmp_service);
7941 ptr->specific.snmp_service = NULL;
7942 ptr->type = 0;
7943
7944 return 0;
7945
7946 default:
7947 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
7948 }
7949 }
7950
idmef_service_destroy_internal(idmef_service_t * ptr)7951 static void idmef_service_destroy_internal(idmef_service_t *ptr)
7952 {
7953 prelude_return_if_fail(ptr);
7954
7955 if ( ptr->ident ) {
7956 prelude_string_destroy(ptr->ident);
7957 ptr->ident = NULL;
7958 }
7959
7960 if ( ptr->iana_protocol_name ) {
7961 prelude_string_destroy(ptr->iana_protocol_name);
7962 ptr->iana_protocol_name = NULL;
7963 }
7964
7965 if ( ptr->name ) {
7966 prelude_string_destroy(ptr->name);
7967 ptr->name = NULL;
7968 }
7969
7970 if ( ptr->portlist ) {
7971 prelude_string_destroy(ptr->portlist);
7972 ptr->portlist = NULL;
7973 }
7974
7975 if ( ptr->protocol ) {
7976 prelude_string_destroy(ptr->protocol);
7977 ptr->protocol = NULL;
7978 }
7979
7980 switch ( ptr->type ) {
7981
7982 case IDMEF_SERVICE_TYPE_WEB:
7983 idmef_web_service_destroy(ptr->specific.web_service);
7984 ptr->specific.web_service = NULL;
7985 break;
7986
7987 case IDMEF_SERVICE_TYPE_SNMP:
7988 idmef_snmp_service_destroy(ptr->specific.snmp_service);
7989 ptr->specific.snmp_service = NULL;
7990 break;
7991
7992 default:
7993 break;
7994 }
7995
7996
7997 /* free() should be done by the caller */
7998 }
7999
8000 /**
8001 * idmef_service_destroy:
8002 * @ptr: pointer to a #idmef_service_t object.
8003 *
8004 * Destroy @ptr and all of it's children.
8005 * The objects are only destroyed if their reference count reach zero.
8006 */
8007
idmef_service_destroy(idmef_service_t * ptr)8008 void idmef_service_destroy(idmef_service_t *ptr)
8009 {
8010 prelude_return_if_fail(ptr);
8011
8012 if ( --ptr->refcount )
8013 return;
8014
8015 idmef_service_destroy_internal(ptr);
8016 free(ptr);
8017 }
8018
8019 /**
8020 * idmef_service_get_ident:
8021 * @ptr: pointer to a #idmef_service_t object.
8022 *
8023 * Get ident children of the #idmef_service_t object.
8024 *
8025 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
8026 */
idmef_service_get_ident(idmef_service_t * ptr)8027 prelude_string_t *idmef_service_get_ident(idmef_service_t *ptr)
8028 {
8029 prelude_return_val_if_fail(ptr, 0); /* FIXME */
8030
8031 return ptr->ident;
8032 }
8033
8034 /**
8035 * idmef_service_set_ident:
8036 * @ptr: pointer to a #idmef_service_t object.
8037 * @ident: pointer to a #prelude_string_t object.
8038 *
8039 * Set @ident object as a children of @ptr.
8040 * if @ptr already contain an @ident object, then it is destroyed,
8041 * and updated to point to the provided @ident object.
8042 */
8043
idmef_service_set_ident(idmef_service_t * ptr,prelude_string_t * ident)8044 void idmef_service_set_ident(idmef_service_t *ptr, prelude_string_t *ident)
8045 {
8046 prelude_return_if_fail(ptr);
8047
8048 if ( ptr->ident )
8049 prelude_string_destroy(ptr->ident);
8050
8051 ptr->ident = ident;
8052 }
8053
8054 /**
8055 * idmef_service_new_ident:
8056 * @ptr: pointer to a #idmef_service_t object.
8057 * @ret: pointer to an address where to store the created #prelude_string_t object.
8058 *
8059 * Create a new ident object, children of #idmef_service_t.
8060 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
8061 *
8062 * Returns: 0 on success, or a negative value if an error occured.
8063 */
idmef_service_new_ident(idmef_service_t * ptr,prelude_string_t ** ret)8064 int idmef_service_new_ident(idmef_service_t *ptr, prelude_string_t **ret)
8065 {
8066 int retval;
8067
8068 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
8069
8070 if ( ! ptr->ident ) {
8071 retval = prelude_string_new(&ptr->ident);
8072 if ( retval < 0 )
8073 return retval;
8074 }
8075
8076 *ret = ptr->ident;
8077 return 0;
8078 }
8079
8080 /**
8081 * idmef_service_get_ip_version:
8082 * @ptr: pointer to a #idmef_service_t object.
8083 *
8084 * Get ip_version children of the #idmef_service_t object.
8085 *
8086 * Returns: a pointer to a uint8_t object, or NULL if the children object is not set.
8087 */
idmef_service_get_ip_version(idmef_service_t * ptr)8088 uint8_t *idmef_service_get_ip_version(idmef_service_t *ptr)
8089 {
8090 prelude_return_val_if_fail(ptr, 0); /* FIXME */
8091
8092 return ptr->ip_version_is_set ? &ptr->ip_version : NULL;
8093 }
8094
8095 /**
8096 * idmef_service_set_ip_version:
8097 * @ptr: pointer to a #idmef_service_t object.
8098 * @ip_version: pointer to a #uint8_t object.
8099 *
8100 * Set @ip_version object as a children of @ptr.
8101 * if @ptr already contain an @ip_version object, then it is destroyed,
8102 * and updated to point to the provided @ip_version object.
8103 */
8104
idmef_service_set_ip_version(idmef_service_t * ptr,uint8_t ip_version)8105 void idmef_service_set_ip_version(idmef_service_t *ptr, uint8_t ip_version)
8106 {
8107 prelude_return_if_fail(ptr);
8108 ptr->ip_version = ip_version;
8109 ptr->ip_version_is_set = 1;
8110 }
8111
8112
idmef_service_unset_ip_version(idmef_service_t * ptr)8113 void idmef_service_unset_ip_version(idmef_service_t *ptr)
8114 {
8115 prelude_return_if_fail(ptr);
8116 ptr->ip_version_is_set = 0;
8117 }
8118
8119
8120 /**
8121 * idmef_service_new_ip_version:
8122 * @ptr: pointer to a #idmef_service_t object.
8123 * @ret: pointer to an address where to store the created #uint8_t object.
8124 *
8125 * Create a new ip_version object, children of #idmef_service_t.
8126 * If @ptr already contain a #uint8_t object, then it is destroyed.
8127 *
8128 * Returns: 0 on success, or a negative value if an error occured.
8129 */
idmef_service_new_ip_version(idmef_service_t * ptr,uint8_t ** ret)8130 int idmef_service_new_ip_version(idmef_service_t *ptr, uint8_t **ret)
8131 {
8132 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
8133 ptr->ip_version_is_set = 1;
8134
8135 *ret = &ptr->ip_version;
8136 return 0;
8137 }
8138
8139 /**
8140 * idmef_service_get_iana_protocol_number:
8141 * @ptr: pointer to a #idmef_service_t object.
8142 *
8143 * Get iana_protocol_number children of the #idmef_service_t object.
8144 *
8145 * Returns: a pointer to a uint8_t object, or NULL if the children object is not set.
8146 */
idmef_service_get_iana_protocol_number(idmef_service_t * ptr)8147 uint8_t *idmef_service_get_iana_protocol_number(idmef_service_t *ptr)
8148 {
8149 prelude_return_val_if_fail(ptr, 0); /* FIXME */
8150
8151 return ptr->iana_protocol_number_is_set ? &ptr->iana_protocol_number : NULL;
8152 }
8153
8154 /**
8155 * idmef_service_set_iana_protocol_number:
8156 * @ptr: pointer to a #idmef_service_t object.
8157 * @iana_protocol_number: pointer to a #uint8_t object.
8158 *
8159 * Set @iana_protocol_number object as a children of @ptr.
8160 * if @ptr already contain an @iana_protocol_number object, then it is destroyed,
8161 * and updated to point to the provided @iana_protocol_number object.
8162 */
8163
idmef_service_set_iana_protocol_number(idmef_service_t * ptr,uint8_t iana_protocol_number)8164 void idmef_service_set_iana_protocol_number(idmef_service_t *ptr, uint8_t iana_protocol_number)
8165 {
8166 prelude_return_if_fail(ptr);
8167 ptr->iana_protocol_number = iana_protocol_number;
8168 ptr->iana_protocol_number_is_set = 1;
8169 }
8170
8171
idmef_service_unset_iana_protocol_number(idmef_service_t * ptr)8172 void idmef_service_unset_iana_protocol_number(idmef_service_t *ptr)
8173 {
8174 prelude_return_if_fail(ptr);
8175 ptr->iana_protocol_number_is_set = 0;
8176 }
8177
8178
8179 /**
8180 * idmef_service_new_iana_protocol_number:
8181 * @ptr: pointer to a #idmef_service_t object.
8182 * @ret: pointer to an address where to store the created #uint8_t object.
8183 *
8184 * Create a new iana_protocol_number object, children of #idmef_service_t.
8185 * If @ptr already contain a #uint8_t object, then it is destroyed.
8186 *
8187 * Returns: 0 on success, or a negative value if an error occured.
8188 */
idmef_service_new_iana_protocol_number(idmef_service_t * ptr,uint8_t ** ret)8189 int idmef_service_new_iana_protocol_number(idmef_service_t *ptr, uint8_t **ret)
8190 {
8191 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
8192 ptr->iana_protocol_number_is_set = 1;
8193
8194 *ret = &ptr->iana_protocol_number;
8195 return 0;
8196 }
8197
8198 /**
8199 * idmef_service_get_iana_protocol_name:
8200 * @ptr: pointer to a #idmef_service_t object.
8201 *
8202 * Get iana_protocol_name children of the #idmef_service_t object.
8203 *
8204 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
8205 */
idmef_service_get_iana_protocol_name(idmef_service_t * ptr)8206 prelude_string_t *idmef_service_get_iana_protocol_name(idmef_service_t *ptr)
8207 {
8208 prelude_return_val_if_fail(ptr, 0); /* FIXME */
8209
8210 return ptr->iana_protocol_name;
8211 }
8212
8213 /**
8214 * idmef_service_set_iana_protocol_name:
8215 * @ptr: pointer to a #idmef_service_t object.
8216 * @iana_protocol_name: pointer to a #prelude_string_t object.
8217 *
8218 * Set @iana_protocol_name object as a children of @ptr.
8219 * if @ptr already contain an @iana_protocol_name object, then it is destroyed,
8220 * and updated to point to the provided @iana_protocol_name object.
8221 */
8222
idmef_service_set_iana_protocol_name(idmef_service_t * ptr,prelude_string_t * iana_protocol_name)8223 void idmef_service_set_iana_protocol_name(idmef_service_t *ptr, prelude_string_t *iana_protocol_name)
8224 {
8225 prelude_return_if_fail(ptr);
8226
8227 if ( ptr->iana_protocol_name )
8228 prelude_string_destroy(ptr->iana_protocol_name);
8229
8230 ptr->iana_protocol_name = iana_protocol_name;
8231 }
8232
8233 /**
8234 * idmef_service_new_iana_protocol_name:
8235 * @ptr: pointer to a #idmef_service_t object.
8236 * @ret: pointer to an address where to store the created #prelude_string_t object.
8237 *
8238 * Create a new iana_protocol_name object, children of #idmef_service_t.
8239 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
8240 *
8241 * Returns: 0 on success, or a negative value if an error occured.
8242 */
idmef_service_new_iana_protocol_name(idmef_service_t * ptr,prelude_string_t ** ret)8243 int idmef_service_new_iana_protocol_name(idmef_service_t *ptr, prelude_string_t **ret)
8244 {
8245 int retval;
8246
8247 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
8248
8249 if ( ! ptr->iana_protocol_name ) {
8250 retval = prelude_string_new(&ptr->iana_protocol_name);
8251 if ( retval < 0 )
8252 return retval;
8253 }
8254
8255 *ret = ptr->iana_protocol_name;
8256 return 0;
8257 }
8258
8259 /**
8260 * idmef_service_get_name:
8261 * @ptr: pointer to a #idmef_service_t object.
8262 *
8263 * Get name children of the #idmef_service_t object.
8264 *
8265 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
8266 */
idmef_service_get_name(idmef_service_t * ptr)8267 prelude_string_t *idmef_service_get_name(idmef_service_t *ptr)
8268 {
8269 prelude_return_val_if_fail(ptr, 0); /* FIXME */
8270
8271 return ptr->name;
8272 }
8273
8274 /**
8275 * idmef_service_set_name:
8276 * @ptr: pointer to a #idmef_service_t object.
8277 * @name: pointer to a #prelude_string_t object.
8278 *
8279 * Set @name object as a children of @ptr.
8280 * if @ptr already contain an @name object, then it is destroyed,
8281 * and updated to point to the provided @name object.
8282 */
8283
idmef_service_set_name(idmef_service_t * ptr,prelude_string_t * name)8284 void idmef_service_set_name(idmef_service_t *ptr, prelude_string_t *name)
8285 {
8286 prelude_return_if_fail(ptr);
8287
8288 if ( ptr->name )
8289 prelude_string_destroy(ptr->name);
8290
8291 ptr->name = name;
8292 }
8293
8294 /**
8295 * idmef_service_new_name:
8296 * @ptr: pointer to a #idmef_service_t object.
8297 * @ret: pointer to an address where to store the created #prelude_string_t object.
8298 *
8299 * Create a new name object, children of #idmef_service_t.
8300 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
8301 *
8302 * Returns: 0 on success, or a negative value if an error occured.
8303 */
idmef_service_new_name(idmef_service_t * ptr,prelude_string_t ** ret)8304 int idmef_service_new_name(idmef_service_t *ptr, prelude_string_t **ret)
8305 {
8306 int retval;
8307
8308 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
8309
8310 if ( ! ptr->name ) {
8311 retval = prelude_string_new(&ptr->name);
8312 if ( retval < 0 )
8313 return retval;
8314 }
8315
8316 *ret = ptr->name;
8317 return 0;
8318 }
8319
8320 /**
8321 * idmef_service_get_port:
8322 * @ptr: pointer to a #idmef_service_t object.
8323 *
8324 * Get port children of the #idmef_service_t object.
8325 *
8326 * Returns: a pointer to a uint16_t object, or NULL if the children object is not set.
8327 */
idmef_service_get_port(idmef_service_t * ptr)8328 uint16_t *idmef_service_get_port(idmef_service_t *ptr)
8329 {
8330 prelude_return_val_if_fail(ptr, 0); /* FIXME */
8331
8332 return ptr->port_is_set ? &ptr->port : NULL;
8333 }
8334
8335 /**
8336 * idmef_service_set_port:
8337 * @ptr: pointer to a #idmef_service_t object.
8338 * @port: pointer to a #uint16_t object.
8339 *
8340 * Set @port object as a children of @ptr.
8341 * if @ptr already contain an @port object, then it is destroyed,
8342 * and updated to point to the provided @port object.
8343 */
8344
idmef_service_set_port(idmef_service_t * ptr,uint16_t port)8345 void idmef_service_set_port(idmef_service_t *ptr, uint16_t port)
8346 {
8347 prelude_return_if_fail(ptr);
8348 ptr->port = port;
8349 ptr->port_is_set = 1;
8350 }
8351
8352
idmef_service_unset_port(idmef_service_t * ptr)8353 void idmef_service_unset_port(idmef_service_t *ptr)
8354 {
8355 prelude_return_if_fail(ptr);
8356 ptr->port_is_set = 0;
8357 }
8358
8359
8360 /**
8361 * idmef_service_new_port:
8362 * @ptr: pointer to a #idmef_service_t object.
8363 * @ret: pointer to an address where to store the created #uint16_t object.
8364 *
8365 * Create a new port object, children of #idmef_service_t.
8366 * If @ptr already contain a #uint16_t object, then it is destroyed.
8367 *
8368 * Returns: 0 on success, or a negative value if an error occured.
8369 */
idmef_service_new_port(idmef_service_t * ptr,uint16_t ** ret)8370 int idmef_service_new_port(idmef_service_t *ptr, uint16_t **ret)
8371 {
8372 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
8373 ptr->port_is_set = 1;
8374
8375 *ret = &ptr->port;
8376 return 0;
8377 }
8378
8379 /**
8380 * idmef_service_get_portlist:
8381 * @ptr: pointer to a #idmef_service_t object.
8382 *
8383 * Get portlist children of the #idmef_service_t object.
8384 *
8385 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
8386 */
idmef_service_get_portlist(idmef_service_t * ptr)8387 prelude_string_t *idmef_service_get_portlist(idmef_service_t *ptr)
8388 {
8389 prelude_return_val_if_fail(ptr, 0); /* FIXME */
8390
8391 return ptr->portlist;
8392 }
8393
8394 /**
8395 * idmef_service_set_portlist:
8396 * @ptr: pointer to a #idmef_service_t object.
8397 * @portlist: pointer to a #prelude_string_t object.
8398 *
8399 * Set @portlist object as a children of @ptr.
8400 * if @ptr already contain an @portlist object, then it is destroyed,
8401 * and updated to point to the provided @portlist object.
8402 */
8403
idmef_service_set_portlist(idmef_service_t * ptr,prelude_string_t * portlist)8404 void idmef_service_set_portlist(idmef_service_t *ptr, prelude_string_t *portlist)
8405 {
8406 prelude_return_if_fail(ptr);
8407
8408 if ( ptr->portlist )
8409 prelude_string_destroy(ptr->portlist);
8410
8411 ptr->portlist = portlist;
8412 }
8413
8414 /**
8415 * idmef_service_new_portlist:
8416 * @ptr: pointer to a #idmef_service_t object.
8417 * @ret: pointer to an address where to store the created #prelude_string_t object.
8418 *
8419 * Create a new portlist object, children of #idmef_service_t.
8420 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
8421 *
8422 * Returns: 0 on success, or a negative value if an error occured.
8423 */
idmef_service_new_portlist(idmef_service_t * ptr,prelude_string_t ** ret)8424 int idmef_service_new_portlist(idmef_service_t *ptr, prelude_string_t **ret)
8425 {
8426 int retval;
8427
8428 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
8429
8430 if ( ! ptr->portlist ) {
8431 retval = prelude_string_new(&ptr->portlist);
8432 if ( retval < 0 )
8433 return retval;
8434 }
8435
8436 *ret = ptr->portlist;
8437 return 0;
8438 }
8439
8440 /**
8441 * idmef_service_get_protocol:
8442 * @ptr: pointer to a #idmef_service_t object.
8443 *
8444 * Get protocol children of the #idmef_service_t object.
8445 *
8446 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
8447 */
idmef_service_get_protocol(idmef_service_t * ptr)8448 prelude_string_t *idmef_service_get_protocol(idmef_service_t *ptr)
8449 {
8450 prelude_return_val_if_fail(ptr, 0); /* FIXME */
8451
8452 return ptr->protocol;
8453 }
8454
8455 /**
8456 * idmef_service_set_protocol:
8457 * @ptr: pointer to a #idmef_service_t object.
8458 * @protocol: pointer to a #prelude_string_t object.
8459 *
8460 * Set @protocol object as a children of @ptr.
8461 * if @ptr already contain an @protocol object, then it is destroyed,
8462 * and updated to point to the provided @protocol object.
8463 */
8464
idmef_service_set_protocol(idmef_service_t * ptr,prelude_string_t * protocol)8465 void idmef_service_set_protocol(idmef_service_t *ptr, prelude_string_t *protocol)
8466 {
8467 prelude_return_if_fail(ptr);
8468
8469 if ( ptr->protocol )
8470 prelude_string_destroy(ptr->protocol);
8471
8472 ptr->protocol = protocol;
8473 }
8474
8475 /**
8476 * idmef_service_new_protocol:
8477 * @ptr: pointer to a #idmef_service_t object.
8478 * @ret: pointer to an address where to store the created #prelude_string_t object.
8479 *
8480 * Create a new protocol object, children of #idmef_service_t.
8481 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
8482 *
8483 * Returns: 0 on success, or a negative value if an error occured.
8484 */
idmef_service_new_protocol(idmef_service_t * ptr,prelude_string_t ** ret)8485 int idmef_service_new_protocol(idmef_service_t *ptr, prelude_string_t **ret)
8486 {
8487 int retval;
8488
8489 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
8490
8491 if ( ! ptr->protocol ) {
8492 retval = prelude_string_new(&ptr->protocol);
8493 if ( retval < 0 )
8494 return retval;
8495 }
8496
8497 *ret = ptr->protocol;
8498 return 0;
8499 }
8500
8501 /**
8502 * idmef_service_get_type:
8503 * @ptr: pointer to a #idmef_service_t object.
8504 *
8505 * Access the type children of @ptr.
8506 *
8507 * Returns: a pointer to the #idmef_service_type_t children, or NULL if it is not set.
8508 */
idmef_service_get_type(idmef_service_t * ptr)8509 idmef_service_type_t idmef_service_get_type(idmef_service_t *ptr)
8510 {
8511 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
8512 return ptr->type;
8513 }
8514
8515 /**
8516 * idmef_service_get_web_service:
8517 * @ptr: pointer to a #idmef_service_t object.
8518 *
8519 * Access the web_service children of @ptr.
8520 *
8521 * Returns: a pointer to the #idmef_web_service_t children, or NULL if it is not set.
8522 */
idmef_service_get_web_service(idmef_service_t * ptr)8523 idmef_web_service_t *idmef_service_get_web_service(idmef_service_t *ptr)
8524 {
8525 prelude_return_val_if_fail(ptr, NULL);
8526 return (ptr->type == IDMEF_SERVICE_TYPE_WEB) ? ptr->specific.web_service : NULL;
8527 }
8528
8529 /**
8530 * idmef_service_set_web_service:
8531 * @ptr: pointer to a #idmef_service_t object.
8532 * @web_service: pointer to a #idmef_web_service_t object.
8533 *
8534 * Set @web_service object as a children of @ptr.
8535 * if @ptr already contain a @web_service object, then it is destroyed,
8536 * and updated to point to the provided @web_service object.
8537 */
idmef_service_set_web_service(idmef_service_t * ptr,idmef_web_service_t * web_service)8538 void idmef_service_set_web_service(idmef_service_t *ptr, idmef_web_service_t *web_service)
8539 {
8540 prelude_return_if_fail(ptr);
8541
8542 switch ( ptr->type ) {
8543
8544 case IDMEF_SERVICE_TYPE_WEB:
8545 idmef_web_service_destroy(ptr->specific.web_service);
8546 break;
8547
8548 case IDMEF_SERVICE_TYPE_SNMP:
8549 idmef_snmp_service_destroy(ptr->specific.snmp_service);
8550 break;
8551
8552 default:
8553 break;
8554 }
8555
8556 ptr->specific.web_service = web_service;
8557 ptr->type = (web_service) ? IDMEF_SERVICE_TYPE_WEB : 0;
8558 }
8559
8560 /**
8561 * idmef_service_new_web_service:
8562 * @ptr: pointer to a #idmef_service_t object.
8563 * @ret: pointer where to store the created #idmef_web_service_t object.
8564 *
8565 * Create a new idmef_web_service_t object, children of #idmef_service_t.
8566 * If @ptr already contain a #idmef_web_service_t object, then it is destroyed.
8567 *
8568 * Returns: 0 on success, or a negative value if an error occured.
8569 */
idmef_service_new_web_service(idmef_service_t * ptr,idmef_web_service_t ** ret)8570 int idmef_service_new_web_service(idmef_service_t *ptr, idmef_web_service_t **ret)
8571 {
8572 int retval;
8573
8574 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
8575
8576 switch ( ptr->type ) {
8577
8578 case IDMEF_SERVICE_TYPE_WEB:
8579 *ret = ptr->specific.web_service;
8580 return 0;
8581
8582 case IDMEF_SERVICE_TYPE_SNMP:
8583 idmef_snmp_service_destroy(ptr->specific.snmp_service);
8584 break;
8585
8586 default:
8587 break;
8588 }
8589
8590 retval = idmef_web_service_new(ret);
8591 if ( retval < 0 )
8592 return retval;
8593
8594 ptr->type = IDMEF_SERVICE_TYPE_WEB;
8595 ptr->specific.web_service = *ret;
8596
8597 return 0;
8598 }
8599
8600 /**
8601 * idmef_service_get_snmp_service:
8602 * @ptr: pointer to a #idmef_service_t object.
8603 *
8604 * Access the snmp_service children of @ptr.
8605 *
8606 * Returns: a pointer to the #idmef_snmp_service_t children, or NULL if it is not set.
8607 */
idmef_service_get_snmp_service(idmef_service_t * ptr)8608 idmef_snmp_service_t *idmef_service_get_snmp_service(idmef_service_t *ptr)
8609 {
8610 prelude_return_val_if_fail(ptr, NULL);
8611 return (ptr->type == IDMEF_SERVICE_TYPE_SNMP) ? ptr->specific.snmp_service : NULL;
8612 }
8613
8614 /**
8615 * idmef_service_set_snmp_service:
8616 * @ptr: pointer to a #idmef_service_t object.
8617 * @snmp_service: pointer to a #idmef_snmp_service_t object.
8618 *
8619 * Set @snmp_service object as a children of @ptr.
8620 * if @ptr already contain a @snmp_service object, then it is destroyed,
8621 * and updated to point to the provided @snmp_service object.
8622 */
idmef_service_set_snmp_service(idmef_service_t * ptr,idmef_snmp_service_t * snmp_service)8623 void idmef_service_set_snmp_service(idmef_service_t *ptr, idmef_snmp_service_t *snmp_service)
8624 {
8625 prelude_return_if_fail(ptr);
8626
8627 switch ( ptr->type ) {
8628
8629 case IDMEF_SERVICE_TYPE_WEB:
8630 idmef_web_service_destroy(ptr->specific.web_service);
8631 break;
8632
8633 case IDMEF_SERVICE_TYPE_SNMP:
8634 idmef_snmp_service_destroy(ptr->specific.snmp_service);
8635 break;
8636
8637 default:
8638 break;
8639 }
8640
8641 ptr->specific.snmp_service = snmp_service;
8642 ptr->type = (snmp_service) ? IDMEF_SERVICE_TYPE_SNMP : 0;
8643 }
8644
8645 /**
8646 * idmef_service_new_snmp_service:
8647 * @ptr: pointer to a #idmef_service_t object.
8648 * @ret: pointer where to store the created #idmef_snmp_service_t object.
8649 *
8650 * Create a new idmef_snmp_service_t object, children of #idmef_service_t.
8651 * If @ptr already contain a #idmef_snmp_service_t object, then it is destroyed.
8652 *
8653 * Returns: 0 on success, or a negative value if an error occured.
8654 */
idmef_service_new_snmp_service(idmef_service_t * ptr,idmef_snmp_service_t ** ret)8655 int idmef_service_new_snmp_service(idmef_service_t *ptr, idmef_snmp_service_t **ret)
8656 {
8657 int retval;
8658
8659 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
8660
8661 switch ( ptr->type ) {
8662
8663 case IDMEF_SERVICE_TYPE_WEB:
8664 idmef_web_service_destroy(ptr->specific.web_service);
8665 break;
8666
8667 case IDMEF_SERVICE_TYPE_SNMP:
8668 *ret = ptr->specific.snmp_service;
8669 return 0;
8670
8671 default:
8672 break;
8673 }
8674
8675 retval = idmef_snmp_service_new(ret);
8676 if ( retval < 0 )
8677 return retval;
8678
8679 ptr->type = IDMEF_SERVICE_TYPE_SNMP;
8680 ptr->specific.snmp_service = *ret;
8681
8682 return 0;
8683 }
8684
8685 /**
8686 * idmef_service_copy:
8687 * @src: Source of the copy.
8688 * @dst: Where to copy the object.
8689 *
8690 * Copy a new #idmef_service_t object from @src to @dst.
8691 *
8692 * Returns: 0 on success, a negative value if an error occured.
8693 */
idmef_service_copy(const idmef_service_t * src,idmef_service_t * dst)8694 int idmef_service_copy(const idmef_service_t *src, idmef_service_t *dst)
8695 {
8696 int ret;
8697
8698 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
8699 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
8700
8701 ret = 0;
8702
8703 if ( src->ident ) {
8704 ret = prelude_string_clone(src->ident, &dst->ident);
8705 if ( ret < 0 )
8706 return ret;
8707 }
8708
8709 dst->ip_version_is_set = src->ip_version_is_set;
8710
8711 dst->ip_version = src->ip_version;
8712
8713 dst->iana_protocol_number_is_set = src->iana_protocol_number_is_set;
8714
8715 dst->iana_protocol_number = src->iana_protocol_number;
8716
8717 if ( src->iana_protocol_name ) {
8718 ret = prelude_string_clone(src->iana_protocol_name, &dst->iana_protocol_name);
8719 if ( ret < 0 )
8720 return ret;
8721 }
8722
8723 if ( src->name ) {
8724 ret = prelude_string_clone(src->name, &dst->name);
8725 if ( ret < 0 )
8726 return ret;
8727 }
8728
8729 dst->port_is_set = src->port_is_set;
8730
8731 dst->port = src->port;
8732
8733 if ( src->portlist ) {
8734 ret = prelude_string_clone(src->portlist, &dst->portlist);
8735 if ( ret < 0 )
8736 return ret;
8737 }
8738
8739 if ( src->protocol ) {
8740 ret = prelude_string_clone(src->protocol, &dst->protocol);
8741 if ( ret < 0 )
8742 return ret;
8743 }
8744
8745 switch ( src->type ) {
8746
8747 case IDMEF_SERVICE_TYPE_WEB:
8748 ret = idmef_web_service_clone(src->specific.web_service, &dst->specific.web_service);
8749 break;
8750
8751 case IDMEF_SERVICE_TYPE_SNMP:
8752 ret = idmef_snmp_service_clone(src->specific.snmp_service, &dst->specific.snmp_service);
8753 break;
8754
8755 default:
8756 break;
8757 }
8758
8759 if ( ret < 0 )
8760 return ret;
8761
8762 dst->type = src->type;
8763
8764 return 0;
8765 }
8766
8767 /**
8768 * idmef_service_clone:
8769 * @src: Object to be cloned.
8770 * @dst: Address where to store the pointer to the cloned object.
8771 *
8772 * Create a copy of @src, and store it in @dst.
8773 *
8774 * Returns: 0 on success, a negative value if an error occured.
8775 */
idmef_service_clone(idmef_service_t * src,idmef_service_t ** dst)8776 int idmef_service_clone(idmef_service_t *src, idmef_service_t **dst)
8777 {
8778 int ret;
8779
8780 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
8781
8782 ret = idmef_service_new(dst);
8783 if ( ret < 0 )
8784 return ret;
8785
8786 return idmef_service_copy(src, *dst);
8787 }
8788
8789 /**
8790 * idmef_service_compare:
8791 * @obj1: Object to compare with @obj2.
8792 * @obj2: Object to compare with @obj1.
8793 *
8794 * Compare @obj1 with @obj2.
8795 *
8796 * Returns: 0 on match, a negative value on comparison failure.
8797 */
idmef_service_compare(const idmef_service_t * obj1,const idmef_service_t * obj2)8798 int idmef_service_compare(const idmef_service_t *obj1, const idmef_service_t *obj2)
8799 {
8800 int ret = 0;
8801
8802 if ( obj1 == NULL && obj2 == NULL )
8803 return 0;
8804
8805 else if ( obj1 == NULL || obj2 == NULL )
8806 return -1;
8807
8808 ret = prelude_string_compare(obj1->ident, obj2->ident);
8809 if ( ret != 0 )
8810 return ret;
8811
8812 if ( obj1->ip_version_is_set != obj2->ip_version_is_set )
8813 return -1;
8814
8815 if ( obj1->ip_version_is_set && obj1->ip_version != obj2->ip_version )
8816 return -1;
8817
8818 if ( obj1->iana_protocol_number_is_set != obj2->iana_protocol_number_is_set )
8819 return -1;
8820
8821 if ( obj1->iana_protocol_number_is_set && obj1->iana_protocol_number != obj2->iana_protocol_number )
8822 return -1;
8823
8824 ret = prelude_string_compare(obj1->iana_protocol_name, obj2->iana_protocol_name);
8825 if ( ret != 0 )
8826 return ret;
8827
8828 ret = prelude_string_compare(obj1->name, obj2->name);
8829 if ( ret != 0 )
8830 return ret;
8831
8832 if ( obj1->port_is_set != obj2->port_is_set )
8833 return -1;
8834
8835 if ( obj1->port_is_set && obj1->port != obj2->port )
8836 return -1;
8837
8838 ret = prelude_string_compare(obj1->portlist, obj2->portlist);
8839 if ( ret != 0 )
8840 return ret;
8841
8842 ret = prelude_string_compare(obj1->protocol, obj2->protocol);
8843 if ( ret != 0 )
8844 return ret;
8845
8846 if ( obj1->type != obj2->type )
8847 return -1;
8848
8849 switch ( obj1->type ) {
8850
8851 case IDMEF_SERVICE_TYPE_WEB:
8852 ret = idmef_web_service_compare(obj1->specific.web_service, obj2->specific.web_service);
8853 break;
8854
8855 case IDMEF_SERVICE_TYPE_SNMP:
8856 ret = idmef_snmp_service_compare(obj1->specific.snmp_service, obj2->specific.snmp_service);
8857 break;
8858
8859 default:
8860 break;
8861 }
8862
8863 return ret;
8864 }
8865
8866 /**
8867 * idmef_node_new:
8868 * @ret: Pointer where to store the created #idmef_node_t object.
8869 *
8870 * Create a new #idmef_node_t object.
8871 *
8872 * Returns: 0 on success, a negative value if an error occured.
8873 */
idmef_node_new(idmef_node_t ** ret)8874 int idmef_node_new(idmef_node_t **ret)
8875 {
8876 *ret = calloc(1, sizeof(**ret));
8877 if ( ! *ret )
8878 return prelude_error_from_errno(errno);
8879
8880 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_NODE;
8881
8882 (*ret)->refcount = 1;
8883
8884 prelude_list_init(&(*ret)->address_list);
8885
8886
8887 return 0;
8888
8889 }
8890
8891 /**
8892 * idmef_node_ref:
8893 * @node: pointer to a #idmef_node_t object.
8894 *
8895 * Increase @node reference count, so that it can be referenced
8896 * multiple time.
8897 *
8898 * Returns: a pointer to @node.
8899 */
idmef_node_ref(idmef_node_t * node)8900 idmef_node_t *idmef_node_ref(idmef_node_t *node)
8901 {
8902 prelude_return_val_if_fail(node, NULL);
8903 node->refcount++;
8904
8905 return node;
8906 }
8907
_idmef_node_get_child(void * p,idmef_class_child_id_t child,void ** childptr)8908 int _idmef_node_get_child(void *p, idmef_class_child_id_t child, void **childptr)
8909 {
8910 idmef_node_t *ptr = p;
8911
8912 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
8913 *childptr = NULL;
8914
8915 switch ( child ) {
8916
8917 case 0:
8918 return get_value_from_string((idmef_value_t **) childptr, ptr->ident, TRUE);
8919 case 1:
8920 return idmef_value_new_enum_from_numeric((idmef_value_t **) childptr,
8921 IDMEF_CLASS_ID_NODE_CATEGORY, ptr->category);
8922
8923 case 2:
8924 return get_value_from_string((idmef_value_t **) childptr, ptr->location, TRUE);
8925 case 3:
8926 return get_value_from_string((idmef_value_t **) childptr, ptr->name, TRUE);
8927 case 4:
8928 *childptr = &ptr->address_list;
8929 return 0;
8930
8931 default:
8932 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
8933 }
8934 }
8935
_idmef_node_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)8936 int _idmef_node_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
8937 {
8938 idmef_node_t *ptr = p;
8939
8940 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
8941
8942 switch ( child ) {
8943
8944 case 0:
8945 return idmef_node_new_ident(ptr, (prelude_string_t **) ret);
8946
8947 case 1:
8948 return idmef_node_new_category(ptr, (idmef_node_category_t **) ret);
8949
8950 case 2:
8951 return idmef_node_new_location(ptr, (prelude_string_t **) ret);
8952
8953 case 3:
8954 return idmef_node_new_name(ptr, (prelude_string_t **) ret);
8955
8956 case 4: {
8957 int i = 0;
8958 prelude_list_t *tmp;
8959
8960 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
8961 return idmef_node_new_address(ptr, (idmef_address_t **) ret, n);
8962
8963 if ( n >= 0 ) {
8964 prelude_list_for_each(&ptr->address_list, tmp) {
8965 if ( i++ == n ) {
8966 *ret = prelude_linked_object_get_object(tmp);
8967 return 0;
8968 }
8969 }
8970
8971 if ( i != n )
8972 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
8973 } else {
8974 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
8975
8976 prelude_list_for_each_reversed(&ptr->address_list, tmp) {
8977 if ( i++ == pos ) {
8978 *ret = prelude_linked_object_get_object(tmp);
8979 return 0;
8980 }
8981 }
8982
8983 if ( i != pos )
8984 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
8985 }
8986
8987 return idmef_node_new_address(ptr, (idmef_address_t **) ret, n);
8988 }
8989
8990 default:
8991 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
8992 }
8993 }
8994
_idmef_node_destroy_child(void * p,idmef_class_child_id_t child,int n)8995 int _idmef_node_destroy_child(void *p, idmef_class_child_id_t child, int n)
8996 {
8997 idmef_node_t *ptr = p;
8998
8999 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
9000
9001 switch ( child ) {
9002
9003 case 0:
9004 if ( ptr->ident ) {
9005 prelude_string_destroy(ptr->ident);
9006 ptr->ident = NULL;
9007 }
9008
9009 return 0;
9010
9011 case 1:
9012 ptr->category = 0;
9013 return 0;
9014
9015 case 2:
9016 if ( ptr->location ) {
9017 prelude_string_destroy(ptr->location);
9018 ptr->location = NULL;
9019 }
9020
9021 return 0;
9022
9023 case 3:
9024 if ( ptr->name ) {
9025 prelude_string_destroy(ptr->name);
9026 ptr->name = NULL;
9027 }
9028
9029 return 0;
9030
9031 case 4: {
9032 int i = 0;
9033 prelude_list_t *tmp;
9034
9035 if ( n >= 0 ) {
9036 prelude_list_for_each(&ptr->address_list, tmp) {
9037 if ( i++ == n ) {
9038 void *b = prelude_linked_object_get_object(tmp);
9039 idmef_address_destroy(b);
9040 return 0;
9041 }
9042 }
9043
9044 if ( i != n )
9045 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
9046 } else {
9047 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
9048
9049 prelude_list_for_each_reversed(&ptr->address_list, tmp) {
9050 if ( i++ == pos ) {
9051 void *b = prelude_linked_object_get_object(tmp);
9052 idmef_address_destroy(b);
9053 return 0;
9054 }
9055 }
9056
9057 if ( i != pos )
9058 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
9059 }
9060 }
9061
9062 default:
9063 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
9064 }
9065 }
9066
idmef_node_destroy_internal(idmef_node_t * ptr)9067 static void idmef_node_destroy_internal(idmef_node_t *ptr)
9068 {
9069 prelude_return_if_fail(ptr);
9070
9071 if ( ptr->ident ) {
9072 prelude_string_destroy(ptr->ident);
9073 ptr->ident = NULL;
9074 }
9075
9076 if ( ptr->location ) {
9077 prelude_string_destroy(ptr->location);
9078 ptr->location = NULL;
9079 }
9080
9081 if ( ptr->name ) {
9082 prelude_string_destroy(ptr->name);
9083 ptr->name = NULL;
9084 }
9085
9086 {
9087 prelude_list_t *n, *tmp;
9088 idmef_address_t *entry;
9089
9090 prelude_list_for_each_safe(&ptr->address_list, tmp, n) {
9091 entry = prelude_linked_object_get_object(tmp);
9092 prelude_list_del_init(tmp);
9093 idmef_address_destroy(entry);
9094 }
9095 }
9096
9097
9098 /* free() should be done by the caller */
9099 }
9100
9101 /**
9102 * idmef_node_destroy:
9103 * @ptr: pointer to a #idmef_node_t object.
9104 *
9105 * Destroy @ptr and all of it's children.
9106 * The objects are only destroyed if their reference count reach zero.
9107 */
9108
idmef_node_destroy(idmef_node_t * ptr)9109 void idmef_node_destroy(idmef_node_t *ptr)
9110 {
9111 prelude_return_if_fail(ptr);
9112
9113 if ( --ptr->refcount )
9114 return;
9115
9116 idmef_node_destroy_internal(ptr);
9117 free(ptr);
9118 }
9119
9120 /**
9121 * idmef_node_get_ident:
9122 * @ptr: pointer to a #idmef_node_t object.
9123 *
9124 * Get ident children of the #idmef_node_t object.
9125 *
9126 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
9127 */
idmef_node_get_ident(idmef_node_t * ptr)9128 prelude_string_t *idmef_node_get_ident(idmef_node_t *ptr)
9129 {
9130 prelude_return_val_if_fail(ptr, 0); /* FIXME */
9131
9132 return ptr->ident;
9133 }
9134
9135 /**
9136 * idmef_node_set_ident:
9137 * @ptr: pointer to a #idmef_node_t object.
9138 * @ident: pointer to a #prelude_string_t object.
9139 *
9140 * Set @ident object as a children of @ptr.
9141 * if @ptr already contain an @ident object, then it is destroyed,
9142 * and updated to point to the provided @ident object.
9143 */
9144
idmef_node_set_ident(idmef_node_t * ptr,prelude_string_t * ident)9145 void idmef_node_set_ident(idmef_node_t *ptr, prelude_string_t *ident)
9146 {
9147 prelude_return_if_fail(ptr);
9148
9149 if ( ptr->ident )
9150 prelude_string_destroy(ptr->ident);
9151
9152 ptr->ident = ident;
9153 }
9154
9155 /**
9156 * idmef_node_new_ident:
9157 * @ptr: pointer to a #idmef_node_t object.
9158 * @ret: pointer to an address where to store the created #prelude_string_t object.
9159 *
9160 * Create a new ident object, children of #idmef_node_t.
9161 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
9162 *
9163 * Returns: 0 on success, or a negative value if an error occured.
9164 */
idmef_node_new_ident(idmef_node_t * ptr,prelude_string_t ** ret)9165 int idmef_node_new_ident(idmef_node_t *ptr, prelude_string_t **ret)
9166 {
9167 int retval;
9168
9169 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
9170
9171 if ( ! ptr->ident ) {
9172 retval = prelude_string_new(&ptr->ident);
9173 if ( retval < 0 )
9174 return retval;
9175 }
9176
9177 *ret = ptr->ident;
9178 return 0;
9179 }
9180
9181 /**
9182 * idmef_node_get_category:
9183 * @ptr: pointer to a #idmef_node_t object.
9184 *
9185 * Get category children of the #idmef_node_t object.
9186 *
9187 * Returns: a pointer to a idmef_node_category_t object, or NULL if the children object is not set.
9188 */
idmef_node_get_category(idmef_node_t * ptr)9189 idmef_node_category_t idmef_node_get_category(idmef_node_t *ptr)
9190 {
9191 prelude_return_val_if_fail(ptr, 0); /* FIXME */
9192
9193 return ptr->category;
9194 }
9195
9196 /**
9197 * idmef_node_set_category:
9198 * @ptr: pointer to a #idmef_node_t object.
9199 * @category: pointer to a #idmef_node_category_t object.
9200 *
9201 * Set @category object as a children of @ptr.
9202 * if @ptr already contain an @category object, then it is destroyed,
9203 * and updated to point to the provided @category object.
9204 */
9205
idmef_node_set_category(idmef_node_t * ptr,idmef_node_category_t category)9206 void idmef_node_set_category(idmef_node_t *ptr, idmef_node_category_t category)
9207 {
9208 prelude_return_if_fail(ptr);
9209 ptr->category = category;
9210 }
9211
9212 /**
9213 * idmef_node_new_category:
9214 * @ptr: pointer to a #idmef_node_t object.
9215 * @ret: pointer to an address where to store the created #idmef_node_category_t object.
9216 *
9217 * Create a new category object, children of #idmef_node_t.
9218 * If @ptr already contain a #idmef_node_category_t object, then it is destroyed.
9219 *
9220 * Returns: 0 on success, or a negative value if an error occured.
9221 */
idmef_node_new_category(idmef_node_t * ptr,idmef_node_category_t ** ret)9222 int idmef_node_new_category(idmef_node_t *ptr, idmef_node_category_t **ret)
9223 {
9224 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
9225
9226 *ret = &ptr->category;
9227 return 0;
9228 }
9229
9230 /**
9231 * idmef_node_get_location:
9232 * @ptr: pointer to a #idmef_node_t object.
9233 *
9234 * Get location children of the #idmef_node_t object.
9235 *
9236 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
9237 */
idmef_node_get_location(idmef_node_t * ptr)9238 prelude_string_t *idmef_node_get_location(idmef_node_t *ptr)
9239 {
9240 prelude_return_val_if_fail(ptr, 0); /* FIXME */
9241
9242 return ptr->location;
9243 }
9244
9245 /**
9246 * idmef_node_set_location:
9247 * @ptr: pointer to a #idmef_node_t object.
9248 * @location: pointer to a #prelude_string_t object.
9249 *
9250 * Set @location object as a children of @ptr.
9251 * if @ptr already contain an @location object, then it is destroyed,
9252 * and updated to point to the provided @location object.
9253 */
9254
idmef_node_set_location(idmef_node_t * ptr,prelude_string_t * location)9255 void idmef_node_set_location(idmef_node_t *ptr, prelude_string_t *location)
9256 {
9257 prelude_return_if_fail(ptr);
9258
9259 if ( ptr->location )
9260 prelude_string_destroy(ptr->location);
9261
9262 ptr->location = location;
9263 }
9264
9265 /**
9266 * idmef_node_new_location:
9267 * @ptr: pointer to a #idmef_node_t object.
9268 * @ret: pointer to an address where to store the created #prelude_string_t object.
9269 *
9270 * Create a new location object, children of #idmef_node_t.
9271 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
9272 *
9273 * Returns: 0 on success, or a negative value if an error occured.
9274 */
idmef_node_new_location(idmef_node_t * ptr,prelude_string_t ** ret)9275 int idmef_node_new_location(idmef_node_t *ptr, prelude_string_t **ret)
9276 {
9277 int retval;
9278
9279 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
9280
9281 if ( ! ptr->location ) {
9282 retval = prelude_string_new(&ptr->location);
9283 if ( retval < 0 )
9284 return retval;
9285 }
9286
9287 *ret = ptr->location;
9288 return 0;
9289 }
9290
9291 /**
9292 * idmef_node_get_name:
9293 * @ptr: pointer to a #idmef_node_t object.
9294 *
9295 * Get name children of the #idmef_node_t object.
9296 *
9297 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
9298 */
idmef_node_get_name(idmef_node_t * ptr)9299 prelude_string_t *idmef_node_get_name(idmef_node_t *ptr)
9300 {
9301 prelude_return_val_if_fail(ptr, 0); /* FIXME */
9302
9303 return ptr->name;
9304 }
9305
9306 /**
9307 * idmef_node_set_name:
9308 * @ptr: pointer to a #idmef_node_t object.
9309 * @name: pointer to a #prelude_string_t object.
9310 *
9311 * Set @name object as a children of @ptr.
9312 * if @ptr already contain an @name object, then it is destroyed,
9313 * and updated to point to the provided @name object.
9314 */
9315
idmef_node_set_name(idmef_node_t * ptr,prelude_string_t * name)9316 void idmef_node_set_name(idmef_node_t *ptr, prelude_string_t *name)
9317 {
9318 prelude_return_if_fail(ptr);
9319
9320 if ( ptr->name )
9321 prelude_string_destroy(ptr->name);
9322
9323 ptr->name = name;
9324 }
9325
9326 /**
9327 * idmef_node_new_name:
9328 * @ptr: pointer to a #idmef_node_t object.
9329 * @ret: pointer to an address where to store the created #prelude_string_t object.
9330 *
9331 * Create a new name object, children of #idmef_node_t.
9332 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
9333 *
9334 * Returns: 0 on success, or a negative value if an error occured.
9335 */
idmef_node_new_name(idmef_node_t * ptr,prelude_string_t ** ret)9336 int idmef_node_new_name(idmef_node_t *ptr, prelude_string_t **ret)
9337 {
9338 int retval;
9339
9340 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
9341
9342 if ( ! ptr->name ) {
9343 retval = prelude_string_new(&ptr->name);
9344 if ( retval < 0 )
9345 return retval;
9346 }
9347
9348 *ret = ptr->name;
9349 return 0;
9350 }
9351
9352 /**
9353 * idmef_node_get_next_address:
9354 * @node: pointer to a #idmef_node_t object.
9355 * @address_cur: pointer to a #idmef_address_t object.
9356 *
9357 * Get the next #idmef_address_t object listed in @ptr.
9358 * When iterating over the idmef_address_t object listed in @ptr,
9359 * @object should be set to the latest returned #idmef_address_t object.
9360 *
9361 * Returns: the next #idmef_address_t in the list.
9362 */
idmef_node_get_next_address(idmef_node_t * node,idmef_address_t * address_cur)9363 idmef_address_t *idmef_node_get_next_address(idmef_node_t *node, idmef_address_t *address_cur)
9364 {
9365 prelude_list_t *tmp = (address_cur) ? &((prelude_linked_object_t *) address_cur)->_list : NULL;
9366
9367 prelude_return_val_if_fail(node, NULL);
9368
9369 prelude_list_for_each_continue(&node->address_list, tmp)
9370 return prelude_linked_object_get_object(tmp);
9371
9372 return NULL;
9373 }
9374
9375
9376 /**
9377 * idmef_node_set_address:
9378 * @ptr: pointer to a #idmef_node_t object.
9379 * @object: pointer to a #idmef_address_t object.
9380 * @pos: Position in the list.
9381 *
9382 * Add @object to position @pos of @ptr list of #idmef_address_t object.
9383 *
9384 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
9385 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
9386 */
idmef_node_set_address(idmef_node_t * ptr,idmef_address_t * object,int pos)9387 void idmef_node_set_address(idmef_node_t *ptr, idmef_address_t *object, int pos)
9388 {
9389 prelude_return_if_fail(ptr);
9390 prelude_return_if_fail(object);
9391
9392 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
9393 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
9394
9395 list_insert(&ptr->address_list, &((prelude_linked_object_t *) object)->_list, pos);
9396 }
9397
9398
9399 /**
9400 * idmef_node_new_address:
9401 * @ptr: pointer to a #idmef_node_t object.
9402 * @ret: pointer to an address where to store the created #idmef_address_t object.
9403 * @pos: position in the list.
9404 *
9405 * Create a new #idmef_address_t children of @ptr, and add it to position @pos of
9406 * @ptr list of #idmef_address_t object. The created #idmef_address_t object is
9407 * stored in @ret.
9408 *
9409 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
9410 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
9411 *
9412 * Returns: 0 on success, or a negative value if an error occured.
9413 */
idmef_node_new_address(idmef_node_t * ptr,idmef_address_t ** ret,int pos)9414 int idmef_node_new_address(idmef_node_t *ptr, idmef_address_t **ret, int pos)
9415 {
9416 int retval;
9417
9418 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
9419
9420 retval = idmef_address_new(ret);
9421 if ( retval < 0 )
9422 return retval;
9423
9424 list_insert(&ptr->address_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
9425
9426 return 0;
9427 }
9428
9429
9430 /**
9431 * idmef_node_copy:
9432 * @src: Source of the copy.
9433 * @dst: Where to copy the object.
9434 *
9435 * Copy a new #idmef_node_t object from @src to @dst.
9436 *
9437 * Returns: 0 on success, a negative value if an error occured.
9438 */
idmef_node_copy(const idmef_node_t * src,idmef_node_t * dst)9439 int idmef_node_copy(const idmef_node_t *src, idmef_node_t *dst)
9440 {
9441 int ret;
9442
9443 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
9444 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
9445
9446 ret = 0;
9447
9448 if ( src->ident ) {
9449 ret = prelude_string_clone(src->ident, &dst->ident);
9450 if ( ret < 0 )
9451 return ret;
9452 }
9453
9454 dst->category = src->category;
9455
9456 if ( src->location ) {
9457 ret = prelude_string_clone(src->location, &dst->location);
9458 if ( ret < 0 )
9459 return ret;
9460 }
9461
9462 if ( src->name ) {
9463 ret = prelude_string_clone(src->name, &dst->name);
9464 if ( ret < 0 )
9465 return ret;
9466 }
9467
9468 {
9469 prelude_list_t *n, *tmp;
9470 idmef_address_t *entry, *new;
9471
9472 prelude_list_for_each_safe(&src->address_list, tmp, n) {
9473 entry = prelude_linked_object_get_object(tmp);
9474 idmef_address_clone(entry, &new);
9475 prelude_list_add_tail(&dst->address_list, &((prelude_linked_object_t *) new)->_list);
9476 }
9477 }
9478
9479 return 0;
9480 }
9481
9482 /**
9483 * idmef_node_clone:
9484 * @src: Object to be cloned.
9485 * @dst: Address where to store the pointer to the cloned object.
9486 *
9487 * Create a copy of @src, and store it in @dst.
9488 *
9489 * Returns: 0 on success, a negative value if an error occured.
9490 */
idmef_node_clone(idmef_node_t * src,idmef_node_t ** dst)9491 int idmef_node_clone(idmef_node_t *src, idmef_node_t **dst)
9492 {
9493 int ret;
9494
9495 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
9496
9497 ret = idmef_node_new(dst);
9498 if ( ret < 0 )
9499 return ret;
9500
9501 return idmef_node_copy(src, *dst);
9502 }
9503
9504 /**
9505 * idmef_node_compare:
9506 * @obj1: Object to compare with @obj2.
9507 * @obj2: Object to compare with @obj1.
9508 *
9509 * Compare @obj1 with @obj2.
9510 *
9511 * Returns: 0 on match, a negative value on comparison failure.
9512 */
idmef_node_compare(const idmef_node_t * obj1,const idmef_node_t * obj2)9513 int idmef_node_compare(const idmef_node_t *obj1, const idmef_node_t *obj2)
9514 {
9515 int ret = 0;
9516
9517 if ( obj1 == NULL && obj2 == NULL )
9518 return 0;
9519
9520 else if ( obj1 == NULL || obj2 == NULL )
9521 return -1;
9522
9523 ret = prelude_string_compare(obj1->ident, obj2->ident);
9524 if ( ret != 0 )
9525 return ret;
9526
9527 if ( obj1->category != obj2->category )
9528 return -1;
9529
9530 ret = prelude_string_compare(obj1->location, obj2->location);
9531 if ( ret != 0 )
9532 return ret;
9533
9534 ret = prelude_string_compare(obj1->name, obj2->name);
9535 if ( ret != 0 )
9536 return ret;
9537
9538 {
9539 prelude_list_t *tmp1, *tmp2;
9540 idmef_address_t *entry1, *entry2;
9541
9542 tmp1 = tmp2 = NULL;
9543 do {
9544 entry1 = entry2 = NULL;
9545
9546 prelude_list_for_each_continue(&obj1->address_list, tmp1) {
9547 entry1 = prelude_linked_object_get_object(tmp1);
9548 break;
9549 }
9550
9551 prelude_list_for_each_continue(&obj2->address_list, tmp2) {
9552 entry2 = prelude_linked_object_get_object(tmp2);
9553 break;
9554 }
9555
9556 ret = idmef_address_compare(entry1, entry2);
9557 if ( ret != 0 )
9558 return ret;
9559
9560 } while ( entry1 && entry2 );
9561 }
9562
9563 return ret;
9564 }
9565
9566 /**
9567 * idmef_source_new:
9568 * @ret: Pointer where to store the created #idmef_source_t object.
9569 *
9570 * Create a new #idmef_source_t object.
9571 *
9572 * Returns: 0 on success, a negative value if an error occured.
9573 */
idmef_source_new(idmef_source_t ** ret)9574 int idmef_source_new(idmef_source_t **ret)
9575 {
9576 *ret = calloc(1, sizeof(**ret));
9577 if ( ! *ret )
9578 return prelude_error_from_errno(errno);
9579
9580 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_SOURCE;
9581
9582 prelude_list_init(&((prelude_linked_object_t *) (*ret))->_list);
9583
9584 (*ret)->refcount = 1;
9585
9586 return 0;
9587
9588 }
9589
9590 /**
9591 * idmef_source_ref:
9592 * @source: pointer to a #idmef_source_t object.
9593 *
9594 * Increase @source reference count, so that it can be referenced
9595 * multiple time.
9596 *
9597 * Returns: a pointer to @source.
9598 */
idmef_source_ref(idmef_source_t * source)9599 idmef_source_t *idmef_source_ref(idmef_source_t *source)
9600 {
9601 prelude_return_val_if_fail(source, NULL);
9602 source->refcount++;
9603
9604 return source;
9605 }
9606
_idmef_source_get_child(void * p,idmef_class_child_id_t child,void ** childptr)9607 int _idmef_source_get_child(void *p, idmef_class_child_id_t child, void **childptr)
9608 {
9609 idmef_source_t *ptr = p;
9610
9611 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
9612 *childptr = NULL;
9613
9614 switch ( child ) {
9615
9616 case 0:
9617 return get_value_from_string((idmef_value_t **) childptr, ptr->ident, TRUE);
9618 case 1:
9619 return idmef_value_new_enum_from_numeric((idmef_value_t **) childptr,
9620 IDMEF_CLASS_ID_SOURCE_SPOOFED, ptr->spoofed);
9621
9622 case 2:
9623 return get_value_from_string((idmef_value_t **) childptr, ptr->interface, TRUE);
9624 case 3:
9625 *childptr = ptr->node;
9626 return 0;
9627
9628 case 4:
9629 *childptr = ptr->user;
9630 return 0;
9631
9632 case 5:
9633 *childptr = ptr->process;
9634 return 0;
9635
9636 case 6:
9637 *childptr = ptr->service;
9638 return 0;
9639
9640 default:
9641 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
9642 }
9643 }
9644
_idmef_source_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)9645 int _idmef_source_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
9646 {
9647 idmef_source_t *ptr = p;
9648
9649 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
9650
9651 switch ( child ) {
9652
9653 case 0:
9654 return idmef_source_new_ident(ptr, (prelude_string_t **) ret);
9655
9656 case 1:
9657 return idmef_source_new_spoofed(ptr, (idmef_source_spoofed_t **) ret);
9658
9659 case 2:
9660 return idmef_source_new_interface(ptr, (prelude_string_t **) ret);
9661
9662 case 3:
9663 return idmef_source_new_node(ptr, (idmef_node_t **) ret);
9664
9665 case 4:
9666 return idmef_source_new_user(ptr, (idmef_user_t **) ret);
9667
9668 case 5:
9669 return idmef_source_new_process(ptr, (idmef_process_t **) ret);
9670
9671 case 6:
9672 return idmef_source_new_service(ptr, (idmef_service_t **) ret);
9673
9674 default:
9675 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
9676 }
9677 }
9678
_idmef_source_destroy_child(void * p,idmef_class_child_id_t child,int n)9679 int _idmef_source_destroy_child(void *p, idmef_class_child_id_t child, int n)
9680 {
9681 idmef_source_t *ptr = p;
9682
9683 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
9684
9685 switch ( child ) {
9686
9687 case 0:
9688 if ( ptr->ident ) {
9689 prelude_string_destroy(ptr->ident);
9690 ptr->ident = NULL;
9691 }
9692
9693 return 0;
9694
9695 case 1:
9696 ptr->spoofed = 0;
9697 return 0;
9698
9699 case 2:
9700 if ( ptr->interface ) {
9701 prelude_string_destroy(ptr->interface);
9702 ptr->interface = NULL;
9703 }
9704
9705 return 0;
9706
9707 case 3:
9708 if ( ptr->node ) {
9709 idmef_node_destroy(ptr->node);
9710 ptr->node = NULL;
9711 }
9712
9713 return 0;
9714
9715 case 4:
9716 if ( ptr->user ) {
9717 idmef_user_destroy(ptr->user);
9718 ptr->user = NULL;
9719 }
9720
9721 return 0;
9722
9723 case 5:
9724 if ( ptr->process ) {
9725 idmef_process_destroy(ptr->process);
9726 ptr->process = NULL;
9727 }
9728
9729 return 0;
9730
9731 case 6:
9732 if ( ptr->service ) {
9733 idmef_service_destroy(ptr->service);
9734 ptr->service = NULL;
9735 }
9736
9737 return 0;
9738
9739 default:
9740 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
9741 }
9742 }
9743
idmef_source_destroy_internal(idmef_source_t * ptr)9744 static void idmef_source_destroy_internal(idmef_source_t *ptr)
9745 {
9746 prelude_return_if_fail(ptr);
9747
9748 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *)ptr)->_list) )
9749 prelude_list_del_init(&((prelude_linked_object_t *)ptr)->_list);
9750
9751 if ( ptr->ident ) {
9752 prelude_string_destroy(ptr->ident);
9753 ptr->ident = NULL;
9754 }
9755
9756 if ( ptr->interface ) {
9757 prelude_string_destroy(ptr->interface);
9758 ptr->interface = NULL;
9759 }
9760
9761 if ( ptr->node ) {
9762 idmef_node_destroy(ptr->node);
9763 ptr->node = NULL;
9764 }
9765
9766 if ( ptr->user ) {
9767 idmef_user_destroy(ptr->user);
9768 ptr->user = NULL;
9769 }
9770
9771 if ( ptr->process ) {
9772 idmef_process_destroy(ptr->process);
9773 ptr->process = NULL;
9774 }
9775
9776 if ( ptr->service ) {
9777 idmef_service_destroy(ptr->service);
9778 ptr->service = NULL;
9779 }
9780
9781
9782 /* free() should be done by the caller */
9783 }
9784
9785 /**
9786 * idmef_source_destroy:
9787 * @ptr: pointer to a #idmef_source_t object.
9788 *
9789 * Destroy @ptr and all of it's children.
9790 * The objects are only destroyed if their reference count reach zero.
9791 */
9792
idmef_source_destroy(idmef_source_t * ptr)9793 void idmef_source_destroy(idmef_source_t *ptr)
9794 {
9795 prelude_return_if_fail(ptr);
9796
9797 if ( --ptr->refcount )
9798 return;
9799
9800 idmef_source_destroy_internal(ptr);
9801 free(ptr);
9802 }
9803
9804 /**
9805 * idmef_source_get_ident:
9806 * @ptr: pointer to a #idmef_source_t object.
9807 *
9808 * Get ident children of the #idmef_source_t object.
9809 *
9810 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
9811 */
idmef_source_get_ident(idmef_source_t * ptr)9812 prelude_string_t *idmef_source_get_ident(idmef_source_t *ptr)
9813 {
9814 prelude_return_val_if_fail(ptr, 0); /* FIXME */
9815
9816 return ptr->ident;
9817 }
9818
9819 /**
9820 * idmef_source_set_ident:
9821 * @ptr: pointer to a #idmef_source_t object.
9822 * @ident: pointer to a #prelude_string_t object.
9823 *
9824 * Set @ident object as a children of @ptr.
9825 * if @ptr already contain an @ident object, then it is destroyed,
9826 * and updated to point to the provided @ident object.
9827 */
9828
idmef_source_set_ident(idmef_source_t * ptr,prelude_string_t * ident)9829 void idmef_source_set_ident(idmef_source_t *ptr, prelude_string_t *ident)
9830 {
9831 prelude_return_if_fail(ptr);
9832
9833 if ( ptr->ident )
9834 prelude_string_destroy(ptr->ident);
9835
9836 ptr->ident = ident;
9837 }
9838
9839 /**
9840 * idmef_source_new_ident:
9841 * @ptr: pointer to a #idmef_source_t object.
9842 * @ret: pointer to an address where to store the created #prelude_string_t object.
9843 *
9844 * Create a new ident object, children of #idmef_source_t.
9845 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
9846 *
9847 * Returns: 0 on success, or a negative value if an error occured.
9848 */
idmef_source_new_ident(idmef_source_t * ptr,prelude_string_t ** ret)9849 int idmef_source_new_ident(idmef_source_t *ptr, prelude_string_t **ret)
9850 {
9851 int retval;
9852
9853 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
9854
9855 if ( ! ptr->ident ) {
9856 retval = prelude_string_new(&ptr->ident);
9857 if ( retval < 0 )
9858 return retval;
9859 }
9860
9861 *ret = ptr->ident;
9862 return 0;
9863 }
9864
9865 /**
9866 * idmef_source_get_spoofed:
9867 * @ptr: pointer to a #idmef_source_t object.
9868 *
9869 * Get spoofed children of the #idmef_source_t object.
9870 *
9871 * Returns: a pointer to a idmef_source_spoofed_t object, or NULL if the children object is not set.
9872 */
idmef_source_get_spoofed(idmef_source_t * ptr)9873 idmef_source_spoofed_t idmef_source_get_spoofed(idmef_source_t *ptr)
9874 {
9875 prelude_return_val_if_fail(ptr, 0); /* FIXME */
9876
9877 return ptr->spoofed;
9878 }
9879
9880 /**
9881 * idmef_source_set_spoofed:
9882 * @ptr: pointer to a #idmef_source_t object.
9883 * @spoofed: pointer to a #idmef_source_spoofed_t object.
9884 *
9885 * Set @spoofed object as a children of @ptr.
9886 * if @ptr already contain an @spoofed object, then it is destroyed,
9887 * and updated to point to the provided @spoofed object.
9888 */
9889
idmef_source_set_spoofed(idmef_source_t * ptr,idmef_source_spoofed_t spoofed)9890 void idmef_source_set_spoofed(idmef_source_t *ptr, idmef_source_spoofed_t spoofed)
9891 {
9892 prelude_return_if_fail(ptr);
9893 ptr->spoofed = spoofed;
9894 }
9895
9896 /**
9897 * idmef_source_new_spoofed:
9898 * @ptr: pointer to a #idmef_source_t object.
9899 * @ret: pointer to an address where to store the created #idmef_source_spoofed_t object.
9900 *
9901 * Create a new spoofed object, children of #idmef_source_t.
9902 * If @ptr already contain a #idmef_source_spoofed_t object, then it is destroyed.
9903 *
9904 * Returns: 0 on success, or a negative value if an error occured.
9905 */
idmef_source_new_spoofed(idmef_source_t * ptr,idmef_source_spoofed_t ** ret)9906 int idmef_source_new_spoofed(idmef_source_t *ptr, idmef_source_spoofed_t **ret)
9907 {
9908 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
9909
9910 *ret = &ptr->spoofed;
9911 return 0;
9912 }
9913
9914 /**
9915 * idmef_source_get_interface:
9916 * @ptr: pointer to a #idmef_source_t object.
9917 *
9918 * Get interface children of the #idmef_source_t object.
9919 *
9920 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
9921 */
idmef_source_get_interface(idmef_source_t * ptr)9922 prelude_string_t *idmef_source_get_interface(idmef_source_t *ptr)
9923 {
9924 prelude_return_val_if_fail(ptr, 0); /* FIXME */
9925
9926 return ptr->interface;
9927 }
9928
9929 /**
9930 * idmef_source_set_interface:
9931 * @ptr: pointer to a #idmef_source_t object.
9932 * @interface: pointer to a #prelude_string_t object.
9933 *
9934 * Set @interface object as a children of @ptr.
9935 * if @ptr already contain an @interface object, then it is destroyed,
9936 * and updated to point to the provided @interface object.
9937 */
9938
idmef_source_set_interface(idmef_source_t * ptr,prelude_string_t * interface)9939 void idmef_source_set_interface(idmef_source_t *ptr, prelude_string_t *interface)
9940 {
9941 prelude_return_if_fail(ptr);
9942
9943 if ( ptr->interface )
9944 prelude_string_destroy(ptr->interface);
9945
9946 ptr->interface = interface;
9947 }
9948
9949 /**
9950 * idmef_source_new_interface:
9951 * @ptr: pointer to a #idmef_source_t object.
9952 * @ret: pointer to an address where to store the created #prelude_string_t object.
9953 *
9954 * Create a new interface object, children of #idmef_source_t.
9955 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
9956 *
9957 * Returns: 0 on success, or a negative value if an error occured.
9958 */
idmef_source_new_interface(idmef_source_t * ptr,prelude_string_t ** ret)9959 int idmef_source_new_interface(idmef_source_t *ptr, prelude_string_t **ret)
9960 {
9961 int retval;
9962
9963 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
9964
9965 if ( ! ptr->interface ) {
9966 retval = prelude_string_new(&ptr->interface);
9967 if ( retval < 0 )
9968 return retval;
9969 }
9970
9971 *ret = ptr->interface;
9972 return 0;
9973 }
9974
9975 /**
9976 * idmef_source_get_node:
9977 * @ptr: pointer to a #idmef_source_t object.
9978 *
9979 * Get node children of the #idmef_source_t object.
9980 *
9981 * Returns: a pointer to a idmef_node_t object, or NULL if the children object is not set.
9982 */
idmef_source_get_node(idmef_source_t * ptr)9983 idmef_node_t *idmef_source_get_node(idmef_source_t *ptr)
9984 {
9985 prelude_return_val_if_fail(ptr, 0); /* FIXME */
9986
9987 return ptr->node;
9988 }
9989
9990 /**
9991 * idmef_source_set_node:
9992 * @ptr: pointer to a #idmef_source_t object.
9993 * @node: pointer to a #idmef_node_t object.
9994 *
9995 * Set @node object as a children of @ptr.
9996 * if @ptr already contain an @node object, then it is destroyed,
9997 * and updated to point to the provided @node object.
9998 */
9999
idmef_source_set_node(idmef_source_t * ptr,idmef_node_t * node)10000 void idmef_source_set_node(idmef_source_t *ptr, idmef_node_t *node)
10001 {
10002 prelude_return_if_fail(ptr);
10003
10004 if ( ptr->node )
10005 idmef_node_destroy(ptr->node);
10006
10007 ptr->node = node;
10008 }
10009
10010 /**
10011 * idmef_source_new_node:
10012 * @ptr: pointer to a #idmef_source_t object.
10013 * @ret: pointer to an address where to store the created #idmef_node_t object.
10014 *
10015 * Create a new node object, children of #idmef_source_t.
10016 * If @ptr already contain a #idmef_node_t object, then it is destroyed.
10017 *
10018 * Returns: 0 on success, or a negative value if an error occured.
10019 */
idmef_source_new_node(idmef_source_t * ptr,idmef_node_t ** ret)10020 int idmef_source_new_node(idmef_source_t *ptr, idmef_node_t **ret)
10021 {
10022 int retval;
10023
10024 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
10025
10026 if ( ! ptr->node ) {
10027 retval = idmef_node_new(&ptr->node);
10028 if ( retval < 0 )
10029 return retval;
10030 }
10031
10032 *ret = ptr->node;
10033 return 0;
10034 }
10035
10036 /**
10037 * idmef_source_get_user:
10038 * @ptr: pointer to a #idmef_source_t object.
10039 *
10040 * Get user children of the #idmef_source_t object.
10041 *
10042 * Returns: a pointer to a idmef_user_t object, or NULL if the children object is not set.
10043 */
idmef_source_get_user(idmef_source_t * ptr)10044 idmef_user_t *idmef_source_get_user(idmef_source_t *ptr)
10045 {
10046 prelude_return_val_if_fail(ptr, 0); /* FIXME */
10047
10048 return ptr->user;
10049 }
10050
10051 /**
10052 * idmef_source_set_user:
10053 * @ptr: pointer to a #idmef_source_t object.
10054 * @user: pointer to a #idmef_user_t object.
10055 *
10056 * Set @user object as a children of @ptr.
10057 * if @ptr already contain an @user object, then it is destroyed,
10058 * and updated to point to the provided @user object.
10059 */
10060
idmef_source_set_user(idmef_source_t * ptr,idmef_user_t * user)10061 void idmef_source_set_user(idmef_source_t *ptr, idmef_user_t *user)
10062 {
10063 prelude_return_if_fail(ptr);
10064
10065 if ( ptr->user )
10066 idmef_user_destroy(ptr->user);
10067
10068 ptr->user = user;
10069 }
10070
10071 /**
10072 * idmef_source_new_user:
10073 * @ptr: pointer to a #idmef_source_t object.
10074 * @ret: pointer to an address where to store the created #idmef_user_t object.
10075 *
10076 * Create a new user object, children of #idmef_source_t.
10077 * If @ptr already contain a #idmef_user_t object, then it is destroyed.
10078 *
10079 * Returns: 0 on success, or a negative value if an error occured.
10080 */
idmef_source_new_user(idmef_source_t * ptr,idmef_user_t ** ret)10081 int idmef_source_new_user(idmef_source_t *ptr, idmef_user_t **ret)
10082 {
10083 int retval;
10084
10085 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
10086
10087 if ( ! ptr->user ) {
10088 retval = idmef_user_new(&ptr->user);
10089 if ( retval < 0 )
10090 return retval;
10091 }
10092
10093 *ret = ptr->user;
10094 return 0;
10095 }
10096
10097 /**
10098 * idmef_source_get_process:
10099 * @ptr: pointer to a #idmef_source_t object.
10100 *
10101 * Get process children of the #idmef_source_t object.
10102 *
10103 * Returns: a pointer to a idmef_process_t object, or NULL if the children object is not set.
10104 */
idmef_source_get_process(idmef_source_t * ptr)10105 idmef_process_t *idmef_source_get_process(idmef_source_t *ptr)
10106 {
10107 prelude_return_val_if_fail(ptr, 0); /* FIXME */
10108
10109 return ptr->process;
10110 }
10111
10112 /**
10113 * idmef_source_set_process:
10114 * @ptr: pointer to a #idmef_source_t object.
10115 * @process: pointer to a #idmef_process_t object.
10116 *
10117 * Set @process object as a children of @ptr.
10118 * if @ptr already contain an @process object, then it is destroyed,
10119 * and updated to point to the provided @process object.
10120 */
10121
idmef_source_set_process(idmef_source_t * ptr,idmef_process_t * process)10122 void idmef_source_set_process(idmef_source_t *ptr, idmef_process_t *process)
10123 {
10124 prelude_return_if_fail(ptr);
10125
10126 if ( ptr->process )
10127 idmef_process_destroy(ptr->process);
10128
10129 ptr->process = process;
10130 }
10131
10132 /**
10133 * idmef_source_new_process:
10134 * @ptr: pointer to a #idmef_source_t object.
10135 * @ret: pointer to an address where to store the created #idmef_process_t object.
10136 *
10137 * Create a new process object, children of #idmef_source_t.
10138 * If @ptr already contain a #idmef_process_t object, then it is destroyed.
10139 *
10140 * Returns: 0 on success, or a negative value if an error occured.
10141 */
idmef_source_new_process(idmef_source_t * ptr,idmef_process_t ** ret)10142 int idmef_source_new_process(idmef_source_t *ptr, idmef_process_t **ret)
10143 {
10144 int retval;
10145
10146 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
10147
10148 if ( ! ptr->process ) {
10149 retval = idmef_process_new(&ptr->process);
10150 if ( retval < 0 )
10151 return retval;
10152 }
10153
10154 *ret = ptr->process;
10155 return 0;
10156 }
10157
10158 /**
10159 * idmef_source_get_service:
10160 * @ptr: pointer to a #idmef_source_t object.
10161 *
10162 * Get service children of the #idmef_source_t object.
10163 *
10164 * Returns: a pointer to a idmef_service_t object, or NULL if the children object is not set.
10165 */
idmef_source_get_service(idmef_source_t * ptr)10166 idmef_service_t *idmef_source_get_service(idmef_source_t *ptr)
10167 {
10168 prelude_return_val_if_fail(ptr, 0); /* FIXME */
10169
10170 return ptr->service;
10171 }
10172
10173 /**
10174 * idmef_source_set_service:
10175 * @ptr: pointer to a #idmef_source_t object.
10176 * @service: pointer to a #idmef_service_t object.
10177 *
10178 * Set @service object as a children of @ptr.
10179 * if @ptr already contain an @service object, then it is destroyed,
10180 * and updated to point to the provided @service object.
10181 */
10182
idmef_source_set_service(idmef_source_t * ptr,idmef_service_t * service)10183 void idmef_source_set_service(idmef_source_t *ptr, idmef_service_t *service)
10184 {
10185 prelude_return_if_fail(ptr);
10186
10187 if ( ptr->service )
10188 idmef_service_destroy(ptr->service);
10189
10190 ptr->service = service;
10191 }
10192
10193 /**
10194 * idmef_source_new_service:
10195 * @ptr: pointer to a #idmef_source_t object.
10196 * @ret: pointer to an address where to store the created #idmef_service_t object.
10197 *
10198 * Create a new service object, children of #idmef_source_t.
10199 * If @ptr already contain a #idmef_service_t object, then it is destroyed.
10200 *
10201 * Returns: 0 on success, or a negative value if an error occured.
10202 */
idmef_source_new_service(idmef_source_t * ptr,idmef_service_t ** ret)10203 int idmef_source_new_service(idmef_source_t *ptr, idmef_service_t **ret)
10204 {
10205 int retval;
10206
10207 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
10208
10209 if ( ! ptr->service ) {
10210 retval = idmef_service_new(&ptr->service);
10211 if ( retval < 0 )
10212 return retval;
10213 }
10214
10215 *ret = ptr->service;
10216 return 0;
10217 }
10218
10219 /**
10220 * idmef_source_copy:
10221 * @src: Source of the copy.
10222 * @dst: Where to copy the object.
10223 *
10224 * Copy a new #idmef_source_t object from @src to @dst.
10225 *
10226 * Returns: 0 on success, a negative value if an error occured.
10227 */
idmef_source_copy(const idmef_source_t * src,idmef_source_t * dst)10228 int idmef_source_copy(const idmef_source_t *src, idmef_source_t *dst)
10229 {
10230 int ret;
10231
10232 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
10233 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
10234
10235 ret = 0;
10236
10237 if ( src->ident ) {
10238 ret = prelude_string_clone(src->ident, &dst->ident);
10239 if ( ret < 0 )
10240 return ret;
10241 }
10242
10243 dst->spoofed = src->spoofed;
10244
10245 if ( src->interface ) {
10246 ret = prelude_string_clone(src->interface, &dst->interface);
10247 if ( ret < 0 )
10248 return ret;
10249 }
10250
10251 if ( src->node ) {
10252 ret = idmef_node_clone(src->node, &dst->node);
10253 if ( ret < 0 )
10254 return ret;
10255 }
10256
10257 if ( src->user ) {
10258 ret = idmef_user_clone(src->user, &dst->user);
10259 if ( ret < 0 )
10260 return ret;
10261 }
10262
10263 if ( src->process ) {
10264 ret = idmef_process_clone(src->process, &dst->process);
10265 if ( ret < 0 )
10266 return ret;
10267 }
10268
10269 if ( src->service ) {
10270 ret = idmef_service_clone(src->service, &dst->service);
10271 if ( ret < 0 )
10272 return ret;
10273 }
10274
10275 return 0;
10276 }
10277
10278 /**
10279 * idmef_source_clone:
10280 * @src: Object to be cloned.
10281 * @dst: Address where to store the pointer to the cloned object.
10282 *
10283 * Create a copy of @src, and store it in @dst.
10284 *
10285 * Returns: 0 on success, a negative value if an error occured.
10286 */
idmef_source_clone(idmef_source_t * src,idmef_source_t ** dst)10287 int idmef_source_clone(idmef_source_t *src, idmef_source_t **dst)
10288 {
10289 int ret;
10290
10291 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
10292
10293 ret = idmef_source_new(dst);
10294 if ( ret < 0 )
10295 return ret;
10296
10297 return idmef_source_copy(src, *dst);
10298 }
10299
10300 /**
10301 * idmef_source_compare:
10302 * @obj1: Object to compare with @obj2.
10303 * @obj2: Object to compare with @obj1.
10304 *
10305 * Compare @obj1 with @obj2.
10306 *
10307 * Returns: 0 on match, a negative value on comparison failure.
10308 */
idmef_source_compare(const idmef_source_t * obj1,const idmef_source_t * obj2)10309 int idmef_source_compare(const idmef_source_t *obj1, const idmef_source_t *obj2)
10310 {
10311 int ret = 0;
10312
10313 if ( obj1 == NULL && obj2 == NULL )
10314 return 0;
10315
10316 else if ( obj1 == NULL || obj2 == NULL )
10317 return -1;
10318
10319 ret = prelude_string_compare(obj1->ident, obj2->ident);
10320 if ( ret != 0 )
10321 return ret;
10322
10323 if ( obj1->spoofed != obj2->spoofed )
10324 return -1;
10325
10326 ret = prelude_string_compare(obj1->interface, obj2->interface);
10327 if ( ret != 0 )
10328 return ret;
10329
10330 ret = idmef_node_compare(obj1->node, obj2->node);
10331 if ( ret != 0 )
10332 return ret;
10333
10334 ret = idmef_user_compare(obj1->user, obj2->user);
10335 if ( ret != 0 )
10336 return ret;
10337
10338 ret = idmef_process_compare(obj1->process, obj2->process);
10339 if ( ret != 0 )
10340 return ret;
10341
10342 ret = idmef_service_compare(obj1->service, obj2->service);
10343 if ( ret != 0 )
10344 return ret;
10345
10346 return ret;
10347 }
10348
10349 /**
10350 * idmef_file_access_new:
10351 * @ret: Pointer where to store the created #idmef_file_access_t object.
10352 *
10353 * Create a new #idmef_file_access_t object.
10354 *
10355 * Returns: 0 on success, a negative value if an error occured.
10356 */
idmef_file_access_new(idmef_file_access_t ** ret)10357 int idmef_file_access_new(idmef_file_access_t **ret)
10358 {
10359 *ret = calloc(1, sizeof(**ret));
10360 if ( ! *ret )
10361 return prelude_error_from_errno(errno);
10362
10363 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_FILE_ACCESS;
10364
10365 prelude_list_init(&((prelude_linked_object_t *) (*ret))->_list);
10366
10367 (*ret)->refcount = 1;
10368
10369 prelude_list_init(&(*ret)->permission_list);
10370
10371
10372 {
10373 int retval = idmef_user_id_new(&(*ret)->user_id);
10374
10375 if ( retval < 0 ) {
10376 idmef_file_access_destroy(*ret);
10377 *ret = NULL;
10378 return retval;
10379 }
10380 }
10381
10382 return 0;
10383
10384 }
10385
10386 /**
10387 * idmef_file_access_ref:
10388 * @file_access: pointer to a #idmef_file_access_t object.
10389 *
10390 * Increase @file_access reference count, so that it can be referenced
10391 * multiple time.
10392 *
10393 * Returns: a pointer to @file_access.
10394 */
idmef_file_access_ref(idmef_file_access_t * file_access)10395 idmef_file_access_t *idmef_file_access_ref(idmef_file_access_t *file_access)
10396 {
10397 prelude_return_val_if_fail(file_access, NULL);
10398 file_access->refcount++;
10399
10400 return file_access;
10401 }
10402
_idmef_file_access_get_child(void * p,idmef_class_child_id_t child,void ** childptr)10403 int _idmef_file_access_get_child(void *p, idmef_class_child_id_t child, void **childptr)
10404 {
10405 idmef_file_access_t *ptr = p;
10406
10407 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
10408 *childptr = NULL;
10409
10410 switch ( child ) {
10411
10412 case 0:
10413 *childptr = ptr->user_id;
10414 return 0;
10415
10416 case 1:
10417 *childptr = &ptr->permission_list;
10418 return 0;
10419
10420 default:
10421 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
10422 }
10423 }
10424
_idmef_file_access_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)10425 int _idmef_file_access_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
10426 {
10427 idmef_file_access_t *ptr = p;
10428
10429 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
10430
10431 switch ( child ) {
10432
10433 case 0:
10434 return idmef_file_access_new_user_id(ptr, (idmef_user_id_t **) ret);
10435
10436 case 1: {
10437 int i = 0;
10438 prelude_list_t *tmp;
10439
10440 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
10441 return idmef_file_access_new_permission(ptr, (prelude_string_t **) ret, n);
10442
10443 if ( n >= 0 ) {
10444 prelude_list_for_each(&ptr->permission_list, tmp) {
10445 if ( i++ == n ) {
10446 *ret = prelude_linked_object_get_object(tmp);
10447 return 0;
10448 }
10449 }
10450
10451 if ( i != n )
10452 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
10453 } else {
10454 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
10455
10456 prelude_list_for_each_reversed(&ptr->permission_list, tmp) {
10457 if ( i++ == pos ) {
10458 *ret = prelude_linked_object_get_object(tmp);
10459 return 0;
10460 }
10461 }
10462
10463 if ( i != pos )
10464 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
10465 }
10466
10467 return idmef_file_access_new_permission(ptr, (prelude_string_t **) ret, n);
10468 }
10469
10470 default:
10471 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
10472 }
10473 }
10474
_idmef_file_access_destroy_child(void * p,idmef_class_child_id_t child,int n)10475 int _idmef_file_access_destroy_child(void *p, idmef_class_child_id_t child, int n)
10476 {
10477 idmef_file_access_t *ptr = p;
10478
10479 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
10480
10481 switch ( child ) {
10482
10483 case 0:
10484 if ( ptr->user_id ) {
10485 idmef_user_id_destroy(ptr->user_id);
10486 ptr->user_id = NULL;
10487 }
10488
10489 return 0;
10490
10491 case 1: {
10492 int i = 0;
10493 prelude_list_t *tmp;
10494
10495 if ( n >= 0 ) {
10496 prelude_list_for_each(&ptr->permission_list, tmp) {
10497 if ( i++ == n ) {
10498 void *b = prelude_linked_object_get_object(tmp);
10499 prelude_string_destroy(b);
10500 return 0;
10501 }
10502 }
10503
10504 if ( i != n )
10505 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
10506 } else {
10507 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
10508
10509 prelude_list_for_each_reversed(&ptr->permission_list, tmp) {
10510 if ( i++ == pos ) {
10511 void *b = prelude_linked_object_get_object(tmp);
10512 prelude_string_destroy(b);
10513 return 0;
10514 }
10515 }
10516
10517 if ( i != pos )
10518 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
10519 }
10520 }
10521
10522 default:
10523 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
10524 }
10525 }
10526
idmef_file_access_destroy_internal(idmef_file_access_t * ptr)10527 static void idmef_file_access_destroy_internal(idmef_file_access_t *ptr)
10528 {
10529 prelude_return_if_fail(ptr);
10530
10531 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *)ptr)->_list) )
10532 prelude_list_del_init(&((prelude_linked_object_t *)ptr)->_list);
10533
10534 if ( ptr->user_id ) {
10535 idmef_user_id_destroy(ptr->user_id);
10536 ptr->user_id = NULL;
10537 }
10538
10539 {
10540 prelude_list_t *n, *tmp;
10541 prelude_string_t *entry;
10542
10543 prelude_list_for_each_safe(&ptr->permission_list, tmp, n) {
10544 entry = prelude_linked_object_get_object(tmp);
10545 prelude_list_del_init(tmp);
10546 prelude_string_destroy(entry);
10547 }
10548 }
10549
10550
10551 /* free() should be done by the caller */
10552 }
10553
10554 /**
10555 * idmef_file_access_destroy:
10556 * @ptr: pointer to a #idmef_file_access_t object.
10557 *
10558 * Destroy @ptr and all of it's children.
10559 * The objects are only destroyed if their reference count reach zero.
10560 */
10561
idmef_file_access_destroy(idmef_file_access_t * ptr)10562 void idmef_file_access_destroy(idmef_file_access_t *ptr)
10563 {
10564 prelude_return_if_fail(ptr);
10565
10566 if ( --ptr->refcount )
10567 return;
10568
10569 idmef_file_access_destroy_internal(ptr);
10570 free(ptr);
10571 }
10572
10573 /**
10574 * idmef_file_access_get_user_id:
10575 * @ptr: pointer to a #idmef_file_access_t object.
10576 *
10577 * Get user_id children of the #idmef_file_access_t object.
10578 *
10579 * Returns: a pointer to a idmef_user_id_t object, or NULL if the children object is not set.
10580 */
idmef_file_access_get_user_id(idmef_file_access_t * ptr)10581 idmef_user_id_t *idmef_file_access_get_user_id(idmef_file_access_t *ptr)
10582 {
10583 prelude_return_val_if_fail(ptr, 0); /* FIXME */
10584
10585 return ptr->user_id;
10586 }
10587
10588 /**
10589 * idmef_file_access_set_user_id:
10590 * @ptr: pointer to a #idmef_file_access_t object.
10591 * @user_id: pointer to a #idmef_user_id_t object.
10592 *
10593 * Set @user_id object as a children of @ptr.
10594 * if @ptr already contain an @user_id object, then it is destroyed,
10595 * and updated to point to the provided @user_id object.
10596 */
10597
idmef_file_access_set_user_id(idmef_file_access_t * ptr,idmef_user_id_t * user_id)10598 void idmef_file_access_set_user_id(idmef_file_access_t *ptr, idmef_user_id_t *user_id)
10599 {
10600 prelude_return_if_fail(ptr);
10601
10602 if ( ptr->user_id )
10603 idmef_user_id_destroy(ptr->user_id);
10604
10605 ptr->user_id = user_id;
10606 }
10607
10608 /**
10609 * idmef_file_access_new_user_id:
10610 * @ptr: pointer to a #idmef_file_access_t object.
10611 * @ret: pointer to an address where to store the created #idmef_user_id_t object.
10612 *
10613 * Create a new user_id object, children of #idmef_file_access_t.
10614 * If @ptr already contain a #idmef_user_id_t object, then it is destroyed.
10615 *
10616 * Returns: 0 on success, or a negative value if an error occured.
10617 */
idmef_file_access_new_user_id(idmef_file_access_t * ptr,idmef_user_id_t ** ret)10618 int idmef_file_access_new_user_id(idmef_file_access_t *ptr, idmef_user_id_t **ret)
10619 {
10620 int retval;
10621
10622 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
10623
10624 if ( ! ptr->user_id ) {
10625 retval = idmef_user_id_new(&ptr->user_id);
10626 if ( retval < 0 )
10627 return retval;
10628 }
10629
10630 *ret = ptr->user_id;
10631 return 0;
10632 }
10633
10634 /**
10635 * idmef_file_access_get_next_permission:
10636 * @file_access: pointer to a #idmef_file_access_t object.
10637 * @prelude_string_cur: pointer to a #prelude_string_t object.
10638 *
10639 * Get the next #prelude_string_t object listed in @ptr.
10640 * When iterating over the prelude_string_t object listed in @ptr,
10641 * @object should be set to the latest returned #prelude_string_t object.
10642 *
10643 * Returns: the next #prelude_string_t in the list.
10644 */
idmef_file_access_get_next_permission(idmef_file_access_t * file_access,prelude_string_t * prelude_string_cur)10645 prelude_string_t *idmef_file_access_get_next_permission(idmef_file_access_t *file_access, prelude_string_t *prelude_string_cur)
10646 {
10647 prelude_list_t *tmp = (prelude_string_cur) ? &((prelude_linked_object_t *) prelude_string_cur)->_list : NULL;
10648
10649 prelude_return_val_if_fail(file_access, NULL);
10650
10651 prelude_list_for_each_continue(&file_access->permission_list, tmp)
10652 return prelude_linked_object_get_object(tmp);
10653
10654 return NULL;
10655 }
10656
10657
10658 /**
10659 * idmef_file_access_set_permission:
10660 * @ptr: pointer to a #idmef_file_access_t object.
10661 * @object: pointer to a #prelude_string_t object.
10662 * @pos: Position in the list.
10663 *
10664 * Add @object to position @pos of @ptr list of #prelude_string_t object.
10665 *
10666 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
10667 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
10668 */
idmef_file_access_set_permission(idmef_file_access_t * ptr,prelude_string_t * object,int pos)10669 void idmef_file_access_set_permission(idmef_file_access_t *ptr, prelude_string_t *object, int pos)
10670 {
10671 prelude_return_if_fail(ptr);
10672 prelude_return_if_fail(object);
10673
10674 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
10675 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
10676
10677 list_insert(&ptr->permission_list, &((prelude_linked_object_t *) object)->_list, pos);
10678 }
10679
10680
10681 /**
10682 * idmef_file_access_new_permission:
10683 * @ptr: pointer to a #idmef_file_access_t object.
10684 * @ret: pointer to an address where to store the created #prelude_string_t object.
10685 * @pos: position in the list.
10686 *
10687 * Create a new #prelude_string_t children of @ptr, and add it to position @pos of
10688 * @ptr list of #prelude_string_t object. The created #prelude_string_t object is
10689 * stored in @ret.
10690 *
10691 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
10692 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
10693 *
10694 * Returns: 0 on success, or a negative value if an error occured.
10695 */
idmef_file_access_new_permission(idmef_file_access_t * ptr,prelude_string_t ** ret,int pos)10696 int idmef_file_access_new_permission(idmef_file_access_t *ptr, prelude_string_t **ret, int pos)
10697 {
10698 int retval;
10699
10700 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
10701
10702 retval = prelude_string_new(ret);
10703 if ( retval < 0 )
10704 return retval;
10705
10706 list_insert(&ptr->permission_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
10707
10708 return 0;
10709 }
10710
10711
10712 /**
10713 * idmef_file_access_copy:
10714 * @src: Source of the copy.
10715 * @dst: Where to copy the object.
10716 *
10717 * Copy a new #idmef_file_access_t object from @src to @dst.
10718 *
10719 * Returns: 0 on success, a negative value if an error occured.
10720 */
idmef_file_access_copy(const idmef_file_access_t * src,idmef_file_access_t * dst)10721 int idmef_file_access_copy(const idmef_file_access_t *src, idmef_file_access_t *dst)
10722 {
10723 int ret;
10724
10725 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
10726 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
10727
10728 ret = 0;
10729
10730 if ( src->user_id ) {
10731 ret = idmef_user_id_copy(src->user_id, dst->user_id);
10732 if ( ret < 0 )
10733 return ret;
10734 }
10735
10736 {
10737 prelude_list_t *n, *tmp;
10738 prelude_string_t *entry, *new;
10739
10740 prelude_list_for_each_safe(&src->permission_list, tmp, n) {
10741 entry = prelude_linked_object_get_object(tmp);
10742 prelude_string_clone(entry, &new);
10743 prelude_list_add_tail(&dst->permission_list, &((prelude_linked_object_t *) new)->_list);
10744 }
10745 }
10746
10747 return 0;
10748 }
10749
10750 /**
10751 * idmef_file_access_clone:
10752 * @src: Object to be cloned.
10753 * @dst: Address where to store the pointer to the cloned object.
10754 *
10755 * Create a copy of @src, and store it in @dst.
10756 *
10757 * Returns: 0 on success, a negative value if an error occured.
10758 */
idmef_file_access_clone(idmef_file_access_t * src,idmef_file_access_t ** dst)10759 int idmef_file_access_clone(idmef_file_access_t *src, idmef_file_access_t **dst)
10760 {
10761 int ret;
10762
10763 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
10764
10765 ret = idmef_file_access_new(dst);
10766 if ( ret < 0 )
10767 return ret;
10768
10769 return idmef_file_access_copy(src, *dst);
10770 }
10771
10772 /**
10773 * idmef_file_access_compare:
10774 * @obj1: Object to compare with @obj2.
10775 * @obj2: Object to compare with @obj1.
10776 *
10777 * Compare @obj1 with @obj2.
10778 *
10779 * Returns: 0 on match, a negative value on comparison failure.
10780 */
idmef_file_access_compare(const idmef_file_access_t * obj1,const idmef_file_access_t * obj2)10781 int idmef_file_access_compare(const idmef_file_access_t *obj1, const idmef_file_access_t *obj2)
10782 {
10783 int ret = 0;
10784
10785 if ( obj1 == NULL && obj2 == NULL )
10786 return 0;
10787
10788 else if ( obj1 == NULL || obj2 == NULL )
10789 return -1;
10790
10791 ret = idmef_user_id_compare(obj1->user_id, obj2->user_id);
10792 if ( ret != 0 )
10793 return ret;
10794
10795 {
10796 prelude_list_t *tmp1, *tmp2;
10797 prelude_string_t *entry1, *entry2;
10798
10799 tmp1 = tmp2 = NULL;
10800 do {
10801 entry1 = entry2 = NULL;
10802
10803 prelude_list_for_each_continue(&obj1->permission_list, tmp1) {
10804 entry1 = prelude_linked_object_get_object(tmp1);
10805 break;
10806 }
10807
10808 prelude_list_for_each_continue(&obj2->permission_list, tmp2) {
10809 entry2 = prelude_linked_object_get_object(tmp2);
10810 break;
10811 }
10812
10813 ret = prelude_string_compare(entry1, entry2);
10814 if ( ret != 0 )
10815 return ret;
10816
10817 } while ( entry1 && entry2 );
10818 }
10819
10820 return ret;
10821 }
10822
10823 /**
10824 * idmef_inode_new:
10825 * @ret: Pointer where to store the created #idmef_inode_t object.
10826 *
10827 * Create a new #idmef_inode_t object.
10828 *
10829 * Returns: 0 on success, a negative value if an error occured.
10830 */
idmef_inode_new(idmef_inode_t ** ret)10831 int idmef_inode_new(idmef_inode_t **ret)
10832 {
10833 *ret = calloc(1, sizeof(**ret));
10834 if ( ! *ret )
10835 return prelude_error_from_errno(errno);
10836
10837 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_INODE;
10838
10839 (*ret)->refcount = 1;
10840
10841 return 0;
10842
10843 }
10844
10845 /**
10846 * idmef_inode_ref:
10847 * @inode: pointer to a #idmef_inode_t object.
10848 *
10849 * Increase @inode reference count, so that it can be referenced
10850 * multiple time.
10851 *
10852 * Returns: a pointer to @inode.
10853 */
idmef_inode_ref(idmef_inode_t * inode)10854 idmef_inode_t *idmef_inode_ref(idmef_inode_t *inode)
10855 {
10856 prelude_return_val_if_fail(inode, NULL);
10857 inode->refcount++;
10858
10859 return inode;
10860 }
10861
_idmef_inode_get_child(void * p,idmef_class_child_id_t child,void ** childptr)10862 int _idmef_inode_get_child(void *p, idmef_class_child_id_t child, void **childptr)
10863 {
10864 idmef_inode_t *ptr = p;
10865
10866 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
10867 *childptr = NULL;
10868
10869 switch ( child ) {
10870
10871 case 0:
10872 return get_value_from_time((idmef_value_t **) childptr, ptr->change_time, TRUE);
10873 case 1:
10874 return (ptr->number_is_set) ? idmef_value_new_uint32((idmef_value_t **) childptr, ptr->number) : 0;
10875
10876 case 2:
10877 return (ptr->major_device_is_set) ? idmef_value_new_uint32((idmef_value_t **) childptr, ptr->major_device) : 0;
10878
10879 case 3:
10880 return (ptr->minor_device_is_set) ? idmef_value_new_uint32((idmef_value_t **) childptr, ptr->minor_device) : 0;
10881
10882 case 4:
10883 return (ptr->c_major_device_is_set) ? idmef_value_new_uint32((idmef_value_t **) childptr, ptr->c_major_device) : 0;
10884
10885 case 5:
10886 return (ptr->c_minor_device_is_set) ? idmef_value_new_uint32((idmef_value_t **) childptr, ptr->c_minor_device) : 0;
10887
10888 default:
10889 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
10890 }
10891 }
10892
_idmef_inode_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)10893 int _idmef_inode_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
10894 {
10895 idmef_inode_t *ptr = p;
10896
10897 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
10898
10899 switch ( child ) {
10900
10901 case 0:
10902 return idmef_inode_new_change_time(ptr, (idmef_time_t **) ret);
10903
10904 case 1:
10905 return idmef_inode_new_number(ptr, (uint32_t **) ret);
10906
10907 case 2:
10908 return idmef_inode_new_major_device(ptr, (uint32_t **) ret);
10909
10910 case 3:
10911 return idmef_inode_new_minor_device(ptr, (uint32_t **) ret);
10912
10913 case 4:
10914 return idmef_inode_new_c_major_device(ptr, (uint32_t **) ret);
10915
10916 case 5:
10917 return idmef_inode_new_c_minor_device(ptr, (uint32_t **) ret);
10918
10919 default:
10920 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
10921 }
10922 }
10923
_idmef_inode_destroy_child(void * p,idmef_class_child_id_t child,int n)10924 int _idmef_inode_destroy_child(void *p, idmef_class_child_id_t child, int n)
10925 {
10926 idmef_inode_t *ptr = p;
10927
10928 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
10929
10930 switch ( child ) {
10931
10932 case 0:
10933 if ( ptr->change_time ) {
10934 idmef_time_destroy(ptr->change_time);
10935 ptr->change_time = NULL;
10936 }
10937
10938 return 0;
10939
10940 case 1:
10941 ptr->number_is_set = 0;
10942 return 0;
10943
10944 case 2:
10945 ptr->major_device_is_set = 0;
10946 return 0;
10947
10948 case 3:
10949 ptr->minor_device_is_set = 0;
10950 return 0;
10951
10952 case 4:
10953 ptr->c_major_device_is_set = 0;
10954 return 0;
10955
10956 case 5:
10957 ptr->c_minor_device_is_set = 0;
10958 return 0;
10959
10960 default:
10961 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
10962 }
10963 }
10964
idmef_inode_destroy_internal(idmef_inode_t * ptr)10965 static void idmef_inode_destroy_internal(idmef_inode_t *ptr)
10966 {
10967 prelude_return_if_fail(ptr);
10968
10969 if ( ptr->change_time ) {
10970 idmef_time_destroy(ptr->change_time);
10971 ptr->change_time = NULL;
10972 }
10973
10974
10975 /* free() should be done by the caller */
10976 }
10977
10978 /**
10979 * idmef_inode_destroy:
10980 * @ptr: pointer to a #idmef_inode_t object.
10981 *
10982 * Destroy @ptr and all of it's children.
10983 * The objects are only destroyed if their reference count reach zero.
10984 */
10985
idmef_inode_destroy(idmef_inode_t * ptr)10986 void idmef_inode_destroy(idmef_inode_t *ptr)
10987 {
10988 prelude_return_if_fail(ptr);
10989
10990 if ( --ptr->refcount )
10991 return;
10992
10993 idmef_inode_destroy_internal(ptr);
10994 free(ptr);
10995 }
10996
10997 /**
10998 * idmef_inode_get_change_time:
10999 * @ptr: pointer to a #idmef_inode_t object.
11000 *
11001 * Get change_time children of the #idmef_inode_t object.
11002 *
11003 * Returns: a pointer to a idmef_time_t object, or NULL if the children object is not set.
11004 */
idmef_inode_get_change_time(idmef_inode_t * ptr)11005 idmef_time_t *idmef_inode_get_change_time(idmef_inode_t *ptr)
11006 {
11007 prelude_return_val_if_fail(ptr, 0); /* FIXME */
11008
11009 return ptr->change_time;
11010 }
11011
11012 /**
11013 * idmef_inode_set_change_time:
11014 * @ptr: pointer to a #idmef_inode_t object.
11015 * @change_time: pointer to a #idmef_time_t object.
11016 *
11017 * Set @change_time object as a children of @ptr.
11018 * if @ptr already contain an @change_time object, then it is destroyed,
11019 * and updated to point to the provided @change_time object.
11020 */
11021
idmef_inode_set_change_time(idmef_inode_t * ptr,idmef_time_t * change_time)11022 void idmef_inode_set_change_time(idmef_inode_t *ptr, idmef_time_t *change_time)
11023 {
11024 prelude_return_if_fail(ptr);
11025
11026 if ( ptr->change_time )
11027 idmef_time_destroy(ptr->change_time);
11028
11029 ptr->change_time = change_time;
11030 }
11031
11032 /**
11033 * idmef_inode_new_change_time:
11034 * @ptr: pointer to a #idmef_inode_t object.
11035 * @ret: pointer to an address where to store the created #idmef_time_t object.
11036 *
11037 * Create a new change_time object, children of #idmef_inode_t.
11038 * If @ptr already contain a #idmef_time_t object, then it is destroyed.
11039 *
11040 * Returns: 0 on success, or a negative value if an error occured.
11041 */
idmef_inode_new_change_time(idmef_inode_t * ptr,idmef_time_t ** ret)11042 int idmef_inode_new_change_time(idmef_inode_t *ptr, idmef_time_t **ret)
11043 {
11044 int retval;
11045
11046 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
11047
11048 if ( ! ptr->change_time ) {
11049 retval = idmef_time_new(&ptr->change_time);
11050 if ( retval < 0 )
11051 return retval;
11052 }
11053
11054 *ret = ptr->change_time;
11055 return 0;
11056 }
11057
11058 /**
11059 * idmef_inode_get_number:
11060 * @ptr: pointer to a #idmef_inode_t object.
11061 *
11062 * Get number children of the #idmef_inode_t object.
11063 *
11064 * Returns: a pointer to a uint32_t object, or NULL if the children object is not set.
11065 */
idmef_inode_get_number(idmef_inode_t * ptr)11066 uint32_t *idmef_inode_get_number(idmef_inode_t *ptr)
11067 {
11068 prelude_return_val_if_fail(ptr, 0); /* FIXME */
11069
11070 return ptr->number_is_set ? &ptr->number : NULL;
11071 }
11072
11073 /**
11074 * idmef_inode_set_number:
11075 * @ptr: pointer to a #idmef_inode_t object.
11076 * @number: pointer to a #uint32_t object.
11077 *
11078 * Set @number object as a children of @ptr.
11079 * if @ptr already contain an @number object, then it is destroyed,
11080 * and updated to point to the provided @number object.
11081 */
11082
idmef_inode_set_number(idmef_inode_t * ptr,uint32_t number)11083 void idmef_inode_set_number(idmef_inode_t *ptr, uint32_t number)
11084 {
11085 prelude_return_if_fail(ptr);
11086 ptr->number = number;
11087 ptr->number_is_set = 1;
11088 }
11089
11090
idmef_inode_unset_number(idmef_inode_t * ptr)11091 void idmef_inode_unset_number(idmef_inode_t *ptr)
11092 {
11093 prelude_return_if_fail(ptr);
11094 ptr->number_is_set = 0;
11095 }
11096
11097
11098 /**
11099 * idmef_inode_new_number:
11100 * @ptr: pointer to a #idmef_inode_t object.
11101 * @ret: pointer to an address where to store the created #uint32_t object.
11102 *
11103 * Create a new number object, children of #idmef_inode_t.
11104 * If @ptr already contain a #uint32_t object, then it is destroyed.
11105 *
11106 * Returns: 0 on success, or a negative value if an error occured.
11107 */
idmef_inode_new_number(idmef_inode_t * ptr,uint32_t ** ret)11108 int idmef_inode_new_number(idmef_inode_t *ptr, uint32_t **ret)
11109 {
11110 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
11111 ptr->number_is_set = 1;
11112
11113 *ret = &ptr->number;
11114 return 0;
11115 }
11116
11117 /**
11118 * idmef_inode_get_major_device:
11119 * @ptr: pointer to a #idmef_inode_t object.
11120 *
11121 * Get major_device children of the #idmef_inode_t object.
11122 *
11123 * Returns: a pointer to a uint32_t object, or NULL if the children object is not set.
11124 */
idmef_inode_get_major_device(idmef_inode_t * ptr)11125 uint32_t *idmef_inode_get_major_device(idmef_inode_t *ptr)
11126 {
11127 prelude_return_val_if_fail(ptr, 0); /* FIXME */
11128
11129 return ptr->major_device_is_set ? &ptr->major_device : NULL;
11130 }
11131
11132 /**
11133 * idmef_inode_set_major_device:
11134 * @ptr: pointer to a #idmef_inode_t object.
11135 * @major_device: pointer to a #uint32_t object.
11136 *
11137 * Set @major_device object as a children of @ptr.
11138 * if @ptr already contain an @major_device object, then it is destroyed,
11139 * and updated to point to the provided @major_device object.
11140 */
11141
idmef_inode_set_major_device(idmef_inode_t * ptr,uint32_t major_device)11142 void idmef_inode_set_major_device(idmef_inode_t *ptr, uint32_t major_device)
11143 {
11144 prelude_return_if_fail(ptr);
11145 ptr->major_device = major_device;
11146 ptr->major_device_is_set = 1;
11147 }
11148
11149
idmef_inode_unset_major_device(idmef_inode_t * ptr)11150 void idmef_inode_unset_major_device(idmef_inode_t *ptr)
11151 {
11152 prelude_return_if_fail(ptr);
11153 ptr->major_device_is_set = 0;
11154 }
11155
11156
11157 /**
11158 * idmef_inode_new_major_device:
11159 * @ptr: pointer to a #idmef_inode_t object.
11160 * @ret: pointer to an address where to store the created #uint32_t object.
11161 *
11162 * Create a new major_device object, children of #idmef_inode_t.
11163 * If @ptr already contain a #uint32_t object, then it is destroyed.
11164 *
11165 * Returns: 0 on success, or a negative value if an error occured.
11166 */
idmef_inode_new_major_device(idmef_inode_t * ptr,uint32_t ** ret)11167 int idmef_inode_new_major_device(idmef_inode_t *ptr, uint32_t **ret)
11168 {
11169 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
11170 ptr->major_device_is_set = 1;
11171
11172 *ret = &ptr->major_device;
11173 return 0;
11174 }
11175
11176 /**
11177 * idmef_inode_get_minor_device:
11178 * @ptr: pointer to a #idmef_inode_t object.
11179 *
11180 * Get minor_device children of the #idmef_inode_t object.
11181 *
11182 * Returns: a pointer to a uint32_t object, or NULL if the children object is not set.
11183 */
idmef_inode_get_minor_device(idmef_inode_t * ptr)11184 uint32_t *idmef_inode_get_minor_device(idmef_inode_t *ptr)
11185 {
11186 prelude_return_val_if_fail(ptr, 0); /* FIXME */
11187
11188 return ptr->minor_device_is_set ? &ptr->minor_device : NULL;
11189 }
11190
11191 /**
11192 * idmef_inode_set_minor_device:
11193 * @ptr: pointer to a #idmef_inode_t object.
11194 * @minor_device: pointer to a #uint32_t object.
11195 *
11196 * Set @minor_device object as a children of @ptr.
11197 * if @ptr already contain an @minor_device object, then it is destroyed,
11198 * and updated to point to the provided @minor_device object.
11199 */
11200
idmef_inode_set_minor_device(idmef_inode_t * ptr,uint32_t minor_device)11201 void idmef_inode_set_minor_device(idmef_inode_t *ptr, uint32_t minor_device)
11202 {
11203 prelude_return_if_fail(ptr);
11204 ptr->minor_device = minor_device;
11205 ptr->minor_device_is_set = 1;
11206 }
11207
11208
idmef_inode_unset_minor_device(idmef_inode_t * ptr)11209 void idmef_inode_unset_minor_device(idmef_inode_t *ptr)
11210 {
11211 prelude_return_if_fail(ptr);
11212 ptr->minor_device_is_set = 0;
11213 }
11214
11215
11216 /**
11217 * idmef_inode_new_minor_device:
11218 * @ptr: pointer to a #idmef_inode_t object.
11219 * @ret: pointer to an address where to store the created #uint32_t object.
11220 *
11221 * Create a new minor_device object, children of #idmef_inode_t.
11222 * If @ptr already contain a #uint32_t object, then it is destroyed.
11223 *
11224 * Returns: 0 on success, or a negative value if an error occured.
11225 */
idmef_inode_new_minor_device(idmef_inode_t * ptr,uint32_t ** ret)11226 int idmef_inode_new_minor_device(idmef_inode_t *ptr, uint32_t **ret)
11227 {
11228 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
11229 ptr->minor_device_is_set = 1;
11230
11231 *ret = &ptr->minor_device;
11232 return 0;
11233 }
11234
11235 /**
11236 * idmef_inode_get_c_major_device:
11237 * @ptr: pointer to a #idmef_inode_t object.
11238 *
11239 * Get c_major_device children of the #idmef_inode_t object.
11240 *
11241 * Returns: a pointer to a uint32_t object, or NULL if the children object is not set.
11242 */
idmef_inode_get_c_major_device(idmef_inode_t * ptr)11243 uint32_t *idmef_inode_get_c_major_device(idmef_inode_t *ptr)
11244 {
11245 prelude_return_val_if_fail(ptr, 0); /* FIXME */
11246
11247 return ptr->c_major_device_is_set ? &ptr->c_major_device : NULL;
11248 }
11249
11250 /**
11251 * idmef_inode_set_c_major_device:
11252 * @ptr: pointer to a #idmef_inode_t object.
11253 * @c_major_device: pointer to a #uint32_t object.
11254 *
11255 * Set @c_major_device object as a children of @ptr.
11256 * if @ptr already contain an @c_major_device object, then it is destroyed,
11257 * and updated to point to the provided @c_major_device object.
11258 */
11259
idmef_inode_set_c_major_device(idmef_inode_t * ptr,uint32_t c_major_device)11260 void idmef_inode_set_c_major_device(idmef_inode_t *ptr, uint32_t c_major_device)
11261 {
11262 prelude_return_if_fail(ptr);
11263 ptr->c_major_device = c_major_device;
11264 ptr->c_major_device_is_set = 1;
11265 }
11266
11267
idmef_inode_unset_c_major_device(idmef_inode_t * ptr)11268 void idmef_inode_unset_c_major_device(idmef_inode_t *ptr)
11269 {
11270 prelude_return_if_fail(ptr);
11271 ptr->c_major_device_is_set = 0;
11272 }
11273
11274
11275 /**
11276 * idmef_inode_new_c_major_device:
11277 * @ptr: pointer to a #idmef_inode_t object.
11278 * @ret: pointer to an address where to store the created #uint32_t object.
11279 *
11280 * Create a new c_major_device object, children of #idmef_inode_t.
11281 * If @ptr already contain a #uint32_t object, then it is destroyed.
11282 *
11283 * Returns: 0 on success, or a negative value if an error occured.
11284 */
idmef_inode_new_c_major_device(idmef_inode_t * ptr,uint32_t ** ret)11285 int idmef_inode_new_c_major_device(idmef_inode_t *ptr, uint32_t **ret)
11286 {
11287 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
11288 ptr->c_major_device_is_set = 1;
11289
11290 *ret = &ptr->c_major_device;
11291 return 0;
11292 }
11293
11294 /**
11295 * idmef_inode_get_c_minor_device:
11296 * @ptr: pointer to a #idmef_inode_t object.
11297 *
11298 * Get c_minor_device children of the #idmef_inode_t object.
11299 *
11300 * Returns: a pointer to a uint32_t object, or NULL if the children object is not set.
11301 */
idmef_inode_get_c_minor_device(idmef_inode_t * ptr)11302 uint32_t *idmef_inode_get_c_minor_device(idmef_inode_t *ptr)
11303 {
11304 prelude_return_val_if_fail(ptr, 0); /* FIXME */
11305
11306 return ptr->c_minor_device_is_set ? &ptr->c_minor_device : NULL;
11307 }
11308
11309 /**
11310 * idmef_inode_set_c_minor_device:
11311 * @ptr: pointer to a #idmef_inode_t object.
11312 * @c_minor_device: pointer to a #uint32_t object.
11313 *
11314 * Set @c_minor_device object as a children of @ptr.
11315 * if @ptr already contain an @c_minor_device object, then it is destroyed,
11316 * and updated to point to the provided @c_minor_device object.
11317 */
11318
idmef_inode_set_c_minor_device(idmef_inode_t * ptr,uint32_t c_minor_device)11319 void idmef_inode_set_c_minor_device(idmef_inode_t *ptr, uint32_t c_minor_device)
11320 {
11321 prelude_return_if_fail(ptr);
11322 ptr->c_minor_device = c_minor_device;
11323 ptr->c_minor_device_is_set = 1;
11324 }
11325
11326
idmef_inode_unset_c_minor_device(idmef_inode_t * ptr)11327 void idmef_inode_unset_c_minor_device(idmef_inode_t *ptr)
11328 {
11329 prelude_return_if_fail(ptr);
11330 ptr->c_minor_device_is_set = 0;
11331 }
11332
11333
11334 /**
11335 * idmef_inode_new_c_minor_device:
11336 * @ptr: pointer to a #idmef_inode_t object.
11337 * @ret: pointer to an address where to store the created #uint32_t object.
11338 *
11339 * Create a new c_minor_device object, children of #idmef_inode_t.
11340 * If @ptr already contain a #uint32_t object, then it is destroyed.
11341 *
11342 * Returns: 0 on success, or a negative value if an error occured.
11343 */
idmef_inode_new_c_minor_device(idmef_inode_t * ptr,uint32_t ** ret)11344 int idmef_inode_new_c_minor_device(idmef_inode_t *ptr, uint32_t **ret)
11345 {
11346 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
11347 ptr->c_minor_device_is_set = 1;
11348
11349 *ret = &ptr->c_minor_device;
11350 return 0;
11351 }
11352
11353 /**
11354 * idmef_inode_copy:
11355 * @src: Source of the copy.
11356 * @dst: Where to copy the object.
11357 *
11358 * Copy a new #idmef_inode_t object from @src to @dst.
11359 *
11360 * Returns: 0 on success, a negative value if an error occured.
11361 */
idmef_inode_copy(const idmef_inode_t * src,idmef_inode_t * dst)11362 int idmef_inode_copy(const idmef_inode_t *src, idmef_inode_t *dst)
11363 {
11364 int ret;
11365
11366 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
11367 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
11368
11369 ret = 0;
11370
11371 if ( src->change_time ) {
11372 ret = idmef_time_clone(src->change_time, &dst->change_time);
11373 if ( ret < 0 )
11374 return ret;
11375 }
11376
11377 dst->number_is_set = src->number_is_set;
11378
11379 dst->number = src->number;
11380
11381 dst->major_device_is_set = src->major_device_is_set;
11382
11383 dst->major_device = src->major_device;
11384
11385 dst->minor_device_is_set = src->minor_device_is_set;
11386
11387 dst->minor_device = src->minor_device;
11388
11389 dst->c_major_device_is_set = src->c_major_device_is_set;
11390
11391 dst->c_major_device = src->c_major_device;
11392
11393 dst->c_minor_device_is_set = src->c_minor_device_is_set;
11394
11395 dst->c_minor_device = src->c_minor_device;
11396
11397 return 0;
11398 }
11399
11400 /**
11401 * idmef_inode_clone:
11402 * @src: Object to be cloned.
11403 * @dst: Address where to store the pointer to the cloned object.
11404 *
11405 * Create a copy of @src, and store it in @dst.
11406 *
11407 * Returns: 0 on success, a negative value if an error occured.
11408 */
idmef_inode_clone(idmef_inode_t * src,idmef_inode_t ** dst)11409 int idmef_inode_clone(idmef_inode_t *src, idmef_inode_t **dst)
11410 {
11411 int ret;
11412
11413 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
11414
11415 ret = idmef_inode_new(dst);
11416 if ( ret < 0 )
11417 return ret;
11418
11419 return idmef_inode_copy(src, *dst);
11420 }
11421
11422 /**
11423 * idmef_inode_compare:
11424 * @obj1: Object to compare with @obj2.
11425 * @obj2: Object to compare with @obj1.
11426 *
11427 * Compare @obj1 with @obj2.
11428 *
11429 * Returns: 0 on match, a negative value on comparison failure.
11430 */
idmef_inode_compare(const idmef_inode_t * obj1,const idmef_inode_t * obj2)11431 int idmef_inode_compare(const idmef_inode_t *obj1, const idmef_inode_t *obj2)
11432 {
11433 int ret = 0;
11434
11435 if ( obj1 == NULL && obj2 == NULL )
11436 return 0;
11437
11438 else if ( obj1 == NULL || obj2 == NULL )
11439 return -1;
11440
11441 ret = idmef_time_compare(obj1->change_time, obj2->change_time);
11442 if ( ret != 0 )
11443 return ret;
11444
11445 if ( obj1->number_is_set != obj2->number_is_set )
11446 return -1;
11447
11448 if ( obj1->number_is_set && obj1->number != obj2->number )
11449 return -1;
11450
11451 if ( obj1->major_device_is_set != obj2->major_device_is_set )
11452 return -1;
11453
11454 if ( obj1->major_device_is_set && obj1->major_device != obj2->major_device )
11455 return -1;
11456
11457 if ( obj1->minor_device_is_set != obj2->minor_device_is_set )
11458 return -1;
11459
11460 if ( obj1->minor_device_is_set && obj1->minor_device != obj2->minor_device )
11461 return -1;
11462
11463 if ( obj1->c_major_device_is_set != obj2->c_major_device_is_set )
11464 return -1;
11465
11466 if ( obj1->c_major_device_is_set && obj1->c_major_device != obj2->c_major_device )
11467 return -1;
11468
11469 if ( obj1->c_minor_device_is_set != obj2->c_minor_device_is_set )
11470 return -1;
11471
11472 if ( obj1->c_minor_device_is_set && obj1->c_minor_device != obj2->c_minor_device )
11473 return -1;
11474
11475 return ret;
11476 }
11477
11478 /**
11479 * idmef_checksum_new:
11480 * @ret: Pointer where to store the created #idmef_checksum_t object.
11481 *
11482 * Create a new #idmef_checksum_t object.
11483 *
11484 * Returns: 0 on success, a negative value if an error occured.
11485 */
idmef_checksum_new(idmef_checksum_t ** ret)11486 int idmef_checksum_new(idmef_checksum_t **ret)
11487 {
11488 *ret = calloc(1, sizeof(**ret));
11489 if ( ! *ret )
11490 return prelude_error_from_errno(errno);
11491
11492 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_CHECKSUM;
11493
11494 prelude_list_init(&((prelude_linked_object_t *) (*ret))->_list);
11495
11496 (*ret)->refcount = 1;
11497
11498 {
11499 int retval = prelude_string_new(&(*ret)->value);
11500
11501 if ( retval < 0 ) {
11502 idmef_checksum_destroy(*ret);
11503 *ret = NULL;
11504 return retval;
11505 }
11506 }
11507
11508 return 0;
11509
11510 }
11511
11512 /**
11513 * idmef_checksum_ref:
11514 * @checksum: pointer to a #idmef_checksum_t object.
11515 *
11516 * Increase @checksum reference count, so that it can be referenced
11517 * multiple time.
11518 *
11519 * Returns: a pointer to @checksum.
11520 */
idmef_checksum_ref(idmef_checksum_t * checksum)11521 idmef_checksum_t *idmef_checksum_ref(idmef_checksum_t *checksum)
11522 {
11523 prelude_return_val_if_fail(checksum, NULL);
11524 checksum->refcount++;
11525
11526 return checksum;
11527 }
11528
_idmef_checksum_get_child(void * p,idmef_class_child_id_t child,void ** childptr)11529 int _idmef_checksum_get_child(void *p, idmef_class_child_id_t child, void **childptr)
11530 {
11531 idmef_checksum_t *ptr = p;
11532
11533 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
11534 *childptr = NULL;
11535
11536 switch ( child ) {
11537
11538 case 0:
11539 return get_value_from_string((idmef_value_t **) childptr, ptr->value, TRUE);
11540 case 1:
11541 return get_value_from_string((idmef_value_t **) childptr, ptr->key, TRUE);
11542 case 2:
11543 return idmef_value_new_enum_from_numeric((idmef_value_t **) childptr,
11544 IDMEF_CLASS_ID_CHECKSUM_ALGORITHM, ptr->algorithm);
11545
11546 default:
11547 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
11548 }
11549 }
11550
_idmef_checksum_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)11551 int _idmef_checksum_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
11552 {
11553 idmef_checksum_t *ptr = p;
11554
11555 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
11556
11557 switch ( child ) {
11558
11559 case 0:
11560 return idmef_checksum_new_value(ptr, (prelude_string_t **) ret);
11561
11562 case 1:
11563 return idmef_checksum_new_key(ptr, (prelude_string_t **) ret);
11564
11565 case 2:
11566 return idmef_checksum_new_algorithm(ptr, (idmef_checksum_algorithm_t **) ret);
11567
11568 default:
11569 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
11570 }
11571 }
11572
_idmef_checksum_destroy_child(void * p,idmef_class_child_id_t child,int n)11573 int _idmef_checksum_destroy_child(void *p, idmef_class_child_id_t child, int n)
11574 {
11575 idmef_checksum_t *ptr = p;
11576
11577 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
11578
11579 switch ( child ) {
11580
11581 case 0:
11582 if ( ptr->value ) {
11583 prelude_string_destroy(ptr->value);
11584 ptr->value = NULL;
11585 }
11586
11587 return 0;
11588
11589 case 1:
11590 if ( ptr->key ) {
11591 prelude_string_destroy(ptr->key);
11592 ptr->key = NULL;
11593 }
11594
11595 return 0;
11596
11597 case 2:
11598 ptr->algorithm = 0;
11599 return 0;
11600
11601 default:
11602 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
11603 }
11604 }
11605
idmef_checksum_destroy_internal(idmef_checksum_t * ptr)11606 static void idmef_checksum_destroy_internal(idmef_checksum_t *ptr)
11607 {
11608 prelude_return_if_fail(ptr);
11609
11610 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *)ptr)->_list) )
11611 prelude_list_del_init(&((prelude_linked_object_t *)ptr)->_list);
11612
11613 if ( ptr->value ) {
11614 prelude_string_destroy(ptr->value);
11615 ptr->value = NULL;
11616 }
11617
11618 if ( ptr->key ) {
11619 prelude_string_destroy(ptr->key);
11620 ptr->key = NULL;
11621 }
11622
11623
11624 /* free() should be done by the caller */
11625 }
11626
11627 /**
11628 * idmef_checksum_destroy:
11629 * @ptr: pointer to a #idmef_checksum_t object.
11630 *
11631 * Destroy @ptr and all of it's children.
11632 * The objects are only destroyed if their reference count reach zero.
11633 */
11634
idmef_checksum_destroy(idmef_checksum_t * ptr)11635 void idmef_checksum_destroy(idmef_checksum_t *ptr)
11636 {
11637 prelude_return_if_fail(ptr);
11638
11639 if ( --ptr->refcount )
11640 return;
11641
11642 idmef_checksum_destroy_internal(ptr);
11643 free(ptr);
11644 }
11645
11646 /**
11647 * idmef_checksum_get_value:
11648 * @ptr: pointer to a #idmef_checksum_t object.
11649 *
11650 * Get value children of the #idmef_checksum_t object.
11651 *
11652 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
11653 */
idmef_checksum_get_value(idmef_checksum_t * ptr)11654 prelude_string_t *idmef_checksum_get_value(idmef_checksum_t *ptr)
11655 {
11656 prelude_return_val_if_fail(ptr, 0); /* FIXME */
11657
11658 return ptr->value;
11659 }
11660
11661 /**
11662 * idmef_checksum_set_value:
11663 * @ptr: pointer to a #idmef_checksum_t object.
11664 * @value: pointer to a #prelude_string_t object.
11665 *
11666 * Set @value object as a children of @ptr.
11667 * if @ptr already contain an @value object, then it is destroyed,
11668 * and updated to point to the provided @value object.
11669 */
11670
idmef_checksum_set_value(idmef_checksum_t * ptr,prelude_string_t * value)11671 void idmef_checksum_set_value(idmef_checksum_t *ptr, prelude_string_t *value)
11672 {
11673 prelude_return_if_fail(ptr);
11674
11675 if ( ptr->value )
11676 prelude_string_destroy(ptr->value);
11677
11678 ptr->value = value;
11679 }
11680
11681 /**
11682 * idmef_checksum_new_value:
11683 * @ptr: pointer to a #idmef_checksum_t object.
11684 * @ret: pointer to an address where to store the created #prelude_string_t object.
11685 *
11686 * Create a new value object, children of #idmef_checksum_t.
11687 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
11688 *
11689 * Returns: 0 on success, or a negative value if an error occured.
11690 */
idmef_checksum_new_value(idmef_checksum_t * ptr,prelude_string_t ** ret)11691 int idmef_checksum_new_value(idmef_checksum_t *ptr, prelude_string_t **ret)
11692 {
11693 int retval;
11694
11695 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
11696
11697 if ( ! ptr->value ) {
11698 retval = prelude_string_new(&ptr->value);
11699 if ( retval < 0 )
11700 return retval;
11701 }
11702
11703 *ret = ptr->value;
11704 return 0;
11705 }
11706
11707 /**
11708 * idmef_checksum_get_key:
11709 * @ptr: pointer to a #idmef_checksum_t object.
11710 *
11711 * Get key children of the #idmef_checksum_t object.
11712 *
11713 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
11714 */
idmef_checksum_get_key(idmef_checksum_t * ptr)11715 prelude_string_t *idmef_checksum_get_key(idmef_checksum_t *ptr)
11716 {
11717 prelude_return_val_if_fail(ptr, 0); /* FIXME */
11718
11719 return ptr->key;
11720 }
11721
11722 /**
11723 * idmef_checksum_set_key:
11724 * @ptr: pointer to a #idmef_checksum_t object.
11725 * @key: pointer to a #prelude_string_t object.
11726 *
11727 * Set @key object as a children of @ptr.
11728 * if @ptr already contain an @key object, then it is destroyed,
11729 * and updated to point to the provided @key object.
11730 */
11731
idmef_checksum_set_key(idmef_checksum_t * ptr,prelude_string_t * key)11732 void idmef_checksum_set_key(idmef_checksum_t *ptr, prelude_string_t *key)
11733 {
11734 prelude_return_if_fail(ptr);
11735
11736 if ( ptr->key )
11737 prelude_string_destroy(ptr->key);
11738
11739 ptr->key = key;
11740 }
11741
11742 /**
11743 * idmef_checksum_new_key:
11744 * @ptr: pointer to a #idmef_checksum_t object.
11745 * @ret: pointer to an address where to store the created #prelude_string_t object.
11746 *
11747 * Create a new key object, children of #idmef_checksum_t.
11748 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
11749 *
11750 * Returns: 0 on success, or a negative value if an error occured.
11751 */
idmef_checksum_new_key(idmef_checksum_t * ptr,prelude_string_t ** ret)11752 int idmef_checksum_new_key(idmef_checksum_t *ptr, prelude_string_t **ret)
11753 {
11754 int retval;
11755
11756 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
11757
11758 if ( ! ptr->key ) {
11759 retval = prelude_string_new(&ptr->key);
11760 if ( retval < 0 )
11761 return retval;
11762 }
11763
11764 *ret = ptr->key;
11765 return 0;
11766 }
11767
11768 /**
11769 * idmef_checksum_get_algorithm:
11770 * @ptr: pointer to a #idmef_checksum_t object.
11771 *
11772 * Get algorithm children of the #idmef_checksum_t object.
11773 *
11774 * Returns: a pointer to a idmef_checksum_algorithm_t object, or NULL if the children object is not set.
11775 */
idmef_checksum_get_algorithm(idmef_checksum_t * ptr)11776 idmef_checksum_algorithm_t idmef_checksum_get_algorithm(idmef_checksum_t *ptr)
11777 {
11778 prelude_return_val_if_fail(ptr, 0); /* FIXME */
11779
11780 return ptr->algorithm;
11781 }
11782
11783 /**
11784 * idmef_checksum_set_algorithm:
11785 * @ptr: pointer to a #idmef_checksum_t object.
11786 * @algorithm: pointer to a #idmef_checksum_algorithm_t object.
11787 *
11788 * Set @algorithm object as a children of @ptr.
11789 * if @ptr already contain an @algorithm object, then it is destroyed,
11790 * and updated to point to the provided @algorithm object.
11791 */
11792
idmef_checksum_set_algorithm(idmef_checksum_t * ptr,idmef_checksum_algorithm_t algorithm)11793 void idmef_checksum_set_algorithm(idmef_checksum_t *ptr, idmef_checksum_algorithm_t algorithm)
11794 {
11795 prelude_return_if_fail(ptr);
11796 ptr->algorithm = algorithm;
11797 }
11798
11799 /**
11800 * idmef_checksum_new_algorithm:
11801 * @ptr: pointer to a #idmef_checksum_t object.
11802 * @ret: pointer to an address where to store the created #idmef_checksum_algorithm_t object.
11803 *
11804 * Create a new algorithm object, children of #idmef_checksum_t.
11805 * If @ptr already contain a #idmef_checksum_algorithm_t object, then it is destroyed.
11806 *
11807 * Returns: 0 on success, or a negative value if an error occured.
11808 */
idmef_checksum_new_algorithm(idmef_checksum_t * ptr,idmef_checksum_algorithm_t ** ret)11809 int idmef_checksum_new_algorithm(idmef_checksum_t *ptr, idmef_checksum_algorithm_t **ret)
11810 {
11811 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
11812
11813 *ret = &ptr->algorithm;
11814 return 0;
11815 }
11816
11817 /**
11818 * idmef_checksum_copy:
11819 * @src: Source of the copy.
11820 * @dst: Where to copy the object.
11821 *
11822 * Copy a new #idmef_checksum_t object from @src to @dst.
11823 *
11824 * Returns: 0 on success, a negative value if an error occured.
11825 */
idmef_checksum_copy(const idmef_checksum_t * src,idmef_checksum_t * dst)11826 int idmef_checksum_copy(const idmef_checksum_t *src, idmef_checksum_t *dst)
11827 {
11828 int ret;
11829
11830 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
11831 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
11832
11833 ret = 0;
11834
11835 if ( src->value ) {
11836 ret = prelude_string_copy(src->value, dst->value);
11837 if ( ret < 0 )
11838 return ret;
11839 }
11840
11841 if ( src->key ) {
11842 ret = prelude_string_clone(src->key, &dst->key);
11843 if ( ret < 0 )
11844 return ret;
11845 }
11846
11847 dst->algorithm = src->algorithm;
11848
11849 return 0;
11850 }
11851
11852 /**
11853 * idmef_checksum_clone:
11854 * @src: Object to be cloned.
11855 * @dst: Address where to store the pointer to the cloned object.
11856 *
11857 * Create a copy of @src, and store it in @dst.
11858 *
11859 * Returns: 0 on success, a negative value if an error occured.
11860 */
idmef_checksum_clone(idmef_checksum_t * src,idmef_checksum_t ** dst)11861 int idmef_checksum_clone(idmef_checksum_t *src, idmef_checksum_t **dst)
11862 {
11863 int ret;
11864
11865 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
11866
11867 ret = idmef_checksum_new(dst);
11868 if ( ret < 0 )
11869 return ret;
11870
11871 return idmef_checksum_copy(src, *dst);
11872 }
11873
11874 /**
11875 * idmef_checksum_compare:
11876 * @obj1: Object to compare with @obj2.
11877 * @obj2: Object to compare with @obj1.
11878 *
11879 * Compare @obj1 with @obj2.
11880 *
11881 * Returns: 0 on match, a negative value on comparison failure.
11882 */
idmef_checksum_compare(const idmef_checksum_t * obj1,const idmef_checksum_t * obj2)11883 int idmef_checksum_compare(const idmef_checksum_t *obj1, const idmef_checksum_t *obj2)
11884 {
11885 int ret = 0;
11886
11887 if ( obj1 == NULL && obj2 == NULL )
11888 return 0;
11889
11890 else if ( obj1 == NULL || obj2 == NULL )
11891 return -1;
11892
11893 ret = prelude_string_compare(obj1->value, obj2->value);
11894 if ( ret != 0 )
11895 return ret;
11896
11897 ret = prelude_string_compare(obj1->key, obj2->key);
11898 if ( ret != 0 )
11899 return ret;
11900
11901 if ( obj1->algorithm != obj2->algorithm )
11902 return -1;
11903
11904 return ret;
11905 }
11906
11907 /**
11908 * idmef_file_new:
11909 * @ret: Pointer where to store the created #idmef_file_t object.
11910 *
11911 * Create a new #idmef_file_t object.
11912 *
11913 * Returns: 0 on success, a negative value if an error occured.
11914 */
idmef_file_new(idmef_file_t ** ret)11915 int idmef_file_new(idmef_file_t **ret)
11916 {
11917 *ret = calloc(1, sizeof(**ret));
11918 if ( ! *ret )
11919 return prelude_error_from_errno(errno);
11920
11921 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_FILE;
11922
11923 prelude_list_init(&((prelude_linked_object_t *) (*ret))->_list);
11924
11925 (*ret)->refcount = 1;
11926
11927 prelude_list_init(&(*ret)->file_access_list);
11928
11929
11930 prelude_list_init(&(*ret)->linkage_list);
11931
11932
11933 prelude_list_init(&(*ret)->checksum_list);
11934
11935
11936 {
11937 int retval = prelude_string_new(&(*ret)->name);
11938
11939 if ( retval < 0 ) {
11940 idmef_file_destroy(*ret);
11941 *ret = NULL;
11942 return retval;
11943 }
11944 }
11945
11946 {
11947 int retval = prelude_string_new(&(*ret)->path);
11948
11949 if ( retval < 0 ) {
11950 idmef_file_destroy(*ret);
11951 *ret = NULL;
11952 return retval;
11953 }
11954 }
11955
11956 return 0;
11957
11958 }
11959
11960 /**
11961 * idmef_file_ref:
11962 * @file: pointer to a #idmef_file_t object.
11963 *
11964 * Increase @file reference count, so that it can be referenced
11965 * multiple time.
11966 *
11967 * Returns: a pointer to @file.
11968 */
idmef_file_ref(idmef_file_t * file)11969 idmef_file_t *idmef_file_ref(idmef_file_t *file)
11970 {
11971 prelude_return_val_if_fail(file, NULL);
11972 file->refcount++;
11973
11974 return file;
11975 }
11976
_idmef_file_get_child(void * p,idmef_class_child_id_t child,void ** childptr)11977 int _idmef_file_get_child(void *p, idmef_class_child_id_t child, void **childptr)
11978 {
11979 idmef_file_t *ptr = p;
11980
11981 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
11982 *childptr = NULL;
11983
11984 switch ( child ) {
11985
11986 case 0:
11987 return get_value_from_string((idmef_value_t **) childptr, ptr->ident, TRUE);
11988 case 1:
11989 return get_value_from_string((idmef_value_t **) childptr, ptr->name, TRUE);
11990 case 2:
11991 return get_value_from_string((idmef_value_t **) childptr, ptr->path, TRUE);
11992 case 3:
11993 return get_value_from_time((idmef_value_t **) childptr, ptr->create_time, TRUE);
11994 case 4:
11995 return get_value_from_time((idmef_value_t **) childptr, ptr->modify_time, TRUE);
11996 case 5:
11997 return get_value_from_time((idmef_value_t **) childptr, ptr->access_time, TRUE);
11998 case 6:
11999 return (ptr->data_size_is_set) ? idmef_value_new_uint64((idmef_value_t **) childptr, ptr->data_size) : 0;
12000
12001 case 7:
12002 return (ptr->disk_size_is_set) ? idmef_value_new_uint64((idmef_value_t **) childptr, ptr->disk_size) : 0;
12003
12004 case 8:
12005 *childptr = &ptr->file_access_list;
12006 return 0;
12007
12008 case 9:
12009 *childptr = &ptr->linkage_list;
12010 return 0;
12011
12012 case 10:
12013 *childptr = ptr->inode;
12014 return 0;
12015
12016 case 11:
12017 *childptr = &ptr->checksum_list;
12018 return 0;
12019
12020 case 12:
12021 return idmef_value_new_enum_from_numeric((idmef_value_t **) childptr,
12022 IDMEF_CLASS_ID_FILE_CATEGORY, ptr->category);
12023
12024 case 13:
12025 if ( ! ptr->fstype_is_set )
12026 return 0;
12027 return idmef_value_new_enum_from_numeric((idmef_value_t **) childptr,
12028 IDMEF_CLASS_ID_FILE_FSTYPE, ptr->fstype);
12029
12030 case 14:
12031 return get_value_from_string((idmef_value_t **) childptr, ptr->file_type, TRUE);
12032 default:
12033 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
12034 }
12035 }
12036
_idmef_file_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)12037 int _idmef_file_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
12038 {
12039 idmef_file_t *ptr = p;
12040
12041 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
12042
12043 switch ( child ) {
12044
12045 case 0:
12046 return idmef_file_new_ident(ptr, (prelude_string_t **) ret);
12047
12048 case 1:
12049 return idmef_file_new_name(ptr, (prelude_string_t **) ret);
12050
12051 case 2:
12052 return idmef_file_new_path(ptr, (prelude_string_t **) ret);
12053
12054 case 3:
12055 return idmef_file_new_create_time(ptr, (idmef_time_t **) ret);
12056
12057 case 4:
12058 return idmef_file_new_modify_time(ptr, (idmef_time_t **) ret);
12059
12060 case 5:
12061 return idmef_file_new_access_time(ptr, (idmef_time_t **) ret);
12062
12063 case 6:
12064 return idmef_file_new_data_size(ptr, (uint64_t **) ret);
12065
12066 case 7:
12067 return idmef_file_new_disk_size(ptr, (uint64_t **) ret);
12068
12069 case 8: {
12070 int i = 0;
12071 prelude_list_t *tmp;
12072
12073 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
12074 return idmef_file_new_file_access(ptr, (idmef_file_access_t **) ret, n);
12075
12076 if ( n >= 0 ) {
12077 prelude_list_for_each(&ptr->file_access_list, tmp) {
12078 if ( i++ == n ) {
12079 *ret = prelude_linked_object_get_object(tmp);
12080 return 0;
12081 }
12082 }
12083
12084 if ( i != n )
12085 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
12086 } else {
12087 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
12088
12089 prelude_list_for_each_reversed(&ptr->file_access_list, tmp) {
12090 if ( i++ == pos ) {
12091 *ret = prelude_linked_object_get_object(tmp);
12092 return 0;
12093 }
12094 }
12095
12096 if ( i != pos )
12097 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
12098 }
12099
12100 return idmef_file_new_file_access(ptr, (idmef_file_access_t **) ret, n);
12101 }
12102
12103 case 9: {
12104 int i = 0;
12105 prelude_list_t *tmp;
12106
12107 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
12108 return idmef_file_new_linkage(ptr, (idmef_linkage_t **) ret, n);
12109
12110 if ( n >= 0 ) {
12111 prelude_list_for_each(&ptr->linkage_list, tmp) {
12112 if ( i++ == n ) {
12113 *ret = prelude_linked_object_get_object(tmp);
12114 return 0;
12115 }
12116 }
12117
12118 if ( i != n )
12119 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
12120 } else {
12121 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
12122
12123 prelude_list_for_each_reversed(&ptr->linkage_list, tmp) {
12124 if ( i++ == pos ) {
12125 *ret = prelude_linked_object_get_object(tmp);
12126 return 0;
12127 }
12128 }
12129
12130 if ( i != pos )
12131 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
12132 }
12133
12134 return idmef_file_new_linkage(ptr, (idmef_linkage_t **) ret, n);
12135 }
12136
12137 case 10:
12138 return idmef_file_new_inode(ptr, (idmef_inode_t **) ret);
12139
12140 case 11: {
12141 int i = 0;
12142 prelude_list_t *tmp;
12143
12144 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
12145 return idmef_file_new_checksum(ptr, (idmef_checksum_t **) ret, n);
12146
12147 if ( n >= 0 ) {
12148 prelude_list_for_each(&ptr->checksum_list, tmp) {
12149 if ( i++ == n ) {
12150 *ret = prelude_linked_object_get_object(tmp);
12151 return 0;
12152 }
12153 }
12154
12155 if ( i != n )
12156 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
12157 } else {
12158 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
12159
12160 prelude_list_for_each_reversed(&ptr->checksum_list, tmp) {
12161 if ( i++ == pos ) {
12162 *ret = prelude_linked_object_get_object(tmp);
12163 return 0;
12164 }
12165 }
12166
12167 if ( i != pos )
12168 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
12169 }
12170
12171 return idmef_file_new_checksum(ptr, (idmef_checksum_t **) ret, n);
12172 }
12173
12174 case 12:
12175 return idmef_file_new_category(ptr, (idmef_file_category_t **) ret);
12176
12177 case 13:
12178 return idmef_file_new_fstype(ptr, (idmef_file_fstype_t **) ret);
12179
12180 case 14:
12181 return idmef_file_new_file_type(ptr, (prelude_string_t **) ret);
12182
12183 default:
12184 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
12185 }
12186 }
12187
_idmef_file_destroy_child(void * p,idmef_class_child_id_t child,int n)12188 int _idmef_file_destroy_child(void *p, idmef_class_child_id_t child, int n)
12189 {
12190 idmef_file_t *ptr = p;
12191
12192 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
12193
12194 switch ( child ) {
12195
12196 case 0:
12197 if ( ptr->ident ) {
12198 prelude_string_destroy(ptr->ident);
12199 ptr->ident = NULL;
12200 }
12201
12202 return 0;
12203
12204 case 1:
12205 if ( ptr->name ) {
12206 prelude_string_destroy(ptr->name);
12207 ptr->name = NULL;
12208 }
12209
12210 return 0;
12211
12212 case 2:
12213 if ( ptr->path ) {
12214 prelude_string_destroy(ptr->path);
12215 ptr->path = NULL;
12216 }
12217
12218 return 0;
12219
12220 case 3:
12221 if ( ptr->create_time ) {
12222 idmef_time_destroy(ptr->create_time);
12223 ptr->create_time = NULL;
12224 }
12225
12226 return 0;
12227
12228 case 4:
12229 if ( ptr->modify_time ) {
12230 idmef_time_destroy(ptr->modify_time);
12231 ptr->modify_time = NULL;
12232 }
12233
12234 return 0;
12235
12236 case 5:
12237 if ( ptr->access_time ) {
12238 idmef_time_destroy(ptr->access_time);
12239 ptr->access_time = NULL;
12240 }
12241
12242 return 0;
12243
12244 case 6:
12245 ptr->data_size_is_set = 0;
12246 return 0;
12247
12248 case 7:
12249 ptr->disk_size_is_set = 0;
12250 return 0;
12251
12252 case 8: {
12253 int i = 0;
12254 prelude_list_t *tmp;
12255
12256 if ( n >= 0 ) {
12257 prelude_list_for_each(&ptr->file_access_list, tmp) {
12258 if ( i++ == n ) {
12259 void *b = prelude_linked_object_get_object(tmp);
12260 idmef_file_access_destroy(b);
12261 return 0;
12262 }
12263 }
12264
12265 if ( i != n )
12266 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
12267 } else {
12268 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
12269
12270 prelude_list_for_each_reversed(&ptr->file_access_list, tmp) {
12271 if ( i++ == pos ) {
12272 void *b = prelude_linked_object_get_object(tmp);
12273 idmef_file_access_destroy(b);
12274 return 0;
12275 }
12276 }
12277
12278 if ( i != pos )
12279 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
12280 }
12281 }
12282
12283 case 9: {
12284 int i = 0;
12285 prelude_list_t *tmp;
12286
12287 if ( n >= 0 ) {
12288 prelude_list_for_each(&ptr->linkage_list, tmp) {
12289 if ( i++ == n ) {
12290 void *b = prelude_linked_object_get_object(tmp);
12291 idmef_linkage_destroy(b);
12292 return 0;
12293 }
12294 }
12295
12296 if ( i != n )
12297 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
12298 } else {
12299 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
12300
12301 prelude_list_for_each_reversed(&ptr->linkage_list, tmp) {
12302 if ( i++ == pos ) {
12303 void *b = prelude_linked_object_get_object(tmp);
12304 idmef_linkage_destroy(b);
12305 return 0;
12306 }
12307 }
12308
12309 if ( i != pos )
12310 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
12311 }
12312 }
12313
12314 case 10:
12315 if ( ptr->inode ) {
12316 idmef_inode_destroy(ptr->inode);
12317 ptr->inode = NULL;
12318 }
12319
12320 return 0;
12321
12322 case 11: {
12323 int i = 0;
12324 prelude_list_t *tmp;
12325
12326 if ( n >= 0 ) {
12327 prelude_list_for_each(&ptr->checksum_list, tmp) {
12328 if ( i++ == n ) {
12329 void *b = prelude_linked_object_get_object(tmp);
12330 idmef_checksum_destroy(b);
12331 return 0;
12332 }
12333 }
12334
12335 if ( i != n )
12336 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
12337 } else {
12338 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
12339
12340 prelude_list_for_each_reversed(&ptr->checksum_list, tmp) {
12341 if ( i++ == pos ) {
12342 void *b = prelude_linked_object_get_object(tmp);
12343 idmef_checksum_destroy(b);
12344 return 0;
12345 }
12346 }
12347
12348 if ( i != pos )
12349 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
12350 }
12351 }
12352
12353 case 12:
12354 ptr->category = 0;
12355 return 0;
12356
12357 case 13:
12358 ptr->fstype_is_set = 0;
12359 return 0;
12360
12361 case 14:
12362 if ( ptr->file_type ) {
12363 prelude_string_destroy(ptr->file_type);
12364 ptr->file_type = NULL;
12365 }
12366
12367 return 0;
12368
12369 default:
12370 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
12371 }
12372 }
12373
idmef_file_destroy_internal(idmef_file_t * ptr)12374 static void idmef_file_destroy_internal(idmef_file_t *ptr)
12375 {
12376 prelude_return_if_fail(ptr);
12377
12378 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *)ptr)->_list) )
12379 prelude_list_del_init(&((prelude_linked_object_t *)ptr)->_list);
12380
12381 if ( ptr->ident ) {
12382 prelude_string_destroy(ptr->ident);
12383 ptr->ident = NULL;
12384 }
12385
12386 if ( ptr->name ) {
12387 prelude_string_destroy(ptr->name);
12388 ptr->name = NULL;
12389 }
12390
12391 if ( ptr->path ) {
12392 prelude_string_destroy(ptr->path);
12393 ptr->path = NULL;
12394 }
12395
12396 if ( ptr->create_time ) {
12397 idmef_time_destroy(ptr->create_time);
12398 ptr->create_time = NULL;
12399 }
12400
12401 if ( ptr->modify_time ) {
12402 idmef_time_destroy(ptr->modify_time);
12403 ptr->modify_time = NULL;
12404 }
12405
12406 if ( ptr->access_time ) {
12407 idmef_time_destroy(ptr->access_time);
12408 ptr->access_time = NULL;
12409 }
12410
12411 {
12412 prelude_list_t *n, *tmp;
12413 idmef_file_access_t *entry;
12414
12415 prelude_list_for_each_safe(&ptr->file_access_list, tmp, n) {
12416 entry = prelude_linked_object_get_object(tmp);
12417 prelude_list_del_init(tmp);
12418 idmef_file_access_destroy(entry);
12419 }
12420 }
12421
12422 {
12423 prelude_list_t *n, *tmp;
12424 idmef_linkage_t *entry;
12425
12426 prelude_list_for_each_safe(&ptr->linkage_list, tmp, n) {
12427 entry = prelude_linked_object_get_object(tmp);
12428 prelude_list_del_init(tmp);
12429 idmef_linkage_destroy(entry);
12430 }
12431 }
12432
12433 if ( ptr->inode ) {
12434 idmef_inode_destroy(ptr->inode);
12435 ptr->inode = NULL;
12436 }
12437
12438 {
12439 prelude_list_t *n, *tmp;
12440 idmef_checksum_t *entry;
12441
12442 prelude_list_for_each_safe(&ptr->checksum_list, tmp, n) {
12443 entry = prelude_linked_object_get_object(tmp);
12444 prelude_list_del_init(tmp);
12445 idmef_checksum_destroy(entry);
12446 }
12447 }
12448
12449 if ( ptr->file_type ) {
12450 prelude_string_destroy(ptr->file_type);
12451 ptr->file_type = NULL;
12452 }
12453
12454
12455 /* free() should be done by the caller */
12456 }
12457
12458 /**
12459 * idmef_file_destroy:
12460 * @ptr: pointer to a #idmef_file_t object.
12461 *
12462 * Destroy @ptr and all of it's children.
12463 * The objects are only destroyed if their reference count reach zero.
12464 */
12465
idmef_file_destroy(idmef_file_t * ptr)12466 void idmef_file_destroy(idmef_file_t *ptr)
12467 {
12468 prelude_return_if_fail(ptr);
12469
12470 if ( --ptr->refcount )
12471 return;
12472
12473 idmef_file_destroy_internal(ptr);
12474 free(ptr);
12475 }
12476
12477 /**
12478 * idmef_file_get_ident:
12479 * @ptr: pointer to a #idmef_file_t object.
12480 *
12481 * Get ident children of the #idmef_file_t object.
12482 *
12483 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
12484 */
idmef_file_get_ident(idmef_file_t * ptr)12485 prelude_string_t *idmef_file_get_ident(idmef_file_t *ptr)
12486 {
12487 prelude_return_val_if_fail(ptr, 0); /* FIXME */
12488
12489 return ptr->ident;
12490 }
12491
12492 /**
12493 * idmef_file_set_ident:
12494 * @ptr: pointer to a #idmef_file_t object.
12495 * @ident: pointer to a #prelude_string_t object.
12496 *
12497 * Set @ident object as a children of @ptr.
12498 * if @ptr already contain an @ident object, then it is destroyed,
12499 * and updated to point to the provided @ident object.
12500 */
12501
idmef_file_set_ident(idmef_file_t * ptr,prelude_string_t * ident)12502 void idmef_file_set_ident(idmef_file_t *ptr, prelude_string_t *ident)
12503 {
12504 prelude_return_if_fail(ptr);
12505
12506 if ( ptr->ident )
12507 prelude_string_destroy(ptr->ident);
12508
12509 ptr->ident = ident;
12510 }
12511
12512 /**
12513 * idmef_file_new_ident:
12514 * @ptr: pointer to a #idmef_file_t object.
12515 * @ret: pointer to an address where to store the created #prelude_string_t object.
12516 *
12517 * Create a new ident object, children of #idmef_file_t.
12518 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
12519 *
12520 * Returns: 0 on success, or a negative value if an error occured.
12521 */
idmef_file_new_ident(idmef_file_t * ptr,prelude_string_t ** ret)12522 int idmef_file_new_ident(idmef_file_t *ptr, prelude_string_t **ret)
12523 {
12524 int retval;
12525
12526 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
12527
12528 if ( ! ptr->ident ) {
12529 retval = prelude_string_new(&ptr->ident);
12530 if ( retval < 0 )
12531 return retval;
12532 }
12533
12534 *ret = ptr->ident;
12535 return 0;
12536 }
12537
12538 /**
12539 * idmef_file_get_name:
12540 * @ptr: pointer to a #idmef_file_t object.
12541 *
12542 * Get name children of the #idmef_file_t object.
12543 *
12544 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
12545 */
idmef_file_get_name(idmef_file_t * ptr)12546 prelude_string_t *idmef_file_get_name(idmef_file_t *ptr)
12547 {
12548 prelude_return_val_if_fail(ptr, 0); /* FIXME */
12549
12550 return ptr->name;
12551 }
12552
12553 /**
12554 * idmef_file_set_name:
12555 * @ptr: pointer to a #idmef_file_t object.
12556 * @name: pointer to a #prelude_string_t object.
12557 *
12558 * Set @name object as a children of @ptr.
12559 * if @ptr already contain an @name object, then it is destroyed,
12560 * and updated to point to the provided @name object.
12561 */
12562
idmef_file_set_name(idmef_file_t * ptr,prelude_string_t * name)12563 void idmef_file_set_name(idmef_file_t *ptr, prelude_string_t *name)
12564 {
12565 prelude_return_if_fail(ptr);
12566
12567 if ( ptr->name )
12568 prelude_string_destroy(ptr->name);
12569
12570 ptr->name = name;
12571 }
12572
12573 /**
12574 * idmef_file_new_name:
12575 * @ptr: pointer to a #idmef_file_t object.
12576 * @ret: pointer to an address where to store the created #prelude_string_t object.
12577 *
12578 * Create a new name object, children of #idmef_file_t.
12579 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
12580 *
12581 * Returns: 0 on success, or a negative value if an error occured.
12582 */
idmef_file_new_name(idmef_file_t * ptr,prelude_string_t ** ret)12583 int idmef_file_new_name(idmef_file_t *ptr, prelude_string_t **ret)
12584 {
12585 int retval;
12586
12587 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
12588
12589 if ( ! ptr->name ) {
12590 retval = prelude_string_new(&ptr->name);
12591 if ( retval < 0 )
12592 return retval;
12593 }
12594
12595 *ret = ptr->name;
12596 return 0;
12597 }
12598
12599 /**
12600 * idmef_file_get_path:
12601 * @ptr: pointer to a #idmef_file_t object.
12602 *
12603 * Get path children of the #idmef_file_t object.
12604 *
12605 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
12606 */
idmef_file_get_path(idmef_file_t * ptr)12607 prelude_string_t *idmef_file_get_path(idmef_file_t *ptr)
12608 {
12609 prelude_return_val_if_fail(ptr, 0); /* FIXME */
12610
12611 return ptr->path;
12612 }
12613
12614 /**
12615 * idmef_file_set_path:
12616 * @ptr: pointer to a #idmef_file_t object.
12617 * @path: pointer to a #prelude_string_t object.
12618 *
12619 * Set @path object as a children of @ptr.
12620 * if @ptr already contain an @path object, then it is destroyed,
12621 * and updated to point to the provided @path object.
12622 */
12623
idmef_file_set_path(idmef_file_t * ptr,prelude_string_t * path)12624 void idmef_file_set_path(idmef_file_t *ptr, prelude_string_t *path)
12625 {
12626 prelude_return_if_fail(ptr);
12627
12628 if ( ptr->path )
12629 prelude_string_destroy(ptr->path);
12630
12631 ptr->path = path;
12632 }
12633
12634 /**
12635 * idmef_file_new_path:
12636 * @ptr: pointer to a #idmef_file_t object.
12637 * @ret: pointer to an address where to store the created #prelude_string_t object.
12638 *
12639 * Create a new path object, children of #idmef_file_t.
12640 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
12641 *
12642 * Returns: 0 on success, or a negative value if an error occured.
12643 */
idmef_file_new_path(idmef_file_t * ptr,prelude_string_t ** ret)12644 int idmef_file_new_path(idmef_file_t *ptr, prelude_string_t **ret)
12645 {
12646 int retval;
12647
12648 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
12649
12650 if ( ! ptr->path ) {
12651 retval = prelude_string_new(&ptr->path);
12652 if ( retval < 0 )
12653 return retval;
12654 }
12655
12656 *ret = ptr->path;
12657 return 0;
12658 }
12659
12660 /**
12661 * idmef_file_get_create_time:
12662 * @ptr: pointer to a #idmef_file_t object.
12663 *
12664 * Get create_time children of the #idmef_file_t object.
12665 *
12666 * Returns: a pointer to a idmef_time_t object, or NULL if the children object is not set.
12667 */
idmef_file_get_create_time(idmef_file_t * ptr)12668 idmef_time_t *idmef_file_get_create_time(idmef_file_t *ptr)
12669 {
12670 prelude_return_val_if_fail(ptr, 0); /* FIXME */
12671
12672 return ptr->create_time;
12673 }
12674
12675 /**
12676 * idmef_file_set_create_time:
12677 * @ptr: pointer to a #idmef_file_t object.
12678 * @create_time: pointer to a #idmef_time_t object.
12679 *
12680 * Set @create_time object as a children of @ptr.
12681 * if @ptr already contain an @create_time object, then it is destroyed,
12682 * and updated to point to the provided @create_time object.
12683 */
12684
idmef_file_set_create_time(idmef_file_t * ptr,idmef_time_t * create_time)12685 void idmef_file_set_create_time(idmef_file_t *ptr, idmef_time_t *create_time)
12686 {
12687 prelude_return_if_fail(ptr);
12688
12689 if ( ptr->create_time )
12690 idmef_time_destroy(ptr->create_time);
12691
12692 ptr->create_time = create_time;
12693 }
12694
12695 /**
12696 * idmef_file_new_create_time:
12697 * @ptr: pointer to a #idmef_file_t object.
12698 * @ret: pointer to an address where to store the created #idmef_time_t object.
12699 *
12700 * Create a new create_time object, children of #idmef_file_t.
12701 * If @ptr already contain a #idmef_time_t object, then it is destroyed.
12702 *
12703 * Returns: 0 on success, or a negative value if an error occured.
12704 */
idmef_file_new_create_time(idmef_file_t * ptr,idmef_time_t ** ret)12705 int idmef_file_new_create_time(idmef_file_t *ptr, idmef_time_t **ret)
12706 {
12707 int retval;
12708
12709 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
12710
12711 if ( ! ptr->create_time ) {
12712 retval = idmef_time_new(&ptr->create_time);
12713 if ( retval < 0 )
12714 return retval;
12715 }
12716
12717 *ret = ptr->create_time;
12718 return 0;
12719 }
12720
12721 /**
12722 * idmef_file_get_modify_time:
12723 * @ptr: pointer to a #idmef_file_t object.
12724 *
12725 * Get modify_time children of the #idmef_file_t object.
12726 *
12727 * Returns: a pointer to a idmef_time_t object, or NULL if the children object is not set.
12728 */
idmef_file_get_modify_time(idmef_file_t * ptr)12729 idmef_time_t *idmef_file_get_modify_time(idmef_file_t *ptr)
12730 {
12731 prelude_return_val_if_fail(ptr, 0); /* FIXME */
12732
12733 return ptr->modify_time;
12734 }
12735
12736 /**
12737 * idmef_file_set_modify_time:
12738 * @ptr: pointer to a #idmef_file_t object.
12739 * @modify_time: pointer to a #idmef_time_t object.
12740 *
12741 * Set @modify_time object as a children of @ptr.
12742 * if @ptr already contain an @modify_time object, then it is destroyed,
12743 * and updated to point to the provided @modify_time object.
12744 */
12745
idmef_file_set_modify_time(idmef_file_t * ptr,idmef_time_t * modify_time)12746 void idmef_file_set_modify_time(idmef_file_t *ptr, idmef_time_t *modify_time)
12747 {
12748 prelude_return_if_fail(ptr);
12749
12750 if ( ptr->modify_time )
12751 idmef_time_destroy(ptr->modify_time);
12752
12753 ptr->modify_time = modify_time;
12754 }
12755
12756 /**
12757 * idmef_file_new_modify_time:
12758 * @ptr: pointer to a #idmef_file_t object.
12759 * @ret: pointer to an address where to store the created #idmef_time_t object.
12760 *
12761 * Create a new modify_time object, children of #idmef_file_t.
12762 * If @ptr already contain a #idmef_time_t object, then it is destroyed.
12763 *
12764 * Returns: 0 on success, or a negative value if an error occured.
12765 */
idmef_file_new_modify_time(idmef_file_t * ptr,idmef_time_t ** ret)12766 int idmef_file_new_modify_time(idmef_file_t *ptr, idmef_time_t **ret)
12767 {
12768 int retval;
12769
12770 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
12771
12772 if ( ! ptr->modify_time ) {
12773 retval = idmef_time_new(&ptr->modify_time);
12774 if ( retval < 0 )
12775 return retval;
12776 }
12777
12778 *ret = ptr->modify_time;
12779 return 0;
12780 }
12781
12782 /**
12783 * idmef_file_get_access_time:
12784 * @ptr: pointer to a #idmef_file_t object.
12785 *
12786 * Get access_time children of the #idmef_file_t object.
12787 *
12788 * Returns: a pointer to a idmef_time_t object, or NULL if the children object is not set.
12789 */
idmef_file_get_access_time(idmef_file_t * ptr)12790 idmef_time_t *idmef_file_get_access_time(idmef_file_t *ptr)
12791 {
12792 prelude_return_val_if_fail(ptr, 0); /* FIXME */
12793
12794 return ptr->access_time;
12795 }
12796
12797 /**
12798 * idmef_file_set_access_time:
12799 * @ptr: pointer to a #idmef_file_t object.
12800 * @access_time: pointer to a #idmef_time_t object.
12801 *
12802 * Set @access_time object as a children of @ptr.
12803 * if @ptr already contain an @access_time object, then it is destroyed,
12804 * and updated to point to the provided @access_time object.
12805 */
12806
idmef_file_set_access_time(idmef_file_t * ptr,idmef_time_t * access_time)12807 void idmef_file_set_access_time(idmef_file_t *ptr, idmef_time_t *access_time)
12808 {
12809 prelude_return_if_fail(ptr);
12810
12811 if ( ptr->access_time )
12812 idmef_time_destroy(ptr->access_time);
12813
12814 ptr->access_time = access_time;
12815 }
12816
12817 /**
12818 * idmef_file_new_access_time:
12819 * @ptr: pointer to a #idmef_file_t object.
12820 * @ret: pointer to an address where to store the created #idmef_time_t object.
12821 *
12822 * Create a new access_time object, children of #idmef_file_t.
12823 * If @ptr already contain a #idmef_time_t object, then it is destroyed.
12824 *
12825 * Returns: 0 on success, or a negative value if an error occured.
12826 */
idmef_file_new_access_time(idmef_file_t * ptr,idmef_time_t ** ret)12827 int idmef_file_new_access_time(idmef_file_t *ptr, idmef_time_t **ret)
12828 {
12829 int retval;
12830
12831 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
12832
12833 if ( ! ptr->access_time ) {
12834 retval = idmef_time_new(&ptr->access_time);
12835 if ( retval < 0 )
12836 return retval;
12837 }
12838
12839 *ret = ptr->access_time;
12840 return 0;
12841 }
12842
12843 /**
12844 * idmef_file_get_data_size:
12845 * @ptr: pointer to a #idmef_file_t object.
12846 *
12847 * Get data_size children of the #idmef_file_t object.
12848 *
12849 * Returns: a pointer to a uint64_t object, or NULL if the children object is not set.
12850 */
idmef_file_get_data_size(idmef_file_t * ptr)12851 uint64_t *idmef_file_get_data_size(idmef_file_t *ptr)
12852 {
12853 prelude_return_val_if_fail(ptr, 0); /* FIXME */
12854
12855 return ptr->data_size_is_set ? &ptr->data_size : NULL;
12856 }
12857
12858 /**
12859 * idmef_file_set_data_size:
12860 * @ptr: pointer to a #idmef_file_t object.
12861 * @data_size: pointer to a #uint64_t object.
12862 *
12863 * Set @data_size object as a children of @ptr.
12864 * if @ptr already contain an @data_size object, then it is destroyed,
12865 * and updated to point to the provided @data_size object.
12866 */
12867
idmef_file_set_data_size(idmef_file_t * ptr,uint64_t data_size)12868 void idmef_file_set_data_size(idmef_file_t *ptr, uint64_t data_size)
12869 {
12870 prelude_return_if_fail(ptr);
12871 ptr->data_size = data_size;
12872 ptr->data_size_is_set = 1;
12873 }
12874
12875
idmef_file_unset_data_size(idmef_file_t * ptr)12876 void idmef_file_unset_data_size(idmef_file_t *ptr)
12877 {
12878 prelude_return_if_fail(ptr);
12879 ptr->data_size_is_set = 0;
12880 }
12881
12882
12883 /**
12884 * idmef_file_new_data_size:
12885 * @ptr: pointer to a #idmef_file_t object.
12886 * @ret: pointer to an address where to store the created #uint64_t object.
12887 *
12888 * Create a new data_size object, children of #idmef_file_t.
12889 * If @ptr already contain a #uint64_t object, then it is destroyed.
12890 *
12891 * Returns: 0 on success, or a negative value if an error occured.
12892 */
idmef_file_new_data_size(idmef_file_t * ptr,uint64_t ** ret)12893 int idmef_file_new_data_size(idmef_file_t *ptr, uint64_t **ret)
12894 {
12895 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
12896 ptr->data_size_is_set = 1;
12897
12898 *ret = &ptr->data_size;
12899 return 0;
12900 }
12901
12902 /**
12903 * idmef_file_get_disk_size:
12904 * @ptr: pointer to a #idmef_file_t object.
12905 *
12906 * Get disk_size children of the #idmef_file_t object.
12907 *
12908 * Returns: a pointer to a uint64_t object, or NULL if the children object is not set.
12909 */
idmef_file_get_disk_size(idmef_file_t * ptr)12910 uint64_t *idmef_file_get_disk_size(idmef_file_t *ptr)
12911 {
12912 prelude_return_val_if_fail(ptr, 0); /* FIXME */
12913
12914 return ptr->disk_size_is_set ? &ptr->disk_size : NULL;
12915 }
12916
12917 /**
12918 * idmef_file_set_disk_size:
12919 * @ptr: pointer to a #idmef_file_t object.
12920 * @disk_size: pointer to a #uint64_t object.
12921 *
12922 * Set @disk_size object as a children of @ptr.
12923 * if @ptr already contain an @disk_size object, then it is destroyed,
12924 * and updated to point to the provided @disk_size object.
12925 */
12926
idmef_file_set_disk_size(idmef_file_t * ptr,uint64_t disk_size)12927 void idmef_file_set_disk_size(idmef_file_t *ptr, uint64_t disk_size)
12928 {
12929 prelude_return_if_fail(ptr);
12930 ptr->disk_size = disk_size;
12931 ptr->disk_size_is_set = 1;
12932 }
12933
12934
idmef_file_unset_disk_size(idmef_file_t * ptr)12935 void idmef_file_unset_disk_size(idmef_file_t *ptr)
12936 {
12937 prelude_return_if_fail(ptr);
12938 ptr->disk_size_is_set = 0;
12939 }
12940
12941
12942 /**
12943 * idmef_file_new_disk_size:
12944 * @ptr: pointer to a #idmef_file_t object.
12945 * @ret: pointer to an address where to store the created #uint64_t object.
12946 *
12947 * Create a new disk_size object, children of #idmef_file_t.
12948 * If @ptr already contain a #uint64_t object, then it is destroyed.
12949 *
12950 * Returns: 0 on success, or a negative value if an error occured.
12951 */
idmef_file_new_disk_size(idmef_file_t * ptr,uint64_t ** ret)12952 int idmef_file_new_disk_size(idmef_file_t *ptr, uint64_t **ret)
12953 {
12954 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
12955 ptr->disk_size_is_set = 1;
12956
12957 *ret = &ptr->disk_size;
12958 return 0;
12959 }
12960
12961 /**
12962 * idmef_file_get_next_file_access:
12963 * @file: pointer to a #idmef_file_t object.
12964 * @file_access_cur: pointer to a #idmef_file_access_t object.
12965 *
12966 * Get the next #idmef_file_access_t object listed in @ptr.
12967 * When iterating over the idmef_file_access_t object listed in @ptr,
12968 * @object should be set to the latest returned #idmef_file_access_t object.
12969 *
12970 * Returns: the next #idmef_file_access_t in the list.
12971 */
idmef_file_get_next_file_access(idmef_file_t * file,idmef_file_access_t * file_access_cur)12972 idmef_file_access_t *idmef_file_get_next_file_access(idmef_file_t *file, idmef_file_access_t *file_access_cur)
12973 {
12974 prelude_list_t *tmp = (file_access_cur) ? &((prelude_linked_object_t *) file_access_cur)->_list : NULL;
12975
12976 prelude_return_val_if_fail(file, NULL);
12977
12978 prelude_list_for_each_continue(&file->file_access_list, tmp)
12979 return prelude_linked_object_get_object(tmp);
12980
12981 return NULL;
12982 }
12983
12984
12985 /**
12986 * idmef_file_set_file_access:
12987 * @ptr: pointer to a #idmef_file_t object.
12988 * @object: pointer to a #idmef_file_access_t object.
12989 * @pos: Position in the list.
12990 *
12991 * Add @object to position @pos of @ptr list of #idmef_file_access_t object.
12992 *
12993 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
12994 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
12995 */
idmef_file_set_file_access(idmef_file_t * ptr,idmef_file_access_t * object,int pos)12996 void idmef_file_set_file_access(idmef_file_t *ptr, idmef_file_access_t *object, int pos)
12997 {
12998 prelude_return_if_fail(ptr);
12999 prelude_return_if_fail(object);
13000
13001 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
13002 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
13003
13004 list_insert(&ptr->file_access_list, &((prelude_linked_object_t *) object)->_list, pos);
13005 }
13006
13007
13008 /**
13009 * idmef_file_new_file_access:
13010 * @ptr: pointer to a #idmef_file_t object.
13011 * @ret: pointer to an address where to store the created #idmef_file_access_t object.
13012 * @pos: position in the list.
13013 *
13014 * Create a new #idmef_file_access_t children of @ptr, and add it to position @pos of
13015 * @ptr list of #idmef_file_access_t object. The created #idmef_file_access_t object is
13016 * stored in @ret.
13017 *
13018 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
13019 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
13020 *
13021 * Returns: 0 on success, or a negative value if an error occured.
13022 */
idmef_file_new_file_access(idmef_file_t * ptr,idmef_file_access_t ** ret,int pos)13023 int idmef_file_new_file_access(idmef_file_t *ptr, idmef_file_access_t **ret, int pos)
13024 {
13025 int retval;
13026
13027 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
13028
13029 retval = idmef_file_access_new(ret);
13030 if ( retval < 0 )
13031 return retval;
13032
13033 list_insert(&ptr->file_access_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
13034
13035 return 0;
13036 }
13037
13038
13039 /**
13040 * idmef_file_get_next_linkage:
13041 * @file: pointer to a #idmef_file_t object.
13042 * @linkage_cur: pointer to a #idmef_linkage_t object.
13043 *
13044 * Get the next #idmef_linkage_t object listed in @ptr.
13045 * When iterating over the idmef_linkage_t object listed in @ptr,
13046 * @object should be set to the latest returned #idmef_linkage_t object.
13047 *
13048 * Returns: the next #idmef_linkage_t in the list.
13049 */
idmef_file_get_next_linkage(idmef_file_t * file,idmef_linkage_t * linkage_cur)13050 idmef_linkage_t *idmef_file_get_next_linkage(idmef_file_t *file, idmef_linkage_t *linkage_cur)
13051 {
13052 prelude_list_t *tmp = (linkage_cur) ? &((prelude_linked_object_t *) linkage_cur)->_list : NULL;
13053
13054 prelude_return_val_if_fail(file, NULL);
13055
13056 prelude_list_for_each_continue(&file->linkage_list, tmp)
13057 return prelude_linked_object_get_object(tmp);
13058
13059 return NULL;
13060 }
13061
13062
13063 /**
13064 * idmef_file_set_linkage:
13065 * @ptr: pointer to a #idmef_file_t object.
13066 * @object: pointer to a #idmef_linkage_t object.
13067 * @pos: Position in the list.
13068 *
13069 * Add @object to position @pos of @ptr list of #idmef_linkage_t object.
13070 *
13071 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
13072 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
13073 */
idmef_file_set_linkage(idmef_file_t * ptr,idmef_linkage_t * object,int pos)13074 void idmef_file_set_linkage(idmef_file_t *ptr, idmef_linkage_t *object, int pos)
13075 {
13076 prelude_return_if_fail(ptr);
13077 prelude_return_if_fail(object);
13078
13079 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
13080 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
13081
13082 list_insert(&ptr->linkage_list, &((prelude_linked_object_t *) object)->_list, pos);
13083 }
13084
13085
13086 /**
13087 * idmef_file_new_linkage:
13088 * @ptr: pointer to a #idmef_file_t object.
13089 * @ret: pointer to an address where to store the created #idmef_linkage_t object.
13090 * @pos: position in the list.
13091 *
13092 * Create a new #idmef_linkage_t children of @ptr, and add it to position @pos of
13093 * @ptr list of #idmef_linkage_t object. The created #idmef_linkage_t object is
13094 * stored in @ret.
13095 *
13096 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
13097 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
13098 *
13099 * Returns: 0 on success, or a negative value if an error occured.
13100 */
idmef_file_new_linkage(idmef_file_t * ptr,idmef_linkage_t ** ret,int pos)13101 int idmef_file_new_linkage(idmef_file_t *ptr, idmef_linkage_t **ret, int pos)
13102 {
13103 int retval;
13104
13105 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
13106
13107 retval = idmef_linkage_new(ret);
13108 if ( retval < 0 )
13109 return retval;
13110
13111 list_insert(&ptr->linkage_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
13112
13113 return 0;
13114 }
13115
13116
13117 /**
13118 * idmef_file_get_inode:
13119 * @ptr: pointer to a #idmef_file_t object.
13120 *
13121 * Get inode children of the #idmef_file_t object.
13122 *
13123 * Returns: a pointer to a idmef_inode_t object, or NULL if the children object is not set.
13124 */
idmef_file_get_inode(idmef_file_t * ptr)13125 idmef_inode_t *idmef_file_get_inode(idmef_file_t *ptr)
13126 {
13127 prelude_return_val_if_fail(ptr, 0); /* FIXME */
13128
13129 return ptr->inode;
13130 }
13131
13132 /**
13133 * idmef_file_set_inode:
13134 * @ptr: pointer to a #idmef_file_t object.
13135 * @inode: pointer to a #idmef_inode_t object.
13136 *
13137 * Set @inode object as a children of @ptr.
13138 * if @ptr already contain an @inode object, then it is destroyed,
13139 * and updated to point to the provided @inode object.
13140 */
13141
idmef_file_set_inode(idmef_file_t * ptr,idmef_inode_t * inode)13142 void idmef_file_set_inode(idmef_file_t *ptr, idmef_inode_t *inode)
13143 {
13144 prelude_return_if_fail(ptr);
13145
13146 if ( ptr->inode )
13147 idmef_inode_destroy(ptr->inode);
13148
13149 ptr->inode = inode;
13150 }
13151
13152 /**
13153 * idmef_file_new_inode:
13154 * @ptr: pointer to a #idmef_file_t object.
13155 * @ret: pointer to an address where to store the created #idmef_inode_t object.
13156 *
13157 * Create a new inode object, children of #idmef_file_t.
13158 * If @ptr already contain a #idmef_inode_t object, then it is destroyed.
13159 *
13160 * Returns: 0 on success, or a negative value if an error occured.
13161 */
idmef_file_new_inode(idmef_file_t * ptr,idmef_inode_t ** ret)13162 int idmef_file_new_inode(idmef_file_t *ptr, idmef_inode_t **ret)
13163 {
13164 int retval;
13165
13166 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
13167
13168 if ( ! ptr->inode ) {
13169 retval = idmef_inode_new(&ptr->inode);
13170 if ( retval < 0 )
13171 return retval;
13172 }
13173
13174 *ret = ptr->inode;
13175 return 0;
13176 }
13177
13178 /**
13179 * idmef_file_get_next_checksum:
13180 * @file: pointer to a #idmef_file_t object.
13181 * @checksum_cur: pointer to a #idmef_checksum_t object.
13182 *
13183 * Get the next #idmef_checksum_t object listed in @ptr.
13184 * When iterating over the idmef_checksum_t object listed in @ptr,
13185 * @object should be set to the latest returned #idmef_checksum_t object.
13186 *
13187 * Returns: the next #idmef_checksum_t in the list.
13188 */
idmef_file_get_next_checksum(idmef_file_t * file,idmef_checksum_t * checksum_cur)13189 idmef_checksum_t *idmef_file_get_next_checksum(idmef_file_t *file, idmef_checksum_t *checksum_cur)
13190 {
13191 prelude_list_t *tmp = (checksum_cur) ? &((prelude_linked_object_t *) checksum_cur)->_list : NULL;
13192
13193 prelude_return_val_if_fail(file, NULL);
13194
13195 prelude_list_for_each_continue(&file->checksum_list, tmp)
13196 return prelude_linked_object_get_object(tmp);
13197
13198 return NULL;
13199 }
13200
13201
13202 /**
13203 * idmef_file_set_checksum:
13204 * @ptr: pointer to a #idmef_file_t object.
13205 * @object: pointer to a #idmef_checksum_t object.
13206 * @pos: Position in the list.
13207 *
13208 * Add @object to position @pos of @ptr list of #idmef_checksum_t object.
13209 *
13210 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
13211 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
13212 */
idmef_file_set_checksum(idmef_file_t * ptr,idmef_checksum_t * object,int pos)13213 void idmef_file_set_checksum(idmef_file_t *ptr, idmef_checksum_t *object, int pos)
13214 {
13215 prelude_return_if_fail(ptr);
13216 prelude_return_if_fail(object);
13217
13218 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
13219 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
13220
13221 list_insert(&ptr->checksum_list, &((prelude_linked_object_t *) object)->_list, pos);
13222 }
13223
13224
13225 /**
13226 * idmef_file_new_checksum:
13227 * @ptr: pointer to a #idmef_file_t object.
13228 * @ret: pointer to an address where to store the created #idmef_checksum_t object.
13229 * @pos: position in the list.
13230 *
13231 * Create a new #idmef_checksum_t children of @ptr, and add it to position @pos of
13232 * @ptr list of #idmef_checksum_t object. The created #idmef_checksum_t object is
13233 * stored in @ret.
13234 *
13235 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
13236 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
13237 *
13238 * Returns: 0 on success, or a negative value if an error occured.
13239 */
idmef_file_new_checksum(idmef_file_t * ptr,idmef_checksum_t ** ret,int pos)13240 int idmef_file_new_checksum(idmef_file_t *ptr, idmef_checksum_t **ret, int pos)
13241 {
13242 int retval;
13243
13244 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
13245
13246 retval = idmef_checksum_new(ret);
13247 if ( retval < 0 )
13248 return retval;
13249
13250 list_insert(&ptr->checksum_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
13251
13252 return 0;
13253 }
13254
13255
13256 /**
13257 * idmef_file_get_category:
13258 * @ptr: pointer to a #idmef_file_t object.
13259 *
13260 * Get category children of the #idmef_file_t object.
13261 *
13262 * Returns: a pointer to a idmef_file_category_t object, or NULL if the children object is not set.
13263 */
idmef_file_get_category(idmef_file_t * ptr)13264 idmef_file_category_t idmef_file_get_category(idmef_file_t *ptr)
13265 {
13266 prelude_return_val_if_fail(ptr, 0); /* FIXME */
13267
13268 return ptr->category;
13269 }
13270
13271 /**
13272 * idmef_file_set_category:
13273 * @ptr: pointer to a #idmef_file_t object.
13274 * @category: pointer to a #idmef_file_category_t object.
13275 *
13276 * Set @category object as a children of @ptr.
13277 * if @ptr already contain an @category object, then it is destroyed,
13278 * and updated to point to the provided @category object.
13279 */
13280
idmef_file_set_category(idmef_file_t * ptr,idmef_file_category_t category)13281 void idmef_file_set_category(idmef_file_t *ptr, idmef_file_category_t category)
13282 {
13283 prelude_return_if_fail(ptr);
13284 ptr->category = category;
13285 }
13286
13287 /**
13288 * idmef_file_new_category:
13289 * @ptr: pointer to a #idmef_file_t object.
13290 * @ret: pointer to an address where to store the created #idmef_file_category_t object.
13291 *
13292 * Create a new category object, children of #idmef_file_t.
13293 * If @ptr already contain a #idmef_file_category_t object, then it is destroyed.
13294 *
13295 * Returns: 0 on success, or a negative value if an error occured.
13296 */
idmef_file_new_category(idmef_file_t * ptr,idmef_file_category_t ** ret)13297 int idmef_file_new_category(idmef_file_t *ptr, idmef_file_category_t **ret)
13298 {
13299 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
13300
13301 *ret = &ptr->category;
13302 return 0;
13303 }
13304
13305 /**
13306 * idmef_file_get_fstype:
13307 * @ptr: pointer to a #idmef_file_t object.
13308 *
13309 * Get fstype children of the #idmef_file_t object.
13310 *
13311 * Returns: a pointer to a idmef_file_fstype_t object, or NULL if the children object is not set.
13312 */
idmef_file_get_fstype(idmef_file_t * ptr)13313 idmef_file_fstype_t *idmef_file_get_fstype(idmef_file_t *ptr)
13314 {
13315 prelude_return_val_if_fail(ptr, 0); /* FIXME */
13316
13317 return ptr->fstype_is_set ? &ptr->fstype : NULL;
13318 }
13319
13320 /**
13321 * idmef_file_set_fstype:
13322 * @ptr: pointer to a #idmef_file_t object.
13323 * @fstype: pointer to a #idmef_file_fstype_t object.
13324 *
13325 * Set @fstype object as a children of @ptr.
13326 * if @ptr already contain an @fstype object, then it is destroyed,
13327 * and updated to point to the provided @fstype object.
13328 */
13329
idmef_file_set_fstype(idmef_file_t * ptr,idmef_file_fstype_t fstype)13330 void idmef_file_set_fstype(idmef_file_t *ptr, idmef_file_fstype_t fstype)
13331 {
13332 prelude_return_if_fail(ptr);
13333 ptr->fstype = fstype;
13334 ptr->fstype_is_set = 1;
13335 }
13336
13337
idmef_file_unset_fstype(idmef_file_t * ptr)13338 void idmef_file_unset_fstype(idmef_file_t *ptr)
13339 {
13340 prelude_return_if_fail(ptr);
13341 ptr->fstype_is_set = 0;
13342 }
13343
13344
13345 /**
13346 * idmef_file_new_fstype:
13347 * @ptr: pointer to a #idmef_file_t object.
13348 * @ret: pointer to an address where to store the created #idmef_file_fstype_t object.
13349 *
13350 * Create a new fstype object, children of #idmef_file_t.
13351 * If @ptr already contain a #idmef_file_fstype_t object, then it is destroyed.
13352 *
13353 * Returns: 0 on success, or a negative value if an error occured.
13354 */
idmef_file_new_fstype(idmef_file_t * ptr,idmef_file_fstype_t ** ret)13355 int idmef_file_new_fstype(idmef_file_t *ptr, idmef_file_fstype_t **ret)
13356 {
13357 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
13358 ptr->fstype_is_set = 1;
13359
13360 *ret = &ptr->fstype;
13361 return 0;
13362 }
13363
13364 /**
13365 * idmef_file_get_file_type:
13366 * @ptr: pointer to a #idmef_file_t object.
13367 *
13368 * Get file_type children of the #idmef_file_t object.
13369 *
13370 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
13371 */
idmef_file_get_file_type(idmef_file_t * ptr)13372 prelude_string_t *idmef_file_get_file_type(idmef_file_t *ptr)
13373 {
13374 prelude_return_val_if_fail(ptr, 0); /* FIXME */
13375
13376 return ptr->file_type;
13377 }
13378
13379 /**
13380 * idmef_file_set_file_type:
13381 * @ptr: pointer to a #idmef_file_t object.
13382 * @file_type: pointer to a #prelude_string_t object.
13383 *
13384 * Set @file_type object as a children of @ptr.
13385 * if @ptr already contain an @file_type object, then it is destroyed,
13386 * and updated to point to the provided @file_type object.
13387 */
13388
idmef_file_set_file_type(idmef_file_t * ptr,prelude_string_t * file_type)13389 void idmef_file_set_file_type(idmef_file_t *ptr, prelude_string_t *file_type)
13390 {
13391 prelude_return_if_fail(ptr);
13392
13393 if ( ptr->file_type )
13394 prelude_string_destroy(ptr->file_type);
13395
13396 ptr->file_type = file_type;
13397 }
13398
13399 /**
13400 * idmef_file_new_file_type:
13401 * @ptr: pointer to a #idmef_file_t object.
13402 * @ret: pointer to an address where to store the created #prelude_string_t object.
13403 *
13404 * Create a new file_type object, children of #idmef_file_t.
13405 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
13406 *
13407 * Returns: 0 on success, or a negative value if an error occured.
13408 */
idmef_file_new_file_type(idmef_file_t * ptr,prelude_string_t ** ret)13409 int idmef_file_new_file_type(idmef_file_t *ptr, prelude_string_t **ret)
13410 {
13411 int retval;
13412
13413 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
13414
13415 if ( ! ptr->file_type ) {
13416 retval = prelude_string_new(&ptr->file_type);
13417 if ( retval < 0 )
13418 return retval;
13419 }
13420
13421 *ret = ptr->file_type;
13422 return 0;
13423 }
13424
13425 /**
13426 * idmef_file_copy:
13427 * @src: Source of the copy.
13428 * @dst: Where to copy the object.
13429 *
13430 * Copy a new #idmef_file_t object from @src to @dst.
13431 *
13432 * Returns: 0 on success, a negative value if an error occured.
13433 */
idmef_file_copy(const idmef_file_t * src,idmef_file_t * dst)13434 int idmef_file_copy(const idmef_file_t *src, idmef_file_t *dst)
13435 {
13436 int ret;
13437
13438 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
13439 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
13440
13441 ret = 0;
13442
13443 if ( src->ident ) {
13444 ret = prelude_string_clone(src->ident, &dst->ident);
13445 if ( ret < 0 )
13446 return ret;
13447 }
13448
13449 if ( src->name ) {
13450 ret = prelude_string_copy(src->name, dst->name);
13451 if ( ret < 0 )
13452 return ret;
13453 }
13454
13455 if ( src->path ) {
13456 ret = prelude_string_copy(src->path, dst->path);
13457 if ( ret < 0 )
13458 return ret;
13459 }
13460
13461 if ( src->create_time ) {
13462 ret = idmef_time_clone(src->create_time, &dst->create_time);
13463 if ( ret < 0 )
13464 return ret;
13465 }
13466
13467 if ( src->modify_time ) {
13468 ret = idmef_time_clone(src->modify_time, &dst->modify_time);
13469 if ( ret < 0 )
13470 return ret;
13471 }
13472
13473 if ( src->access_time ) {
13474 ret = idmef_time_clone(src->access_time, &dst->access_time);
13475 if ( ret < 0 )
13476 return ret;
13477 }
13478
13479 dst->data_size_is_set = src->data_size_is_set;
13480
13481 dst->data_size = src->data_size;
13482
13483 dst->disk_size_is_set = src->disk_size_is_set;
13484
13485 dst->disk_size = src->disk_size;
13486
13487 {
13488 prelude_list_t *n, *tmp;
13489 idmef_file_access_t *entry, *new;
13490
13491 prelude_list_for_each_safe(&src->file_access_list, tmp, n) {
13492 entry = prelude_linked_object_get_object(tmp);
13493 idmef_file_access_clone(entry, &new);
13494 prelude_list_add_tail(&dst->file_access_list, &((prelude_linked_object_t *) new)->_list);
13495 }
13496 }
13497
13498 {
13499 prelude_list_t *n, *tmp;
13500 idmef_linkage_t *entry, *new;
13501
13502 prelude_list_for_each_safe(&src->linkage_list, tmp, n) {
13503 entry = prelude_linked_object_get_object(tmp);
13504 idmef_linkage_clone(entry, &new);
13505 prelude_list_add_tail(&dst->linkage_list, &((prelude_linked_object_t *) new)->_list);
13506 }
13507 }
13508
13509 if ( src->inode ) {
13510 ret = idmef_inode_clone(src->inode, &dst->inode);
13511 if ( ret < 0 )
13512 return ret;
13513 }
13514
13515 {
13516 prelude_list_t *n, *tmp;
13517 idmef_checksum_t *entry, *new;
13518
13519 prelude_list_for_each_safe(&src->checksum_list, tmp, n) {
13520 entry = prelude_linked_object_get_object(tmp);
13521 idmef_checksum_clone(entry, &new);
13522 prelude_list_add_tail(&dst->checksum_list, &((prelude_linked_object_t *) new)->_list);
13523 }
13524 }
13525
13526 dst->category = src->category;
13527
13528 dst->fstype_is_set = src->fstype_is_set;
13529
13530 dst->fstype = src->fstype;
13531
13532 if ( src->file_type ) {
13533 ret = prelude_string_clone(src->file_type, &dst->file_type);
13534 if ( ret < 0 )
13535 return ret;
13536 }
13537
13538 return 0;
13539 }
13540
13541 /**
13542 * idmef_file_clone:
13543 * @src: Object to be cloned.
13544 * @dst: Address where to store the pointer to the cloned object.
13545 *
13546 * Create a copy of @src, and store it in @dst.
13547 *
13548 * Returns: 0 on success, a negative value if an error occured.
13549 */
idmef_file_clone(idmef_file_t * src,idmef_file_t ** dst)13550 int idmef_file_clone(idmef_file_t *src, idmef_file_t **dst)
13551 {
13552 int ret;
13553
13554 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
13555
13556 ret = idmef_file_new(dst);
13557 if ( ret < 0 )
13558 return ret;
13559
13560 return idmef_file_copy(src, *dst);
13561 }
13562
13563 /**
13564 * idmef_file_compare:
13565 * @obj1: Object to compare with @obj2.
13566 * @obj2: Object to compare with @obj1.
13567 *
13568 * Compare @obj1 with @obj2.
13569 *
13570 * Returns: 0 on match, a negative value on comparison failure.
13571 */
idmef_file_compare(const idmef_file_t * obj1,const idmef_file_t * obj2)13572 int idmef_file_compare(const idmef_file_t *obj1, const idmef_file_t *obj2)
13573 {
13574 int ret = 0;
13575
13576 if ( obj1 == NULL && obj2 == NULL )
13577 return 0;
13578
13579 else if ( obj1 == NULL || obj2 == NULL )
13580 return -1;
13581
13582 ret = prelude_string_compare(obj1->ident, obj2->ident);
13583 if ( ret != 0 )
13584 return ret;
13585
13586 ret = prelude_string_compare(obj1->name, obj2->name);
13587 if ( ret != 0 )
13588 return ret;
13589
13590 ret = prelude_string_compare(obj1->path, obj2->path);
13591 if ( ret != 0 )
13592 return ret;
13593
13594 ret = idmef_time_compare(obj1->create_time, obj2->create_time);
13595 if ( ret != 0 )
13596 return ret;
13597
13598 ret = idmef_time_compare(obj1->modify_time, obj2->modify_time);
13599 if ( ret != 0 )
13600 return ret;
13601
13602 ret = idmef_time_compare(obj1->access_time, obj2->access_time);
13603 if ( ret != 0 )
13604 return ret;
13605
13606 if ( obj1->data_size_is_set != obj2->data_size_is_set )
13607 return -1;
13608
13609 if ( obj1->data_size_is_set && obj1->data_size != obj2->data_size )
13610 return -1;
13611
13612 if ( obj1->disk_size_is_set != obj2->disk_size_is_set )
13613 return -1;
13614
13615 if ( obj1->disk_size_is_set && obj1->disk_size != obj2->disk_size )
13616 return -1;
13617
13618 {
13619 prelude_list_t *tmp1, *tmp2;
13620 idmef_file_access_t *entry1, *entry2;
13621
13622 tmp1 = tmp2 = NULL;
13623 do {
13624 entry1 = entry2 = NULL;
13625
13626 prelude_list_for_each_continue(&obj1->file_access_list, tmp1) {
13627 entry1 = prelude_linked_object_get_object(tmp1);
13628 break;
13629 }
13630
13631 prelude_list_for_each_continue(&obj2->file_access_list, tmp2) {
13632 entry2 = prelude_linked_object_get_object(tmp2);
13633 break;
13634 }
13635
13636 ret = idmef_file_access_compare(entry1, entry2);
13637 if ( ret != 0 )
13638 return ret;
13639
13640 } while ( entry1 && entry2 );
13641 }
13642
13643 {
13644 prelude_list_t *tmp1, *tmp2;
13645 idmef_linkage_t *entry1, *entry2;
13646
13647 tmp1 = tmp2 = NULL;
13648 do {
13649 entry1 = entry2 = NULL;
13650
13651 prelude_list_for_each_continue(&obj1->linkage_list, tmp1) {
13652 entry1 = prelude_linked_object_get_object(tmp1);
13653 break;
13654 }
13655
13656 prelude_list_for_each_continue(&obj2->linkage_list, tmp2) {
13657 entry2 = prelude_linked_object_get_object(tmp2);
13658 break;
13659 }
13660
13661 ret = idmef_linkage_compare(entry1, entry2);
13662 if ( ret != 0 )
13663 return ret;
13664
13665 } while ( entry1 && entry2 );
13666 }
13667
13668 ret = idmef_inode_compare(obj1->inode, obj2->inode);
13669 if ( ret != 0 )
13670 return ret;
13671
13672 {
13673 prelude_list_t *tmp1, *tmp2;
13674 idmef_checksum_t *entry1, *entry2;
13675
13676 tmp1 = tmp2 = NULL;
13677 do {
13678 entry1 = entry2 = NULL;
13679
13680 prelude_list_for_each_continue(&obj1->checksum_list, tmp1) {
13681 entry1 = prelude_linked_object_get_object(tmp1);
13682 break;
13683 }
13684
13685 prelude_list_for_each_continue(&obj2->checksum_list, tmp2) {
13686 entry2 = prelude_linked_object_get_object(tmp2);
13687 break;
13688 }
13689
13690 ret = idmef_checksum_compare(entry1, entry2);
13691 if ( ret != 0 )
13692 return ret;
13693
13694 } while ( entry1 && entry2 );
13695 }
13696
13697 if ( obj1->category != obj2->category )
13698 return -1;
13699
13700 if ( obj1->fstype_is_set != obj2->fstype_is_set )
13701 return -1;
13702
13703 if ( obj1->fstype_is_set && obj1->fstype != obj2->fstype )
13704 return -1;
13705
13706 ret = prelude_string_compare(obj1->file_type, obj2->file_type);
13707 if ( ret != 0 )
13708 return ret;
13709
13710 return ret;
13711 }
13712
13713 /**
13714 * idmef_linkage_new:
13715 * @ret: Pointer where to store the created #idmef_linkage_t object.
13716 *
13717 * Create a new #idmef_linkage_t object.
13718 *
13719 * Returns: 0 on success, a negative value if an error occured.
13720 */
idmef_linkage_new(idmef_linkage_t ** ret)13721 int idmef_linkage_new(idmef_linkage_t **ret)
13722 {
13723 *ret = calloc(1, sizeof(**ret));
13724 if ( ! *ret )
13725 return prelude_error_from_errno(errno);
13726
13727 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_LINKAGE;
13728
13729 prelude_list_init(&((prelude_linked_object_t *) (*ret))->_list);
13730
13731 (*ret)->refcount = 1;
13732
13733 {
13734 int retval = prelude_string_new(&(*ret)->name);
13735
13736 if ( retval < 0 ) {
13737 idmef_linkage_destroy(*ret);
13738 *ret = NULL;
13739 return retval;
13740 }
13741 }
13742
13743 {
13744 int retval = prelude_string_new(&(*ret)->path);
13745
13746 if ( retval < 0 ) {
13747 idmef_linkage_destroy(*ret);
13748 *ret = NULL;
13749 return retval;
13750 }
13751 }
13752
13753 {
13754 int retval = idmef_file_new(&(*ret)->file);
13755
13756 if ( retval < 0 ) {
13757 idmef_linkage_destroy(*ret);
13758 *ret = NULL;
13759 return retval;
13760 }
13761 }
13762
13763 return 0;
13764
13765 }
13766
13767 /**
13768 * idmef_linkage_ref:
13769 * @linkage: pointer to a #idmef_linkage_t object.
13770 *
13771 * Increase @linkage reference count, so that it can be referenced
13772 * multiple time.
13773 *
13774 * Returns: a pointer to @linkage.
13775 */
idmef_linkage_ref(idmef_linkage_t * linkage)13776 idmef_linkage_t *idmef_linkage_ref(idmef_linkage_t *linkage)
13777 {
13778 prelude_return_val_if_fail(linkage, NULL);
13779 linkage->refcount++;
13780
13781 return linkage;
13782 }
13783
_idmef_linkage_get_child(void * p,idmef_class_child_id_t child,void ** childptr)13784 int _idmef_linkage_get_child(void *p, idmef_class_child_id_t child, void **childptr)
13785 {
13786 idmef_linkage_t *ptr = p;
13787
13788 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
13789 *childptr = NULL;
13790
13791 switch ( child ) {
13792
13793 case 0:
13794 return idmef_value_new_enum_from_numeric((idmef_value_t **) childptr,
13795 IDMEF_CLASS_ID_LINKAGE_CATEGORY, ptr->category);
13796
13797 case 1:
13798 return get_value_from_string((idmef_value_t **) childptr, ptr->name, TRUE);
13799 case 2:
13800 return get_value_from_string((idmef_value_t **) childptr, ptr->path, TRUE);
13801 case 3:
13802 *childptr = ptr->file;
13803 return 0;
13804
13805 default:
13806 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
13807 }
13808 }
13809
_idmef_linkage_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)13810 int _idmef_linkage_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
13811 {
13812 idmef_linkage_t *ptr = p;
13813
13814 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
13815
13816 switch ( child ) {
13817
13818 case 0:
13819 return idmef_linkage_new_category(ptr, (idmef_linkage_category_t **) ret);
13820
13821 case 1:
13822 return idmef_linkage_new_name(ptr, (prelude_string_t **) ret);
13823
13824 case 2:
13825 return idmef_linkage_new_path(ptr, (prelude_string_t **) ret);
13826
13827 case 3:
13828 return idmef_linkage_new_file(ptr, (idmef_file_t **) ret);
13829
13830 default:
13831 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
13832 }
13833 }
13834
_idmef_linkage_destroy_child(void * p,idmef_class_child_id_t child,int n)13835 int _idmef_linkage_destroy_child(void *p, idmef_class_child_id_t child, int n)
13836 {
13837 idmef_linkage_t *ptr = p;
13838
13839 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
13840
13841 switch ( child ) {
13842
13843 case 0:
13844 ptr->category = 0;
13845 return 0;
13846
13847 case 1:
13848 if ( ptr->name ) {
13849 prelude_string_destroy(ptr->name);
13850 ptr->name = NULL;
13851 }
13852
13853 return 0;
13854
13855 case 2:
13856 if ( ptr->path ) {
13857 prelude_string_destroy(ptr->path);
13858 ptr->path = NULL;
13859 }
13860
13861 return 0;
13862
13863 case 3:
13864 if ( ptr->file ) {
13865 idmef_file_destroy(ptr->file);
13866 ptr->file = NULL;
13867 }
13868
13869 return 0;
13870
13871 default:
13872 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
13873 }
13874 }
13875
idmef_linkage_destroy_internal(idmef_linkage_t * ptr)13876 static void idmef_linkage_destroy_internal(idmef_linkage_t *ptr)
13877 {
13878 prelude_return_if_fail(ptr);
13879
13880 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *)ptr)->_list) )
13881 prelude_list_del_init(&((prelude_linked_object_t *)ptr)->_list);
13882
13883 if ( ptr->name ) {
13884 prelude_string_destroy(ptr->name);
13885 ptr->name = NULL;
13886 }
13887
13888 if ( ptr->path ) {
13889 prelude_string_destroy(ptr->path);
13890 ptr->path = NULL;
13891 }
13892
13893 if ( ptr->file ) {
13894 idmef_file_destroy(ptr->file);
13895 ptr->file = NULL;
13896 }
13897
13898
13899 /* free() should be done by the caller */
13900 }
13901
13902 /**
13903 * idmef_linkage_destroy:
13904 * @ptr: pointer to a #idmef_linkage_t object.
13905 *
13906 * Destroy @ptr and all of it's children.
13907 * The objects are only destroyed if their reference count reach zero.
13908 */
13909
idmef_linkage_destroy(idmef_linkage_t * ptr)13910 void idmef_linkage_destroy(idmef_linkage_t *ptr)
13911 {
13912 prelude_return_if_fail(ptr);
13913
13914 if ( --ptr->refcount )
13915 return;
13916
13917 idmef_linkage_destroy_internal(ptr);
13918 free(ptr);
13919 }
13920
13921 /**
13922 * idmef_linkage_get_category:
13923 * @ptr: pointer to a #idmef_linkage_t object.
13924 *
13925 * Get category children of the #idmef_linkage_t object.
13926 *
13927 * Returns: a pointer to a idmef_linkage_category_t object, or NULL if the children object is not set.
13928 */
idmef_linkage_get_category(idmef_linkage_t * ptr)13929 idmef_linkage_category_t idmef_linkage_get_category(idmef_linkage_t *ptr)
13930 {
13931 prelude_return_val_if_fail(ptr, 0); /* FIXME */
13932
13933 return ptr->category;
13934 }
13935
13936 /**
13937 * idmef_linkage_set_category:
13938 * @ptr: pointer to a #idmef_linkage_t object.
13939 * @category: pointer to a #idmef_linkage_category_t object.
13940 *
13941 * Set @category object as a children of @ptr.
13942 * if @ptr already contain an @category object, then it is destroyed,
13943 * and updated to point to the provided @category object.
13944 */
13945
idmef_linkage_set_category(idmef_linkage_t * ptr,idmef_linkage_category_t category)13946 void idmef_linkage_set_category(idmef_linkage_t *ptr, idmef_linkage_category_t category)
13947 {
13948 prelude_return_if_fail(ptr);
13949 ptr->category = category;
13950 }
13951
13952 /**
13953 * idmef_linkage_new_category:
13954 * @ptr: pointer to a #idmef_linkage_t object.
13955 * @ret: pointer to an address where to store the created #idmef_linkage_category_t object.
13956 *
13957 * Create a new category object, children of #idmef_linkage_t.
13958 * If @ptr already contain a #idmef_linkage_category_t object, then it is destroyed.
13959 *
13960 * Returns: 0 on success, or a negative value if an error occured.
13961 */
idmef_linkage_new_category(idmef_linkage_t * ptr,idmef_linkage_category_t ** ret)13962 int idmef_linkage_new_category(idmef_linkage_t *ptr, idmef_linkage_category_t **ret)
13963 {
13964 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
13965
13966 *ret = &ptr->category;
13967 return 0;
13968 }
13969
13970 /**
13971 * idmef_linkage_get_name:
13972 * @ptr: pointer to a #idmef_linkage_t object.
13973 *
13974 * Get name children of the #idmef_linkage_t object.
13975 *
13976 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
13977 */
idmef_linkage_get_name(idmef_linkage_t * ptr)13978 prelude_string_t *idmef_linkage_get_name(idmef_linkage_t *ptr)
13979 {
13980 prelude_return_val_if_fail(ptr, 0); /* FIXME */
13981
13982 return ptr->name;
13983 }
13984
13985 /**
13986 * idmef_linkage_set_name:
13987 * @ptr: pointer to a #idmef_linkage_t object.
13988 * @name: pointer to a #prelude_string_t object.
13989 *
13990 * Set @name object as a children of @ptr.
13991 * if @ptr already contain an @name object, then it is destroyed,
13992 * and updated to point to the provided @name object.
13993 */
13994
idmef_linkage_set_name(idmef_linkage_t * ptr,prelude_string_t * name)13995 void idmef_linkage_set_name(idmef_linkage_t *ptr, prelude_string_t *name)
13996 {
13997 prelude_return_if_fail(ptr);
13998
13999 if ( ptr->name )
14000 prelude_string_destroy(ptr->name);
14001
14002 ptr->name = name;
14003 }
14004
14005 /**
14006 * idmef_linkage_new_name:
14007 * @ptr: pointer to a #idmef_linkage_t object.
14008 * @ret: pointer to an address where to store the created #prelude_string_t object.
14009 *
14010 * Create a new name object, children of #idmef_linkage_t.
14011 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
14012 *
14013 * Returns: 0 on success, or a negative value if an error occured.
14014 */
idmef_linkage_new_name(idmef_linkage_t * ptr,prelude_string_t ** ret)14015 int idmef_linkage_new_name(idmef_linkage_t *ptr, prelude_string_t **ret)
14016 {
14017 int retval;
14018
14019 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
14020
14021 if ( ! ptr->name ) {
14022 retval = prelude_string_new(&ptr->name);
14023 if ( retval < 0 )
14024 return retval;
14025 }
14026
14027 *ret = ptr->name;
14028 return 0;
14029 }
14030
14031 /**
14032 * idmef_linkage_get_path:
14033 * @ptr: pointer to a #idmef_linkage_t object.
14034 *
14035 * Get path children of the #idmef_linkage_t object.
14036 *
14037 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
14038 */
idmef_linkage_get_path(idmef_linkage_t * ptr)14039 prelude_string_t *idmef_linkage_get_path(idmef_linkage_t *ptr)
14040 {
14041 prelude_return_val_if_fail(ptr, 0); /* FIXME */
14042
14043 return ptr->path;
14044 }
14045
14046 /**
14047 * idmef_linkage_set_path:
14048 * @ptr: pointer to a #idmef_linkage_t object.
14049 * @path: pointer to a #prelude_string_t object.
14050 *
14051 * Set @path object as a children of @ptr.
14052 * if @ptr already contain an @path object, then it is destroyed,
14053 * and updated to point to the provided @path object.
14054 */
14055
idmef_linkage_set_path(idmef_linkage_t * ptr,prelude_string_t * path)14056 void idmef_linkage_set_path(idmef_linkage_t *ptr, prelude_string_t *path)
14057 {
14058 prelude_return_if_fail(ptr);
14059
14060 if ( ptr->path )
14061 prelude_string_destroy(ptr->path);
14062
14063 ptr->path = path;
14064 }
14065
14066 /**
14067 * idmef_linkage_new_path:
14068 * @ptr: pointer to a #idmef_linkage_t object.
14069 * @ret: pointer to an address where to store the created #prelude_string_t object.
14070 *
14071 * Create a new path object, children of #idmef_linkage_t.
14072 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
14073 *
14074 * Returns: 0 on success, or a negative value if an error occured.
14075 */
idmef_linkage_new_path(idmef_linkage_t * ptr,prelude_string_t ** ret)14076 int idmef_linkage_new_path(idmef_linkage_t *ptr, prelude_string_t **ret)
14077 {
14078 int retval;
14079
14080 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
14081
14082 if ( ! ptr->path ) {
14083 retval = prelude_string_new(&ptr->path);
14084 if ( retval < 0 )
14085 return retval;
14086 }
14087
14088 *ret = ptr->path;
14089 return 0;
14090 }
14091
14092 /**
14093 * idmef_linkage_get_file:
14094 * @ptr: pointer to a #idmef_linkage_t object.
14095 *
14096 * Get file children of the #idmef_linkage_t object.
14097 *
14098 * Returns: a pointer to a idmef_file_t object, or NULL if the children object is not set.
14099 */
idmef_linkage_get_file(idmef_linkage_t * ptr)14100 idmef_file_t *idmef_linkage_get_file(idmef_linkage_t *ptr)
14101 {
14102 prelude_return_val_if_fail(ptr, 0); /* FIXME */
14103
14104 return ptr->file;
14105 }
14106
14107 /**
14108 * idmef_linkage_set_file:
14109 * @ptr: pointer to a #idmef_linkage_t object.
14110 * @file: pointer to a #idmef_file_t object.
14111 *
14112 * Set @file object as a children of @ptr.
14113 * if @ptr already contain an @file object, then it is destroyed,
14114 * and updated to point to the provided @file object.
14115 */
14116
idmef_linkage_set_file(idmef_linkage_t * ptr,idmef_file_t * file)14117 void idmef_linkage_set_file(idmef_linkage_t *ptr, idmef_file_t *file)
14118 {
14119 prelude_return_if_fail(ptr);
14120
14121 if ( ptr->file )
14122 idmef_file_destroy(ptr->file);
14123
14124 ptr->file = file;
14125 }
14126
14127 /**
14128 * idmef_linkage_new_file:
14129 * @ptr: pointer to a #idmef_linkage_t object.
14130 * @ret: pointer to an address where to store the created #idmef_file_t object.
14131 *
14132 * Create a new file object, children of #idmef_linkage_t.
14133 * If @ptr already contain a #idmef_file_t object, then it is destroyed.
14134 *
14135 * Returns: 0 on success, or a negative value if an error occured.
14136 */
idmef_linkage_new_file(idmef_linkage_t * ptr,idmef_file_t ** ret)14137 int idmef_linkage_new_file(idmef_linkage_t *ptr, idmef_file_t **ret)
14138 {
14139 int retval;
14140
14141 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
14142
14143 if ( ! ptr->file ) {
14144 retval = idmef_file_new(&ptr->file);
14145 if ( retval < 0 )
14146 return retval;
14147 }
14148
14149 *ret = ptr->file;
14150 return 0;
14151 }
14152
14153 /**
14154 * idmef_linkage_copy:
14155 * @src: Source of the copy.
14156 * @dst: Where to copy the object.
14157 *
14158 * Copy a new #idmef_linkage_t object from @src to @dst.
14159 *
14160 * Returns: 0 on success, a negative value if an error occured.
14161 */
idmef_linkage_copy(const idmef_linkage_t * src,idmef_linkage_t * dst)14162 int idmef_linkage_copy(const idmef_linkage_t *src, idmef_linkage_t *dst)
14163 {
14164 int ret;
14165
14166 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
14167 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
14168
14169 ret = 0;
14170
14171 dst->category = src->category;
14172
14173 if ( src->name ) {
14174 ret = prelude_string_copy(src->name, dst->name);
14175 if ( ret < 0 )
14176 return ret;
14177 }
14178
14179 if ( src->path ) {
14180 ret = prelude_string_copy(src->path, dst->path);
14181 if ( ret < 0 )
14182 return ret;
14183 }
14184
14185 if ( src->file ) {
14186 ret = idmef_file_copy(src->file, dst->file);
14187 if ( ret < 0 )
14188 return ret;
14189 }
14190
14191 return 0;
14192 }
14193
14194 /**
14195 * idmef_linkage_clone:
14196 * @src: Object to be cloned.
14197 * @dst: Address where to store the pointer to the cloned object.
14198 *
14199 * Create a copy of @src, and store it in @dst.
14200 *
14201 * Returns: 0 on success, a negative value if an error occured.
14202 */
idmef_linkage_clone(idmef_linkage_t * src,idmef_linkage_t ** dst)14203 int idmef_linkage_clone(idmef_linkage_t *src, idmef_linkage_t **dst)
14204 {
14205 int ret;
14206
14207 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
14208
14209 ret = idmef_linkage_new(dst);
14210 if ( ret < 0 )
14211 return ret;
14212
14213 return idmef_linkage_copy(src, *dst);
14214 }
14215
14216 /**
14217 * idmef_linkage_compare:
14218 * @obj1: Object to compare with @obj2.
14219 * @obj2: Object to compare with @obj1.
14220 *
14221 * Compare @obj1 with @obj2.
14222 *
14223 * Returns: 0 on match, a negative value on comparison failure.
14224 */
idmef_linkage_compare(const idmef_linkage_t * obj1,const idmef_linkage_t * obj2)14225 int idmef_linkage_compare(const idmef_linkage_t *obj1, const idmef_linkage_t *obj2)
14226 {
14227 int ret = 0;
14228
14229 if ( obj1 == NULL && obj2 == NULL )
14230 return 0;
14231
14232 else if ( obj1 == NULL || obj2 == NULL )
14233 return -1;
14234
14235 if ( obj1->category != obj2->category )
14236 return -1;
14237
14238 ret = prelude_string_compare(obj1->name, obj2->name);
14239 if ( ret != 0 )
14240 return ret;
14241
14242 ret = prelude_string_compare(obj1->path, obj2->path);
14243 if ( ret != 0 )
14244 return ret;
14245
14246 ret = idmef_file_compare(obj1->file, obj2->file);
14247 if ( ret != 0 )
14248 return ret;
14249
14250 return ret;
14251 }
14252
14253 /**
14254 * idmef_target_new:
14255 * @ret: Pointer where to store the created #idmef_target_t object.
14256 *
14257 * Create a new #idmef_target_t object.
14258 *
14259 * Returns: 0 on success, a negative value if an error occured.
14260 */
idmef_target_new(idmef_target_t ** ret)14261 int idmef_target_new(idmef_target_t **ret)
14262 {
14263 *ret = calloc(1, sizeof(**ret));
14264 if ( ! *ret )
14265 return prelude_error_from_errno(errno);
14266
14267 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_TARGET;
14268
14269 prelude_list_init(&((prelude_linked_object_t *) (*ret))->_list);
14270
14271 (*ret)->refcount = 1;
14272
14273 prelude_list_init(&(*ret)->file_list);
14274
14275
14276 return 0;
14277
14278 }
14279
14280 /**
14281 * idmef_target_ref:
14282 * @target: pointer to a #idmef_target_t object.
14283 *
14284 * Increase @target reference count, so that it can be referenced
14285 * multiple time.
14286 *
14287 * Returns: a pointer to @target.
14288 */
idmef_target_ref(idmef_target_t * target)14289 idmef_target_t *idmef_target_ref(idmef_target_t *target)
14290 {
14291 prelude_return_val_if_fail(target, NULL);
14292 target->refcount++;
14293
14294 return target;
14295 }
14296
_idmef_target_get_child(void * p,idmef_class_child_id_t child,void ** childptr)14297 int _idmef_target_get_child(void *p, idmef_class_child_id_t child, void **childptr)
14298 {
14299 idmef_target_t *ptr = p;
14300
14301 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
14302 *childptr = NULL;
14303
14304 switch ( child ) {
14305
14306 case 0:
14307 return get_value_from_string((idmef_value_t **) childptr, ptr->ident, TRUE);
14308 case 1:
14309 return idmef_value_new_enum_from_numeric((idmef_value_t **) childptr,
14310 IDMEF_CLASS_ID_TARGET_DECOY, ptr->decoy);
14311
14312 case 2:
14313 return get_value_from_string((idmef_value_t **) childptr, ptr->interface, TRUE);
14314 case 3:
14315 *childptr = ptr->node;
14316 return 0;
14317
14318 case 4:
14319 *childptr = ptr->user;
14320 return 0;
14321
14322 case 5:
14323 *childptr = ptr->process;
14324 return 0;
14325
14326 case 6:
14327 *childptr = ptr->service;
14328 return 0;
14329
14330 case 7:
14331 *childptr = &ptr->file_list;
14332 return 0;
14333
14334 default:
14335 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
14336 }
14337 }
14338
_idmef_target_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)14339 int _idmef_target_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
14340 {
14341 idmef_target_t *ptr = p;
14342
14343 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
14344
14345 switch ( child ) {
14346
14347 case 0:
14348 return idmef_target_new_ident(ptr, (prelude_string_t **) ret);
14349
14350 case 1:
14351 return idmef_target_new_decoy(ptr, (idmef_target_decoy_t **) ret);
14352
14353 case 2:
14354 return idmef_target_new_interface(ptr, (prelude_string_t **) ret);
14355
14356 case 3:
14357 return idmef_target_new_node(ptr, (idmef_node_t **) ret);
14358
14359 case 4:
14360 return idmef_target_new_user(ptr, (idmef_user_t **) ret);
14361
14362 case 5:
14363 return idmef_target_new_process(ptr, (idmef_process_t **) ret);
14364
14365 case 6:
14366 return idmef_target_new_service(ptr, (idmef_service_t **) ret);
14367
14368 case 7: {
14369 int i = 0;
14370 prelude_list_t *tmp;
14371
14372 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
14373 return idmef_target_new_file(ptr, (idmef_file_t **) ret, n);
14374
14375 if ( n >= 0 ) {
14376 prelude_list_for_each(&ptr->file_list, tmp) {
14377 if ( i++ == n ) {
14378 *ret = prelude_linked_object_get_object(tmp);
14379 return 0;
14380 }
14381 }
14382
14383 if ( i != n )
14384 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
14385 } else {
14386 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
14387
14388 prelude_list_for_each_reversed(&ptr->file_list, tmp) {
14389 if ( i++ == pos ) {
14390 *ret = prelude_linked_object_get_object(tmp);
14391 return 0;
14392 }
14393 }
14394
14395 if ( i != pos )
14396 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
14397 }
14398
14399 return idmef_target_new_file(ptr, (idmef_file_t **) ret, n);
14400 }
14401
14402 default:
14403 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
14404 }
14405 }
14406
_idmef_target_destroy_child(void * p,idmef_class_child_id_t child,int n)14407 int _idmef_target_destroy_child(void *p, idmef_class_child_id_t child, int n)
14408 {
14409 idmef_target_t *ptr = p;
14410
14411 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
14412
14413 switch ( child ) {
14414
14415 case 0:
14416 if ( ptr->ident ) {
14417 prelude_string_destroy(ptr->ident);
14418 ptr->ident = NULL;
14419 }
14420
14421 return 0;
14422
14423 case 1:
14424 ptr->decoy = 0;
14425 return 0;
14426
14427 case 2:
14428 if ( ptr->interface ) {
14429 prelude_string_destroy(ptr->interface);
14430 ptr->interface = NULL;
14431 }
14432
14433 return 0;
14434
14435 case 3:
14436 if ( ptr->node ) {
14437 idmef_node_destroy(ptr->node);
14438 ptr->node = NULL;
14439 }
14440
14441 return 0;
14442
14443 case 4:
14444 if ( ptr->user ) {
14445 idmef_user_destroy(ptr->user);
14446 ptr->user = NULL;
14447 }
14448
14449 return 0;
14450
14451 case 5:
14452 if ( ptr->process ) {
14453 idmef_process_destroy(ptr->process);
14454 ptr->process = NULL;
14455 }
14456
14457 return 0;
14458
14459 case 6:
14460 if ( ptr->service ) {
14461 idmef_service_destroy(ptr->service);
14462 ptr->service = NULL;
14463 }
14464
14465 return 0;
14466
14467 case 7: {
14468 int i = 0;
14469 prelude_list_t *tmp;
14470
14471 if ( n >= 0 ) {
14472 prelude_list_for_each(&ptr->file_list, tmp) {
14473 if ( i++ == n ) {
14474 void *b = prelude_linked_object_get_object(tmp);
14475 idmef_file_destroy(b);
14476 return 0;
14477 }
14478 }
14479
14480 if ( i != n )
14481 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
14482 } else {
14483 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
14484
14485 prelude_list_for_each_reversed(&ptr->file_list, tmp) {
14486 if ( i++ == pos ) {
14487 void *b = prelude_linked_object_get_object(tmp);
14488 idmef_file_destroy(b);
14489 return 0;
14490 }
14491 }
14492
14493 if ( i != pos )
14494 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
14495 }
14496 }
14497
14498 default:
14499 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
14500 }
14501 }
14502
idmef_target_destroy_internal(idmef_target_t * ptr)14503 static void idmef_target_destroy_internal(idmef_target_t *ptr)
14504 {
14505 prelude_return_if_fail(ptr);
14506
14507 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *)ptr)->_list) )
14508 prelude_list_del_init(&((prelude_linked_object_t *)ptr)->_list);
14509
14510 if ( ptr->ident ) {
14511 prelude_string_destroy(ptr->ident);
14512 ptr->ident = NULL;
14513 }
14514
14515 if ( ptr->interface ) {
14516 prelude_string_destroy(ptr->interface);
14517 ptr->interface = NULL;
14518 }
14519
14520 if ( ptr->node ) {
14521 idmef_node_destroy(ptr->node);
14522 ptr->node = NULL;
14523 }
14524
14525 if ( ptr->user ) {
14526 idmef_user_destroy(ptr->user);
14527 ptr->user = NULL;
14528 }
14529
14530 if ( ptr->process ) {
14531 idmef_process_destroy(ptr->process);
14532 ptr->process = NULL;
14533 }
14534
14535 if ( ptr->service ) {
14536 idmef_service_destroy(ptr->service);
14537 ptr->service = NULL;
14538 }
14539
14540 {
14541 prelude_list_t *n, *tmp;
14542 idmef_file_t *entry;
14543
14544 prelude_list_for_each_safe(&ptr->file_list, tmp, n) {
14545 entry = prelude_linked_object_get_object(tmp);
14546 prelude_list_del_init(tmp);
14547 idmef_file_destroy(entry);
14548 }
14549 }
14550
14551
14552 /* free() should be done by the caller */
14553 }
14554
14555 /**
14556 * idmef_target_destroy:
14557 * @ptr: pointer to a #idmef_target_t object.
14558 *
14559 * Destroy @ptr and all of it's children.
14560 * The objects are only destroyed if their reference count reach zero.
14561 */
14562
idmef_target_destroy(idmef_target_t * ptr)14563 void idmef_target_destroy(idmef_target_t *ptr)
14564 {
14565 prelude_return_if_fail(ptr);
14566
14567 if ( --ptr->refcount )
14568 return;
14569
14570 idmef_target_destroy_internal(ptr);
14571 free(ptr);
14572 }
14573
14574 /**
14575 * idmef_target_get_ident:
14576 * @ptr: pointer to a #idmef_target_t object.
14577 *
14578 * Get ident children of the #idmef_target_t object.
14579 *
14580 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
14581 */
idmef_target_get_ident(idmef_target_t * ptr)14582 prelude_string_t *idmef_target_get_ident(idmef_target_t *ptr)
14583 {
14584 prelude_return_val_if_fail(ptr, 0); /* FIXME */
14585
14586 return ptr->ident;
14587 }
14588
14589 /**
14590 * idmef_target_set_ident:
14591 * @ptr: pointer to a #idmef_target_t object.
14592 * @ident: pointer to a #prelude_string_t object.
14593 *
14594 * Set @ident object as a children of @ptr.
14595 * if @ptr already contain an @ident object, then it is destroyed,
14596 * and updated to point to the provided @ident object.
14597 */
14598
idmef_target_set_ident(idmef_target_t * ptr,prelude_string_t * ident)14599 void idmef_target_set_ident(idmef_target_t *ptr, prelude_string_t *ident)
14600 {
14601 prelude_return_if_fail(ptr);
14602
14603 if ( ptr->ident )
14604 prelude_string_destroy(ptr->ident);
14605
14606 ptr->ident = ident;
14607 }
14608
14609 /**
14610 * idmef_target_new_ident:
14611 * @ptr: pointer to a #idmef_target_t object.
14612 * @ret: pointer to an address where to store the created #prelude_string_t object.
14613 *
14614 * Create a new ident object, children of #idmef_target_t.
14615 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
14616 *
14617 * Returns: 0 on success, or a negative value if an error occured.
14618 */
idmef_target_new_ident(idmef_target_t * ptr,prelude_string_t ** ret)14619 int idmef_target_new_ident(idmef_target_t *ptr, prelude_string_t **ret)
14620 {
14621 int retval;
14622
14623 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
14624
14625 if ( ! ptr->ident ) {
14626 retval = prelude_string_new(&ptr->ident);
14627 if ( retval < 0 )
14628 return retval;
14629 }
14630
14631 *ret = ptr->ident;
14632 return 0;
14633 }
14634
14635 /**
14636 * idmef_target_get_decoy:
14637 * @ptr: pointer to a #idmef_target_t object.
14638 *
14639 * Get decoy children of the #idmef_target_t object.
14640 *
14641 * Returns: a pointer to a idmef_target_decoy_t object, or NULL if the children object is not set.
14642 */
idmef_target_get_decoy(idmef_target_t * ptr)14643 idmef_target_decoy_t idmef_target_get_decoy(idmef_target_t *ptr)
14644 {
14645 prelude_return_val_if_fail(ptr, 0); /* FIXME */
14646
14647 return ptr->decoy;
14648 }
14649
14650 /**
14651 * idmef_target_set_decoy:
14652 * @ptr: pointer to a #idmef_target_t object.
14653 * @decoy: pointer to a #idmef_target_decoy_t object.
14654 *
14655 * Set @decoy object as a children of @ptr.
14656 * if @ptr already contain an @decoy object, then it is destroyed,
14657 * and updated to point to the provided @decoy object.
14658 */
14659
idmef_target_set_decoy(idmef_target_t * ptr,idmef_target_decoy_t decoy)14660 void idmef_target_set_decoy(idmef_target_t *ptr, idmef_target_decoy_t decoy)
14661 {
14662 prelude_return_if_fail(ptr);
14663 ptr->decoy = decoy;
14664 }
14665
14666 /**
14667 * idmef_target_new_decoy:
14668 * @ptr: pointer to a #idmef_target_t object.
14669 * @ret: pointer to an address where to store the created #idmef_target_decoy_t object.
14670 *
14671 * Create a new decoy object, children of #idmef_target_t.
14672 * If @ptr already contain a #idmef_target_decoy_t object, then it is destroyed.
14673 *
14674 * Returns: 0 on success, or a negative value if an error occured.
14675 */
idmef_target_new_decoy(idmef_target_t * ptr,idmef_target_decoy_t ** ret)14676 int idmef_target_new_decoy(idmef_target_t *ptr, idmef_target_decoy_t **ret)
14677 {
14678 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
14679
14680 *ret = &ptr->decoy;
14681 return 0;
14682 }
14683
14684 /**
14685 * idmef_target_get_interface:
14686 * @ptr: pointer to a #idmef_target_t object.
14687 *
14688 * Get interface children of the #idmef_target_t object.
14689 *
14690 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
14691 */
idmef_target_get_interface(idmef_target_t * ptr)14692 prelude_string_t *idmef_target_get_interface(idmef_target_t *ptr)
14693 {
14694 prelude_return_val_if_fail(ptr, 0); /* FIXME */
14695
14696 return ptr->interface;
14697 }
14698
14699 /**
14700 * idmef_target_set_interface:
14701 * @ptr: pointer to a #idmef_target_t object.
14702 * @interface: pointer to a #prelude_string_t object.
14703 *
14704 * Set @interface object as a children of @ptr.
14705 * if @ptr already contain an @interface object, then it is destroyed,
14706 * and updated to point to the provided @interface object.
14707 */
14708
idmef_target_set_interface(idmef_target_t * ptr,prelude_string_t * interface)14709 void idmef_target_set_interface(idmef_target_t *ptr, prelude_string_t *interface)
14710 {
14711 prelude_return_if_fail(ptr);
14712
14713 if ( ptr->interface )
14714 prelude_string_destroy(ptr->interface);
14715
14716 ptr->interface = interface;
14717 }
14718
14719 /**
14720 * idmef_target_new_interface:
14721 * @ptr: pointer to a #idmef_target_t object.
14722 * @ret: pointer to an address where to store the created #prelude_string_t object.
14723 *
14724 * Create a new interface object, children of #idmef_target_t.
14725 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
14726 *
14727 * Returns: 0 on success, or a negative value if an error occured.
14728 */
idmef_target_new_interface(idmef_target_t * ptr,prelude_string_t ** ret)14729 int idmef_target_new_interface(idmef_target_t *ptr, prelude_string_t **ret)
14730 {
14731 int retval;
14732
14733 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
14734
14735 if ( ! ptr->interface ) {
14736 retval = prelude_string_new(&ptr->interface);
14737 if ( retval < 0 )
14738 return retval;
14739 }
14740
14741 *ret = ptr->interface;
14742 return 0;
14743 }
14744
14745 /**
14746 * idmef_target_get_node:
14747 * @ptr: pointer to a #idmef_target_t object.
14748 *
14749 * Get node children of the #idmef_target_t object.
14750 *
14751 * Returns: a pointer to a idmef_node_t object, or NULL if the children object is not set.
14752 */
idmef_target_get_node(idmef_target_t * ptr)14753 idmef_node_t *idmef_target_get_node(idmef_target_t *ptr)
14754 {
14755 prelude_return_val_if_fail(ptr, 0); /* FIXME */
14756
14757 return ptr->node;
14758 }
14759
14760 /**
14761 * idmef_target_set_node:
14762 * @ptr: pointer to a #idmef_target_t object.
14763 * @node: pointer to a #idmef_node_t object.
14764 *
14765 * Set @node object as a children of @ptr.
14766 * if @ptr already contain an @node object, then it is destroyed,
14767 * and updated to point to the provided @node object.
14768 */
14769
idmef_target_set_node(idmef_target_t * ptr,idmef_node_t * node)14770 void idmef_target_set_node(idmef_target_t *ptr, idmef_node_t *node)
14771 {
14772 prelude_return_if_fail(ptr);
14773
14774 if ( ptr->node )
14775 idmef_node_destroy(ptr->node);
14776
14777 ptr->node = node;
14778 }
14779
14780 /**
14781 * idmef_target_new_node:
14782 * @ptr: pointer to a #idmef_target_t object.
14783 * @ret: pointer to an address where to store the created #idmef_node_t object.
14784 *
14785 * Create a new node object, children of #idmef_target_t.
14786 * If @ptr already contain a #idmef_node_t object, then it is destroyed.
14787 *
14788 * Returns: 0 on success, or a negative value if an error occured.
14789 */
idmef_target_new_node(idmef_target_t * ptr,idmef_node_t ** ret)14790 int idmef_target_new_node(idmef_target_t *ptr, idmef_node_t **ret)
14791 {
14792 int retval;
14793
14794 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
14795
14796 if ( ! ptr->node ) {
14797 retval = idmef_node_new(&ptr->node);
14798 if ( retval < 0 )
14799 return retval;
14800 }
14801
14802 *ret = ptr->node;
14803 return 0;
14804 }
14805
14806 /**
14807 * idmef_target_get_user:
14808 * @ptr: pointer to a #idmef_target_t object.
14809 *
14810 * Get user children of the #idmef_target_t object.
14811 *
14812 * Returns: a pointer to a idmef_user_t object, or NULL if the children object is not set.
14813 */
idmef_target_get_user(idmef_target_t * ptr)14814 idmef_user_t *idmef_target_get_user(idmef_target_t *ptr)
14815 {
14816 prelude_return_val_if_fail(ptr, 0); /* FIXME */
14817
14818 return ptr->user;
14819 }
14820
14821 /**
14822 * idmef_target_set_user:
14823 * @ptr: pointer to a #idmef_target_t object.
14824 * @user: pointer to a #idmef_user_t object.
14825 *
14826 * Set @user object as a children of @ptr.
14827 * if @ptr already contain an @user object, then it is destroyed,
14828 * and updated to point to the provided @user object.
14829 */
14830
idmef_target_set_user(idmef_target_t * ptr,idmef_user_t * user)14831 void idmef_target_set_user(idmef_target_t *ptr, idmef_user_t *user)
14832 {
14833 prelude_return_if_fail(ptr);
14834
14835 if ( ptr->user )
14836 idmef_user_destroy(ptr->user);
14837
14838 ptr->user = user;
14839 }
14840
14841 /**
14842 * idmef_target_new_user:
14843 * @ptr: pointer to a #idmef_target_t object.
14844 * @ret: pointer to an address where to store the created #idmef_user_t object.
14845 *
14846 * Create a new user object, children of #idmef_target_t.
14847 * If @ptr already contain a #idmef_user_t object, then it is destroyed.
14848 *
14849 * Returns: 0 on success, or a negative value if an error occured.
14850 */
idmef_target_new_user(idmef_target_t * ptr,idmef_user_t ** ret)14851 int idmef_target_new_user(idmef_target_t *ptr, idmef_user_t **ret)
14852 {
14853 int retval;
14854
14855 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
14856
14857 if ( ! ptr->user ) {
14858 retval = idmef_user_new(&ptr->user);
14859 if ( retval < 0 )
14860 return retval;
14861 }
14862
14863 *ret = ptr->user;
14864 return 0;
14865 }
14866
14867 /**
14868 * idmef_target_get_process:
14869 * @ptr: pointer to a #idmef_target_t object.
14870 *
14871 * Get process children of the #idmef_target_t object.
14872 *
14873 * Returns: a pointer to a idmef_process_t object, or NULL if the children object is not set.
14874 */
idmef_target_get_process(idmef_target_t * ptr)14875 idmef_process_t *idmef_target_get_process(idmef_target_t *ptr)
14876 {
14877 prelude_return_val_if_fail(ptr, 0); /* FIXME */
14878
14879 return ptr->process;
14880 }
14881
14882 /**
14883 * idmef_target_set_process:
14884 * @ptr: pointer to a #idmef_target_t object.
14885 * @process: pointer to a #idmef_process_t object.
14886 *
14887 * Set @process object as a children of @ptr.
14888 * if @ptr already contain an @process object, then it is destroyed,
14889 * and updated to point to the provided @process object.
14890 */
14891
idmef_target_set_process(idmef_target_t * ptr,idmef_process_t * process)14892 void idmef_target_set_process(idmef_target_t *ptr, idmef_process_t *process)
14893 {
14894 prelude_return_if_fail(ptr);
14895
14896 if ( ptr->process )
14897 idmef_process_destroy(ptr->process);
14898
14899 ptr->process = process;
14900 }
14901
14902 /**
14903 * idmef_target_new_process:
14904 * @ptr: pointer to a #idmef_target_t object.
14905 * @ret: pointer to an address where to store the created #idmef_process_t object.
14906 *
14907 * Create a new process object, children of #idmef_target_t.
14908 * If @ptr already contain a #idmef_process_t object, then it is destroyed.
14909 *
14910 * Returns: 0 on success, or a negative value if an error occured.
14911 */
idmef_target_new_process(idmef_target_t * ptr,idmef_process_t ** ret)14912 int idmef_target_new_process(idmef_target_t *ptr, idmef_process_t **ret)
14913 {
14914 int retval;
14915
14916 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
14917
14918 if ( ! ptr->process ) {
14919 retval = idmef_process_new(&ptr->process);
14920 if ( retval < 0 )
14921 return retval;
14922 }
14923
14924 *ret = ptr->process;
14925 return 0;
14926 }
14927
14928 /**
14929 * idmef_target_get_service:
14930 * @ptr: pointer to a #idmef_target_t object.
14931 *
14932 * Get service children of the #idmef_target_t object.
14933 *
14934 * Returns: a pointer to a idmef_service_t object, or NULL if the children object is not set.
14935 */
idmef_target_get_service(idmef_target_t * ptr)14936 idmef_service_t *idmef_target_get_service(idmef_target_t *ptr)
14937 {
14938 prelude_return_val_if_fail(ptr, 0); /* FIXME */
14939
14940 return ptr->service;
14941 }
14942
14943 /**
14944 * idmef_target_set_service:
14945 * @ptr: pointer to a #idmef_target_t object.
14946 * @service: pointer to a #idmef_service_t object.
14947 *
14948 * Set @service object as a children of @ptr.
14949 * if @ptr already contain an @service object, then it is destroyed,
14950 * and updated to point to the provided @service object.
14951 */
14952
idmef_target_set_service(idmef_target_t * ptr,idmef_service_t * service)14953 void idmef_target_set_service(idmef_target_t *ptr, idmef_service_t *service)
14954 {
14955 prelude_return_if_fail(ptr);
14956
14957 if ( ptr->service )
14958 idmef_service_destroy(ptr->service);
14959
14960 ptr->service = service;
14961 }
14962
14963 /**
14964 * idmef_target_new_service:
14965 * @ptr: pointer to a #idmef_target_t object.
14966 * @ret: pointer to an address where to store the created #idmef_service_t object.
14967 *
14968 * Create a new service object, children of #idmef_target_t.
14969 * If @ptr already contain a #idmef_service_t object, then it is destroyed.
14970 *
14971 * Returns: 0 on success, or a negative value if an error occured.
14972 */
idmef_target_new_service(idmef_target_t * ptr,idmef_service_t ** ret)14973 int idmef_target_new_service(idmef_target_t *ptr, idmef_service_t **ret)
14974 {
14975 int retval;
14976
14977 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
14978
14979 if ( ! ptr->service ) {
14980 retval = idmef_service_new(&ptr->service);
14981 if ( retval < 0 )
14982 return retval;
14983 }
14984
14985 *ret = ptr->service;
14986 return 0;
14987 }
14988
14989 /**
14990 * idmef_target_get_next_file:
14991 * @target: pointer to a #idmef_target_t object.
14992 * @file_cur: pointer to a #idmef_file_t object.
14993 *
14994 * Get the next #idmef_file_t object listed in @ptr.
14995 * When iterating over the idmef_file_t object listed in @ptr,
14996 * @object should be set to the latest returned #idmef_file_t object.
14997 *
14998 * Returns: the next #idmef_file_t in the list.
14999 */
idmef_target_get_next_file(idmef_target_t * target,idmef_file_t * file_cur)15000 idmef_file_t *idmef_target_get_next_file(idmef_target_t *target, idmef_file_t *file_cur)
15001 {
15002 prelude_list_t *tmp = (file_cur) ? &((prelude_linked_object_t *) file_cur)->_list : NULL;
15003
15004 prelude_return_val_if_fail(target, NULL);
15005
15006 prelude_list_for_each_continue(&target->file_list, tmp)
15007 return prelude_linked_object_get_object(tmp);
15008
15009 return NULL;
15010 }
15011
15012
15013 /**
15014 * idmef_target_set_file:
15015 * @ptr: pointer to a #idmef_target_t object.
15016 * @object: pointer to a #idmef_file_t object.
15017 * @pos: Position in the list.
15018 *
15019 * Add @object to position @pos of @ptr list of #idmef_file_t object.
15020 *
15021 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
15022 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
15023 */
idmef_target_set_file(idmef_target_t * ptr,idmef_file_t * object,int pos)15024 void idmef_target_set_file(idmef_target_t *ptr, idmef_file_t *object, int pos)
15025 {
15026 prelude_return_if_fail(ptr);
15027 prelude_return_if_fail(object);
15028
15029 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
15030 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
15031
15032 list_insert(&ptr->file_list, &((prelude_linked_object_t *) object)->_list, pos);
15033 }
15034
15035
15036 /**
15037 * idmef_target_new_file:
15038 * @ptr: pointer to a #idmef_target_t object.
15039 * @ret: pointer to an address where to store the created #idmef_file_t object.
15040 * @pos: position in the list.
15041 *
15042 * Create a new #idmef_file_t children of @ptr, and add it to position @pos of
15043 * @ptr list of #idmef_file_t object. The created #idmef_file_t object is
15044 * stored in @ret.
15045 *
15046 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
15047 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
15048 *
15049 * Returns: 0 on success, or a negative value if an error occured.
15050 */
idmef_target_new_file(idmef_target_t * ptr,idmef_file_t ** ret,int pos)15051 int idmef_target_new_file(idmef_target_t *ptr, idmef_file_t **ret, int pos)
15052 {
15053 int retval;
15054
15055 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
15056
15057 retval = idmef_file_new(ret);
15058 if ( retval < 0 )
15059 return retval;
15060
15061 list_insert(&ptr->file_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
15062
15063 return 0;
15064 }
15065
15066
15067 /**
15068 * idmef_target_copy:
15069 * @src: Source of the copy.
15070 * @dst: Where to copy the object.
15071 *
15072 * Copy a new #idmef_target_t object from @src to @dst.
15073 *
15074 * Returns: 0 on success, a negative value if an error occured.
15075 */
idmef_target_copy(const idmef_target_t * src,idmef_target_t * dst)15076 int idmef_target_copy(const idmef_target_t *src, idmef_target_t *dst)
15077 {
15078 int ret;
15079
15080 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
15081 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
15082
15083 ret = 0;
15084
15085 if ( src->ident ) {
15086 ret = prelude_string_clone(src->ident, &dst->ident);
15087 if ( ret < 0 )
15088 return ret;
15089 }
15090
15091 dst->decoy = src->decoy;
15092
15093 if ( src->interface ) {
15094 ret = prelude_string_clone(src->interface, &dst->interface);
15095 if ( ret < 0 )
15096 return ret;
15097 }
15098
15099 if ( src->node ) {
15100 ret = idmef_node_clone(src->node, &dst->node);
15101 if ( ret < 0 )
15102 return ret;
15103 }
15104
15105 if ( src->user ) {
15106 ret = idmef_user_clone(src->user, &dst->user);
15107 if ( ret < 0 )
15108 return ret;
15109 }
15110
15111 if ( src->process ) {
15112 ret = idmef_process_clone(src->process, &dst->process);
15113 if ( ret < 0 )
15114 return ret;
15115 }
15116
15117 if ( src->service ) {
15118 ret = idmef_service_clone(src->service, &dst->service);
15119 if ( ret < 0 )
15120 return ret;
15121 }
15122
15123 {
15124 prelude_list_t *n, *tmp;
15125 idmef_file_t *entry, *new;
15126
15127 prelude_list_for_each_safe(&src->file_list, tmp, n) {
15128 entry = prelude_linked_object_get_object(tmp);
15129 idmef_file_clone(entry, &new);
15130 prelude_list_add_tail(&dst->file_list, &((prelude_linked_object_t *) new)->_list);
15131 }
15132 }
15133
15134 return 0;
15135 }
15136
15137 /**
15138 * idmef_target_clone:
15139 * @src: Object to be cloned.
15140 * @dst: Address where to store the pointer to the cloned object.
15141 *
15142 * Create a copy of @src, and store it in @dst.
15143 *
15144 * Returns: 0 on success, a negative value if an error occured.
15145 */
idmef_target_clone(idmef_target_t * src,idmef_target_t ** dst)15146 int idmef_target_clone(idmef_target_t *src, idmef_target_t **dst)
15147 {
15148 int ret;
15149
15150 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
15151
15152 ret = idmef_target_new(dst);
15153 if ( ret < 0 )
15154 return ret;
15155
15156 return idmef_target_copy(src, *dst);
15157 }
15158
15159 /**
15160 * idmef_target_compare:
15161 * @obj1: Object to compare with @obj2.
15162 * @obj2: Object to compare with @obj1.
15163 *
15164 * Compare @obj1 with @obj2.
15165 *
15166 * Returns: 0 on match, a negative value on comparison failure.
15167 */
idmef_target_compare(const idmef_target_t * obj1,const idmef_target_t * obj2)15168 int idmef_target_compare(const idmef_target_t *obj1, const idmef_target_t *obj2)
15169 {
15170 int ret = 0;
15171
15172 if ( obj1 == NULL && obj2 == NULL )
15173 return 0;
15174
15175 else if ( obj1 == NULL || obj2 == NULL )
15176 return -1;
15177
15178 ret = prelude_string_compare(obj1->ident, obj2->ident);
15179 if ( ret != 0 )
15180 return ret;
15181
15182 if ( obj1->decoy != obj2->decoy )
15183 return -1;
15184
15185 ret = prelude_string_compare(obj1->interface, obj2->interface);
15186 if ( ret != 0 )
15187 return ret;
15188
15189 ret = idmef_node_compare(obj1->node, obj2->node);
15190 if ( ret != 0 )
15191 return ret;
15192
15193 ret = idmef_user_compare(obj1->user, obj2->user);
15194 if ( ret != 0 )
15195 return ret;
15196
15197 ret = idmef_process_compare(obj1->process, obj2->process);
15198 if ( ret != 0 )
15199 return ret;
15200
15201 ret = idmef_service_compare(obj1->service, obj2->service);
15202 if ( ret != 0 )
15203 return ret;
15204
15205 {
15206 prelude_list_t *tmp1, *tmp2;
15207 idmef_file_t *entry1, *entry2;
15208
15209 tmp1 = tmp2 = NULL;
15210 do {
15211 entry1 = entry2 = NULL;
15212
15213 prelude_list_for_each_continue(&obj1->file_list, tmp1) {
15214 entry1 = prelude_linked_object_get_object(tmp1);
15215 break;
15216 }
15217
15218 prelude_list_for_each_continue(&obj2->file_list, tmp2) {
15219 entry2 = prelude_linked_object_get_object(tmp2);
15220 break;
15221 }
15222
15223 ret = idmef_file_compare(entry1, entry2);
15224 if ( ret != 0 )
15225 return ret;
15226
15227 } while ( entry1 && entry2 );
15228 }
15229
15230 return ret;
15231 }
15232
15233 /**
15234 * idmef_analyzer_new:
15235 * @ret: Pointer where to store the created #idmef_analyzer_t object.
15236 *
15237 * Create a new #idmef_analyzer_t object.
15238 *
15239 * Returns: 0 on success, a negative value if an error occured.
15240 */
idmef_analyzer_new(idmef_analyzer_t ** ret)15241 int idmef_analyzer_new(idmef_analyzer_t **ret)
15242 {
15243 *ret = calloc(1, sizeof(**ret));
15244 if ( ! *ret )
15245 return prelude_error_from_errno(errno);
15246
15247 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_ANALYZER;
15248
15249 prelude_list_init(&((prelude_linked_object_t *) (*ret))->_list);
15250
15251 (*ret)->refcount = 1;
15252
15253 return 0;
15254
15255 }
15256
15257 /**
15258 * idmef_analyzer_ref:
15259 * @analyzer: pointer to a #idmef_analyzer_t object.
15260 *
15261 * Increase @analyzer reference count, so that it can be referenced
15262 * multiple time.
15263 *
15264 * Returns: a pointer to @analyzer.
15265 */
idmef_analyzer_ref(idmef_analyzer_t * analyzer)15266 idmef_analyzer_t *idmef_analyzer_ref(idmef_analyzer_t *analyzer)
15267 {
15268 prelude_return_val_if_fail(analyzer, NULL);
15269 analyzer->refcount++;
15270
15271 return analyzer;
15272 }
15273
_idmef_analyzer_get_child(void * p,idmef_class_child_id_t child,void ** childptr)15274 int _idmef_analyzer_get_child(void *p, idmef_class_child_id_t child, void **childptr)
15275 {
15276 idmef_analyzer_t *ptr = p;
15277
15278 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
15279 *childptr = NULL;
15280
15281 switch ( child ) {
15282
15283 case 0:
15284 return get_value_from_string((idmef_value_t **) childptr, ptr->analyzerid, TRUE);
15285 case 1:
15286 return get_value_from_string((idmef_value_t **) childptr, ptr->name, TRUE);
15287 case 2:
15288 return get_value_from_string((idmef_value_t **) childptr, ptr->manufacturer, TRUE);
15289 case 3:
15290 return get_value_from_string((idmef_value_t **) childptr, ptr->model, TRUE);
15291 case 4:
15292 return get_value_from_string((idmef_value_t **) childptr, ptr->version, TRUE);
15293 case 5:
15294 return get_value_from_string((idmef_value_t **) childptr, ptr->class, TRUE);
15295 case 6:
15296 return get_value_from_string((idmef_value_t **) childptr, ptr->ostype, TRUE);
15297 case 7:
15298 return get_value_from_string((idmef_value_t **) childptr, ptr->osversion, TRUE);
15299 case 8:
15300 *childptr = ptr->node;
15301 return 0;
15302
15303 case 9:
15304 *childptr = ptr->process;
15305 return 0;
15306
15307 default:
15308 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
15309 }
15310 }
15311
_idmef_analyzer_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)15312 int _idmef_analyzer_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
15313 {
15314 idmef_analyzer_t *ptr = p;
15315
15316 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
15317
15318 switch ( child ) {
15319
15320 case 0:
15321 return idmef_analyzer_new_analyzerid(ptr, (prelude_string_t **) ret);
15322
15323 case 1:
15324 return idmef_analyzer_new_name(ptr, (prelude_string_t **) ret);
15325
15326 case 2:
15327 return idmef_analyzer_new_manufacturer(ptr, (prelude_string_t **) ret);
15328
15329 case 3:
15330 return idmef_analyzer_new_model(ptr, (prelude_string_t **) ret);
15331
15332 case 4:
15333 return idmef_analyzer_new_version(ptr, (prelude_string_t **) ret);
15334
15335 case 5:
15336 return idmef_analyzer_new_class(ptr, (prelude_string_t **) ret);
15337
15338 case 6:
15339 return idmef_analyzer_new_ostype(ptr, (prelude_string_t **) ret);
15340
15341 case 7:
15342 return idmef_analyzer_new_osversion(ptr, (prelude_string_t **) ret);
15343
15344 case 8:
15345 return idmef_analyzer_new_node(ptr, (idmef_node_t **) ret);
15346
15347 case 9:
15348 return idmef_analyzer_new_process(ptr, (idmef_process_t **) ret);
15349
15350 default:
15351 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
15352 }
15353 }
15354
_idmef_analyzer_destroy_child(void * p,idmef_class_child_id_t child,int n)15355 int _idmef_analyzer_destroy_child(void *p, idmef_class_child_id_t child, int n)
15356 {
15357 idmef_analyzer_t *ptr = p;
15358
15359 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
15360
15361 switch ( child ) {
15362
15363 case 0:
15364 if ( ptr->analyzerid ) {
15365 prelude_string_destroy(ptr->analyzerid);
15366 ptr->analyzerid = NULL;
15367 }
15368
15369 return 0;
15370
15371 case 1:
15372 if ( ptr->name ) {
15373 prelude_string_destroy(ptr->name);
15374 ptr->name = NULL;
15375 }
15376
15377 return 0;
15378
15379 case 2:
15380 if ( ptr->manufacturer ) {
15381 prelude_string_destroy(ptr->manufacturer);
15382 ptr->manufacturer = NULL;
15383 }
15384
15385 return 0;
15386
15387 case 3:
15388 if ( ptr->model ) {
15389 prelude_string_destroy(ptr->model);
15390 ptr->model = NULL;
15391 }
15392
15393 return 0;
15394
15395 case 4:
15396 if ( ptr->version ) {
15397 prelude_string_destroy(ptr->version);
15398 ptr->version = NULL;
15399 }
15400
15401 return 0;
15402
15403 case 5:
15404 if ( ptr->class ) {
15405 prelude_string_destroy(ptr->class);
15406 ptr->class = NULL;
15407 }
15408
15409 return 0;
15410
15411 case 6:
15412 if ( ptr->ostype ) {
15413 prelude_string_destroy(ptr->ostype);
15414 ptr->ostype = NULL;
15415 }
15416
15417 return 0;
15418
15419 case 7:
15420 if ( ptr->osversion ) {
15421 prelude_string_destroy(ptr->osversion);
15422 ptr->osversion = NULL;
15423 }
15424
15425 return 0;
15426
15427 case 8:
15428 if ( ptr->node ) {
15429 idmef_node_destroy(ptr->node);
15430 ptr->node = NULL;
15431 }
15432
15433 return 0;
15434
15435 case 9:
15436 if ( ptr->process ) {
15437 idmef_process_destroy(ptr->process);
15438 ptr->process = NULL;
15439 }
15440
15441 return 0;
15442
15443 default:
15444 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
15445 }
15446 }
15447
idmef_analyzer_destroy_internal(idmef_analyzer_t * ptr)15448 static void idmef_analyzer_destroy_internal(idmef_analyzer_t *ptr)
15449 {
15450 prelude_return_if_fail(ptr);
15451
15452 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *)ptr)->_list) )
15453 prelude_list_del_init(&((prelude_linked_object_t *)ptr)->_list);
15454
15455 if ( ptr->analyzerid ) {
15456 prelude_string_destroy(ptr->analyzerid);
15457 ptr->analyzerid = NULL;
15458 }
15459
15460 if ( ptr->name ) {
15461 prelude_string_destroy(ptr->name);
15462 ptr->name = NULL;
15463 }
15464
15465 if ( ptr->manufacturer ) {
15466 prelude_string_destroy(ptr->manufacturer);
15467 ptr->manufacturer = NULL;
15468 }
15469
15470 if ( ptr->model ) {
15471 prelude_string_destroy(ptr->model);
15472 ptr->model = NULL;
15473 }
15474
15475 if ( ptr->version ) {
15476 prelude_string_destroy(ptr->version);
15477 ptr->version = NULL;
15478 }
15479
15480 if ( ptr->class ) {
15481 prelude_string_destroy(ptr->class);
15482 ptr->class = NULL;
15483 }
15484
15485 if ( ptr->ostype ) {
15486 prelude_string_destroy(ptr->ostype);
15487 ptr->ostype = NULL;
15488 }
15489
15490 if ( ptr->osversion ) {
15491 prelude_string_destroy(ptr->osversion);
15492 ptr->osversion = NULL;
15493 }
15494
15495 if ( ptr->node ) {
15496 idmef_node_destroy(ptr->node);
15497 ptr->node = NULL;
15498 }
15499
15500 if ( ptr->process ) {
15501 idmef_process_destroy(ptr->process);
15502 ptr->process = NULL;
15503 }
15504
15505
15506 /* free() should be done by the caller */
15507 }
15508
15509 /**
15510 * idmef_analyzer_destroy:
15511 * @ptr: pointer to a #idmef_analyzer_t object.
15512 *
15513 * Destroy @ptr and all of it's children.
15514 * The objects are only destroyed if their reference count reach zero.
15515 */
15516
idmef_analyzer_destroy(idmef_analyzer_t * ptr)15517 void idmef_analyzer_destroy(idmef_analyzer_t *ptr)
15518 {
15519 prelude_return_if_fail(ptr);
15520
15521 if ( --ptr->refcount )
15522 return;
15523
15524 idmef_analyzer_destroy_internal(ptr);
15525 free(ptr);
15526 }
15527
15528 /**
15529 * idmef_analyzer_get_analyzerid:
15530 * @ptr: pointer to a #idmef_analyzer_t object.
15531 *
15532 * Get analyzerid children of the #idmef_analyzer_t object.
15533 *
15534 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
15535 */
idmef_analyzer_get_analyzerid(idmef_analyzer_t * ptr)15536 prelude_string_t *idmef_analyzer_get_analyzerid(idmef_analyzer_t *ptr)
15537 {
15538 prelude_return_val_if_fail(ptr, 0); /* FIXME */
15539
15540 return ptr->analyzerid;
15541 }
15542
15543 /**
15544 * idmef_analyzer_set_analyzerid:
15545 * @ptr: pointer to a #idmef_analyzer_t object.
15546 * @analyzerid: pointer to a #prelude_string_t object.
15547 *
15548 * Set @analyzerid object as a children of @ptr.
15549 * if @ptr already contain an @analyzerid object, then it is destroyed,
15550 * and updated to point to the provided @analyzerid object.
15551 */
15552
idmef_analyzer_set_analyzerid(idmef_analyzer_t * ptr,prelude_string_t * analyzerid)15553 void idmef_analyzer_set_analyzerid(idmef_analyzer_t *ptr, prelude_string_t *analyzerid)
15554 {
15555 prelude_return_if_fail(ptr);
15556
15557 if ( ptr->analyzerid )
15558 prelude_string_destroy(ptr->analyzerid);
15559
15560 ptr->analyzerid = analyzerid;
15561 }
15562
15563 /**
15564 * idmef_analyzer_new_analyzerid:
15565 * @ptr: pointer to a #idmef_analyzer_t object.
15566 * @ret: pointer to an address where to store the created #prelude_string_t object.
15567 *
15568 * Create a new analyzerid object, children of #idmef_analyzer_t.
15569 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
15570 *
15571 * Returns: 0 on success, or a negative value if an error occured.
15572 */
idmef_analyzer_new_analyzerid(idmef_analyzer_t * ptr,prelude_string_t ** ret)15573 int idmef_analyzer_new_analyzerid(idmef_analyzer_t *ptr, prelude_string_t **ret)
15574 {
15575 int retval;
15576
15577 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
15578
15579 if ( ! ptr->analyzerid ) {
15580 retval = prelude_string_new(&ptr->analyzerid);
15581 if ( retval < 0 )
15582 return retval;
15583 }
15584
15585 *ret = ptr->analyzerid;
15586 return 0;
15587 }
15588
15589 /**
15590 * idmef_analyzer_get_name:
15591 * @ptr: pointer to a #idmef_analyzer_t object.
15592 *
15593 * Get name children of the #idmef_analyzer_t object.
15594 *
15595 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
15596 */
idmef_analyzer_get_name(idmef_analyzer_t * ptr)15597 prelude_string_t *idmef_analyzer_get_name(idmef_analyzer_t *ptr)
15598 {
15599 prelude_return_val_if_fail(ptr, 0); /* FIXME */
15600
15601 return ptr->name;
15602 }
15603
15604 /**
15605 * idmef_analyzer_set_name:
15606 * @ptr: pointer to a #idmef_analyzer_t object.
15607 * @name: pointer to a #prelude_string_t object.
15608 *
15609 * Set @name object as a children of @ptr.
15610 * if @ptr already contain an @name object, then it is destroyed,
15611 * and updated to point to the provided @name object.
15612 */
15613
idmef_analyzer_set_name(idmef_analyzer_t * ptr,prelude_string_t * name)15614 void idmef_analyzer_set_name(idmef_analyzer_t *ptr, prelude_string_t *name)
15615 {
15616 prelude_return_if_fail(ptr);
15617
15618 if ( ptr->name )
15619 prelude_string_destroy(ptr->name);
15620
15621 ptr->name = name;
15622 }
15623
15624 /**
15625 * idmef_analyzer_new_name:
15626 * @ptr: pointer to a #idmef_analyzer_t object.
15627 * @ret: pointer to an address where to store the created #prelude_string_t object.
15628 *
15629 * Create a new name object, children of #idmef_analyzer_t.
15630 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
15631 *
15632 * Returns: 0 on success, or a negative value if an error occured.
15633 */
idmef_analyzer_new_name(idmef_analyzer_t * ptr,prelude_string_t ** ret)15634 int idmef_analyzer_new_name(idmef_analyzer_t *ptr, prelude_string_t **ret)
15635 {
15636 int retval;
15637
15638 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
15639
15640 if ( ! ptr->name ) {
15641 retval = prelude_string_new(&ptr->name);
15642 if ( retval < 0 )
15643 return retval;
15644 }
15645
15646 *ret = ptr->name;
15647 return 0;
15648 }
15649
15650 /**
15651 * idmef_analyzer_get_manufacturer:
15652 * @ptr: pointer to a #idmef_analyzer_t object.
15653 *
15654 * Get manufacturer children of the #idmef_analyzer_t object.
15655 *
15656 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
15657 */
idmef_analyzer_get_manufacturer(idmef_analyzer_t * ptr)15658 prelude_string_t *idmef_analyzer_get_manufacturer(idmef_analyzer_t *ptr)
15659 {
15660 prelude_return_val_if_fail(ptr, 0); /* FIXME */
15661
15662 return ptr->manufacturer;
15663 }
15664
15665 /**
15666 * idmef_analyzer_set_manufacturer:
15667 * @ptr: pointer to a #idmef_analyzer_t object.
15668 * @manufacturer: pointer to a #prelude_string_t object.
15669 *
15670 * Set @manufacturer object as a children of @ptr.
15671 * if @ptr already contain an @manufacturer object, then it is destroyed,
15672 * and updated to point to the provided @manufacturer object.
15673 */
15674
idmef_analyzer_set_manufacturer(idmef_analyzer_t * ptr,prelude_string_t * manufacturer)15675 void idmef_analyzer_set_manufacturer(idmef_analyzer_t *ptr, prelude_string_t *manufacturer)
15676 {
15677 prelude_return_if_fail(ptr);
15678
15679 if ( ptr->manufacturer )
15680 prelude_string_destroy(ptr->manufacturer);
15681
15682 ptr->manufacturer = manufacturer;
15683 }
15684
15685 /**
15686 * idmef_analyzer_new_manufacturer:
15687 * @ptr: pointer to a #idmef_analyzer_t object.
15688 * @ret: pointer to an address where to store the created #prelude_string_t object.
15689 *
15690 * Create a new manufacturer object, children of #idmef_analyzer_t.
15691 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
15692 *
15693 * Returns: 0 on success, or a negative value if an error occured.
15694 */
idmef_analyzer_new_manufacturer(idmef_analyzer_t * ptr,prelude_string_t ** ret)15695 int idmef_analyzer_new_manufacturer(idmef_analyzer_t *ptr, prelude_string_t **ret)
15696 {
15697 int retval;
15698
15699 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
15700
15701 if ( ! ptr->manufacturer ) {
15702 retval = prelude_string_new(&ptr->manufacturer);
15703 if ( retval < 0 )
15704 return retval;
15705 }
15706
15707 *ret = ptr->manufacturer;
15708 return 0;
15709 }
15710
15711 /**
15712 * idmef_analyzer_get_model:
15713 * @ptr: pointer to a #idmef_analyzer_t object.
15714 *
15715 * Get model children of the #idmef_analyzer_t object.
15716 *
15717 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
15718 */
idmef_analyzer_get_model(idmef_analyzer_t * ptr)15719 prelude_string_t *idmef_analyzer_get_model(idmef_analyzer_t *ptr)
15720 {
15721 prelude_return_val_if_fail(ptr, 0); /* FIXME */
15722
15723 return ptr->model;
15724 }
15725
15726 /**
15727 * idmef_analyzer_set_model:
15728 * @ptr: pointer to a #idmef_analyzer_t object.
15729 * @model: pointer to a #prelude_string_t object.
15730 *
15731 * Set @model object as a children of @ptr.
15732 * if @ptr already contain an @model object, then it is destroyed,
15733 * and updated to point to the provided @model object.
15734 */
15735
idmef_analyzer_set_model(idmef_analyzer_t * ptr,prelude_string_t * model)15736 void idmef_analyzer_set_model(idmef_analyzer_t *ptr, prelude_string_t *model)
15737 {
15738 prelude_return_if_fail(ptr);
15739
15740 if ( ptr->model )
15741 prelude_string_destroy(ptr->model);
15742
15743 ptr->model = model;
15744 }
15745
15746 /**
15747 * idmef_analyzer_new_model:
15748 * @ptr: pointer to a #idmef_analyzer_t object.
15749 * @ret: pointer to an address where to store the created #prelude_string_t object.
15750 *
15751 * Create a new model object, children of #idmef_analyzer_t.
15752 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
15753 *
15754 * Returns: 0 on success, or a negative value if an error occured.
15755 */
idmef_analyzer_new_model(idmef_analyzer_t * ptr,prelude_string_t ** ret)15756 int idmef_analyzer_new_model(idmef_analyzer_t *ptr, prelude_string_t **ret)
15757 {
15758 int retval;
15759
15760 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
15761
15762 if ( ! ptr->model ) {
15763 retval = prelude_string_new(&ptr->model);
15764 if ( retval < 0 )
15765 return retval;
15766 }
15767
15768 *ret = ptr->model;
15769 return 0;
15770 }
15771
15772 /**
15773 * idmef_analyzer_get_version:
15774 * @ptr: pointer to a #idmef_analyzer_t object.
15775 *
15776 * Get version children of the #idmef_analyzer_t object.
15777 *
15778 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
15779 */
idmef_analyzer_get_version(idmef_analyzer_t * ptr)15780 prelude_string_t *idmef_analyzer_get_version(idmef_analyzer_t *ptr)
15781 {
15782 prelude_return_val_if_fail(ptr, 0); /* FIXME */
15783
15784 return ptr->version;
15785 }
15786
15787 /**
15788 * idmef_analyzer_set_version:
15789 * @ptr: pointer to a #idmef_analyzer_t object.
15790 * @version: pointer to a #prelude_string_t object.
15791 *
15792 * Set @version object as a children of @ptr.
15793 * if @ptr already contain an @version object, then it is destroyed,
15794 * and updated to point to the provided @version object.
15795 */
15796
idmef_analyzer_set_version(idmef_analyzer_t * ptr,prelude_string_t * version)15797 void idmef_analyzer_set_version(idmef_analyzer_t *ptr, prelude_string_t *version)
15798 {
15799 prelude_return_if_fail(ptr);
15800
15801 if ( ptr->version )
15802 prelude_string_destroy(ptr->version);
15803
15804 ptr->version = version;
15805 }
15806
15807 /**
15808 * idmef_analyzer_new_version:
15809 * @ptr: pointer to a #idmef_analyzer_t object.
15810 * @ret: pointer to an address where to store the created #prelude_string_t object.
15811 *
15812 * Create a new version object, children of #idmef_analyzer_t.
15813 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
15814 *
15815 * Returns: 0 on success, or a negative value if an error occured.
15816 */
idmef_analyzer_new_version(idmef_analyzer_t * ptr,prelude_string_t ** ret)15817 int idmef_analyzer_new_version(idmef_analyzer_t *ptr, prelude_string_t **ret)
15818 {
15819 int retval;
15820
15821 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
15822
15823 if ( ! ptr->version ) {
15824 retval = prelude_string_new(&ptr->version);
15825 if ( retval < 0 )
15826 return retval;
15827 }
15828
15829 *ret = ptr->version;
15830 return 0;
15831 }
15832
15833 /**
15834 * idmef_analyzer_get_class:
15835 * @ptr: pointer to a #idmef_analyzer_t object.
15836 *
15837 * Get class children of the #idmef_analyzer_t object.
15838 *
15839 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
15840 */
idmef_analyzer_get_class(idmef_analyzer_t * ptr)15841 prelude_string_t *idmef_analyzer_get_class(idmef_analyzer_t *ptr)
15842 {
15843 prelude_return_val_if_fail(ptr, 0); /* FIXME */
15844
15845 return ptr->class;
15846 }
15847
15848 /**
15849 * idmef_analyzer_set_class:
15850 * @ptr: pointer to a #idmef_analyzer_t object.
15851 * @class_str: pointer to a #prelude_string_t object.
15852 *
15853 * Set @class_str object as a children of @ptr.
15854 * if @ptr already contain an @class_str object, then it is destroyed,
15855 * and updated to point to the provided @class_str object.
15856 */
15857
idmef_analyzer_set_class(idmef_analyzer_t * ptr,prelude_string_t * class_str)15858 void idmef_analyzer_set_class(idmef_analyzer_t *ptr, prelude_string_t *class_str)
15859 {
15860 prelude_return_if_fail(ptr);
15861
15862 if ( ptr->class )
15863 prelude_string_destroy(ptr->class);
15864
15865 ptr->class = class_str;
15866 }
15867
15868 /**
15869 * idmef_analyzer_new_class:
15870 * @ptr: pointer to a #idmef_analyzer_t object.
15871 * @ret: pointer to an address where to store the created #prelude_string_t object.
15872 *
15873 * Create a new class object, children of #idmef_analyzer_t.
15874 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
15875 *
15876 * Returns: 0 on success, or a negative value if an error occured.
15877 */
idmef_analyzer_new_class(idmef_analyzer_t * ptr,prelude_string_t ** ret)15878 int idmef_analyzer_new_class(idmef_analyzer_t *ptr, prelude_string_t **ret)
15879 {
15880 int retval;
15881
15882 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
15883
15884 if ( ! ptr->class ) {
15885 retval = prelude_string_new(&ptr->class);
15886 if ( retval < 0 )
15887 return retval;
15888 }
15889
15890 *ret = ptr->class;
15891 return 0;
15892 }
15893
15894 /**
15895 * idmef_analyzer_get_ostype:
15896 * @ptr: pointer to a #idmef_analyzer_t object.
15897 *
15898 * Get ostype children of the #idmef_analyzer_t object.
15899 *
15900 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
15901 */
idmef_analyzer_get_ostype(idmef_analyzer_t * ptr)15902 prelude_string_t *idmef_analyzer_get_ostype(idmef_analyzer_t *ptr)
15903 {
15904 prelude_return_val_if_fail(ptr, 0); /* FIXME */
15905
15906 return ptr->ostype;
15907 }
15908
15909 /**
15910 * idmef_analyzer_set_ostype:
15911 * @ptr: pointer to a #idmef_analyzer_t object.
15912 * @ostype: pointer to a #prelude_string_t object.
15913 *
15914 * Set @ostype object as a children of @ptr.
15915 * if @ptr already contain an @ostype object, then it is destroyed,
15916 * and updated to point to the provided @ostype object.
15917 */
15918
idmef_analyzer_set_ostype(idmef_analyzer_t * ptr,prelude_string_t * ostype)15919 void idmef_analyzer_set_ostype(idmef_analyzer_t *ptr, prelude_string_t *ostype)
15920 {
15921 prelude_return_if_fail(ptr);
15922
15923 if ( ptr->ostype )
15924 prelude_string_destroy(ptr->ostype);
15925
15926 ptr->ostype = ostype;
15927 }
15928
15929 /**
15930 * idmef_analyzer_new_ostype:
15931 * @ptr: pointer to a #idmef_analyzer_t object.
15932 * @ret: pointer to an address where to store the created #prelude_string_t object.
15933 *
15934 * Create a new ostype object, children of #idmef_analyzer_t.
15935 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
15936 *
15937 * Returns: 0 on success, or a negative value if an error occured.
15938 */
idmef_analyzer_new_ostype(idmef_analyzer_t * ptr,prelude_string_t ** ret)15939 int idmef_analyzer_new_ostype(idmef_analyzer_t *ptr, prelude_string_t **ret)
15940 {
15941 int retval;
15942
15943 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
15944
15945 if ( ! ptr->ostype ) {
15946 retval = prelude_string_new(&ptr->ostype);
15947 if ( retval < 0 )
15948 return retval;
15949 }
15950
15951 *ret = ptr->ostype;
15952 return 0;
15953 }
15954
15955 /**
15956 * idmef_analyzer_get_osversion:
15957 * @ptr: pointer to a #idmef_analyzer_t object.
15958 *
15959 * Get osversion children of the #idmef_analyzer_t object.
15960 *
15961 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
15962 */
idmef_analyzer_get_osversion(idmef_analyzer_t * ptr)15963 prelude_string_t *idmef_analyzer_get_osversion(idmef_analyzer_t *ptr)
15964 {
15965 prelude_return_val_if_fail(ptr, 0); /* FIXME */
15966
15967 return ptr->osversion;
15968 }
15969
15970 /**
15971 * idmef_analyzer_set_osversion:
15972 * @ptr: pointer to a #idmef_analyzer_t object.
15973 * @osversion: pointer to a #prelude_string_t object.
15974 *
15975 * Set @osversion object as a children of @ptr.
15976 * if @ptr already contain an @osversion object, then it is destroyed,
15977 * and updated to point to the provided @osversion object.
15978 */
15979
idmef_analyzer_set_osversion(idmef_analyzer_t * ptr,prelude_string_t * osversion)15980 void idmef_analyzer_set_osversion(idmef_analyzer_t *ptr, prelude_string_t *osversion)
15981 {
15982 prelude_return_if_fail(ptr);
15983
15984 if ( ptr->osversion )
15985 prelude_string_destroy(ptr->osversion);
15986
15987 ptr->osversion = osversion;
15988 }
15989
15990 /**
15991 * idmef_analyzer_new_osversion:
15992 * @ptr: pointer to a #idmef_analyzer_t object.
15993 * @ret: pointer to an address where to store the created #prelude_string_t object.
15994 *
15995 * Create a new osversion object, children of #idmef_analyzer_t.
15996 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
15997 *
15998 * Returns: 0 on success, or a negative value if an error occured.
15999 */
idmef_analyzer_new_osversion(idmef_analyzer_t * ptr,prelude_string_t ** ret)16000 int idmef_analyzer_new_osversion(idmef_analyzer_t *ptr, prelude_string_t **ret)
16001 {
16002 int retval;
16003
16004 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
16005
16006 if ( ! ptr->osversion ) {
16007 retval = prelude_string_new(&ptr->osversion);
16008 if ( retval < 0 )
16009 return retval;
16010 }
16011
16012 *ret = ptr->osversion;
16013 return 0;
16014 }
16015
16016 /**
16017 * idmef_analyzer_get_node:
16018 * @ptr: pointer to a #idmef_analyzer_t object.
16019 *
16020 * Get node children of the #idmef_analyzer_t object.
16021 *
16022 * Returns: a pointer to a idmef_node_t object, or NULL if the children object is not set.
16023 */
idmef_analyzer_get_node(idmef_analyzer_t * ptr)16024 idmef_node_t *idmef_analyzer_get_node(idmef_analyzer_t *ptr)
16025 {
16026 prelude_return_val_if_fail(ptr, 0); /* FIXME */
16027
16028 return ptr->node;
16029 }
16030
16031 /**
16032 * idmef_analyzer_set_node:
16033 * @ptr: pointer to a #idmef_analyzer_t object.
16034 * @node: pointer to a #idmef_node_t object.
16035 *
16036 * Set @node object as a children of @ptr.
16037 * if @ptr already contain an @node object, then it is destroyed,
16038 * and updated to point to the provided @node object.
16039 */
16040
idmef_analyzer_set_node(idmef_analyzer_t * ptr,idmef_node_t * node)16041 void idmef_analyzer_set_node(idmef_analyzer_t *ptr, idmef_node_t *node)
16042 {
16043 prelude_return_if_fail(ptr);
16044
16045 if ( ptr->node )
16046 idmef_node_destroy(ptr->node);
16047
16048 ptr->node = node;
16049 }
16050
16051 /**
16052 * idmef_analyzer_new_node:
16053 * @ptr: pointer to a #idmef_analyzer_t object.
16054 * @ret: pointer to an address where to store the created #idmef_node_t object.
16055 *
16056 * Create a new node object, children of #idmef_analyzer_t.
16057 * If @ptr already contain a #idmef_node_t object, then it is destroyed.
16058 *
16059 * Returns: 0 on success, or a negative value if an error occured.
16060 */
idmef_analyzer_new_node(idmef_analyzer_t * ptr,idmef_node_t ** ret)16061 int idmef_analyzer_new_node(idmef_analyzer_t *ptr, idmef_node_t **ret)
16062 {
16063 int retval;
16064
16065 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
16066
16067 if ( ! ptr->node ) {
16068 retval = idmef_node_new(&ptr->node);
16069 if ( retval < 0 )
16070 return retval;
16071 }
16072
16073 *ret = ptr->node;
16074 return 0;
16075 }
16076
16077 /**
16078 * idmef_analyzer_get_process:
16079 * @ptr: pointer to a #idmef_analyzer_t object.
16080 *
16081 * Get process children of the #idmef_analyzer_t object.
16082 *
16083 * Returns: a pointer to a idmef_process_t object, or NULL if the children object is not set.
16084 */
idmef_analyzer_get_process(idmef_analyzer_t * ptr)16085 idmef_process_t *idmef_analyzer_get_process(idmef_analyzer_t *ptr)
16086 {
16087 prelude_return_val_if_fail(ptr, 0); /* FIXME */
16088
16089 return ptr->process;
16090 }
16091
16092 /**
16093 * idmef_analyzer_set_process:
16094 * @ptr: pointer to a #idmef_analyzer_t object.
16095 * @process: pointer to a #idmef_process_t object.
16096 *
16097 * Set @process object as a children of @ptr.
16098 * if @ptr already contain an @process object, then it is destroyed,
16099 * and updated to point to the provided @process object.
16100 */
16101
idmef_analyzer_set_process(idmef_analyzer_t * ptr,idmef_process_t * process)16102 void idmef_analyzer_set_process(idmef_analyzer_t *ptr, idmef_process_t *process)
16103 {
16104 prelude_return_if_fail(ptr);
16105
16106 if ( ptr->process )
16107 idmef_process_destroy(ptr->process);
16108
16109 ptr->process = process;
16110 }
16111
16112 /**
16113 * idmef_analyzer_new_process:
16114 * @ptr: pointer to a #idmef_analyzer_t object.
16115 * @ret: pointer to an address where to store the created #idmef_process_t object.
16116 *
16117 * Create a new process object, children of #idmef_analyzer_t.
16118 * If @ptr already contain a #idmef_process_t object, then it is destroyed.
16119 *
16120 * Returns: 0 on success, or a negative value if an error occured.
16121 */
idmef_analyzer_new_process(idmef_analyzer_t * ptr,idmef_process_t ** ret)16122 int idmef_analyzer_new_process(idmef_analyzer_t *ptr, idmef_process_t **ret)
16123 {
16124 int retval;
16125
16126 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
16127
16128 if ( ! ptr->process ) {
16129 retval = idmef_process_new(&ptr->process);
16130 if ( retval < 0 )
16131 return retval;
16132 }
16133
16134 *ret = ptr->process;
16135 return 0;
16136 }
16137
16138 /**
16139 * idmef_analyzer_copy:
16140 * @src: Source of the copy.
16141 * @dst: Where to copy the object.
16142 *
16143 * Copy a new #idmef_analyzer_t object from @src to @dst.
16144 *
16145 * Returns: 0 on success, a negative value if an error occured.
16146 */
idmef_analyzer_copy(const idmef_analyzer_t * src,idmef_analyzer_t * dst)16147 int idmef_analyzer_copy(const idmef_analyzer_t *src, idmef_analyzer_t *dst)
16148 {
16149 int ret;
16150
16151 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
16152 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
16153
16154 ret = 0;
16155
16156 if ( src->analyzerid ) {
16157 ret = prelude_string_clone(src->analyzerid, &dst->analyzerid);
16158 if ( ret < 0 )
16159 return ret;
16160 }
16161
16162 if ( src->name ) {
16163 ret = prelude_string_clone(src->name, &dst->name);
16164 if ( ret < 0 )
16165 return ret;
16166 }
16167
16168 if ( src->manufacturer ) {
16169 ret = prelude_string_clone(src->manufacturer, &dst->manufacturer);
16170 if ( ret < 0 )
16171 return ret;
16172 }
16173
16174 if ( src->model ) {
16175 ret = prelude_string_clone(src->model, &dst->model);
16176 if ( ret < 0 )
16177 return ret;
16178 }
16179
16180 if ( src->version ) {
16181 ret = prelude_string_clone(src->version, &dst->version);
16182 if ( ret < 0 )
16183 return ret;
16184 }
16185
16186 if ( src->class ) {
16187 ret = prelude_string_clone(src->class, &dst->class);
16188 if ( ret < 0 )
16189 return ret;
16190 }
16191
16192 if ( src->ostype ) {
16193 ret = prelude_string_clone(src->ostype, &dst->ostype);
16194 if ( ret < 0 )
16195 return ret;
16196 }
16197
16198 if ( src->osversion ) {
16199 ret = prelude_string_clone(src->osversion, &dst->osversion);
16200 if ( ret < 0 )
16201 return ret;
16202 }
16203
16204 if ( src->node ) {
16205 ret = idmef_node_clone(src->node, &dst->node);
16206 if ( ret < 0 )
16207 return ret;
16208 }
16209
16210 if ( src->process ) {
16211 ret = idmef_process_clone(src->process, &dst->process);
16212 if ( ret < 0 )
16213 return ret;
16214 }
16215
16216 return 0;
16217 }
16218
16219 /**
16220 * idmef_analyzer_clone:
16221 * @src: Object to be cloned.
16222 * @dst: Address where to store the pointer to the cloned object.
16223 *
16224 * Create a copy of @src, and store it in @dst.
16225 *
16226 * Returns: 0 on success, a negative value if an error occured.
16227 */
idmef_analyzer_clone(idmef_analyzer_t * src,idmef_analyzer_t ** dst)16228 int idmef_analyzer_clone(idmef_analyzer_t *src, idmef_analyzer_t **dst)
16229 {
16230 int ret;
16231
16232 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
16233
16234 ret = idmef_analyzer_new(dst);
16235 if ( ret < 0 )
16236 return ret;
16237
16238 return idmef_analyzer_copy(src, *dst);
16239 }
16240
16241 /**
16242 * idmef_analyzer_compare:
16243 * @obj1: Object to compare with @obj2.
16244 * @obj2: Object to compare with @obj1.
16245 *
16246 * Compare @obj1 with @obj2.
16247 *
16248 * Returns: 0 on match, a negative value on comparison failure.
16249 */
idmef_analyzer_compare(const idmef_analyzer_t * obj1,const idmef_analyzer_t * obj2)16250 int idmef_analyzer_compare(const idmef_analyzer_t *obj1, const idmef_analyzer_t *obj2)
16251 {
16252 int ret = 0;
16253
16254 if ( obj1 == NULL && obj2 == NULL )
16255 return 0;
16256
16257 else if ( obj1 == NULL || obj2 == NULL )
16258 return -1;
16259
16260 ret = prelude_string_compare(obj1->analyzerid, obj2->analyzerid);
16261 if ( ret != 0 )
16262 return ret;
16263
16264 ret = prelude_string_compare(obj1->name, obj2->name);
16265 if ( ret != 0 )
16266 return ret;
16267
16268 ret = prelude_string_compare(obj1->manufacturer, obj2->manufacturer);
16269 if ( ret != 0 )
16270 return ret;
16271
16272 ret = prelude_string_compare(obj1->model, obj2->model);
16273 if ( ret != 0 )
16274 return ret;
16275
16276 ret = prelude_string_compare(obj1->version, obj2->version);
16277 if ( ret != 0 )
16278 return ret;
16279
16280 ret = prelude_string_compare(obj1->class, obj2->class);
16281 if ( ret != 0 )
16282 return ret;
16283
16284 ret = prelude_string_compare(obj1->ostype, obj2->ostype);
16285 if ( ret != 0 )
16286 return ret;
16287
16288 ret = prelude_string_compare(obj1->osversion, obj2->osversion);
16289 if ( ret != 0 )
16290 return ret;
16291
16292 ret = idmef_node_compare(obj1->node, obj2->node);
16293 if ( ret != 0 )
16294 return ret;
16295
16296 ret = idmef_process_compare(obj1->process, obj2->process);
16297 if ( ret != 0 )
16298 return ret;
16299
16300 return ret;
16301 }
16302
16303 /**
16304 * idmef_alertident_new:
16305 * @ret: Pointer where to store the created #idmef_alertident_t object.
16306 *
16307 * Create a new #idmef_alertident_t object.
16308 *
16309 * Returns: 0 on success, a negative value if an error occured.
16310 */
idmef_alertident_new(idmef_alertident_t ** ret)16311 int idmef_alertident_new(idmef_alertident_t **ret)
16312 {
16313 *ret = calloc(1, sizeof(**ret));
16314 if ( ! *ret )
16315 return prelude_error_from_errno(errno);
16316
16317 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_ALERTIDENT;
16318
16319 prelude_list_init(&((prelude_linked_object_t *) (*ret))->_list);
16320
16321 (*ret)->refcount = 1;
16322
16323 {
16324 int retval = prelude_string_new(&(*ret)->alertident);
16325
16326 if ( retval < 0 ) {
16327 idmef_alertident_destroy(*ret);
16328 *ret = NULL;
16329 return retval;
16330 }
16331 }
16332
16333 return 0;
16334
16335 }
16336
16337 /**
16338 * idmef_alertident_ref:
16339 * @alertident: pointer to a #idmef_alertident_t object.
16340 *
16341 * Increase @alertident reference count, so that it can be referenced
16342 * multiple time.
16343 *
16344 * Returns: a pointer to @alertident.
16345 */
idmef_alertident_ref(idmef_alertident_t * alertident)16346 idmef_alertident_t *idmef_alertident_ref(idmef_alertident_t *alertident)
16347 {
16348 prelude_return_val_if_fail(alertident, NULL);
16349 alertident->refcount++;
16350
16351 return alertident;
16352 }
16353
_idmef_alertident_get_child(void * p,idmef_class_child_id_t child,void ** childptr)16354 int _idmef_alertident_get_child(void *p, idmef_class_child_id_t child, void **childptr)
16355 {
16356 idmef_alertident_t *ptr = p;
16357
16358 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
16359 *childptr = NULL;
16360
16361 switch ( child ) {
16362
16363 case 0:
16364 return get_value_from_string((idmef_value_t **) childptr, ptr->alertident, TRUE);
16365 case 1:
16366 return get_value_from_string((idmef_value_t **) childptr, ptr->analyzerid, TRUE);
16367 default:
16368 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
16369 }
16370 }
16371
_idmef_alertident_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)16372 int _idmef_alertident_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
16373 {
16374 idmef_alertident_t *ptr = p;
16375
16376 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
16377
16378 switch ( child ) {
16379
16380 case 0:
16381 return idmef_alertident_new_alertident(ptr, (prelude_string_t **) ret);
16382
16383 case 1:
16384 return idmef_alertident_new_analyzerid(ptr, (prelude_string_t **) ret);
16385
16386 default:
16387 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
16388 }
16389 }
16390
_idmef_alertident_destroy_child(void * p,idmef_class_child_id_t child,int n)16391 int _idmef_alertident_destroy_child(void *p, idmef_class_child_id_t child, int n)
16392 {
16393 idmef_alertident_t *ptr = p;
16394
16395 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
16396
16397 switch ( child ) {
16398
16399 case 0:
16400 if ( ptr->alertident ) {
16401 prelude_string_destroy(ptr->alertident);
16402 ptr->alertident = NULL;
16403 }
16404
16405 return 0;
16406
16407 case 1:
16408 if ( ptr->analyzerid ) {
16409 prelude_string_destroy(ptr->analyzerid);
16410 ptr->analyzerid = NULL;
16411 }
16412
16413 return 0;
16414
16415 default:
16416 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
16417 }
16418 }
16419
idmef_alertident_destroy_internal(idmef_alertident_t * ptr)16420 static void idmef_alertident_destroy_internal(idmef_alertident_t *ptr)
16421 {
16422 prelude_return_if_fail(ptr);
16423
16424 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *)ptr)->_list) )
16425 prelude_list_del_init(&((prelude_linked_object_t *)ptr)->_list);
16426
16427 if ( ptr->alertident ) {
16428 prelude_string_destroy(ptr->alertident);
16429 ptr->alertident = NULL;
16430 }
16431
16432 if ( ptr->analyzerid ) {
16433 prelude_string_destroy(ptr->analyzerid);
16434 ptr->analyzerid = NULL;
16435 }
16436
16437
16438 /* free() should be done by the caller */
16439 }
16440
16441 /**
16442 * idmef_alertident_destroy:
16443 * @ptr: pointer to a #idmef_alertident_t object.
16444 *
16445 * Destroy @ptr and all of it's children.
16446 * The objects are only destroyed if their reference count reach zero.
16447 */
16448
idmef_alertident_destroy(idmef_alertident_t * ptr)16449 void idmef_alertident_destroy(idmef_alertident_t *ptr)
16450 {
16451 prelude_return_if_fail(ptr);
16452
16453 if ( --ptr->refcount )
16454 return;
16455
16456 idmef_alertident_destroy_internal(ptr);
16457 free(ptr);
16458 }
16459
16460 /**
16461 * idmef_alertident_get_alertident:
16462 * @ptr: pointer to a #idmef_alertident_t object.
16463 *
16464 * Get alertident children of the #idmef_alertident_t object.
16465 *
16466 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
16467 */
idmef_alertident_get_alertident(idmef_alertident_t * ptr)16468 prelude_string_t *idmef_alertident_get_alertident(idmef_alertident_t *ptr)
16469 {
16470 prelude_return_val_if_fail(ptr, 0); /* FIXME */
16471
16472 return ptr->alertident;
16473 }
16474
16475 /**
16476 * idmef_alertident_set_alertident:
16477 * @ptr: pointer to a #idmef_alertident_t object.
16478 * @alertident: pointer to a #prelude_string_t object.
16479 *
16480 * Set @alertident object as a children of @ptr.
16481 * if @ptr already contain an @alertident object, then it is destroyed,
16482 * and updated to point to the provided @alertident object.
16483 */
16484
idmef_alertident_set_alertident(idmef_alertident_t * ptr,prelude_string_t * alertident)16485 void idmef_alertident_set_alertident(idmef_alertident_t *ptr, prelude_string_t *alertident)
16486 {
16487 prelude_return_if_fail(ptr);
16488
16489 if ( ptr->alertident )
16490 prelude_string_destroy(ptr->alertident);
16491
16492 ptr->alertident = alertident;
16493 }
16494
16495 /**
16496 * idmef_alertident_new_alertident:
16497 * @ptr: pointer to a #idmef_alertident_t object.
16498 * @ret: pointer to an address where to store the created #prelude_string_t object.
16499 *
16500 * Create a new alertident object, children of #idmef_alertident_t.
16501 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
16502 *
16503 * Returns: 0 on success, or a negative value if an error occured.
16504 */
idmef_alertident_new_alertident(idmef_alertident_t * ptr,prelude_string_t ** ret)16505 int idmef_alertident_new_alertident(idmef_alertident_t *ptr, prelude_string_t **ret)
16506 {
16507 int retval;
16508
16509 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
16510
16511 if ( ! ptr->alertident ) {
16512 retval = prelude_string_new(&ptr->alertident);
16513 if ( retval < 0 )
16514 return retval;
16515 }
16516
16517 *ret = ptr->alertident;
16518 return 0;
16519 }
16520
16521 /**
16522 * idmef_alertident_get_analyzerid:
16523 * @ptr: pointer to a #idmef_alertident_t object.
16524 *
16525 * Get analyzerid children of the #idmef_alertident_t object.
16526 *
16527 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
16528 */
idmef_alertident_get_analyzerid(idmef_alertident_t * ptr)16529 prelude_string_t *idmef_alertident_get_analyzerid(idmef_alertident_t *ptr)
16530 {
16531 prelude_return_val_if_fail(ptr, 0); /* FIXME */
16532
16533 return ptr->analyzerid;
16534 }
16535
16536 /**
16537 * idmef_alertident_set_analyzerid:
16538 * @ptr: pointer to a #idmef_alertident_t object.
16539 * @analyzerid: pointer to a #prelude_string_t object.
16540 *
16541 * Set @analyzerid object as a children of @ptr.
16542 * if @ptr already contain an @analyzerid object, then it is destroyed,
16543 * and updated to point to the provided @analyzerid object.
16544 */
16545
idmef_alertident_set_analyzerid(idmef_alertident_t * ptr,prelude_string_t * analyzerid)16546 void idmef_alertident_set_analyzerid(idmef_alertident_t *ptr, prelude_string_t *analyzerid)
16547 {
16548 prelude_return_if_fail(ptr);
16549
16550 if ( ptr->analyzerid )
16551 prelude_string_destroy(ptr->analyzerid);
16552
16553 ptr->analyzerid = analyzerid;
16554 }
16555
16556 /**
16557 * idmef_alertident_new_analyzerid:
16558 * @ptr: pointer to a #idmef_alertident_t object.
16559 * @ret: pointer to an address where to store the created #prelude_string_t object.
16560 *
16561 * Create a new analyzerid object, children of #idmef_alertident_t.
16562 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
16563 *
16564 * Returns: 0 on success, or a negative value if an error occured.
16565 */
idmef_alertident_new_analyzerid(idmef_alertident_t * ptr,prelude_string_t ** ret)16566 int idmef_alertident_new_analyzerid(idmef_alertident_t *ptr, prelude_string_t **ret)
16567 {
16568 int retval;
16569
16570 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
16571
16572 if ( ! ptr->analyzerid ) {
16573 retval = prelude_string_new(&ptr->analyzerid);
16574 if ( retval < 0 )
16575 return retval;
16576 }
16577
16578 *ret = ptr->analyzerid;
16579 return 0;
16580 }
16581
16582 /**
16583 * idmef_alertident_copy:
16584 * @src: Source of the copy.
16585 * @dst: Where to copy the object.
16586 *
16587 * Copy a new #idmef_alertident_t object from @src to @dst.
16588 *
16589 * Returns: 0 on success, a negative value if an error occured.
16590 */
idmef_alertident_copy(const idmef_alertident_t * src,idmef_alertident_t * dst)16591 int idmef_alertident_copy(const idmef_alertident_t *src, idmef_alertident_t *dst)
16592 {
16593 int ret;
16594
16595 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
16596 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
16597
16598 ret = 0;
16599
16600 if ( src->alertident ) {
16601 ret = prelude_string_copy(src->alertident, dst->alertident);
16602 if ( ret < 0 )
16603 return ret;
16604 }
16605
16606 if ( src->analyzerid ) {
16607 ret = prelude_string_clone(src->analyzerid, &dst->analyzerid);
16608 if ( ret < 0 )
16609 return ret;
16610 }
16611
16612 return 0;
16613 }
16614
16615 /**
16616 * idmef_alertident_clone:
16617 * @src: Object to be cloned.
16618 * @dst: Address where to store the pointer to the cloned object.
16619 *
16620 * Create a copy of @src, and store it in @dst.
16621 *
16622 * Returns: 0 on success, a negative value if an error occured.
16623 */
idmef_alertident_clone(idmef_alertident_t * src,idmef_alertident_t ** dst)16624 int idmef_alertident_clone(idmef_alertident_t *src, idmef_alertident_t **dst)
16625 {
16626 int ret;
16627
16628 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
16629
16630 ret = idmef_alertident_new(dst);
16631 if ( ret < 0 )
16632 return ret;
16633
16634 return idmef_alertident_copy(src, *dst);
16635 }
16636
16637 /**
16638 * idmef_alertident_compare:
16639 * @obj1: Object to compare with @obj2.
16640 * @obj2: Object to compare with @obj1.
16641 *
16642 * Compare @obj1 with @obj2.
16643 *
16644 * Returns: 0 on match, a negative value on comparison failure.
16645 */
idmef_alertident_compare(const idmef_alertident_t * obj1,const idmef_alertident_t * obj2)16646 int idmef_alertident_compare(const idmef_alertident_t *obj1, const idmef_alertident_t *obj2)
16647 {
16648 int ret = 0;
16649
16650 if ( obj1 == NULL && obj2 == NULL )
16651 return 0;
16652
16653 else if ( obj1 == NULL || obj2 == NULL )
16654 return -1;
16655
16656 ret = prelude_string_compare(obj1->alertident, obj2->alertident);
16657 if ( ret != 0 )
16658 return ret;
16659
16660 ret = prelude_string_compare(obj1->analyzerid, obj2->analyzerid);
16661 if ( ret != 0 )
16662 return ret;
16663
16664 return ret;
16665 }
16666
16667 /**
16668 * idmef_impact_new:
16669 * @ret: Pointer where to store the created #idmef_impact_t object.
16670 *
16671 * Create a new #idmef_impact_t object.
16672 *
16673 * Returns: 0 on success, a negative value if an error occured.
16674 */
idmef_impact_new(idmef_impact_t ** ret)16675 int idmef_impact_new(idmef_impact_t **ret)
16676 {
16677 *ret = calloc(1, sizeof(**ret));
16678 if ( ! *ret )
16679 return prelude_error_from_errno(errno);
16680
16681 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_IMPACT;
16682
16683 (*ret)->refcount = 1;
16684
16685 return 0;
16686
16687 }
16688
16689 /**
16690 * idmef_impact_ref:
16691 * @impact: pointer to a #idmef_impact_t object.
16692 *
16693 * Increase @impact reference count, so that it can be referenced
16694 * multiple time.
16695 *
16696 * Returns: a pointer to @impact.
16697 */
idmef_impact_ref(idmef_impact_t * impact)16698 idmef_impact_t *idmef_impact_ref(idmef_impact_t *impact)
16699 {
16700 prelude_return_val_if_fail(impact, NULL);
16701 impact->refcount++;
16702
16703 return impact;
16704 }
16705
_idmef_impact_get_child(void * p,idmef_class_child_id_t child,void ** childptr)16706 int _idmef_impact_get_child(void *p, idmef_class_child_id_t child, void **childptr)
16707 {
16708 idmef_impact_t *ptr = p;
16709
16710 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
16711 *childptr = NULL;
16712
16713 switch ( child ) {
16714
16715 case 0:
16716 if ( ! ptr->severity_is_set )
16717 return 0;
16718 return idmef_value_new_enum_from_numeric((idmef_value_t **) childptr,
16719 IDMEF_CLASS_ID_IMPACT_SEVERITY, ptr->severity);
16720
16721 case 1:
16722 if ( ! ptr->completion_is_set )
16723 return 0;
16724 return idmef_value_new_enum_from_numeric((idmef_value_t **) childptr,
16725 IDMEF_CLASS_ID_IMPACT_COMPLETION, ptr->completion);
16726
16727 case 2:
16728 return idmef_value_new_enum_from_numeric((idmef_value_t **) childptr,
16729 IDMEF_CLASS_ID_IMPACT_TYPE, ptr->type);
16730
16731 case 3:
16732 return get_value_from_string((idmef_value_t **) childptr, ptr->description, TRUE);
16733 default:
16734 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
16735 }
16736 }
16737
_idmef_impact_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)16738 int _idmef_impact_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
16739 {
16740 idmef_impact_t *ptr = p;
16741
16742 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
16743
16744 switch ( child ) {
16745
16746 case 0:
16747 return idmef_impact_new_severity(ptr, (idmef_impact_severity_t **) ret);
16748
16749 case 1:
16750 return idmef_impact_new_completion(ptr, (idmef_impact_completion_t **) ret);
16751
16752 case 2:
16753 return idmef_impact_new_type(ptr, (idmef_impact_type_t **) ret);
16754
16755 case 3:
16756 return idmef_impact_new_description(ptr, (prelude_string_t **) ret);
16757
16758 default:
16759 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
16760 }
16761 }
16762
_idmef_impact_destroy_child(void * p,idmef_class_child_id_t child,int n)16763 int _idmef_impact_destroy_child(void *p, idmef_class_child_id_t child, int n)
16764 {
16765 idmef_impact_t *ptr = p;
16766
16767 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
16768
16769 switch ( child ) {
16770
16771 case 0:
16772 ptr->severity_is_set = 0;
16773 return 0;
16774
16775 case 1:
16776 ptr->completion_is_set = 0;
16777 return 0;
16778
16779 case 2:
16780 ptr->type = 0;
16781 return 0;
16782
16783 case 3:
16784 if ( ptr->description ) {
16785 prelude_string_destroy(ptr->description);
16786 ptr->description = NULL;
16787 }
16788
16789 return 0;
16790
16791 default:
16792 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
16793 }
16794 }
16795
idmef_impact_destroy_internal(idmef_impact_t * ptr)16796 static void idmef_impact_destroy_internal(idmef_impact_t *ptr)
16797 {
16798 prelude_return_if_fail(ptr);
16799
16800 if ( ptr->description ) {
16801 prelude_string_destroy(ptr->description);
16802 ptr->description = NULL;
16803 }
16804
16805
16806 /* free() should be done by the caller */
16807 }
16808
16809 /**
16810 * idmef_impact_destroy:
16811 * @ptr: pointer to a #idmef_impact_t object.
16812 *
16813 * Destroy @ptr and all of it's children.
16814 * The objects are only destroyed if their reference count reach zero.
16815 */
16816
idmef_impact_destroy(idmef_impact_t * ptr)16817 void idmef_impact_destroy(idmef_impact_t *ptr)
16818 {
16819 prelude_return_if_fail(ptr);
16820
16821 if ( --ptr->refcount )
16822 return;
16823
16824 idmef_impact_destroy_internal(ptr);
16825 free(ptr);
16826 }
16827
16828 /**
16829 * idmef_impact_get_severity:
16830 * @ptr: pointer to a #idmef_impact_t object.
16831 *
16832 * Get severity children of the #idmef_impact_t object.
16833 *
16834 * Returns: a pointer to a idmef_impact_severity_t object, or NULL if the children object is not set.
16835 */
idmef_impact_get_severity(idmef_impact_t * ptr)16836 idmef_impact_severity_t *idmef_impact_get_severity(idmef_impact_t *ptr)
16837 {
16838 prelude_return_val_if_fail(ptr, 0); /* FIXME */
16839
16840 return ptr->severity_is_set ? &ptr->severity : NULL;
16841 }
16842
16843 /**
16844 * idmef_impact_set_severity:
16845 * @ptr: pointer to a #idmef_impact_t object.
16846 * @severity: pointer to a #idmef_impact_severity_t object.
16847 *
16848 * Set @severity object as a children of @ptr.
16849 * if @ptr already contain an @severity object, then it is destroyed,
16850 * and updated to point to the provided @severity object.
16851 */
16852
idmef_impact_set_severity(idmef_impact_t * ptr,idmef_impact_severity_t severity)16853 void idmef_impact_set_severity(idmef_impact_t *ptr, idmef_impact_severity_t severity)
16854 {
16855 prelude_return_if_fail(ptr);
16856 ptr->severity = severity;
16857 ptr->severity_is_set = 1;
16858 }
16859
16860
idmef_impact_unset_severity(idmef_impact_t * ptr)16861 void idmef_impact_unset_severity(idmef_impact_t *ptr)
16862 {
16863 prelude_return_if_fail(ptr);
16864 ptr->severity_is_set = 0;
16865 }
16866
16867
16868 /**
16869 * idmef_impact_new_severity:
16870 * @ptr: pointer to a #idmef_impact_t object.
16871 * @ret: pointer to an address where to store the created #idmef_impact_severity_t object.
16872 *
16873 * Create a new severity object, children of #idmef_impact_t.
16874 * If @ptr already contain a #idmef_impact_severity_t object, then it is destroyed.
16875 *
16876 * Returns: 0 on success, or a negative value if an error occured.
16877 */
idmef_impact_new_severity(idmef_impact_t * ptr,idmef_impact_severity_t ** ret)16878 int idmef_impact_new_severity(idmef_impact_t *ptr, idmef_impact_severity_t **ret)
16879 {
16880 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
16881 ptr->severity_is_set = 1;
16882
16883 *ret = &ptr->severity;
16884 return 0;
16885 }
16886
16887 /**
16888 * idmef_impact_get_completion:
16889 * @ptr: pointer to a #idmef_impact_t object.
16890 *
16891 * Get completion children of the #idmef_impact_t object.
16892 *
16893 * Returns: a pointer to a idmef_impact_completion_t object, or NULL if the children object is not set.
16894 */
idmef_impact_get_completion(idmef_impact_t * ptr)16895 idmef_impact_completion_t *idmef_impact_get_completion(idmef_impact_t *ptr)
16896 {
16897 prelude_return_val_if_fail(ptr, 0); /* FIXME */
16898
16899 return ptr->completion_is_set ? &ptr->completion : NULL;
16900 }
16901
16902 /**
16903 * idmef_impact_set_completion:
16904 * @ptr: pointer to a #idmef_impact_t object.
16905 * @completion: pointer to a #idmef_impact_completion_t object.
16906 *
16907 * Set @completion object as a children of @ptr.
16908 * if @ptr already contain an @completion object, then it is destroyed,
16909 * and updated to point to the provided @completion object.
16910 */
16911
idmef_impact_set_completion(idmef_impact_t * ptr,idmef_impact_completion_t completion)16912 void idmef_impact_set_completion(idmef_impact_t *ptr, idmef_impact_completion_t completion)
16913 {
16914 prelude_return_if_fail(ptr);
16915 ptr->completion = completion;
16916 ptr->completion_is_set = 1;
16917 }
16918
16919
idmef_impact_unset_completion(idmef_impact_t * ptr)16920 void idmef_impact_unset_completion(idmef_impact_t *ptr)
16921 {
16922 prelude_return_if_fail(ptr);
16923 ptr->completion_is_set = 0;
16924 }
16925
16926
16927 /**
16928 * idmef_impact_new_completion:
16929 * @ptr: pointer to a #idmef_impact_t object.
16930 * @ret: pointer to an address where to store the created #idmef_impact_completion_t object.
16931 *
16932 * Create a new completion object, children of #idmef_impact_t.
16933 * If @ptr already contain a #idmef_impact_completion_t object, then it is destroyed.
16934 *
16935 * Returns: 0 on success, or a negative value if an error occured.
16936 */
idmef_impact_new_completion(idmef_impact_t * ptr,idmef_impact_completion_t ** ret)16937 int idmef_impact_new_completion(idmef_impact_t *ptr, idmef_impact_completion_t **ret)
16938 {
16939 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
16940 ptr->completion_is_set = 1;
16941
16942 *ret = &ptr->completion;
16943 return 0;
16944 }
16945
16946 /**
16947 * idmef_impact_get_type:
16948 * @ptr: pointer to a #idmef_impact_t object.
16949 *
16950 * Get type children of the #idmef_impact_t object.
16951 *
16952 * Returns: a pointer to a idmef_impact_type_t object, or NULL if the children object is not set.
16953 */
idmef_impact_get_type(idmef_impact_t * ptr)16954 idmef_impact_type_t idmef_impact_get_type(idmef_impact_t *ptr)
16955 {
16956 prelude_return_val_if_fail(ptr, 0); /* FIXME */
16957
16958 return ptr->type;
16959 }
16960
16961 /**
16962 * idmef_impact_set_type:
16963 * @ptr: pointer to a #idmef_impact_t object.
16964 * @type: pointer to a #idmef_impact_type_t object.
16965 *
16966 * Set @type object as a children of @ptr.
16967 * if @ptr already contain an @type object, then it is destroyed,
16968 * and updated to point to the provided @type object.
16969 */
16970
idmef_impact_set_type(idmef_impact_t * ptr,idmef_impact_type_t type)16971 void idmef_impact_set_type(idmef_impact_t *ptr, idmef_impact_type_t type)
16972 {
16973 prelude_return_if_fail(ptr);
16974 ptr->type = type;
16975 }
16976
16977 /**
16978 * idmef_impact_new_type:
16979 * @ptr: pointer to a #idmef_impact_t object.
16980 * @ret: pointer to an address where to store the created #idmef_impact_type_t object.
16981 *
16982 * Create a new type object, children of #idmef_impact_t.
16983 * If @ptr already contain a #idmef_impact_type_t object, then it is destroyed.
16984 *
16985 * Returns: 0 on success, or a negative value if an error occured.
16986 */
idmef_impact_new_type(idmef_impact_t * ptr,idmef_impact_type_t ** ret)16987 int idmef_impact_new_type(idmef_impact_t *ptr, idmef_impact_type_t **ret)
16988 {
16989 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
16990
16991 *ret = &ptr->type;
16992 return 0;
16993 }
16994
16995 /**
16996 * idmef_impact_get_description:
16997 * @ptr: pointer to a #idmef_impact_t object.
16998 *
16999 * Get description children of the #idmef_impact_t object.
17000 *
17001 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
17002 */
idmef_impact_get_description(idmef_impact_t * ptr)17003 prelude_string_t *idmef_impact_get_description(idmef_impact_t *ptr)
17004 {
17005 prelude_return_val_if_fail(ptr, 0); /* FIXME */
17006
17007 return ptr->description;
17008 }
17009
17010 /**
17011 * idmef_impact_set_description:
17012 * @ptr: pointer to a #idmef_impact_t object.
17013 * @description: pointer to a #prelude_string_t object.
17014 *
17015 * Set @description object as a children of @ptr.
17016 * if @ptr already contain an @description object, then it is destroyed,
17017 * and updated to point to the provided @description object.
17018 */
17019
idmef_impact_set_description(idmef_impact_t * ptr,prelude_string_t * description)17020 void idmef_impact_set_description(idmef_impact_t *ptr, prelude_string_t *description)
17021 {
17022 prelude_return_if_fail(ptr);
17023
17024 if ( ptr->description )
17025 prelude_string_destroy(ptr->description);
17026
17027 ptr->description = description;
17028 }
17029
17030 /**
17031 * idmef_impact_new_description:
17032 * @ptr: pointer to a #idmef_impact_t object.
17033 * @ret: pointer to an address where to store the created #prelude_string_t object.
17034 *
17035 * Create a new description object, children of #idmef_impact_t.
17036 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
17037 *
17038 * Returns: 0 on success, or a negative value if an error occured.
17039 */
idmef_impact_new_description(idmef_impact_t * ptr,prelude_string_t ** ret)17040 int idmef_impact_new_description(idmef_impact_t *ptr, prelude_string_t **ret)
17041 {
17042 int retval;
17043
17044 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
17045
17046 if ( ! ptr->description ) {
17047 retval = prelude_string_new(&ptr->description);
17048 if ( retval < 0 )
17049 return retval;
17050 }
17051
17052 *ret = ptr->description;
17053 return 0;
17054 }
17055
17056 /**
17057 * idmef_impact_copy:
17058 * @src: Source of the copy.
17059 * @dst: Where to copy the object.
17060 *
17061 * Copy a new #idmef_impact_t object from @src to @dst.
17062 *
17063 * Returns: 0 on success, a negative value if an error occured.
17064 */
idmef_impact_copy(const idmef_impact_t * src,idmef_impact_t * dst)17065 int idmef_impact_copy(const idmef_impact_t *src, idmef_impact_t *dst)
17066 {
17067 int ret;
17068
17069 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
17070 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
17071
17072 ret = 0;
17073
17074 dst->severity_is_set = src->severity_is_set;
17075
17076 dst->severity = src->severity;
17077
17078 dst->completion_is_set = src->completion_is_set;
17079
17080 dst->completion = src->completion;
17081
17082 dst->type = src->type;
17083
17084 if ( src->description ) {
17085 ret = prelude_string_clone(src->description, &dst->description);
17086 if ( ret < 0 )
17087 return ret;
17088 }
17089
17090 return 0;
17091 }
17092
17093 /**
17094 * idmef_impact_clone:
17095 * @src: Object to be cloned.
17096 * @dst: Address where to store the pointer to the cloned object.
17097 *
17098 * Create a copy of @src, and store it in @dst.
17099 *
17100 * Returns: 0 on success, a negative value if an error occured.
17101 */
idmef_impact_clone(idmef_impact_t * src,idmef_impact_t ** dst)17102 int idmef_impact_clone(idmef_impact_t *src, idmef_impact_t **dst)
17103 {
17104 int ret;
17105
17106 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
17107
17108 ret = idmef_impact_new(dst);
17109 if ( ret < 0 )
17110 return ret;
17111
17112 return idmef_impact_copy(src, *dst);
17113 }
17114
17115 /**
17116 * idmef_impact_compare:
17117 * @obj1: Object to compare with @obj2.
17118 * @obj2: Object to compare with @obj1.
17119 *
17120 * Compare @obj1 with @obj2.
17121 *
17122 * Returns: 0 on match, a negative value on comparison failure.
17123 */
idmef_impact_compare(const idmef_impact_t * obj1,const idmef_impact_t * obj2)17124 int idmef_impact_compare(const idmef_impact_t *obj1, const idmef_impact_t *obj2)
17125 {
17126 int ret = 0;
17127
17128 if ( obj1 == NULL && obj2 == NULL )
17129 return 0;
17130
17131 else if ( obj1 == NULL || obj2 == NULL )
17132 return -1;
17133
17134 if ( obj1->severity_is_set != obj2->severity_is_set )
17135 return -1;
17136
17137 if ( obj1->severity_is_set && obj1->severity != obj2->severity )
17138 return -1;
17139
17140 if ( obj1->completion_is_set != obj2->completion_is_set )
17141 return -1;
17142
17143 if ( obj1->completion_is_set && obj1->completion != obj2->completion )
17144 return -1;
17145
17146 if ( obj1->type != obj2->type )
17147 return -1;
17148
17149 ret = prelude_string_compare(obj1->description, obj2->description);
17150 if ( ret != 0 )
17151 return ret;
17152
17153 return ret;
17154 }
17155
17156 /**
17157 * idmef_action_new:
17158 * @ret: Pointer where to store the created #idmef_action_t object.
17159 *
17160 * Create a new #idmef_action_t object.
17161 *
17162 * Returns: 0 on success, a negative value if an error occured.
17163 */
idmef_action_new(idmef_action_t ** ret)17164 int idmef_action_new(idmef_action_t **ret)
17165 {
17166 *ret = calloc(1, sizeof(**ret));
17167 if ( ! *ret )
17168 return prelude_error_from_errno(errno);
17169
17170 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_ACTION;
17171
17172 prelude_list_init(&((prelude_linked_object_t *) (*ret))->_list);
17173
17174 (*ret)->refcount = 1;
17175
17176 return 0;
17177
17178 }
17179
17180 /**
17181 * idmef_action_ref:
17182 * @action: pointer to a #idmef_action_t object.
17183 *
17184 * Increase @action reference count, so that it can be referenced
17185 * multiple time.
17186 *
17187 * Returns: a pointer to @action.
17188 */
idmef_action_ref(idmef_action_t * action)17189 idmef_action_t *idmef_action_ref(idmef_action_t *action)
17190 {
17191 prelude_return_val_if_fail(action, NULL);
17192 action->refcount++;
17193
17194 return action;
17195 }
17196
_idmef_action_get_child(void * p,idmef_class_child_id_t child,void ** childptr)17197 int _idmef_action_get_child(void *p, idmef_class_child_id_t child, void **childptr)
17198 {
17199 idmef_action_t *ptr = p;
17200
17201 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
17202 *childptr = NULL;
17203
17204 switch ( child ) {
17205
17206 case 0:
17207 return idmef_value_new_enum_from_numeric((idmef_value_t **) childptr,
17208 IDMEF_CLASS_ID_ACTION_CATEGORY, ptr->category);
17209
17210 case 1:
17211 return get_value_from_string((idmef_value_t **) childptr, ptr->description, TRUE);
17212 default:
17213 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
17214 }
17215 }
17216
_idmef_action_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)17217 int _idmef_action_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
17218 {
17219 idmef_action_t *ptr = p;
17220
17221 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
17222
17223 switch ( child ) {
17224
17225 case 0:
17226 return idmef_action_new_category(ptr, (idmef_action_category_t **) ret);
17227
17228 case 1:
17229 return idmef_action_new_description(ptr, (prelude_string_t **) ret);
17230
17231 default:
17232 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
17233 }
17234 }
17235
_idmef_action_destroy_child(void * p,idmef_class_child_id_t child,int n)17236 int _idmef_action_destroy_child(void *p, idmef_class_child_id_t child, int n)
17237 {
17238 idmef_action_t *ptr = p;
17239
17240 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
17241
17242 switch ( child ) {
17243
17244 case 0:
17245 ptr->category = 0;
17246 return 0;
17247
17248 case 1:
17249 if ( ptr->description ) {
17250 prelude_string_destroy(ptr->description);
17251 ptr->description = NULL;
17252 }
17253
17254 return 0;
17255
17256 default:
17257 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
17258 }
17259 }
17260
idmef_action_destroy_internal(idmef_action_t * ptr)17261 static void idmef_action_destroy_internal(idmef_action_t *ptr)
17262 {
17263 prelude_return_if_fail(ptr);
17264
17265 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *)ptr)->_list) )
17266 prelude_list_del_init(&((prelude_linked_object_t *)ptr)->_list);
17267
17268 if ( ptr->description ) {
17269 prelude_string_destroy(ptr->description);
17270 ptr->description = NULL;
17271 }
17272
17273
17274 /* free() should be done by the caller */
17275 }
17276
17277 /**
17278 * idmef_action_destroy:
17279 * @ptr: pointer to a #idmef_action_t object.
17280 *
17281 * Destroy @ptr and all of it's children.
17282 * The objects are only destroyed if their reference count reach zero.
17283 */
17284
idmef_action_destroy(idmef_action_t * ptr)17285 void idmef_action_destroy(idmef_action_t *ptr)
17286 {
17287 prelude_return_if_fail(ptr);
17288
17289 if ( --ptr->refcount )
17290 return;
17291
17292 idmef_action_destroy_internal(ptr);
17293 free(ptr);
17294 }
17295
17296 /**
17297 * idmef_action_get_category:
17298 * @ptr: pointer to a #idmef_action_t object.
17299 *
17300 * Get category children of the #idmef_action_t object.
17301 *
17302 * Returns: a pointer to a idmef_action_category_t object, or NULL if the children object is not set.
17303 */
idmef_action_get_category(idmef_action_t * ptr)17304 idmef_action_category_t idmef_action_get_category(idmef_action_t *ptr)
17305 {
17306 prelude_return_val_if_fail(ptr, 0); /* FIXME */
17307
17308 return ptr->category;
17309 }
17310
17311 /**
17312 * idmef_action_set_category:
17313 * @ptr: pointer to a #idmef_action_t object.
17314 * @category: pointer to a #idmef_action_category_t object.
17315 *
17316 * Set @category object as a children of @ptr.
17317 * if @ptr already contain an @category object, then it is destroyed,
17318 * and updated to point to the provided @category object.
17319 */
17320
idmef_action_set_category(idmef_action_t * ptr,idmef_action_category_t category)17321 void idmef_action_set_category(idmef_action_t *ptr, idmef_action_category_t category)
17322 {
17323 prelude_return_if_fail(ptr);
17324 ptr->category = category;
17325 }
17326
17327 /**
17328 * idmef_action_new_category:
17329 * @ptr: pointer to a #idmef_action_t object.
17330 * @ret: pointer to an address where to store the created #idmef_action_category_t object.
17331 *
17332 * Create a new category object, children of #idmef_action_t.
17333 * If @ptr already contain a #idmef_action_category_t object, then it is destroyed.
17334 *
17335 * Returns: 0 on success, or a negative value if an error occured.
17336 */
idmef_action_new_category(idmef_action_t * ptr,idmef_action_category_t ** ret)17337 int idmef_action_new_category(idmef_action_t *ptr, idmef_action_category_t **ret)
17338 {
17339 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
17340
17341 *ret = &ptr->category;
17342 return 0;
17343 }
17344
17345 /**
17346 * idmef_action_get_description:
17347 * @ptr: pointer to a #idmef_action_t object.
17348 *
17349 * Get description children of the #idmef_action_t object.
17350 *
17351 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
17352 */
idmef_action_get_description(idmef_action_t * ptr)17353 prelude_string_t *idmef_action_get_description(idmef_action_t *ptr)
17354 {
17355 prelude_return_val_if_fail(ptr, 0); /* FIXME */
17356
17357 return ptr->description;
17358 }
17359
17360 /**
17361 * idmef_action_set_description:
17362 * @ptr: pointer to a #idmef_action_t object.
17363 * @description: pointer to a #prelude_string_t object.
17364 *
17365 * Set @description object as a children of @ptr.
17366 * if @ptr already contain an @description object, then it is destroyed,
17367 * and updated to point to the provided @description object.
17368 */
17369
idmef_action_set_description(idmef_action_t * ptr,prelude_string_t * description)17370 void idmef_action_set_description(idmef_action_t *ptr, prelude_string_t *description)
17371 {
17372 prelude_return_if_fail(ptr);
17373
17374 if ( ptr->description )
17375 prelude_string_destroy(ptr->description);
17376
17377 ptr->description = description;
17378 }
17379
17380 /**
17381 * idmef_action_new_description:
17382 * @ptr: pointer to a #idmef_action_t object.
17383 * @ret: pointer to an address where to store the created #prelude_string_t object.
17384 *
17385 * Create a new description object, children of #idmef_action_t.
17386 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
17387 *
17388 * Returns: 0 on success, or a negative value if an error occured.
17389 */
idmef_action_new_description(idmef_action_t * ptr,prelude_string_t ** ret)17390 int idmef_action_new_description(idmef_action_t *ptr, prelude_string_t **ret)
17391 {
17392 int retval;
17393
17394 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
17395
17396 if ( ! ptr->description ) {
17397 retval = prelude_string_new(&ptr->description);
17398 if ( retval < 0 )
17399 return retval;
17400 }
17401
17402 *ret = ptr->description;
17403 return 0;
17404 }
17405
17406 /**
17407 * idmef_action_copy:
17408 * @src: Source of the copy.
17409 * @dst: Where to copy the object.
17410 *
17411 * Copy a new #idmef_action_t object from @src to @dst.
17412 *
17413 * Returns: 0 on success, a negative value if an error occured.
17414 */
idmef_action_copy(const idmef_action_t * src,idmef_action_t * dst)17415 int idmef_action_copy(const idmef_action_t *src, idmef_action_t *dst)
17416 {
17417 int ret;
17418
17419 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
17420 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
17421
17422 ret = 0;
17423
17424 dst->category = src->category;
17425
17426 if ( src->description ) {
17427 ret = prelude_string_clone(src->description, &dst->description);
17428 if ( ret < 0 )
17429 return ret;
17430 }
17431
17432 return 0;
17433 }
17434
17435 /**
17436 * idmef_action_clone:
17437 * @src: Object to be cloned.
17438 * @dst: Address where to store the pointer to the cloned object.
17439 *
17440 * Create a copy of @src, and store it in @dst.
17441 *
17442 * Returns: 0 on success, a negative value if an error occured.
17443 */
idmef_action_clone(idmef_action_t * src,idmef_action_t ** dst)17444 int idmef_action_clone(idmef_action_t *src, idmef_action_t **dst)
17445 {
17446 int ret;
17447
17448 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
17449
17450 ret = idmef_action_new(dst);
17451 if ( ret < 0 )
17452 return ret;
17453
17454 return idmef_action_copy(src, *dst);
17455 }
17456
17457 /**
17458 * idmef_action_compare:
17459 * @obj1: Object to compare with @obj2.
17460 * @obj2: Object to compare with @obj1.
17461 *
17462 * Compare @obj1 with @obj2.
17463 *
17464 * Returns: 0 on match, a negative value on comparison failure.
17465 */
idmef_action_compare(const idmef_action_t * obj1,const idmef_action_t * obj2)17466 int idmef_action_compare(const idmef_action_t *obj1, const idmef_action_t *obj2)
17467 {
17468 int ret = 0;
17469
17470 if ( obj1 == NULL && obj2 == NULL )
17471 return 0;
17472
17473 else if ( obj1 == NULL || obj2 == NULL )
17474 return -1;
17475
17476 if ( obj1->category != obj2->category )
17477 return -1;
17478
17479 ret = prelude_string_compare(obj1->description, obj2->description);
17480 if ( ret != 0 )
17481 return ret;
17482
17483 return ret;
17484 }
17485
17486 /**
17487 * idmef_confidence_new:
17488 * @ret: Pointer where to store the created #idmef_confidence_t object.
17489 *
17490 * Create a new #idmef_confidence_t object.
17491 *
17492 * Returns: 0 on success, a negative value if an error occured.
17493 */
idmef_confidence_new(idmef_confidence_t ** ret)17494 int idmef_confidence_new(idmef_confidence_t **ret)
17495 {
17496 *ret = calloc(1, sizeof(**ret));
17497 if ( ! *ret )
17498 return prelude_error_from_errno(errno);
17499
17500 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_CONFIDENCE;
17501
17502 (*ret)->refcount = 1;
17503
17504 return 0;
17505
17506 }
17507
17508 /**
17509 * idmef_confidence_ref:
17510 * @confidence: pointer to a #idmef_confidence_t object.
17511 *
17512 * Increase @confidence reference count, so that it can be referenced
17513 * multiple time.
17514 *
17515 * Returns: a pointer to @confidence.
17516 */
idmef_confidence_ref(idmef_confidence_t * confidence)17517 idmef_confidence_t *idmef_confidence_ref(idmef_confidence_t *confidence)
17518 {
17519 prelude_return_val_if_fail(confidence, NULL);
17520 confidence->refcount++;
17521
17522 return confidence;
17523 }
17524
_idmef_confidence_get_child(void * p,idmef_class_child_id_t child,void ** childptr)17525 int _idmef_confidence_get_child(void *p, idmef_class_child_id_t child, void **childptr)
17526 {
17527 idmef_confidence_t *ptr = p;
17528
17529 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
17530 *childptr = NULL;
17531
17532 switch ( child ) {
17533
17534 case 0:
17535 return idmef_value_new_enum_from_numeric((idmef_value_t **) childptr,
17536 IDMEF_CLASS_ID_CONFIDENCE_RATING, ptr->rating);
17537
17538 case 1:
17539 return idmef_value_new_float((idmef_value_t **) childptr, ptr->confidence);
17540 default:
17541 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
17542 }
17543 }
17544
_idmef_confidence_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)17545 int _idmef_confidence_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
17546 {
17547 idmef_confidence_t *ptr = p;
17548
17549 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
17550
17551 switch ( child ) {
17552
17553 case 0:
17554 return idmef_confidence_new_rating(ptr, (idmef_confidence_rating_t **) ret);
17555
17556 case 1:
17557 return idmef_confidence_new_confidence(ptr, (float **) ret);
17558
17559 default:
17560 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
17561 }
17562 }
17563
_idmef_confidence_destroy_child(void * p,idmef_class_child_id_t child,int n)17564 int _idmef_confidence_destroy_child(void *p, idmef_class_child_id_t child, int n)
17565 {
17566 idmef_confidence_t *ptr = p;
17567
17568 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
17569
17570 switch ( child ) {
17571
17572 case 0:
17573 ptr->rating = 0;
17574 return 0;
17575
17576 default:
17577 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
17578 }
17579 }
17580
idmef_confidence_destroy_internal(idmef_confidence_t * ptr)17581 static void idmef_confidence_destroy_internal(idmef_confidence_t *ptr)
17582 {
17583 prelude_return_if_fail(ptr);
17584
17585
17586 /* free() should be done by the caller */
17587 }
17588
17589 /**
17590 * idmef_confidence_destroy:
17591 * @ptr: pointer to a #idmef_confidence_t object.
17592 *
17593 * Destroy @ptr and all of it's children.
17594 * The objects are only destroyed if their reference count reach zero.
17595 */
17596
idmef_confidence_destroy(idmef_confidence_t * ptr)17597 void idmef_confidence_destroy(idmef_confidence_t *ptr)
17598 {
17599 prelude_return_if_fail(ptr);
17600
17601 if ( --ptr->refcount )
17602 return;
17603
17604 idmef_confidence_destroy_internal(ptr);
17605 free(ptr);
17606 }
17607
17608 /**
17609 * idmef_confidence_get_rating:
17610 * @ptr: pointer to a #idmef_confidence_t object.
17611 *
17612 * Get rating children of the #idmef_confidence_t object.
17613 *
17614 * Returns: a pointer to a idmef_confidence_rating_t object, or NULL if the children object is not set.
17615 */
idmef_confidence_get_rating(idmef_confidence_t * ptr)17616 idmef_confidence_rating_t idmef_confidence_get_rating(idmef_confidence_t *ptr)
17617 {
17618 prelude_return_val_if_fail(ptr, 0); /* FIXME */
17619
17620 return ptr->rating;
17621 }
17622
17623 /**
17624 * idmef_confidence_set_rating:
17625 * @ptr: pointer to a #idmef_confidence_t object.
17626 * @rating: pointer to a #idmef_confidence_rating_t object.
17627 *
17628 * Set @rating object as a children of @ptr.
17629 * if @ptr already contain an @rating object, then it is destroyed,
17630 * and updated to point to the provided @rating object.
17631 */
17632
idmef_confidence_set_rating(idmef_confidence_t * ptr,idmef_confidence_rating_t rating)17633 void idmef_confidence_set_rating(idmef_confidence_t *ptr, idmef_confidence_rating_t rating)
17634 {
17635 prelude_return_if_fail(ptr);
17636 ptr->rating = rating;
17637 }
17638
17639 /**
17640 * idmef_confidence_new_rating:
17641 * @ptr: pointer to a #idmef_confidence_t object.
17642 * @ret: pointer to an address where to store the created #idmef_confidence_rating_t object.
17643 *
17644 * Create a new rating object, children of #idmef_confidence_t.
17645 * If @ptr already contain a #idmef_confidence_rating_t object, then it is destroyed.
17646 *
17647 * Returns: 0 on success, or a negative value if an error occured.
17648 */
idmef_confidence_new_rating(idmef_confidence_t * ptr,idmef_confidence_rating_t ** ret)17649 int idmef_confidence_new_rating(idmef_confidence_t *ptr, idmef_confidence_rating_t **ret)
17650 {
17651 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
17652
17653 *ret = &ptr->rating;
17654 return 0;
17655 }
17656
17657 /**
17658 * idmef_confidence_get_confidence:
17659 * @ptr: pointer to a #idmef_confidence_t object.
17660 *
17661 * Get confidence children of the #idmef_confidence_t object.
17662 *
17663 * Returns: a pointer to a float object, or NULL if the children object is not set.
17664 */
idmef_confidence_get_confidence(idmef_confidence_t * ptr)17665 float idmef_confidence_get_confidence(idmef_confidence_t *ptr)
17666 {
17667 prelude_return_val_if_fail(ptr, 0); /* FIXME */
17668
17669 return ptr->confidence;
17670 }
17671
17672 /**
17673 * idmef_confidence_set_confidence:
17674 * @ptr: pointer to a #idmef_confidence_t object.
17675 * @confidence: pointer to a #float object.
17676 *
17677 * Set @confidence object as a children of @ptr.
17678 * if @ptr already contain an @confidence object, then it is destroyed,
17679 * and updated to point to the provided @confidence object.
17680 */
17681
idmef_confidence_set_confidence(idmef_confidence_t * ptr,float confidence)17682 void idmef_confidence_set_confidence(idmef_confidence_t *ptr, float confidence)
17683 {
17684 prelude_return_if_fail(ptr);
17685 ptr->confidence = confidence;
17686 }
17687
17688 /**
17689 * idmef_confidence_new_confidence:
17690 * @ptr: pointer to a #idmef_confidence_t object.
17691 * @ret: pointer to an address where to store the created #float object.
17692 *
17693 * Create a new confidence object, children of #idmef_confidence_t.
17694 * If @ptr already contain a #float object, then it is destroyed.
17695 *
17696 * Returns: 0 on success, or a negative value if an error occured.
17697 */
idmef_confidence_new_confidence(idmef_confidence_t * ptr,float ** ret)17698 int idmef_confidence_new_confidence(idmef_confidence_t *ptr, float **ret)
17699 {
17700 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
17701
17702 *ret = &ptr->confidence;
17703 return 0;
17704 }
17705
17706 /**
17707 * idmef_confidence_copy:
17708 * @src: Source of the copy.
17709 * @dst: Where to copy the object.
17710 *
17711 * Copy a new #idmef_confidence_t object from @src to @dst.
17712 *
17713 * Returns: 0 on success, a negative value if an error occured.
17714 */
idmef_confidence_copy(const idmef_confidence_t * src,idmef_confidence_t * dst)17715 int idmef_confidence_copy(const idmef_confidence_t *src, idmef_confidence_t *dst)
17716 {
17717 int ret;
17718
17719 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
17720 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
17721
17722 ret = 0;
17723
17724 dst->rating = src->rating;
17725
17726 dst->confidence = src->confidence;
17727
17728 return 0;
17729 }
17730
17731 /**
17732 * idmef_confidence_clone:
17733 * @src: Object to be cloned.
17734 * @dst: Address where to store the pointer to the cloned object.
17735 *
17736 * Create a copy of @src, and store it in @dst.
17737 *
17738 * Returns: 0 on success, a negative value if an error occured.
17739 */
idmef_confidence_clone(idmef_confidence_t * src,idmef_confidence_t ** dst)17740 int idmef_confidence_clone(idmef_confidence_t *src, idmef_confidence_t **dst)
17741 {
17742 int ret;
17743
17744 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
17745
17746 ret = idmef_confidence_new(dst);
17747 if ( ret < 0 )
17748 return ret;
17749
17750 return idmef_confidence_copy(src, *dst);
17751 }
17752
17753 /**
17754 * idmef_confidence_compare:
17755 * @obj1: Object to compare with @obj2.
17756 * @obj2: Object to compare with @obj1.
17757 *
17758 * Compare @obj1 with @obj2.
17759 *
17760 * Returns: 0 on match, a negative value on comparison failure.
17761 */
idmef_confidence_compare(const idmef_confidence_t * obj1,const idmef_confidence_t * obj2)17762 int idmef_confidence_compare(const idmef_confidence_t *obj1, const idmef_confidence_t *obj2)
17763 {
17764 int ret = 0;
17765
17766 if ( obj1 == NULL && obj2 == NULL )
17767 return 0;
17768
17769 else if ( obj1 == NULL || obj2 == NULL )
17770 return -1;
17771
17772 if ( obj1->rating != obj2->rating )
17773 return -1;
17774
17775 ret = float_compare(obj1->confidence, obj2->confidence);
17776
17777 return ret;
17778 }
17779
17780 /**
17781 * idmef_assessment_new:
17782 * @ret: Pointer where to store the created #idmef_assessment_t object.
17783 *
17784 * Create a new #idmef_assessment_t object.
17785 *
17786 * Returns: 0 on success, a negative value if an error occured.
17787 */
idmef_assessment_new(idmef_assessment_t ** ret)17788 int idmef_assessment_new(idmef_assessment_t **ret)
17789 {
17790 *ret = calloc(1, sizeof(**ret));
17791 if ( ! *ret )
17792 return prelude_error_from_errno(errno);
17793
17794 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_ASSESSMENT;
17795
17796 (*ret)->refcount = 1;
17797
17798 prelude_list_init(&(*ret)->action_list);
17799
17800
17801 return 0;
17802
17803 }
17804
17805 /**
17806 * idmef_assessment_ref:
17807 * @assessment: pointer to a #idmef_assessment_t object.
17808 *
17809 * Increase @assessment reference count, so that it can be referenced
17810 * multiple time.
17811 *
17812 * Returns: a pointer to @assessment.
17813 */
idmef_assessment_ref(idmef_assessment_t * assessment)17814 idmef_assessment_t *idmef_assessment_ref(idmef_assessment_t *assessment)
17815 {
17816 prelude_return_val_if_fail(assessment, NULL);
17817 assessment->refcount++;
17818
17819 return assessment;
17820 }
17821
_idmef_assessment_get_child(void * p,idmef_class_child_id_t child,void ** childptr)17822 int _idmef_assessment_get_child(void *p, idmef_class_child_id_t child, void **childptr)
17823 {
17824 idmef_assessment_t *ptr = p;
17825
17826 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
17827 *childptr = NULL;
17828
17829 switch ( child ) {
17830
17831 case 0:
17832 *childptr = ptr->impact;
17833 return 0;
17834
17835 case 1:
17836 *childptr = &ptr->action_list;
17837 return 0;
17838
17839 case 2:
17840 *childptr = ptr->confidence;
17841 return 0;
17842
17843 default:
17844 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
17845 }
17846 }
17847
_idmef_assessment_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)17848 int _idmef_assessment_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
17849 {
17850 idmef_assessment_t *ptr = p;
17851
17852 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
17853
17854 switch ( child ) {
17855
17856 case 0:
17857 return idmef_assessment_new_impact(ptr, (idmef_impact_t **) ret);
17858
17859 case 1: {
17860 int i = 0;
17861 prelude_list_t *tmp;
17862
17863 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
17864 return idmef_assessment_new_action(ptr, (idmef_action_t **) ret, n);
17865
17866 if ( n >= 0 ) {
17867 prelude_list_for_each(&ptr->action_list, tmp) {
17868 if ( i++ == n ) {
17869 *ret = prelude_linked_object_get_object(tmp);
17870 return 0;
17871 }
17872 }
17873
17874 if ( i != n )
17875 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
17876 } else {
17877 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
17878
17879 prelude_list_for_each_reversed(&ptr->action_list, tmp) {
17880 if ( i++ == pos ) {
17881 *ret = prelude_linked_object_get_object(tmp);
17882 return 0;
17883 }
17884 }
17885
17886 if ( i != pos )
17887 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
17888 }
17889
17890 return idmef_assessment_new_action(ptr, (idmef_action_t **) ret, n);
17891 }
17892
17893 case 2:
17894 return idmef_assessment_new_confidence(ptr, (idmef_confidence_t **) ret);
17895
17896 default:
17897 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
17898 }
17899 }
17900
_idmef_assessment_destroy_child(void * p,idmef_class_child_id_t child,int n)17901 int _idmef_assessment_destroy_child(void *p, idmef_class_child_id_t child, int n)
17902 {
17903 idmef_assessment_t *ptr = p;
17904
17905 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
17906
17907 switch ( child ) {
17908
17909 case 0:
17910 if ( ptr->impact ) {
17911 idmef_impact_destroy(ptr->impact);
17912 ptr->impact = NULL;
17913 }
17914
17915 return 0;
17916
17917 case 1: {
17918 int i = 0;
17919 prelude_list_t *tmp;
17920
17921 if ( n >= 0 ) {
17922 prelude_list_for_each(&ptr->action_list, tmp) {
17923 if ( i++ == n ) {
17924 void *b = prelude_linked_object_get_object(tmp);
17925 idmef_action_destroy(b);
17926 return 0;
17927 }
17928 }
17929
17930 if ( i != n )
17931 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
17932 } else {
17933 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
17934
17935 prelude_list_for_each_reversed(&ptr->action_list, tmp) {
17936 if ( i++ == pos ) {
17937 void *b = prelude_linked_object_get_object(tmp);
17938 idmef_action_destroy(b);
17939 return 0;
17940 }
17941 }
17942
17943 if ( i != pos )
17944 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
17945 }
17946 }
17947
17948 case 2:
17949 if ( ptr->confidence ) {
17950 idmef_confidence_destroy(ptr->confidence);
17951 ptr->confidence = NULL;
17952 }
17953
17954 return 0;
17955
17956 default:
17957 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
17958 }
17959 }
17960
idmef_assessment_destroy_internal(idmef_assessment_t * ptr)17961 static void idmef_assessment_destroy_internal(idmef_assessment_t *ptr)
17962 {
17963 prelude_return_if_fail(ptr);
17964
17965 if ( ptr->impact ) {
17966 idmef_impact_destroy(ptr->impact);
17967 ptr->impact = NULL;
17968 }
17969
17970 {
17971 prelude_list_t *n, *tmp;
17972 idmef_action_t *entry;
17973
17974 prelude_list_for_each_safe(&ptr->action_list, tmp, n) {
17975 entry = prelude_linked_object_get_object(tmp);
17976 prelude_list_del_init(tmp);
17977 idmef_action_destroy(entry);
17978 }
17979 }
17980
17981 if ( ptr->confidence ) {
17982 idmef_confidence_destroy(ptr->confidence);
17983 ptr->confidence = NULL;
17984 }
17985
17986
17987 /* free() should be done by the caller */
17988 }
17989
17990 /**
17991 * idmef_assessment_destroy:
17992 * @ptr: pointer to a #idmef_assessment_t object.
17993 *
17994 * Destroy @ptr and all of it's children.
17995 * The objects are only destroyed if their reference count reach zero.
17996 */
17997
idmef_assessment_destroy(idmef_assessment_t * ptr)17998 void idmef_assessment_destroy(idmef_assessment_t *ptr)
17999 {
18000 prelude_return_if_fail(ptr);
18001
18002 if ( --ptr->refcount )
18003 return;
18004
18005 idmef_assessment_destroy_internal(ptr);
18006 free(ptr);
18007 }
18008
18009 /**
18010 * idmef_assessment_get_impact:
18011 * @ptr: pointer to a #idmef_assessment_t object.
18012 *
18013 * Get impact children of the #idmef_assessment_t object.
18014 *
18015 * Returns: a pointer to a idmef_impact_t object, or NULL if the children object is not set.
18016 */
idmef_assessment_get_impact(idmef_assessment_t * ptr)18017 idmef_impact_t *idmef_assessment_get_impact(idmef_assessment_t *ptr)
18018 {
18019 prelude_return_val_if_fail(ptr, 0); /* FIXME */
18020
18021 return ptr->impact;
18022 }
18023
18024 /**
18025 * idmef_assessment_set_impact:
18026 * @ptr: pointer to a #idmef_assessment_t object.
18027 * @impact: pointer to a #idmef_impact_t object.
18028 *
18029 * Set @impact object as a children of @ptr.
18030 * if @ptr already contain an @impact object, then it is destroyed,
18031 * and updated to point to the provided @impact object.
18032 */
18033
idmef_assessment_set_impact(idmef_assessment_t * ptr,idmef_impact_t * impact)18034 void idmef_assessment_set_impact(idmef_assessment_t *ptr, idmef_impact_t *impact)
18035 {
18036 prelude_return_if_fail(ptr);
18037
18038 if ( ptr->impact )
18039 idmef_impact_destroy(ptr->impact);
18040
18041 ptr->impact = impact;
18042 }
18043
18044 /**
18045 * idmef_assessment_new_impact:
18046 * @ptr: pointer to a #idmef_assessment_t object.
18047 * @ret: pointer to an address where to store the created #idmef_impact_t object.
18048 *
18049 * Create a new impact object, children of #idmef_assessment_t.
18050 * If @ptr already contain a #idmef_impact_t object, then it is destroyed.
18051 *
18052 * Returns: 0 on success, or a negative value if an error occured.
18053 */
idmef_assessment_new_impact(idmef_assessment_t * ptr,idmef_impact_t ** ret)18054 int idmef_assessment_new_impact(idmef_assessment_t *ptr, idmef_impact_t **ret)
18055 {
18056 int retval;
18057
18058 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
18059
18060 if ( ! ptr->impact ) {
18061 retval = idmef_impact_new(&ptr->impact);
18062 if ( retval < 0 )
18063 return retval;
18064 }
18065
18066 *ret = ptr->impact;
18067 return 0;
18068 }
18069
18070 /**
18071 * idmef_assessment_get_next_action:
18072 * @assessment: pointer to a #idmef_assessment_t object.
18073 * @action_cur: pointer to a #idmef_action_t object.
18074 *
18075 * Get the next #idmef_action_t object listed in @ptr.
18076 * When iterating over the idmef_action_t object listed in @ptr,
18077 * @object should be set to the latest returned #idmef_action_t object.
18078 *
18079 * Returns: the next #idmef_action_t in the list.
18080 */
idmef_assessment_get_next_action(idmef_assessment_t * assessment,idmef_action_t * action_cur)18081 idmef_action_t *idmef_assessment_get_next_action(idmef_assessment_t *assessment, idmef_action_t *action_cur)
18082 {
18083 prelude_list_t *tmp = (action_cur) ? &((prelude_linked_object_t *) action_cur)->_list : NULL;
18084
18085 prelude_return_val_if_fail(assessment, NULL);
18086
18087 prelude_list_for_each_continue(&assessment->action_list, tmp)
18088 return prelude_linked_object_get_object(tmp);
18089
18090 return NULL;
18091 }
18092
18093
18094 /**
18095 * idmef_assessment_set_action:
18096 * @ptr: pointer to a #idmef_assessment_t object.
18097 * @object: pointer to a #idmef_action_t object.
18098 * @pos: Position in the list.
18099 *
18100 * Add @object to position @pos of @ptr list of #idmef_action_t object.
18101 *
18102 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
18103 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
18104 */
idmef_assessment_set_action(idmef_assessment_t * ptr,idmef_action_t * object,int pos)18105 void idmef_assessment_set_action(idmef_assessment_t *ptr, idmef_action_t *object, int pos)
18106 {
18107 prelude_return_if_fail(ptr);
18108 prelude_return_if_fail(object);
18109
18110 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
18111 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
18112
18113 list_insert(&ptr->action_list, &((prelude_linked_object_t *) object)->_list, pos);
18114 }
18115
18116
18117 /**
18118 * idmef_assessment_new_action:
18119 * @ptr: pointer to a #idmef_assessment_t object.
18120 * @ret: pointer to an address where to store the created #idmef_action_t object.
18121 * @pos: position in the list.
18122 *
18123 * Create a new #idmef_action_t children of @ptr, and add it to position @pos of
18124 * @ptr list of #idmef_action_t object. The created #idmef_action_t object is
18125 * stored in @ret.
18126 *
18127 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
18128 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
18129 *
18130 * Returns: 0 on success, or a negative value if an error occured.
18131 */
idmef_assessment_new_action(idmef_assessment_t * ptr,idmef_action_t ** ret,int pos)18132 int idmef_assessment_new_action(idmef_assessment_t *ptr, idmef_action_t **ret, int pos)
18133 {
18134 int retval;
18135
18136 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
18137
18138 retval = idmef_action_new(ret);
18139 if ( retval < 0 )
18140 return retval;
18141
18142 list_insert(&ptr->action_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
18143
18144 return 0;
18145 }
18146
18147
18148 /**
18149 * idmef_assessment_get_confidence:
18150 * @ptr: pointer to a #idmef_assessment_t object.
18151 *
18152 * Get confidence children of the #idmef_assessment_t object.
18153 *
18154 * Returns: a pointer to a idmef_confidence_t object, or NULL if the children object is not set.
18155 */
idmef_assessment_get_confidence(idmef_assessment_t * ptr)18156 idmef_confidence_t *idmef_assessment_get_confidence(idmef_assessment_t *ptr)
18157 {
18158 prelude_return_val_if_fail(ptr, 0); /* FIXME */
18159
18160 return ptr->confidence;
18161 }
18162
18163 /**
18164 * idmef_assessment_set_confidence:
18165 * @ptr: pointer to a #idmef_assessment_t object.
18166 * @confidence: pointer to a #idmef_confidence_t object.
18167 *
18168 * Set @confidence object as a children of @ptr.
18169 * if @ptr already contain an @confidence object, then it is destroyed,
18170 * and updated to point to the provided @confidence object.
18171 */
18172
idmef_assessment_set_confidence(idmef_assessment_t * ptr,idmef_confidence_t * confidence)18173 void idmef_assessment_set_confidence(idmef_assessment_t *ptr, idmef_confidence_t *confidence)
18174 {
18175 prelude_return_if_fail(ptr);
18176
18177 if ( ptr->confidence )
18178 idmef_confidence_destroy(ptr->confidence);
18179
18180 ptr->confidence = confidence;
18181 }
18182
18183 /**
18184 * idmef_assessment_new_confidence:
18185 * @ptr: pointer to a #idmef_assessment_t object.
18186 * @ret: pointer to an address where to store the created #idmef_confidence_t object.
18187 *
18188 * Create a new confidence object, children of #idmef_assessment_t.
18189 * If @ptr already contain a #idmef_confidence_t object, then it is destroyed.
18190 *
18191 * Returns: 0 on success, or a negative value if an error occured.
18192 */
idmef_assessment_new_confidence(idmef_assessment_t * ptr,idmef_confidence_t ** ret)18193 int idmef_assessment_new_confidence(idmef_assessment_t *ptr, idmef_confidence_t **ret)
18194 {
18195 int retval;
18196
18197 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
18198
18199 if ( ! ptr->confidence ) {
18200 retval = idmef_confidence_new(&ptr->confidence);
18201 if ( retval < 0 )
18202 return retval;
18203 }
18204
18205 *ret = ptr->confidence;
18206 return 0;
18207 }
18208
18209 /**
18210 * idmef_assessment_copy:
18211 * @src: Source of the copy.
18212 * @dst: Where to copy the object.
18213 *
18214 * Copy a new #idmef_assessment_t object from @src to @dst.
18215 *
18216 * Returns: 0 on success, a negative value if an error occured.
18217 */
idmef_assessment_copy(const idmef_assessment_t * src,idmef_assessment_t * dst)18218 int idmef_assessment_copy(const idmef_assessment_t *src, idmef_assessment_t *dst)
18219 {
18220 int ret;
18221
18222 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
18223 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
18224
18225 ret = 0;
18226
18227 if ( src->impact ) {
18228 ret = idmef_impact_clone(src->impact, &dst->impact);
18229 if ( ret < 0 )
18230 return ret;
18231 }
18232
18233 {
18234 prelude_list_t *n, *tmp;
18235 idmef_action_t *entry, *new;
18236
18237 prelude_list_for_each_safe(&src->action_list, tmp, n) {
18238 entry = prelude_linked_object_get_object(tmp);
18239 idmef_action_clone(entry, &new);
18240 prelude_list_add_tail(&dst->action_list, &((prelude_linked_object_t *) new)->_list);
18241 }
18242 }
18243
18244 if ( src->confidence ) {
18245 ret = idmef_confidence_clone(src->confidence, &dst->confidence);
18246 if ( ret < 0 )
18247 return ret;
18248 }
18249
18250 return 0;
18251 }
18252
18253 /**
18254 * idmef_assessment_clone:
18255 * @src: Object to be cloned.
18256 * @dst: Address where to store the pointer to the cloned object.
18257 *
18258 * Create a copy of @src, and store it in @dst.
18259 *
18260 * Returns: 0 on success, a negative value if an error occured.
18261 */
idmef_assessment_clone(idmef_assessment_t * src,idmef_assessment_t ** dst)18262 int idmef_assessment_clone(idmef_assessment_t *src, idmef_assessment_t **dst)
18263 {
18264 int ret;
18265
18266 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
18267
18268 ret = idmef_assessment_new(dst);
18269 if ( ret < 0 )
18270 return ret;
18271
18272 return idmef_assessment_copy(src, *dst);
18273 }
18274
18275 /**
18276 * idmef_assessment_compare:
18277 * @obj1: Object to compare with @obj2.
18278 * @obj2: Object to compare with @obj1.
18279 *
18280 * Compare @obj1 with @obj2.
18281 *
18282 * Returns: 0 on match, a negative value on comparison failure.
18283 */
idmef_assessment_compare(const idmef_assessment_t * obj1,const idmef_assessment_t * obj2)18284 int idmef_assessment_compare(const idmef_assessment_t *obj1, const idmef_assessment_t *obj2)
18285 {
18286 int ret = 0;
18287
18288 if ( obj1 == NULL && obj2 == NULL )
18289 return 0;
18290
18291 else if ( obj1 == NULL || obj2 == NULL )
18292 return -1;
18293
18294 ret = idmef_impact_compare(obj1->impact, obj2->impact);
18295 if ( ret != 0 )
18296 return ret;
18297
18298 {
18299 prelude_list_t *tmp1, *tmp2;
18300 idmef_action_t *entry1, *entry2;
18301
18302 tmp1 = tmp2 = NULL;
18303 do {
18304 entry1 = entry2 = NULL;
18305
18306 prelude_list_for_each_continue(&obj1->action_list, tmp1) {
18307 entry1 = prelude_linked_object_get_object(tmp1);
18308 break;
18309 }
18310
18311 prelude_list_for_each_continue(&obj2->action_list, tmp2) {
18312 entry2 = prelude_linked_object_get_object(tmp2);
18313 break;
18314 }
18315
18316 ret = idmef_action_compare(entry1, entry2);
18317 if ( ret != 0 )
18318 return ret;
18319
18320 } while ( entry1 && entry2 );
18321 }
18322
18323 ret = idmef_confidence_compare(obj1->confidence, obj2->confidence);
18324 if ( ret != 0 )
18325 return ret;
18326
18327 return ret;
18328 }
18329
18330 /**
18331 * idmef_tool_alert_new:
18332 * @ret: Pointer where to store the created #idmef_tool_alert_t object.
18333 *
18334 * Create a new #idmef_tool_alert_t object.
18335 *
18336 * Returns: 0 on success, a negative value if an error occured.
18337 */
idmef_tool_alert_new(idmef_tool_alert_t ** ret)18338 int idmef_tool_alert_new(idmef_tool_alert_t **ret)
18339 {
18340 *ret = calloc(1, sizeof(**ret));
18341 if ( ! *ret )
18342 return prelude_error_from_errno(errno);
18343
18344 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_TOOL_ALERT;
18345
18346 (*ret)->refcount = 1;
18347
18348 prelude_list_init(&(*ret)->alertident_list);
18349
18350
18351 {
18352 int retval = prelude_string_new(&(*ret)->name);
18353
18354 if ( retval < 0 ) {
18355 idmef_tool_alert_destroy(*ret);
18356 *ret = NULL;
18357 return retval;
18358 }
18359 }
18360
18361 return 0;
18362
18363 }
18364
18365 /**
18366 * idmef_tool_alert_ref:
18367 * @tool_alert: pointer to a #idmef_tool_alert_t object.
18368 *
18369 * Increase @tool_alert reference count, so that it can be referenced
18370 * multiple time.
18371 *
18372 * Returns: a pointer to @tool_alert.
18373 */
idmef_tool_alert_ref(idmef_tool_alert_t * tool_alert)18374 idmef_tool_alert_t *idmef_tool_alert_ref(idmef_tool_alert_t *tool_alert)
18375 {
18376 prelude_return_val_if_fail(tool_alert, NULL);
18377 tool_alert->refcount++;
18378
18379 return tool_alert;
18380 }
18381
_idmef_tool_alert_get_child(void * p,idmef_class_child_id_t child,void ** childptr)18382 int _idmef_tool_alert_get_child(void *p, idmef_class_child_id_t child, void **childptr)
18383 {
18384 idmef_tool_alert_t *ptr = p;
18385
18386 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
18387 *childptr = NULL;
18388
18389 switch ( child ) {
18390
18391 case 0:
18392 return get_value_from_string((idmef_value_t **) childptr, ptr->name, TRUE);
18393 case 1:
18394 return get_value_from_string((idmef_value_t **) childptr, ptr->command, TRUE);
18395 case 2:
18396 *childptr = &ptr->alertident_list;
18397 return 0;
18398
18399 default:
18400 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
18401 }
18402 }
18403
_idmef_tool_alert_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)18404 int _idmef_tool_alert_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
18405 {
18406 idmef_tool_alert_t *ptr = p;
18407
18408 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
18409
18410 switch ( child ) {
18411
18412 case 0:
18413 return idmef_tool_alert_new_name(ptr, (prelude_string_t **) ret);
18414
18415 case 1:
18416 return idmef_tool_alert_new_command(ptr, (prelude_string_t **) ret);
18417
18418 case 2: {
18419 int i = 0;
18420 prelude_list_t *tmp;
18421
18422 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
18423 return idmef_tool_alert_new_alertident(ptr, (idmef_alertident_t **) ret, n);
18424
18425 if ( n >= 0 ) {
18426 prelude_list_for_each(&ptr->alertident_list, tmp) {
18427 if ( i++ == n ) {
18428 *ret = prelude_linked_object_get_object(tmp);
18429 return 0;
18430 }
18431 }
18432
18433 if ( i != n )
18434 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
18435 } else {
18436 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
18437
18438 prelude_list_for_each_reversed(&ptr->alertident_list, tmp) {
18439 if ( i++ == pos ) {
18440 *ret = prelude_linked_object_get_object(tmp);
18441 return 0;
18442 }
18443 }
18444
18445 if ( i != pos )
18446 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
18447 }
18448
18449 return idmef_tool_alert_new_alertident(ptr, (idmef_alertident_t **) ret, n);
18450 }
18451
18452 default:
18453 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
18454 }
18455 }
18456
_idmef_tool_alert_destroy_child(void * p,idmef_class_child_id_t child,int n)18457 int _idmef_tool_alert_destroy_child(void *p, idmef_class_child_id_t child, int n)
18458 {
18459 idmef_tool_alert_t *ptr = p;
18460
18461 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
18462
18463 switch ( child ) {
18464
18465 case 0:
18466 if ( ptr->name ) {
18467 prelude_string_destroy(ptr->name);
18468 ptr->name = NULL;
18469 }
18470
18471 return 0;
18472
18473 case 1:
18474 if ( ptr->command ) {
18475 prelude_string_destroy(ptr->command);
18476 ptr->command = NULL;
18477 }
18478
18479 return 0;
18480
18481 case 2: {
18482 int i = 0;
18483 prelude_list_t *tmp;
18484
18485 if ( n >= 0 ) {
18486 prelude_list_for_each(&ptr->alertident_list, tmp) {
18487 if ( i++ == n ) {
18488 void *b = prelude_linked_object_get_object(tmp);
18489 idmef_alertident_destroy(b);
18490 return 0;
18491 }
18492 }
18493
18494 if ( i != n )
18495 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
18496 } else {
18497 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
18498
18499 prelude_list_for_each_reversed(&ptr->alertident_list, tmp) {
18500 if ( i++ == pos ) {
18501 void *b = prelude_linked_object_get_object(tmp);
18502 idmef_alertident_destroy(b);
18503 return 0;
18504 }
18505 }
18506
18507 if ( i != pos )
18508 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
18509 }
18510 }
18511
18512 default:
18513 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
18514 }
18515 }
18516
idmef_tool_alert_destroy_internal(idmef_tool_alert_t * ptr)18517 static void idmef_tool_alert_destroy_internal(idmef_tool_alert_t *ptr)
18518 {
18519 prelude_return_if_fail(ptr);
18520
18521 if ( ptr->name ) {
18522 prelude_string_destroy(ptr->name);
18523 ptr->name = NULL;
18524 }
18525
18526 if ( ptr->command ) {
18527 prelude_string_destroy(ptr->command);
18528 ptr->command = NULL;
18529 }
18530
18531 {
18532 prelude_list_t *n, *tmp;
18533 idmef_alertident_t *entry;
18534
18535 prelude_list_for_each_safe(&ptr->alertident_list, tmp, n) {
18536 entry = prelude_linked_object_get_object(tmp);
18537 prelude_list_del_init(tmp);
18538 idmef_alertident_destroy(entry);
18539 }
18540 }
18541
18542
18543 /* free() should be done by the caller */
18544 }
18545
18546 /**
18547 * idmef_tool_alert_destroy:
18548 * @ptr: pointer to a #idmef_tool_alert_t object.
18549 *
18550 * Destroy @ptr and all of it's children.
18551 * The objects are only destroyed if their reference count reach zero.
18552 */
18553
idmef_tool_alert_destroy(idmef_tool_alert_t * ptr)18554 void idmef_tool_alert_destroy(idmef_tool_alert_t *ptr)
18555 {
18556 prelude_return_if_fail(ptr);
18557
18558 if ( --ptr->refcount )
18559 return;
18560
18561 idmef_tool_alert_destroy_internal(ptr);
18562 free(ptr);
18563 }
18564
18565 /**
18566 * idmef_tool_alert_get_name:
18567 * @ptr: pointer to a #idmef_tool_alert_t object.
18568 *
18569 * Get name children of the #idmef_tool_alert_t object.
18570 *
18571 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
18572 */
idmef_tool_alert_get_name(idmef_tool_alert_t * ptr)18573 prelude_string_t *idmef_tool_alert_get_name(idmef_tool_alert_t *ptr)
18574 {
18575 prelude_return_val_if_fail(ptr, 0); /* FIXME */
18576
18577 return ptr->name;
18578 }
18579
18580 /**
18581 * idmef_tool_alert_set_name:
18582 * @ptr: pointer to a #idmef_tool_alert_t object.
18583 * @name: pointer to a #prelude_string_t object.
18584 *
18585 * Set @name object as a children of @ptr.
18586 * if @ptr already contain an @name object, then it is destroyed,
18587 * and updated to point to the provided @name object.
18588 */
18589
idmef_tool_alert_set_name(idmef_tool_alert_t * ptr,prelude_string_t * name)18590 void idmef_tool_alert_set_name(idmef_tool_alert_t *ptr, prelude_string_t *name)
18591 {
18592 prelude_return_if_fail(ptr);
18593
18594 if ( ptr->name )
18595 prelude_string_destroy(ptr->name);
18596
18597 ptr->name = name;
18598 }
18599
18600 /**
18601 * idmef_tool_alert_new_name:
18602 * @ptr: pointer to a #idmef_tool_alert_t object.
18603 * @ret: pointer to an address where to store the created #prelude_string_t object.
18604 *
18605 * Create a new name object, children of #idmef_tool_alert_t.
18606 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
18607 *
18608 * Returns: 0 on success, or a negative value if an error occured.
18609 */
idmef_tool_alert_new_name(idmef_tool_alert_t * ptr,prelude_string_t ** ret)18610 int idmef_tool_alert_new_name(idmef_tool_alert_t *ptr, prelude_string_t **ret)
18611 {
18612 int retval;
18613
18614 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
18615
18616 if ( ! ptr->name ) {
18617 retval = prelude_string_new(&ptr->name);
18618 if ( retval < 0 )
18619 return retval;
18620 }
18621
18622 *ret = ptr->name;
18623 return 0;
18624 }
18625
18626 /**
18627 * idmef_tool_alert_get_command:
18628 * @ptr: pointer to a #idmef_tool_alert_t object.
18629 *
18630 * Get command children of the #idmef_tool_alert_t object.
18631 *
18632 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
18633 */
idmef_tool_alert_get_command(idmef_tool_alert_t * ptr)18634 prelude_string_t *idmef_tool_alert_get_command(idmef_tool_alert_t *ptr)
18635 {
18636 prelude_return_val_if_fail(ptr, 0); /* FIXME */
18637
18638 return ptr->command;
18639 }
18640
18641 /**
18642 * idmef_tool_alert_set_command:
18643 * @ptr: pointer to a #idmef_tool_alert_t object.
18644 * @command: pointer to a #prelude_string_t object.
18645 *
18646 * Set @command object as a children of @ptr.
18647 * if @ptr already contain an @command object, then it is destroyed,
18648 * and updated to point to the provided @command object.
18649 */
18650
idmef_tool_alert_set_command(idmef_tool_alert_t * ptr,prelude_string_t * command)18651 void idmef_tool_alert_set_command(idmef_tool_alert_t *ptr, prelude_string_t *command)
18652 {
18653 prelude_return_if_fail(ptr);
18654
18655 if ( ptr->command )
18656 prelude_string_destroy(ptr->command);
18657
18658 ptr->command = command;
18659 }
18660
18661 /**
18662 * idmef_tool_alert_new_command:
18663 * @ptr: pointer to a #idmef_tool_alert_t object.
18664 * @ret: pointer to an address where to store the created #prelude_string_t object.
18665 *
18666 * Create a new command object, children of #idmef_tool_alert_t.
18667 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
18668 *
18669 * Returns: 0 on success, or a negative value if an error occured.
18670 */
idmef_tool_alert_new_command(idmef_tool_alert_t * ptr,prelude_string_t ** ret)18671 int idmef_tool_alert_new_command(idmef_tool_alert_t *ptr, prelude_string_t **ret)
18672 {
18673 int retval;
18674
18675 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
18676
18677 if ( ! ptr->command ) {
18678 retval = prelude_string_new(&ptr->command);
18679 if ( retval < 0 )
18680 return retval;
18681 }
18682
18683 *ret = ptr->command;
18684 return 0;
18685 }
18686
18687 /**
18688 * idmef_tool_alert_get_next_alertident:
18689 * @tool_alert: pointer to a #idmef_tool_alert_t object.
18690 * @alertident_cur: pointer to a #idmef_alertident_t object.
18691 *
18692 * Get the next #idmef_alertident_t object listed in @ptr.
18693 * When iterating over the idmef_alertident_t object listed in @ptr,
18694 * @object should be set to the latest returned #idmef_alertident_t object.
18695 *
18696 * Returns: the next #idmef_alertident_t in the list.
18697 */
idmef_tool_alert_get_next_alertident(idmef_tool_alert_t * tool_alert,idmef_alertident_t * alertident_cur)18698 idmef_alertident_t *idmef_tool_alert_get_next_alertident(idmef_tool_alert_t *tool_alert, idmef_alertident_t *alertident_cur)
18699 {
18700 prelude_list_t *tmp = (alertident_cur) ? &((prelude_linked_object_t *) alertident_cur)->_list : NULL;
18701
18702 prelude_return_val_if_fail(tool_alert, NULL);
18703
18704 prelude_list_for_each_continue(&tool_alert->alertident_list, tmp)
18705 return prelude_linked_object_get_object(tmp);
18706
18707 return NULL;
18708 }
18709
18710
18711 /**
18712 * idmef_tool_alert_set_alertident:
18713 * @ptr: pointer to a #idmef_tool_alert_t object.
18714 * @object: pointer to a #idmef_alertident_t object.
18715 * @pos: Position in the list.
18716 *
18717 * Add @object to position @pos of @ptr list of #idmef_alertident_t object.
18718 *
18719 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
18720 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
18721 */
idmef_tool_alert_set_alertident(idmef_tool_alert_t * ptr,idmef_alertident_t * object,int pos)18722 void idmef_tool_alert_set_alertident(idmef_tool_alert_t *ptr, idmef_alertident_t *object, int pos)
18723 {
18724 prelude_return_if_fail(ptr);
18725 prelude_return_if_fail(object);
18726
18727 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
18728 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
18729
18730 list_insert(&ptr->alertident_list, &((prelude_linked_object_t *) object)->_list, pos);
18731 }
18732
18733
18734 /**
18735 * idmef_tool_alert_new_alertident:
18736 * @ptr: pointer to a #idmef_tool_alert_t object.
18737 * @ret: pointer to an address where to store the created #idmef_alertident_t object.
18738 * @pos: position in the list.
18739 *
18740 * Create a new #idmef_alertident_t children of @ptr, and add it to position @pos of
18741 * @ptr list of #idmef_alertident_t object. The created #idmef_alertident_t object is
18742 * stored in @ret.
18743 *
18744 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
18745 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
18746 *
18747 * Returns: 0 on success, or a negative value if an error occured.
18748 */
idmef_tool_alert_new_alertident(idmef_tool_alert_t * ptr,idmef_alertident_t ** ret,int pos)18749 int idmef_tool_alert_new_alertident(idmef_tool_alert_t *ptr, idmef_alertident_t **ret, int pos)
18750 {
18751 int retval;
18752
18753 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
18754
18755 retval = idmef_alertident_new(ret);
18756 if ( retval < 0 )
18757 return retval;
18758
18759 list_insert(&ptr->alertident_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
18760
18761 return 0;
18762 }
18763
18764
18765 /**
18766 * idmef_tool_alert_copy:
18767 * @src: Source of the copy.
18768 * @dst: Where to copy the object.
18769 *
18770 * Copy a new #idmef_tool_alert_t object from @src to @dst.
18771 *
18772 * Returns: 0 on success, a negative value if an error occured.
18773 */
idmef_tool_alert_copy(const idmef_tool_alert_t * src,idmef_tool_alert_t * dst)18774 int idmef_tool_alert_copy(const idmef_tool_alert_t *src, idmef_tool_alert_t *dst)
18775 {
18776 int ret;
18777
18778 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
18779 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
18780
18781 ret = 0;
18782
18783 if ( src->name ) {
18784 ret = prelude_string_copy(src->name, dst->name);
18785 if ( ret < 0 )
18786 return ret;
18787 }
18788
18789 if ( src->command ) {
18790 ret = prelude_string_clone(src->command, &dst->command);
18791 if ( ret < 0 )
18792 return ret;
18793 }
18794
18795 {
18796 prelude_list_t *n, *tmp;
18797 idmef_alertident_t *entry, *new;
18798
18799 prelude_list_for_each_safe(&src->alertident_list, tmp, n) {
18800 entry = prelude_linked_object_get_object(tmp);
18801 idmef_alertident_clone(entry, &new);
18802 prelude_list_add_tail(&dst->alertident_list, &((prelude_linked_object_t *) new)->_list);
18803 }
18804 }
18805
18806 return 0;
18807 }
18808
18809 /**
18810 * idmef_tool_alert_clone:
18811 * @src: Object to be cloned.
18812 * @dst: Address where to store the pointer to the cloned object.
18813 *
18814 * Create a copy of @src, and store it in @dst.
18815 *
18816 * Returns: 0 on success, a negative value if an error occured.
18817 */
idmef_tool_alert_clone(idmef_tool_alert_t * src,idmef_tool_alert_t ** dst)18818 int idmef_tool_alert_clone(idmef_tool_alert_t *src, idmef_tool_alert_t **dst)
18819 {
18820 int ret;
18821
18822 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
18823
18824 ret = idmef_tool_alert_new(dst);
18825 if ( ret < 0 )
18826 return ret;
18827
18828 return idmef_tool_alert_copy(src, *dst);
18829 }
18830
18831 /**
18832 * idmef_tool_alert_compare:
18833 * @obj1: Object to compare with @obj2.
18834 * @obj2: Object to compare with @obj1.
18835 *
18836 * Compare @obj1 with @obj2.
18837 *
18838 * Returns: 0 on match, a negative value on comparison failure.
18839 */
idmef_tool_alert_compare(const idmef_tool_alert_t * obj1,const idmef_tool_alert_t * obj2)18840 int idmef_tool_alert_compare(const idmef_tool_alert_t *obj1, const idmef_tool_alert_t *obj2)
18841 {
18842 int ret = 0;
18843
18844 if ( obj1 == NULL && obj2 == NULL )
18845 return 0;
18846
18847 else if ( obj1 == NULL || obj2 == NULL )
18848 return -1;
18849
18850 ret = prelude_string_compare(obj1->name, obj2->name);
18851 if ( ret != 0 )
18852 return ret;
18853
18854 ret = prelude_string_compare(obj1->command, obj2->command);
18855 if ( ret != 0 )
18856 return ret;
18857
18858 {
18859 prelude_list_t *tmp1, *tmp2;
18860 idmef_alertident_t *entry1, *entry2;
18861
18862 tmp1 = tmp2 = NULL;
18863 do {
18864 entry1 = entry2 = NULL;
18865
18866 prelude_list_for_each_continue(&obj1->alertident_list, tmp1) {
18867 entry1 = prelude_linked_object_get_object(tmp1);
18868 break;
18869 }
18870
18871 prelude_list_for_each_continue(&obj2->alertident_list, tmp2) {
18872 entry2 = prelude_linked_object_get_object(tmp2);
18873 break;
18874 }
18875
18876 ret = idmef_alertident_compare(entry1, entry2);
18877 if ( ret != 0 )
18878 return ret;
18879
18880 } while ( entry1 && entry2 );
18881 }
18882
18883 return ret;
18884 }
18885
18886 /**
18887 * idmef_correlation_alert_new:
18888 * @ret: Pointer where to store the created #idmef_correlation_alert_t object.
18889 *
18890 * Create a new #idmef_correlation_alert_t object.
18891 *
18892 * Returns: 0 on success, a negative value if an error occured.
18893 */
idmef_correlation_alert_new(idmef_correlation_alert_t ** ret)18894 int idmef_correlation_alert_new(idmef_correlation_alert_t **ret)
18895 {
18896 *ret = calloc(1, sizeof(**ret));
18897 if ( ! *ret )
18898 return prelude_error_from_errno(errno);
18899
18900 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_CORRELATION_ALERT;
18901
18902 (*ret)->refcount = 1;
18903
18904 prelude_list_init(&(*ret)->alertident_list);
18905
18906
18907 {
18908 int retval = prelude_string_new(&(*ret)->name);
18909
18910 if ( retval < 0 ) {
18911 idmef_correlation_alert_destroy(*ret);
18912 *ret = NULL;
18913 return retval;
18914 }
18915 }
18916
18917 return 0;
18918
18919 }
18920
18921 /**
18922 * idmef_correlation_alert_ref:
18923 * @correlation_alert: pointer to a #idmef_correlation_alert_t object.
18924 *
18925 * Increase @correlation_alert reference count, so that it can be referenced
18926 * multiple time.
18927 *
18928 * Returns: a pointer to @correlation_alert.
18929 */
idmef_correlation_alert_ref(idmef_correlation_alert_t * correlation_alert)18930 idmef_correlation_alert_t *idmef_correlation_alert_ref(idmef_correlation_alert_t *correlation_alert)
18931 {
18932 prelude_return_val_if_fail(correlation_alert, NULL);
18933 correlation_alert->refcount++;
18934
18935 return correlation_alert;
18936 }
18937
_idmef_correlation_alert_get_child(void * p,idmef_class_child_id_t child,void ** childptr)18938 int _idmef_correlation_alert_get_child(void *p, idmef_class_child_id_t child, void **childptr)
18939 {
18940 idmef_correlation_alert_t *ptr = p;
18941
18942 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
18943 *childptr = NULL;
18944
18945 switch ( child ) {
18946
18947 case 0:
18948 return get_value_from_string((idmef_value_t **) childptr, ptr->name, TRUE);
18949 case 1:
18950 *childptr = &ptr->alertident_list;
18951 return 0;
18952
18953 default:
18954 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
18955 }
18956 }
18957
_idmef_correlation_alert_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)18958 int _idmef_correlation_alert_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
18959 {
18960 idmef_correlation_alert_t *ptr = p;
18961
18962 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
18963
18964 switch ( child ) {
18965
18966 case 0:
18967 return idmef_correlation_alert_new_name(ptr, (prelude_string_t **) ret);
18968
18969 case 1: {
18970 int i = 0;
18971 prelude_list_t *tmp;
18972
18973 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
18974 return idmef_correlation_alert_new_alertident(ptr, (idmef_alertident_t **) ret, n);
18975
18976 if ( n >= 0 ) {
18977 prelude_list_for_each(&ptr->alertident_list, tmp) {
18978 if ( i++ == n ) {
18979 *ret = prelude_linked_object_get_object(tmp);
18980 return 0;
18981 }
18982 }
18983
18984 if ( i != n )
18985 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
18986 } else {
18987 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
18988
18989 prelude_list_for_each_reversed(&ptr->alertident_list, tmp) {
18990 if ( i++ == pos ) {
18991 *ret = prelude_linked_object_get_object(tmp);
18992 return 0;
18993 }
18994 }
18995
18996 if ( i != pos )
18997 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
18998 }
18999
19000 return idmef_correlation_alert_new_alertident(ptr, (idmef_alertident_t **) ret, n);
19001 }
19002
19003 default:
19004 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
19005 }
19006 }
19007
_idmef_correlation_alert_destroy_child(void * p,idmef_class_child_id_t child,int n)19008 int _idmef_correlation_alert_destroy_child(void *p, idmef_class_child_id_t child, int n)
19009 {
19010 idmef_correlation_alert_t *ptr = p;
19011
19012 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
19013
19014 switch ( child ) {
19015
19016 case 0:
19017 if ( ptr->name ) {
19018 prelude_string_destroy(ptr->name);
19019 ptr->name = NULL;
19020 }
19021
19022 return 0;
19023
19024 case 1: {
19025 int i = 0;
19026 prelude_list_t *tmp;
19027
19028 if ( n >= 0 ) {
19029 prelude_list_for_each(&ptr->alertident_list, tmp) {
19030 if ( i++ == n ) {
19031 void *b = prelude_linked_object_get_object(tmp);
19032 idmef_alertident_destroy(b);
19033 return 0;
19034 }
19035 }
19036
19037 if ( i != n )
19038 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
19039 } else {
19040 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
19041
19042 prelude_list_for_each_reversed(&ptr->alertident_list, tmp) {
19043 if ( i++ == pos ) {
19044 void *b = prelude_linked_object_get_object(tmp);
19045 idmef_alertident_destroy(b);
19046 return 0;
19047 }
19048 }
19049
19050 if ( i != pos )
19051 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
19052 }
19053 }
19054
19055 default:
19056 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
19057 }
19058 }
19059
idmef_correlation_alert_destroy_internal(idmef_correlation_alert_t * ptr)19060 static void idmef_correlation_alert_destroy_internal(idmef_correlation_alert_t *ptr)
19061 {
19062 prelude_return_if_fail(ptr);
19063
19064 if ( ptr->name ) {
19065 prelude_string_destroy(ptr->name);
19066 ptr->name = NULL;
19067 }
19068
19069 {
19070 prelude_list_t *n, *tmp;
19071 idmef_alertident_t *entry;
19072
19073 prelude_list_for_each_safe(&ptr->alertident_list, tmp, n) {
19074 entry = prelude_linked_object_get_object(tmp);
19075 prelude_list_del_init(tmp);
19076 idmef_alertident_destroy(entry);
19077 }
19078 }
19079
19080
19081 /* free() should be done by the caller */
19082 }
19083
19084 /**
19085 * idmef_correlation_alert_destroy:
19086 * @ptr: pointer to a #idmef_correlation_alert_t object.
19087 *
19088 * Destroy @ptr and all of it's children.
19089 * The objects are only destroyed if their reference count reach zero.
19090 */
19091
idmef_correlation_alert_destroy(idmef_correlation_alert_t * ptr)19092 void idmef_correlation_alert_destroy(idmef_correlation_alert_t *ptr)
19093 {
19094 prelude_return_if_fail(ptr);
19095
19096 if ( --ptr->refcount )
19097 return;
19098
19099 idmef_correlation_alert_destroy_internal(ptr);
19100 free(ptr);
19101 }
19102
19103 /**
19104 * idmef_correlation_alert_get_name:
19105 * @ptr: pointer to a #idmef_correlation_alert_t object.
19106 *
19107 * Get name children of the #idmef_correlation_alert_t object.
19108 *
19109 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
19110 */
idmef_correlation_alert_get_name(idmef_correlation_alert_t * ptr)19111 prelude_string_t *idmef_correlation_alert_get_name(idmef_correlation_alert_t *ptr)
19112 {
19113 prelude_return_val_if_fail(ptr, 0); /* FIXME */
19114
19115 return ptr->name;
19116 }
19117
19118 /**
19119 * idmef_correlation_alert_set_name:
19120 * @ptr: pointer to a #idmef_correlation_alert_t object.
19121 * @name: pointer to a #prelude_string_t object.
19122 *
19123 * Set @name object as a children of @ptr.
19124 * if @ptr already contain an @name object, then it is destroyed,
19125 * and updated to point to the provided @name object.
19126 */
19127
idmef_correlation_alert_set_name(idmef_correlation_alert_t * ptr,prelude_string_t * name)19128 void idmef_correlation_alert_set_name(idmef_correlation_alert_t *ptr, prelude_string_t *name)
19129 {
19130 prelude_return_if_fail(ptr);
19131
19132 if ( ptr->name )
19133 prelude_string_destroy(ptr->name);
19134
19135 ptr->name = name;
19136 }
19137
19138 /**
19139 * idmef_correlation_alert_new_name:
19140 * @ptr: pointer to a #idmef_correlation_alert_t object.
19141 * @ret: pointer to an address where to store the created #prelude_string_t object.
19142 *
19143 * Create a new name object, children of #idmef_correlation_alert_t.
19144 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
19145 *
19146 * Returns: 0 on success, or a negative value if an error occured.
19147 */
idmef_correlation_alert_new_name(idmef_correlation_alert_t * ptr,prelude_string_t ** ret)19148 int idmef_correlation_alert_new_name(idmef_correlation_alert_t *ptr, prelude_string_t **ret)
19149 {
19150 int retval;
19151
19152 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
19153
19154 if ( ! ptr->name ) {
19155 retval = prelude_string_new(&ptr->name);
19156 if ( retval < 0 )
19157 return retval;
19158 }
19159
19160 *ret = ptr->name;
19161 return 0;
19162 }
19163
19164 /**
19165 * idmef_correlation_alert_get_next_alertident:
19166 * @correlation_alert: pointer to a #idmef_correlation_alert_t object.
19167 * @alertident_cur: pointer to a #idmef_alertident_t object.
19168 *
19169 * Get the next #idmef_alertident_t object listed in @ptr.
19170 * When iterating over the idmef_alertident_t object listed in @ptr,
19171 * @object should be set to the latest returned #idmef_alertident_t object.
19172 *
19173 * Returns: the next #idmef_alertident_t in the list.
19174 */
idmef_correlation_alert_get_next_alertident(idmef_correlation_alert_t * correlation_alert,idmef_alertident_t * alertident_cur)19175 idmef_alertident_t *idmef_correlation_alert_get_next_alertident(idmef_correlation_alert_t *correlation_alert, idmef_alertident_t *alertident_cur)
19176 {
19177 prelude_list_t *tmp = (alertident_cur) ? &((prelude_linked_object_t *) alertident_cur)->_list : NULL;
19178
19179 prelude_return_val_if_fail(correlation_alert, NULL);
19180
19181 prelude_list_for_each_continue(&correlation_alert->alertident_list, tmp)
19182 return prelude_linked_object_get_object(tmp);
19183
19184 return NULL;
19185 }
19186
19187
19188 /**
19189 * idmef_correlation_alert_set_alertident:
19190 * @ptr: pointer to a #idmef_correlation_alert_t object.
19191 * @object: pointer to a #idmef_alertident_t object.
19192 * @pos: Position in the list.
19193 *
19194 * Add @object to position @pos of @ptr list of #idmef_alertident_t object.
19195 *
19196 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
19197 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
19198 */
idmef_correlation_alert_set_alertident(idmef_correlation_alert_t * ptr,idmef_alertident_t * object,int pos)19199 void idmef_correlation_alert_set_alertident(idmef_correlation_alert_t *ptr, idmef_alertident_t *object, int pos)
19200 {
19201 prelude_return_if_fail(ptr);
19202 prelude_return_if_fail(object);
19203
19204 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
19205 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
19206
19207 list_insert(&ptr->alertident_list, &((prelude_linked_object_t *) object)->_list, pos);
19208 }
19209
19210
19211 /**
19212 * idmef_correlation_alert_new_alertident:
19213 * @ptr: pointer to a #idmef_correlation_alert_t object.
19214 * @ret: pointer to an address where to store the created #idmef_alertident_t object.
19215 * @pos: position in the list.
19216 *
19217 * Create a new #idmef_alertident_t children of @ptr, and add it to position @pos of
19218 * @ptr list of #idmef_alertident_t object. The created #idmef_alertident_t object is
19219 * stored in @ret.
19220 *
19221 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
19222 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
19223 *
19224 * Returns: 0 on success, or a negative value if an error occured.
19225 */
idmef_correlation_alert_new_alertident(idmef_correlation_alert_t * ptr,idmef_alertident_t ** ret,int pos)19226 int idmef_correlation_alert_new_alertident(idmef_correlation_alert_t *ptr, idmef_alertident_t **ret, int pos)
19227 {
19228 int retval;
19229
19230 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
19231
19232 retval = idmef_alertident_new(ret);
19233 if ( retval < 0 )
19234 return retval;
19235
19236 list_insert(&ptr->alertident_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
19237
19238 return 0;
19239 }
19240
19241
19242 /**
19243 * idmef_correlation_alert_copy:
19244 * @src: Source of the copy.
19245 * @dst: Where to copy the object.
19246 *
19247 * Copy a new #idmef_correlation_alert_t object from @src to @dst.
19248 *
19249 * Returns: 0 on success, a negative value if an error occured.
19250 */
idmef_correlation_alert_copy(const idmef_correlation_alert_t * src,idmef_correlation_alert_t * dst)19251 int idmef_correlation_alert_copy(const idmef_correlation_alert_t *src, idmef_correlation_alert_t *dst)
19252 {
19253 int ret;
19254
19255 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
19256 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
19257
19258 ret = 0;
19259
19260 if ( src->name ) {
19261 ret = prelude_string_copy(src->name, dst->name);
19262 if ( ret < 0 )
19263 return ret;
19264 }
19265
19266 {
19267 prelude_list_t *n, *tmp;
19268 idmef_alertident_t *entry, *new;
19269
19270 prelude_list_for_each_safe(&src->alertident_list, tmp, n) {
19271 entry = prelude_linked_object_get_object(tmp);
19272 idmef_alertident_clone(entry, &new);
19273 prelude_list_add_tail(&dst->alertident_list, &((prelude_linked_object_t *) new)->_list);
19274 }
19275 }
19276
19277 return 0;
19278 }
19279
19280 /**
19281 * idmef_correlation_alert_clone:
19282 * @src: Object to be cloned.
19283 * @dst: Address where to store the pointer to the cloned object.
19284 *
19285 * Create a copy of @src, and store it in @dst.
19286 *
19287 * Returns: 0 on success, a negative value if an error occured.
19288 */
idmef_correlation_alert_clone(idmef_correlation_alert_t * src,idmef_correlation_alert_t ** dst)19289 int idmef_correlation_alert_clone(idmef_correlation_alert_t *src, idmef_correlation_alert_t **dst)
19290 {
19291 int ret;
19292
19293 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
19294
19295 ret = idmef_correlation_alert_new(dst);
19296 if ( ret < 0 )
19297 return ret;
19298
19299 return idmef_correlation_alert_copy(src, *dst);
19300 }
19301
19302 /**
19303 * idmef_correlation_alert_compare:
19304 * @obj1: Object to compare with @obj2.
19305 * @obj2: Object to compare with @obj1.
19306 *
19307 * Compare @obj1 with @obj2.
19308 *
19309 * Returns: 0 on match, a negative value on comparison failure.
19310 */
idmef_correlation_alert_compare(const idmef_correlation_alert_t * obj1,const idmef_correlation_alert_t * obj2)19311 int idmef_correlation_alert_compare(const idmef_correlation_alert_t *obj1, const idmef_correlation_alert_t *obj2)
19312 {
19313 int ret = 0;
19314
19315 if ( obj1 == NULL && obj2 == NULL )
19316 return 0;
19317
19318 else if ( obj1 == NULL || obj2 == NULL )
19319 return -1;
19320
19321 ret = prelude_string_compare(obj1->name, obj2->name);
19322 if ( ret != 0 )
19323 return ret;
19324
19325 {
19326 prelude_list_t *tmp1, *tmp2;
19327 idmef_alertident_t *entry1, *entry2;
19328
19329 tmp1 = tmp2 = NULL;
19330 do {
19331 entry1 = entry2 = NULL;
19332
19333 prelude_list_for_each_continue(&obj1->alertident_list, tmp1) {
19334 entry1 = prelude_linked_object_get_object(tmp1);
19335 break;
19336 }
19337
19338 prelude_list_for_each_continue(&obj2->alertident_list, tmp2) {
19339 entry2 = prelude_linked_object_get_object(tmp2);
19340 break;
19341 }
19342
19343 ret = idmef_alertident_compare(entry1, entry2);
19344 if ( ret != 0 )
19345 return ret;
19346
19347 } while ( entry1 && entry2 );
19348 }
19349
19350 return ret;
19351 }
19352
19353 /**
19354 * idmef_overflow_alert_new:
19355 * @ret: Pointer where to store the created #idmef_overflow_alert_t object.
19356 *
19357 * Create a new #idmef_overflow_alert_t object.
19358 *
19359 * Returns: 0 on success, a negative value if an error occured.
19360 */
idmef_overflow_alert_new(idmef_overflow_alert_t ** ret)19361 int idmef_overflow_alert_new(idmef_overflow_alert_t **ret)
19362 {
19363 *ret = calloc(1, sizeof(**ret));
19364 if ( ! *ret )
19365 return prelude_error_from_errno(errno);
19366
19367 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_OVERFLOW_ALERT;
19368
19369 (*ret)->refcount = 1;
19370
19371 {
19372 int retval = prelude_string_new(&(*ret)->program);
19373
19374 if ( retval < 0 ) {
19375 idmef_overflow_alert_destroy(*ret);
19376 *ret = NULL;
19377 return retval;
19378 }
19379 }
19380
19381 return 0;
19382
19383 }
19384
19385 /**
19386 * idmef_overflow_alert_ref:
19387 * @overflow_alert: pointer to a #idmef_overflow_alert_t object.
19388 *
19389 * Increase @overflow_alert reference count, so that it can be referenced
19390 * multiple time.
19391 *
19392 * Returns: a pointer to @overflow_alert.
19393 */
idmef_overflow_alert_ref(idmef_overflow_alert_t * overflow_alert)19394 idmef_overflow_alert_t *idmef_overflow_alert_ref(idmef_overflow_alert_t *overflow_alert)
19395 {
19396 prelude_return_val_if_fail(overflow_alert, NULL);
19397 overflow_alert->refcount++;
19398
19399 return overflow_alert;
19400 }
19401
_idmef_overflow_alert_get_child(void * p,idmef_class_child_id_t child,void ** childptr)19402 int _idmef_overflow_alert_get_child(void *p, idmef_class_child_id_t child, void **childptr)
19403 {
19404 idmef_overflow_alert_t *ptr = p;
19405
19406 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
19407 *childptr = NULL;
19408
19409 switch ( child ) {
19410
19411 case 0:
19412 return get_value_from_string((idmef_value_t **) childptr, ptr->program, TRUE);
19413 case 1:
19414 return (ptr->size_is_set) ? idmef_value_new_uint32((idmef_value_t **) childptr, ptr->size) : 0;
19415
19416 case 2:
19417 return get_value_from_data((idmef_value_t **) childptr, ptr->buffer, TRUE);
19418 default:
19419 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
19420 }
19421 }
19422
_idmef_overflow_alert_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)19423 int _idmef_overflow_alert_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
19424 {
19425 idmef_overflow_alert_t *ptr = p;
19426
19427 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
19428
19429 switch ( child ) {
19430
19431 case 0:
19432 return idmef_overflow_alert_new_program(ptr, (prelude_string_t **) ret);
19433
19434 case 1:
19435 return idmef_overflow_alert_new_size(ptr, (uint32_t **) ret);
19436
19437 case 2:
19438 return idmef_overflow_alert_new_buffer(ptr, (idmef_data_t **) ret);
19439
19440 default:
19441 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
19442 }
19443 }
19444
_idmef_overflow_alert_destroy_child(void * p,idmef_class_child_id_t child,int n)19445 int _idmef_overflow_alert_destroy_child(void *p, idmef_class_child_id_t child, int n)
19446 {
19447 idmef_overflow_alert_t *ptr = p;
19448
19449 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
19450
19451 switch ( child ) {
19452
19453 case 0:
19454 if ( ptr->program ) {
19455 prelude_string_destroy(ptr->program);
19456 ptr->program = NULL;
19457 }
19458
19459 return 0;
19460
19461 case 1:
19462 ptr->size_is_set = 0;
19463 return 0;
19464
19465 case 2:
19466 if ( ptr->buffer ) {
19467 idmef_data_destroy(ptr->buffer);
19468 ptr->buffer = NULL;
19469 }
19470
19471 return 0;
19472
19473 default:
19474 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
19475 }
19476 }
19477
idmef_overflow_alert_destroy_internal(idmef_overflow_alert_t * ptr)19478 static void idmef_overflow_alert_destroy_internal(idmef_overflow_alert_t *ptr)
19479 {
19480 prelude_return_if_fail(ptr);
19481
19482 if ( ptr->program ) {
19483 prelude_string_destroy(ptr->program);
19484 ptr->program = NULL;
19485 }
19486
19487 if ( ptr->buffer ) {
19488 idmef_data_destroy(ptr->buffer);
19489 ptr->buffer = NULL;
19490 }
19491
19492
19493 /* free() should be done by the caller */
19494 }
19495
19496 /**
19497 * idmef_overflow_alert_destroy:
19498 * @ptr: pointer to a #idmef_overflow_alert_t object.
19499 *
19500 * Destroy @ptr and all of it's children.
19501 * The objects are only destroyed if their reference count reach zero.
19502 */
19503
idmef_overflow_alert_destroy(idmef_overflow_alert_t * ptr)19504 void idmef_overflow_alert_destroy(idmef_overflow_alert_t *ptr)
19505 {
19506 prelude_return_if_fail(ptr);
19507
19508 if ( --ptr->refcount )
19509 return;
19510
19511 idmef_overflow_alert_destroy_internal(ptr);
19512 free(ptr);
19513 }
19514
19515 /**
19516 * idmef_overflow_alert_get_program:
19517 * @ptr: pointer to a #idmef_overflow_alert_t object.
19518 *
19519 * Get program children of the #idmef_overflow_alert_t object.
19520 *
19521 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
19522 */
idmef_overflow_alert_get_program(idmef_overflow_alert_t * ptr)19523 prelude_string_t *idmef_overflow_alert_get_program(idmef_overflow_alert_t *ptr)
19524 {
19525 prelude_return_val_if_fail(ptr, 0); /* FIXME */
19526
19527 return ptr->program;
19528 }
19529
19530 /**
19531 * idmef_overflow_alert_set_program:
19532 * @ptr: pointer to a #idmef_overflow_alert_t object.
19533 * @program: pointer to a #prelude_string_t object.
19534 *
19535 * Set @program object as a children of @ptr.
19536 * if @ptr already contain an @program object, then it is destroyed,
19537 * and updated to point to the provided @program object.
19538 */
19539
idmef_overflow_alert_set_program(idmef_overflow_alert_t * ptr,prelude_string_t * program)19540 void idmef_overflow_alert_set_program(idmef_overflow_alert_t *ptr, prelude_string_t *program)
19541 {
19542 prelude_return_if_fail(ptr);
19543
19544 if ( ptr->program )
19545 prelude_string_destroy(ptr->program);
19546
19547 ptr->program = program;
19548 }
19549
19550 /**
19551 * idmef_overflow_alert_new_program:
19552 * @ptr: pointer to a #idmef_overflow_alert_t object.
19553 * @ret: pointer to an address where to store the created #prelude_string_t object.
19554 *
19555 * Create a new program object, children of #idmef_overflow_alert_t.
19556 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
19557 *
19558 * Returns: 0 on success, or a negative value if an error occured.
19559 */
idmef_overflow_alert_new_program(idmef_overflow_alert_t * ptr,prelude_string_t ** ret)19560 int idmef_overflow_alert_new_program(idmef_overflow_alert_t *ptr, prelude_string_t **ret)
19561 {
19562 int retval;
19563
19564 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
19565
19566 if ( ! ptr->program ) {
19567 retval = prelude_string_new(&ptr->program);
19568 if ( retval < 0 )
19569 return retval;
19570 }
19571
19572 *ret = ptr->program;
19573 return 0;
19574 }
19575
19576 /**
19577 * idmef_overflow_alert_get_size:
19578 * @ptr: pointer to a #idmef_overflow_alert_t object.
19579 *
19580 * Get size children of the #idmef_overflow_alert_t object.
19581 *
19582 * Returns: a pointer to a uint32_t object, or NULL if the children object is not set.
19583 */
idmef_overflow_alert_get_size(idmef_overflow_alert_t * ptr)19584 uint32_t *idmef_overflow_alert_get_size(idmef_overflow_alert_t *ptr)
19585 {
19586 prelude_return_val_if_fail(ptr, 0); /* FIXME */
19587
19588 return ptr->size_is_set ? &ptr->size : NULL;
19589 }
19590
19591 /**
19592 * idmef_overflow_alert_set_size:
19593 * @ptr: pointer to a #idmef_overflow_alert_t object.
19594 * @size: pointer to a #uint32_t object.
19595 *
19596 * Set @size object as a children of @ptr.
19597 * if @ptr already contain an @size object, then it is destroyed,
19598 * and updated to point to the provided @size object.
19599 */
19600
idmef_overflow_alert_set_size(idmef_overflow_alert_t * ptr,uint32_t size)19601 void idmef_overflow_alert_set_size(idmef_overflow_alert_t *ptr, uint32_t size)
19602 {
19603 prelude_return_if_fail(ptr);
19604 ptr->size = size;
19605 ptr->size_is_set = 1;
19606 }
19607
19608
idmef_overflow_alert_unset_size(idmef_overflow_alert_t * ptr)19609 void idmef_overflow_alert_unset_size(idmef_overflow_alert_t *ptr)
19610 {
19611 prelude_return_if_fail(ptr);
19612 ptr->size_is_set = 0;
19613 }
19614
19615
19616 /**
19617 * idmef_overflow_alert_new_size:
19618 * @ptr: pointer to a #idmef_overflow_alert_t object.
19619 * @ret: pointer to an address where to store the created #uint32_t object.
19620 *
19621 * Create a new size object, children of #idmef_overflow_alert_t.
19622 * If @ptr already contain a #uint32_t object, then it is destroyed.
19623 *
19624 * Returns: 0 on success, or a negative value if an error occured.
19625 */
idmef_overflow_alert_new_size(idmef_overflow_alert_t * ptr,uint32_t ** ret)19626 int idmef_overflow_alert_new_size(idmef_overflow_alert_t *ptr, uint32_t **ret)
19627 {
19628 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
19629 ptr->size_is_set = 1;
19630
19631 *ret = &ptr->size;
19632 return 0;
19633 }
19634
19635 /**
19636 * idmef_overflow_alert_get_buffer:
19637 * @ptr: pointer to a #idmef_overflow_alert_t object.
19638 *
19639 * Get buffer children of the #idmef_overflow_alert_t object.
19640 *
19641 * Returns: a pointer to a idmef_data_t object, or NULL if the children object is not set.
19642 */
idmef_overflow_alert_get_buffer(idmef_overflow_alert_t * ptr)19643 idmef_data_t *idmef_overflow_alert_get_buffer(idmef_overflow_alert_t *ptr)
19644 {
19645 prelude_return_val_if_fail(ptr, 0); /* FIXME */
19646
19647 return ptr->buffer;
19648 }
19649
19650 /**
19651 * idmef_overflow_alert_set_buffer:
19652 * @ptr: pointer to a #idmef_overflow_alert_t object.
19653 * @buffer: pointer to a #idmef_data_t object.
19654 *
19655 * Set @buffer object as a children of @ptr.
19656 * if @ptr already contain an @buffer object, then it is destroyed,
19657 * and updated to point to the provided @buffer object.
19658 */
19659
idmef_overflow_alert_set_buffer(idmef_overflow_alert_t * ptr,idmef_data_t * buffer)19660 void idmef_overflow_alert_set_buffer(idmef_overflow_alert_t *ptr, idmef_data_t *buffer)
19661 {
19662 prelude_return_if_fail(ptr);
19663
19664 if ( ptr->buffer )
19665 idmef_data_destroy(ptr->buffer);
19666
19667 ptr->buffer = buffer;
19668 }
19669
19670 /**
19671 * idmef_overflow_alert_new_buffer:
19672 * @ptr: pointer to a #idmef_overflow_alert_t object.
19673 * @ret: pointer to an address where to store the created #idmef_data_t object.
19674 *
19675 * Create a new buffer object, children of #idmef_overflow_alert_t.
19676 * If @ptr already contain a #idmef_data_t object, then it is destroyed.
19677 *
19678 * Returns: 0 on success, or a negative value if an error occured.
19679 */
idmef_overflow_alert_new_buffer(idmef_overflow_alert_t * ptr,idmef_data_t ** ret)19680 int idmef_overflow_alert_new_buffer(idmef_overflow_alert_t *ptr, idmef_data_t **ret)
19681 {
19682 int retval;
19683
19684 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
19685
19686 if ( ! ptr->buffer ) {
19687 retval = idmef_data_new(&ptr->buffer);
19688 if ( retval < 0 )
19689 return retval;
19690 }
19691
19692 *ret = ptr->buffer;
19693 return 0;
19694 }
19695
19696 /**
19697 * idmef_overflow_alert_copy:
19698 * @src: Source of the copy.
19699 * @dst: Where to copy the object.
19700 *
19701 * Copy a new #idmef_overflow_alert_t object from @src to @dst.
19702 *
19703 * Returns: 0 on success, a negative value if an error occured.
19704 */
idmef_overflow_alert_copy(const idmef_overflow_alert_t * src,idmef_overflow_alert_t * dst)19705 int idmef_overflow_alert_copy(const idmef_overflow_alert_t *src, idmef_overflow_alert_t *dst)
19706 {
19707 int ret;
19708
19709 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
19710 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
19711
19712 ret = 0;
19713
19714 if ( src->program ) {
19715 ret = prelude_string_copy(src->program, dst->program);
19716 if ( ret < 0 )
19717 return ret;
19718 }
19719
19720 dst->size_is_set = src->size_is_set;
19721
19722 dst->size = src->size;
19723
19724 if ( src->buffer ) {
19725 ret = idmef_data_clone(src->buffer, &dst->buffer);
19726 if ( ret < 0 )
19727 return ret;
19728 }
19729
19730 return 0;
19731 }
19732
19733 /**
19734 * idmef_overflow_alert_clone:
19735 * @src: Object to be cloned.
19736 * @dst: Address where to store the pointer to the cloned object.
19737 *
19738 * Create a copy of @src, and store it in @dst.
19739 *
19740 * Returns: 0 on success, a negative value if an error occured.
19741 */
idmef_overflow_alert_clone(idmef_overflow_alert_t * src,idmef_overflow_alert_t ** dst)19742 int idmef_overflow_alert_clone(idmef_overflow_alert_t *src, idmef_overflow_alert_t **dst)
19743 {
19744 int ret;
19745
19746 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
19747
19748 ret = idmef_overflow_alert_new(dst);
19749 if ( ret < 0 )
19750 return ret;
19751
19752 return idmef_overflow_alert_copy(src, *dst);
19753 }
19754
19755 /**
19756 * idmef_overflow_alert_compare:
19757 * @obj1: Object to compare with @obj2.
19758 * @obj2: Object to compare with @obj1.
19759 *
19760 * Compare @obj1 with @obj2.
19761 *
19762 * Returns: 0 on match, a negative value on comparison failure.
19763 */
idmef_overflow_alert_compare(const idmef_overflow_alert_t * obj1,const idmef_overflow_alert_t * obj2)19764 int idmef_overflow_alert_compare(const idmef_overflow_alert_t *obj1, const idmef_overflow_alert_t *obj2)
19765 {
19766 int ret = 0;
19767
19768 if ( obj1 == NULL && obj2 == NULL )
19769 return 0;
19770
19771 else if ( obj1 == NULL || obj2 == NULL )
19772 return -1;
19773
19774 ret = prelude_string_compare(obj1->program, obj2->program);
19775 if ( ret != 0 )
19776 return ret;
19777
19778 if ( obj1->size_is_set != obj2->size_is_set )
19779 return -1;
19780
19781 if ( obj1->size_is_set && obj1->size != obj2->size )
19782 return -1;
19783
19784 ret = idmef_data_compare(obj1->buffer, obj2->buffer);
19785 if ( ret != 0 )
19786 return ret;
19787
19788 return ret;
19789 }
19790
19791 /**
19792 * idmef_alert_new:
19793 * @ret: Pointer where to store the created #idmef_alert_t object.
19794 *
19795 * Create a new #idmef_alert_t object.
19796 *
19797 * Returns: 0 on success, a negative value if an error occured.
19798 */
idmef_alert_new(idmef_alert_t ** ret)19799 int idmef_alert_new(idmef_alert_t **ret)
19800 {
19801 *ret = calloc(1, sizeof(**ret));
19802 if ( ! *ret )
19803 return prelude_error_from_errno(errno);
19804
19805 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_ALERT;
19806
19807 (*ret)->refcount = 1;
19808
19809 prelude_list_init(&(*ret)->analyzer_list);
19810
19811
19812 prelude_list_init(&(*ret)->source_list);
19813
19814
19815 prelude_list_init(&(*ret)->target_list);
19816
19817
19818 prelude_list_init(&(*ret)->additional_data_list);
19819
19820
19821 {
19822 int retval = idmef_time_new(&(*ret)->create_time);
19823
19824 if ( retval < 0 ) {
19825 idmef_alert_destroy(*ret);
19826 *ret = NULL;
19827 return retval;
19828 }
19829 }
19830
19831 idmef_time_set_from_gettimeofday((*ret)->create_time);
19832
19833 {
19834 int retval = idmef_classification_new(&(*ret)->classification);
19835
19836 if ( retval < 0 ) {
19837 idmef_alert_destroy(*ret);
19838 *ret = NULL;
19839 return retval;
19840 }
19841 }
19842
19843 return 0;
19844
19845 }
19846
19847 /**
19848 * idmef_alert_ref:
19849 * @alert: pointer to a #idmef_alert_t object.
19850 *
19851 * Increase @alert reference count, so that it can be referenced
19852 * multiple time.
19853 *
19854 * Returns: a pointer to @alert.
19855 */
idmef_alert_ref(idmef_alert_t * alert)19856 idmef_alert_t *idmef_alert_ref(idmef_alert_t *alert)
19857 {
19858 prelude_return_val_if_fail(alert, NULL);
19859 alert->refcount++;
19860
19861 return alert;
19862 }
19863
_idmef_alert_get_child(void * p,idmef_class_child_id_t child,void ** childptr)19864 int _idmef_alert_get_child(void *p, idmef_class_child_id_t child, void **childptr)
19865 {
19866 idmef_alert_t *ptr = p;
19867
19868 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
19869 *childptr = NULL;
19870
19871 switch ( child ) {
19872
19873 case 0:
19874 return get_value_from_string((idmef_value_t **) childptr, ptr->messageid, TRUE);
19875 case 1:
19876 *childptr = &ptr->analyzer_list;
19877 return 0;
19878
19879 case 2:
19880 return get_value_from_time((idmef_value_t **) childptr, ptr->create_time, TRUE);
19881 case 3:
19882 *childptr = ptr->classification;
19883 return 0;
19884
19885 case 4:
19886 return get_value_from_time((idmef_value_t **) childptr, ptr->detect_time, TRUE);
19887 case 5:
19888 return get_value_from_time((idmef_value_t **) childptr, ptr->analyzer_time, TRUE);
19889 case 6:
19890 *childptr = &ptr->source_list;
19891 return 0;
19892
19893 case 7:
19894 *childptr = &ptr->target_list;
19895 return 0;
19896
19897 case 8:
19898 *childptr = ptr->assessment;
19899 return 0;
19900
19901 case 9:
19902 *childptr = &ptr->additional_data_list;
19903 return 0;
19904
19905 case 10:
19906 *childptr = ( ptr->type == IDMEF_ALERT_TYPE_TOOL ) ? ptr->detail.tool_alert : NULL;
19907 return 0;
19908
19909 case 11:
19910 *childptr = ( ptr->type == IDMEF_ALERT_TYPE_CORRELATION ) ? ptr->detail.correlation_alert : NULL;
19911 return 0;
19912
19913 case 12:
19914 *childptr = ( ptr->type == IDMEF_ALERT_TYPE_OVERFLOW ) ? ptr->detail.overflow_alert : NULL;
19915 return 0;
19916
19917 default:
19918 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
19919 }
19920 }
19921
_idmef_alert_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)19922 int _idmef_alert_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
19923 {
19924 idmef_alert_t *ptr = p;
19925
19926 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
19927
19928 switch ( child ) {
19929
19930 case 0:
19931 return idmef_alert_new_messageid(ptr, (prelude_string_t **) ret);
19932
19933 case 1: {
19934 int i = 0;
19935 prelude_list_t *tmp;
19936
19937 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
19938 return idmef_alert_new_analyzer(ptr, (idmef_analyzer_t **) ret, n);
19939
19940 if ( n >= 0 ) {
19941 prelude_list_for_each(&ptr->analyzer_list, tmp) {
19942 if ( i++ == n ) {
19943 *ret = prelude_linked_object_get_object(tmp);
19944 return 0;
19945 }
19946 }
19947
19948 if ( i != n )
19949 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
19950 } else {
19951 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
19952
19953 prelude_list_for_each_reversed(&ptr->analyzer_list, tmp) {
19954 if ( i++ == pos ) {
19955 *ret = prelude_linked_object_get_object(tmp);
19956 return 0;
19957 }
19958 }
19959
19960 if ( i != pos )
19961 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
19962 }
19963
19964 return idmef_alert_new_analyzer(ptr, (idmef_analyzer_t **) ret, n);
19965 }
19966
19967 case 2:
19968 return idmef_alert_new_create_time(ptr, (idmef_time_t **) ret);
19969
19970 case 3:
19971 return idmef_alert_new_classification(ptr, (idmef_classification_t **) ret);
19972
19973 case 4:
19974 return idmef_alert_new_detect_time(ptr, (idmef_time_t **) ret);
19975
19976 case 5:
19977 return idmef_alert_new_analyzer_time(ptr, (idmef_time_t **) ret);
19978
19979 case 6: {
19980 int i = 0;
19981 prelude_list_t *tmp;
19982
19983 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
19984 return idmef_alert_new_source(ptr, (idmef_source_t **) ret, n);
19985
19986 if ( n >= 0 ) {
19987 prelude_list_for_each(&ptr->source_list, tmp) {
19988 if ( i++ == n ) {
19989 *ret = prelude_linked_object_get_object(tmp);
19990 return 0;
19991 }
19992 }
19993
19994 if ( i != n )
19995 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
19996 } else {
19997 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
19998
19999 prelude_list_for_each_reversed(&ptr->source_list, tmp) {
20000 if ( i++ == pos ) {
20001 *ret = prelude_linked_object_get_object(tmp);
20002 return 0;
20003 }
20004 }
20005
20006 if ( i != pos )
20007 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
20008 }
20009
20010 return idmef_alert_new_source(ptr, (idmef_source_t **) ret, n);
20011 }
20012
20013 case 7: {
20014 int i = 0;
20015 prelude_list_t *tmp;
20016
20017 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
20018 return idmef_alert_new_target(ptr, (idmef_target_t **) ret, n);
20019
20020 if ( n >= 0 ) {
20021 prelude_list_for_each(&ptr->target_list, tmp) {
20022 if ( i++ == n ) {
20023 *ret = prelude_linked_object_get_object(tmp);
20024 return 0;
20025 }
20026 }
20027
20028 if ( i != n )
20029 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
20030 } else {
20031 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
20032
20033 prelude_list_for_each_reversed(&ptr->target_list, tmp) {
20034 if ( i++ == pos ) {
20035 *ret = prelude_linked_object_get_object(tmp);
20036 return 0;
20037 }
20038 }
20039
20040 if ( i != pos )
20041 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
20042 }
20043
20044 return idmef_alert_new_target(ptr, (idmef_target_t **) ret, n);
20045 }
20046
20047 case 8:
20048 return idmef_alert_new_assessment(ptr, (idmef_assessment_t **) ret);
20049
20050 case 9: {
20051 int i = 0;
20052 prelude_list_t *tmp;
20053
20054 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
20055 return idmef_alert_new_additional_data(ptr, (idmef_additional_data_t **) ret, n);
20056
20057 if ( n >= 0 ) {
20058 prelude_list_for_each(&ptr->additional_data_list, tmp) {
20059 if ( i++ == n ) {
20060 *ret = prelude_linked_object_get_object(tmp);
20061 return 0;
20062 }
20063 }
20064
20065 if ( i != n )
20066 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
20067 } else {
20068 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
20069
20070 prelude_list_for_each_reversed(&ptr->additional_data_list, tmp) {
20071 if ( i++ == pos ) {
20072 *ret = prelude_linked_object_get_object(tmp);
20073 return 0;
20074 }
20075 }
20076
20077 if ( i != pos )
20078 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
20079 }
20080
20081 return idmef_alert_new_additional_data(ptr, (idmef_additional_data_t **) ret, n);
20082 }
20083
20084 case 10:
20085 return idmef_alert_new_tool_alert(ptr, (idmef_tool_alert_t **) ret);
20086
20087 case 11:
20088 return idmef_alert_new_correlation_alert(ptr, (idmef_correlation_alert_t **) ret);
20089
20090 case 12:
20091 return idmef_alert_new_overflow_alert(ptr, (idmef_overflow_alert_t **) ret);
20092
20093 default:
20094 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
20095 }
20096 }
20097
_idmef_alert_destroy_child(void * p,idmef_class_child_id_t child,int n)20098 int _idmef_alert_destroy_child(void *p, idmef_class_child_id_t child, int n)
20099 {
20100 idmef_alert_t *ptr = p;
20101
20102 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
20103
20104 switch ( child ) {
20105
20106 case 0:
20107 if ( ptr->messageid ) {
20108 prelude_string_destroy(ptr->messageid);
20109 ptr->messageid = NULL;
20110 }
20111
20112 return 0;
20113
20114 case 1: {
20115 int i = 0;
20116 prelude_list_t *tmp;
20117
20118 if ( n >= 0 ) {
20119 prelude_list_for_each(&ptr->analyzer_list, tmp) {
20120 if ( i++ == n ) {
20121 void *b = prelude_linked_object_get_object(tmp);
20122 idmef_analyzer_destroy(b);
20123 return 0;
20124 }
20125 }
20126
20127 if ( i != n )
20128 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
20129 } else {
20130 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
20131
20132 prelude_list_for_each_reversed(&ptr->analyzer_list, tmp) {
20133 if ( i++ == pos ) {
20134 void *b = prelude_linked_object_get_object(tmp);
20135 idmef_analyzer_destroy(b);
20136 return 0;
20137 }
20138 }
20139
20140 if ( i != pos )
20141 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
20142 }
20143 }
20144
20145 case 2:
20146 if ( ptr->create_time ) {
20147 idmef_time_destroy(ptr->create_time);
20148 ptr->create_time = NULL;
20149 }
20150
20151 return 0;
20152
20153 case 3:
20154 if ( ptr->classification ) {
20155 idmef_classification_destroy(ptr->classification);
20156 ptr->classification = NULL;
20157 }
20158
20159 return 0;
20160
20161 case 4:
20162 if ( ptr->detect_time ) {
20163 idmef_time_destroy(ptr->detect_time);
20164 ptr->detect_time = NULL;
20165 }
20166
20167 return 0;
20168
20169 case 5:
20170 if ( ptr->analyzer_time ) {
20171 idmef_time_destroy(ptr->analyzer_time);
20172 ptr->analyzer_time = NULL;
20173 }
20174
20175 return 0;
20176
20177 case 6: {
20178 int i = 0;
20179 prelude_list_t *tmp;
20180
20181 if ( n >= 0 ) {
20182 prelude_list_for_each(&ptr->source_list, tmp) {
20183 if ( i++ == n ) {
20184 void *b = prelude_linked_object_get_object(tmp);
20185 idmef_source_destroy(b);
20186 return 0;
20187 }
20188 }
20189
20190 if ( i != n )
20191 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
20192 } else {
20193 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
20194
20195 prelude_list_for_each_reversed(&ptr->source_list, tmp) {
20196 if ( i++ == pos ) {
20197 void *b = prelude_linked_object_get_object(tmp);
20198 idmef_source_destroy(b);
20199 return 0;
20200 }
20201 }
20202
20203 if ( i != pos )
20204 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
20205 }
20206 }
20207
20208 case 7: {
20209 int i = 0;
20210 prelude_list_t *tmp;
20211
20212 if ( n >= 0 ) {
20213 prelude_list_for_each(&ptr->target_list, tmp) {
20214 if ( i++ == n ) {
20215 void *b = prelude_linked_object_get_object(tmp);
20216 idmef_target_destroy(b);
20217 return 0;
20218 }
20219 }
20220
20221 if ( i != n )
20222 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
20223 } else {
20224 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
20225
20226 prelude_list_for_each_reversed(&ptr->target_list, tmp) {
20227 if ( i++ == pos ) {
20228 void *b = prelude_linked_object_get_object(tmp);
20229 idmef_target_destroy(b);
20230 return 0;
20231 }
20232 }
20233
20234 if ( i != pos )
20235 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
20236 }
20237 }
20238
20239 case 8:
20240 if ( ptr->assessment ) {
20241 idmef_assessment_destroy(ptr->assessment);
20242 ptr->assessment = NULL;
20243 }
20244
20245 return 0;
20246
20247 case 9: {
20248 int i = 0;
20249 prelude_list_t *tmp;
20250
20251 if ( n >= 0 ) {
20252 prelude_list_for_each(&ptr->additional_data_list, tmp) {
20253 if ( i++ == n ) {
20254 void *b = prelude_linked_object_get_object(tmp);
20255 idmef_additional_data_destroy(b);
20256 return 0;
20257 }
20258 }
20259
20260 if ( i != n )
20261 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
20262 } else {
20263 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
20264
20265 prelude_list_for_each_reversed(&ptr->additional_data_list, tmp) {
20266 if ( i++ == pos ) {
20267 void *b = prelude_linked_object_get_object(tmp);
20268 idmef_additional_data_destroy(b);
20269 return 0;
20270 }
20271 }
20272
20273 if ( i != pos )
20274 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
20275 }
20276 }
20277
20278 case 10:
20279 if ( ptr->type != IDMEF_ALERT_TYPE_TOOL )
20280 return 0;
20281
20282 idmef_tool_alert_destroy(ptr->detail.tool_alert);
20283 ptr->detail.tool_alert = NULL;
20284 ptr->type = 0;
20285
20286 return 0;
20287
20288 case 11:
20289 if ( ptr->type != IDMEF_ALERT_TYPE_CORRELATION )
20290 return 0;
20291
20292 idmef_correlation_alert_destroy(ptr->detail.correlation_alert);
20293 ptr->detail.correlation_alert = NULL;
20294 ptr->type = 0;
20295
20296 return 0;
20297
20298 case 12:
20299 if ( ptr->type != IDMEF_ALERT_TYPE_OVERFLOW )
20300 return 0;
20301
20302 idmef_overflow_alert_destroy(ptr->detail.overflow_alert);
20303 ptr->detail.overflow_alert = NULL;
20304 ptr->type = 0;
20305
20306 return 0;
20307
20308 default:
20309 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
20310 }
20311 }
20312
idmef_alert_destroy_internal(idmef_alert_t * ptr)20313 static void idmef_alert_destroy_internal(idmef_alert_t *ptr)
20314 {
20315 prelude_return_if_fail(ptr);
20316
20317 if ( ptr->messageid ) {
20318 prelude_string_destroy(ptr->messageid);
20319 ptr->messageid = NULL;
20320 }
20321
20322 {
20323 prelude_list_t *n, *tmp;
20324 idmef_analyzer_t *entry;
20325
20326 prelude_list_for_each_safe(&ptr->analyzer_list, tmp, n) {
20327 entry = prelude_linked_object_get_object(tmp);
20328 prelude_list_del_init(tmp);
20329 idmef_analyzer_destroy(entry);
20330 }
20331 }
20332
20333 if ( ptr->create_time ) {
20334 idmef_time_destroy(ptr->create_time);
20335 ptr->create_time = NULL;
20336 }
20337
20338 if ( ptr->classification ) {
20339 idmef_classification_destroy(ptr->classification);
20340 ptr->classification = NULL;
20341 }
20342
20343 if ( ptr->detect_time ) {
20344 idmef_time_destroy(ptr->detect_time);
20345 ptr->detect_time = NULL;
20346 }
20347
20348 if ( ptr->analyzer_time ) {
20349 idmef_time_destroy(ptr->analyzer_time);
20350 ptr->analyzer_time = NULL;
20351 }
20352
20353 {
20354 prelude_list_t *n, *tmp;
20355 idmef_source_t *entry;
20356
20357 prelude_list_for_each_safe(&ptr->source_list, tmp, n) {
20358 entry = prelude_linked_object_get_object(tmp);
20359 prelude_list_del_init(tmp);
20360 idmef_source_destroy(entry);
20361 }
20362 }
20363
20364 {
20365 prelude_list_t *n, *tmp;
20366 idmef_target_t *entry;
20367
20368 prelude_list_for_each_safe(&ptr->target_list, tmp, n) {
20369 entry = prelude_linked_object_get_object(tmp);
20370 prelude_list_del_init(tmp);
20371 idmef_target_destroy(entry);
20372 }
20373 }
20374
20375 if ( ptr->assessment ) {
20376 idmef_assessment_destroy(ptr->assessment);
20377 ptr->assessment = NULL;
20378 }
20379
20380 {
20381 prelude_list_t *n, *tmp;
20382 idmef_additional_data_t *entry;
20383
20384 prelude_list_for_each_safe(&ptr->additional_data_list, tmp, n) {
20385 entry = prelude_linked_object_get_object(tmp);
20386 prelude_list_del_init(tmp);
20387 idmef_additional_data_destroy(entry);
20388 }
20389 }
20390
20391 switch ( ptr->type ) {
20392
20393 case IDMEF_ALERT_TYPE_TOOL:
20394 idmef_tool_alert_destroy(ptr->detail.tool_alert);
20395 ptr->detail.tool_alert = NULL;
20396 break;
20397
20398 case IDMEF_ALERT_TYPE_CORRELATION:
20399 idmef_correlation_alert_destroy(ptr->detail.correlation_alert);
20400 ptr->detail.correlation_alert = NULL;
20401 break;
20402
20403 case IDMEF_ALERT_TYPE_OVERFLOW:
20404 idmef_overflow_alert_destroy(ptr->detail.overflow_alert);
20405 ptr->detail.overflow_alert = NULL;
20406 break;
20407
20408 default:
20409 break;
20410 }
20411
20412
20413 /* free() should be done by the caller */
20414 }
20415
20416 /**
20417 * idmef_alert_destroy:
20418 * @ptr: pointer to a #idmef_alert_t object.
20419 *
20420 * Destroy @ptr and all of it's children.
20421 * The objects are only destroyed if their reference count reach zero.
20422 */
20423
idmef_alert_destroy(idmef_alert_t * ptr)20424 void idmef_alert_destroy(idmef_alert_t *ptr)
20425 {
20426 prelude_return_if_fail(ptr);
20427
20428 if ( --ptr->refcount )
20429 return;
20430
20431 idmef_alert_destroy_internal(ptr);
20432 free(ptr);
20433 }
20434
20435 /**
20436 * idmef_alert_get_messageid:
20437 * @ptr: pointer to a #idmef_alert_t object.
20438 *
20439 * Get messageid children of the #idmef_alert_t object.
20440 *
20441 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
20442 */
idmef_alert_get_messageid(idmef_alert_t * ptr)20443 prelude_string_t *idmef_alert_get_messageid(idmef_alert_t *ptr)
20444 {
20445 prelude_return_val_if_fail(ptr, 0); /* FIXME */
20446
20447 return ptr->messageid;
20448 }
20449
20450 /**
20451 * idmef_alert_set_messageid:
20452 * @ptr: pointer to a #idmef_alert_t object.
20453 * @messageid: pointer to a #prelude_string_t object.
20454 *
20455 * Set @messageid object as a children of @ptr.
20456 * if @ptr already contain an @messageid object, then it is destroyed,
20457 * and updated to point to the provided @messageid object.
20458 */
20459
idmef_alert_set_messageid(idmef_alert_t * ptr,prelude_string_t * messageid)20460 void idmef_alert_set_messageid(idmef_alert_t *ptr, prelude_string_t *messageid)
20461 {
20462 prelude_return_if_fail(ptr);
20463
20464 if ( ptr->messageid )
20465 prelude_string_destroy(ptr->messageid);
20466
20467 ptr->messageid = messageid;
20468 }
20469
20470 /**
20471 * idmef_alert_new_messageid:
20472 * @ptr: pointer to a #idmef_alert_t object.
20473 * @ret: pointer to an address where to store the created #prelude_string_t object.
20474 *
20475 * Create a new messageid object, children of #idmef_alert_t.
20476 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
20477 *
20478 * Returns: 0 on success, or a negative value if an error occured.
20479 */
idmef_alert_new_messageid(idmef_alert_t * ptr,prelude_string_t ** ret)20480 int idmef_alert_new_messageid(idmef_alert_t *ptr, prelude_string_t **ret)
20481 {
20482 int retval;
20483
20484 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
20485
20486 if ( ! ptr->messageid ) {
20487 retval = prelude_string_new(&ptr->messageid);
20488 if ( retval < 0 )
20489 return retval;
20490 }
20491
20492 *ret = ptr->messageid;
20493 return 0;
20494 }
20495
20496 /**
20497 * idmef_alert_get_next_analyzer:
20498 * @alert: pointer to a #idmef_alert_t object.
20499 * @analyzer_cur: pointer to a #idmef_analyzer_t object.
20500 *
20501 * Get the next #idmef_analyzer_t object listed in @ptr.
20502 * When iterating over the idmef_analyzer_t object listed in @ptr,
20503 * @object should be set to the latest returned #idmef_analyzer_t object.
20504 *
20505 * Returns: the next #idmef_analyzer_t in the list.
20506 */
idmef_alert_get_next_analyzer(idmef_alert_t * alert,idmef_analyzer_t * analyzer_cur)20507 idmef_analyzer_t *idmef_alert_get_next_analyzer(idmef_alert_t *alert, idmef_analyzer_t *analyzer_cur)
20508 {
20509 prelude_list_t *tmp = (analyzer_cur) ? &((prelude_linked_object_t *) analyzer_cur)->_list : NULL;
20510
20511 prelude_return_val_if_fail(alert, NULL);
20512
20513 prelude_list_for_each_continue(&alert->analyzer_list, tmp)
20514 return prelude_linked_object_get_object(tmp);
20515
20516 return NULL;
20517 }
20518
20519
20520 /**
20521 * idmef_alert_set_analyzer:
20522 * @ptr: pointer to a #idmef_alert_t object.
20523 * @object: pointer to a #idmef_analyzer_t object.
20524 * @pos: Position in the list.
20525 *
20526 * Add @object to position @pos of @ptr list of #idmef_analyzer_t object.
20527 *
20528 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
20529 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
20530 */
idmef_alert_set_analyzer(idmef_alert_t * ptr,idmef_analyzer_t * object,int pos)20531 void idmef_alert_set_analyzer(idmef_alert_t *ptr, idmef_analyzer_t *object, int pos)
20532 {
20533 prelude_return_if_fail(ptr);
20534 prelude_return_if_fail(object);
20535
20536 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
20537 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
20538
20539 list_insert(&ptr->analyzer_list, &((prelude_linked_object_t *) object)->_list, pos);
20540 }
20541
20542
20543 /**
20544 * idmef_alert_new_analyzer:
20545 * @ptr: pointer to a #idmef_alert_t object.
20546 * @ret: pointer to an address where to store the created #idmef_analyzer_t object.
20547 * @pos: position in the list.
20548 *
20549 * Create a new #idmef_analyzer_t children of @ptr, and add it to position @pos of
20550 * @ptr list of #idmef_analyzer_t object. The created #idmef_analyzer_t object is
20551 * stored in @ret.
20552 *
20553 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
20554 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
20555 *
20556 * Returns: 0 on success, or a negative value if an error occured.
20557 */
idmef_alert_new_analyzer(idmef_alert_t * ptr,idmef_analyzer_t ** ret,int pos)20558 int idmef_alert_new_analyzer(idmef_alert_t *ptr, idmef_analyzer_t **ret, int pos)
20559 {
20560 int retval;
20561
20562 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
20563
20564 retval = idmef_analyzer_new(ret);
20565 if ( retval < 0 )
20566 return retval;
20567
20568 list_insert(&ptr->analyzer_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
20569
20570 return 0;
20571 }
20572
20573
20574 /**
20575 * idmef_alert_get_create_time:
20576 * @ptr: pointer to a #idmef_alert_t object.
20577 *
20578 * Get create_time children of the #idmef_alert_t object.
20579 *
20580 * Returns: a pointer to a idmef_time_t object, or NULL if the children object is not set.
20581 */
idmef_alert_get_create_time(idmef_alert_t * ptr)20582 idmef_time_t *idmef_alert_get_create_time(idmef_alert_t *ptr)
20583 {
20584 prelude_return_val_if_fail(ptr, 0); /* FIXME */
20585
20586 return ptr->create_time;
20587 }
20588
20589 /**
20590 * idmef_alert_set_create_time:
20591 * @ptr: pointer to a #idmef_alert_t object.
20592 * @create_time: pointer to a #idmef_time_t object.
20593 *
20594 * Set @create_time object as a children of @ptr.
20595 * if @ptr already contain an @create_time object, then it is destroyed,
20596 * and updated to point to the provided @create_time object.
20597 */
20598
idmef_alert_set_create_time(idmef_alert_t * ptr,idmef_time_t * create_time)20599 void idmef_alert_set_create_time(idmef_alert_t *ptr, idmef_time_t *create_time)
20600 {
20601 prelude_return_if_fail(ptr);
20602
20603 if ( ptr->create_time )
20604 idmef_time_destroy(ptr->create_time);
20605
20606 ptr->create_time = create_time;
20607 }
20608
20609 /**
20610 * idmef_alert_new_create_time:
20611 * @ptr: pointer to a #idmef_alert_t object.
20612 * @ret: pointer to an address where to store the created #idmef_time_t object.
20613 *
20614 * Create a new create_time object, children of #idmef_alert_t.
20615 * If @ptr already contain a #idmef_time_t object, then it is destroyed.
20616 *
20617 * Returns: 0 on success, or a negative value if an error occured.
20618 */
idmef_alert_new_create_time(idmef_alert_t * ptr,idmef_time_t ** ret)20619 int idmef_alert_new_create_time(idmef_alert_t *ptr, idmef_time_t **ret)
20620 {
20621 int retval;
20622
20623 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
20624
20625 if ( ! ptr->create_time ) {
20626 retval = idmef_time_new(&ptr->create_time);
20627 if ( retval < 0 )
20628 return retval;
20629 }
20630
20631 *ret = ptr->create_time;
20632 return 0;
20633 }
20634
20635 /**
20636 * idmef_alert_get_classification:
20637 * @ptr: pointer to a #idmef_alert_t object.
20638 *
20639 * Get classification children of the #idmef_alert_t object.
20640 *
20641 * Returns: a pointer to a idmef_classification_t object, or NULL if the children object is not set.
20642 */
idmef_alert_get_classification(idmef_alert_t * ptr)20643 idmef_classification_t *idmef_alert_get_classification(idmef_alert_t *ptr)
20644 {
20645 prelude_return_val_if_fail(ptr, 0); /* FIXME */
20646
20647 return ptr->classification;
20648 }
20649
20650 /**
20651 * idmef_alert_set_classification:
20652 * @ptr: pointer to a #idmef_alert_t object.
20653 * @classification: pointer to a #idmef_classification_t object.
20654 *
20655 * Set @classification object as a children of @ptr.
20656 * if @ptr already contain an @classification object, then it is destroyed,
20657 * and updated to point to the provided @classification object.
20658 */
20659
idmef_alert_set_classification(idmef_alert_t * ptr,idmef_classification_t * classification)20660 void idmef_alert_set_classification(idmef_alert_t *ptr, idmef_classification_t *classification)
20661 {
20662 prelude_return_if_fail(ptr);
20663
20664 if ( ptr->classification )
20665 idmef_classification_destroy(ptr->classification);
20666
20667 ptr->classification = classification;
20668 }
20669
20670 /**
20671 * idmef_alert_new_classification:
20672 * @ptr: pointer to a #idmef_alert_t object.
20673 * @ret: pointer to an address where to store the created #idmef_classification_t object.
20674 *
20675 * Create a new classification object, children of #idmef_alert_t.
20676 * If @ptr already contain a #idmef_classification_t object, then it is destroyed.
20677 *
20678 * Returns: 0 on success, or a negative value if an error occured.
20679 */
idmef_alert_new_classification(idmef_alert_t * ptr,idmef_classification_t ** ret)20680 int idmef_alert_new_classification(idmef_alert_t *ptr, idmef_classification_t **ret)
20681 {
20682 int retval;
20683
20684 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
20685
20686 if ( ! ptr->classification ) {
20687 retval = idmef_classification_new(&ptr->classification);
20688 if ( retval < 0 )
20689 return retval;
20690 }
20691
20692 *ret = ptr->classification;
20693 return 0;
20694 }
20695
20696 /**
20697 * idmef_alert_get_detect_time:
20698 * @ptr: pointer to a #idmef_alert_t object.
20699 *
20700 * Get detect_time children of the #idmef_alert_t object.
20701 *
20702 * Returns: a pointer to a idmef_time_t object, or NULL if the children object is not set.
20703 */
idmef_alert_get_detect_time(idmef_alert_t * ptr)20704 idmef_time_t *idmef_alert_get_detect_time(idmef_alert_t *ptr)
20705 {
20706 prelude_return_val_if_fail(ptr, 0); /* FIXME */
20707
20708 return ptr->detect_time;
20709 }
20710
20711 /**
20712 * idmef_alert_set_detect_time:
20713 * @ptr: pointer to a #idmef_alert_t object.
20714 * @detect_time: pointer to a #idmef_time_t object.
20715 *
20716 * Set @detect_time object as a children of @ptr.
20717 * if @ptr already contain an @detect_time object, then it is destroyed,
20718 * and updated to point to the provided @detect_time object.
20719 */
20720
idmef_alert_set_detect_time(idmef_alert_t * ptr,idmef_time_t * detect_time)20721 void idmef_alert_set_detect_time(idmef_alert_t *ptr, idmef_time_t *detect_time)
20722 {
20723 prelude_return_if_fail(ptr);
20724
20725 if ( ptr->detect_time )
20726 idmef_time_destroy(ptr->detect_time);
20727
20728 ptr->detect_time = detect_time;
20729 }
20730
20731 /**
20732 * idmef_alert_new_detect_time:
20733 * @ptr: pointer to a #idmef_alert_t object.
20734 * @ret: pointer to an address where to store the created #idmef_time_t object.
20735 *
20736 * Create a new detect_time object, children of #idmef_alert_t.
20737 * If @ptr already contain a #idmef_time_t object, then it is destroyed.
20738 *
20739 * Returns: 0 on success, or a negative value if an error occured.
20740 */
idmef_alert_new_detect_time(idmef_alert_t * ptr,idmef_time_t ** ret)20741 int idmef_alert_new_detect_time(idmef_alert_t *ptr, idmef_time_t **ret)
20742 {
20743 int retval;
20744
20745 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
20746
20747 if ( ! ptr->detect_time ) {
20748 retval = idmef_time_new(&ptr->detect_time);
20749 if ( retval < 0 )
20750 return retval;
20751 }
20752
20753 *ret = ptr->detect_time;
20754 return 0;
20755 }
20756
20757 /**
20758 * idmef_alert_get_analyzer_time:
20759 * @ptr: pointer to a #idmef_alert_t object.
20760 *
20761 * Get analyzer_time children of the #idmef_alert_t object.
20762 *
20763 * Returns: a pointer to a idmef_time_t object, or NULL if the children object is not set.
20764 */
idmef_alert_get_analyzer_time(idmef_alert_t * ptr)20765 idmef_time_t *idmef_alert_get_analyzer_time(idmef_alert_t *ptr)
20766 {
20767 prelude_return_val_if_fail(ptr, 0); /* FIXME */
20768
20769 return ptr->analyzer_time;
20770 }
20771
20772 /**
20773 * idmef_alert_set_analyzer_time:
20774 * @ptr: pointer to a #idmef_alert_t object.
20775 * @analyzer_time: pointer to a #idmef_time_t object.
20776 *
20777 * Set @analyzer_time object as a children of @ptr.
20778 * if @ptr already contain an @analyzer_time object, then it is destroyed,
20779 * and updated to point to the provided @analyzer_time object.
20780 */
20781
idmef_alert_set_analyzer_time(idmef_alert_t * ptr,idmef_time_t * analyzer_time)20782 void idmef_alert_set_analyzer_time(idmef_alert_t *ptr, idmef_time_t *analyzer_time)
20783 {
20784 prelude_return_if_fail(ptr);
20785
20786 if ( ptr->analyzer_time )
20787 idmef_time_destroy(ptr->analyzer_time);
20788
20789 ptr->analyzer_time = analyzer_time;
20790 }
20791
20792 /**
20793 * idmef_alert_new_analyzer_time:
20794 * @ptr: pointer to a #idmef_alert_t object.
20795 * @ret: pointer to an address where to store the created #idmef_time_t object.
20796 *
20797 * Create a new analyzer_time object, children of #idmef_alert_t.
20798 * If @ptr already contain a #idmef_time_t object, then it is destroyed.
20799 *
20800 * Returns: 0 on success, or a negative value if an error occured.
20801 */
idmef_alert_new_analyzer_time(idmef_alert_t * ptr,idmef_time_t ** ret)20802 int idmef_alert_new_analyzer_time(idmef_alert_t *ptr, idmef_time_t **ret)
20803 {
20804 int retval;
20805
20806 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
20807
20808 if ( ! ptr->analyzer_time ) {
20809 retval = idmef_time_new(&ptr->analyzer_time);
20810 if ( retval < 0 )
20811 return retval;
20812 }
20813
20814 *ret = ptr->analyzer_time;
20815 return 0;
20816 }
20817
20818 /**
20819 * idmef_alert_get_next_source:
20820 * @alert: pointer to a #idmef_alert_t object.
20821 * @source_cur: pointer to a #idmef_source_t object.
20822 *
20823 * Get the next #idmef_source_t object listed in @ptr.
20824 * When iterating over the idmef_source_t object listed in @ptr,
20825 * @object should be set to the latest returned #idmef_source_t object.
20826 *
20827 * Returns: the next #idmef_source_t in the list.
20828 */
idmef_alert_get_next_source(idmef_alert_t * alert,idmef_source_t * source_cur)20829 idmef_source_t *idmef_alert_get_next_source(idmef_alert_t *alert, idmef_source_t *source_cur)
20830 {
20831 prelude_list_t *tmp = (source_cur) ? &((prelude_linked_object_t *) source_cur)->_list : NULL;
20832
20833 prelude_return_val_if_fail(alert, NULL);
20834
20835 prelude_list_for_each_continue(&alert->source_list, tmp)
20836 return prelude_linked_object_get_object(tmp);
20837
20838 return NULL;
20839 }
20840
20841
20842 /**
20843 * idmef_alert_set_source:
20844 * @ptr: pointer to a #idmef_alert_t object.
20845 * @object: pointer to a #idmef_source_t object.
20846 * @pos: Position in the list.
20847 *
20848 * Add @object to position @pos of @ptr list of #idmef_source_t object.
20849 *
20850 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
20851 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
20852 */
idmef_alert_set_source(idmef_alert_t * ptr,idmef_source_t * object,int pos)20853 void idmef_alert_set_source(idmef_alert_t *ptr, idmef_source_t *object, int pos)
20854 {
20855 prelude_return_if_fail(ptr);
20856 prelude_return_if_fail(object);
20857
20858 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
20859 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
20860
20861 list_insert(&ptr->source_list, &((prelude_linked_object_t *) object)->_list, pos);
20862 }
20863
20864
20865 /**
20866 * idmef_alert_new_source:
20867 * @ptr: pointer to a #idmef_alert_t object.
20868 * @ret: pointer to an address where to store the created #idmef_source_t object.
20869 * @pos: position in the list.
20870 *
20871 * Create a new #idmef_source_t children of @ptr, and add it to position @pos of
20872 * @ptr list of #idmef_source_t object. The created #idmef_source_t object is
20873 * stored in @ret.
20874 *
20875 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
20876 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
20877 *
20878 * Returns: 0 on success, or a negative value if an error occured.
20879 */
idmef_alert_new_source(idmef_alert_t * ptr,idmef_source_t ** ret,int pos)20880 int idmef_alert_new_source(idmef_alert_t *ptr, idmef_source_t **ret, int pos)
20881 {
20882 int retval;
20883
20884 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
20885
20886 retval = idmef_source_new(ret);
20887 if ( retval < 0 )
20888 return retval;
20889
20890 list_insert(&ptr->source_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
20891
20892 return 0;
20893 }
20894
20895
20896 /**
20897 * idmef_alert_get_next_target:
20898 * @alert: pointer to a #idmef_alert_t object.
20899 * @target_cur: pointer to a #idmef_target_t object.
20900 *
20901 * Get the next #idmef_target_t object listed in @ptr.
20902 * When iterating over the idmef_target_t object listed in @ptr,
20903 * @object should be set to the latest returned #idmef_target_t object.
20904 *
20905 * Returns: the next #idmef_target_t in the list.
20906 */
idmef_alert_get_next_target(idmef_alert_t * alert,idmef_target_t * target_cur)20907 idmef_target_t *idmef_alert_get_next_target(idmef_alert_t *alert, idmef_target_t *target_cur)
20908 {
20909 prelude_list_t *tmp = (target_cur) ? &((prelude_linked_object_t *) target_cur)->_list : NULL;
20910
20911 prelude_return_val_if_fail(alert, NULL);
20912
20913 prelude_list_for_each_continue(&alert->target_list, tmp)
20914 return prelude_linked_object_get_object(tmp);
20915
20916 return NULL;
20917 }
20918
20919
20920 /**
20921 * idmef_alert_set_target:
20922 * @ptr: pointer to a #idmef_alert_t object.
20923 * @object: pointer to a #idmef_target_t object.
20924 * @pos: Position in the list.
20925 *
20926 * Add @object to position @pos of @ptr list of #idmef_target_t object.
20927 *
20928 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
20929 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
20930 */
idmef_alert_set_target(idmef_alert_t * ptr,idmef_target_t * object,int pos)20931 void idmef_alert_set_target(idmef_alert_t *ptr, idmef_target_t *object, int pos)
20932 {
20933 prelude_return_if_fail(ptr);
20934 prelude_return_if_fail(object);
20935
20936 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
20937 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
20938
20939 list_insert(&ptr->target_list, &((prelude_linked_object_t *) object)->_list, pos);
20940 }
20941
20942
20943 /**
20944 * idmef_alert_new_target:
20945 * @ptr: pointer to a #idmef_alert_t object.
20946 * @ret: pointer to an address where to store the created #idmef_target_t object.
20947 * @pos: position in the list.
20948 *
20949 * Create a new #idmef_target_t children of @ptr, and add it to position @pos of
20950 * @ptr list of #idmef_target_t object. The created #idmef_target_t object is
20951 * stored in @ret.
20952 *
20953 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
20954 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
20955 *
20956 * Returns: 0 on success, or a negative value if an error occured.
20957 */
idmef_alert_new_target(idmef_alert_t * ptr,idmef_target_t ** ret,int pos)20958 int idmef_alert_new_target(idmef_alert_t *ptr, idmef_target_t **ret, int pos)
20959 {
20960 int retval;
20961
20962 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
20963
20964 retval = idmef_target_new(ret);
20965 if ( retval < 0 )
20966 return retval;
20967
20968 list_insert(&ptr->target_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
20969
20970 return 0;
20971 }
20972
20973
20974 /**
20975 * idmef_alert_get_assessment:
20976 * @ptr: pointer to a #idmef_alert_t object.
20977 *
20978 * Get assessment children of the #idmef_alert_t object.
20979 *
20980 * Returns: a pointer to a idmef_assessment_t object, or NULL if the children object is not set.
20981 */
idmef_alert_get_assessment(idmef_alert_t * ptr)20982 idmef_assessment_t *idmef_alert_get_assessment(idmef_alert_t *ptr)
20983 {
20984 prelude_return_val_if_fail(ptr, 0); /* FIXME */
20985
20986 return ptr->assessment;
20987 }
20988
20989 /**
20990 * idmef_alert_set_assessment:
20991 * @ptr: pointer to a #idmef_alert_t object.
20992 * @assessment: pointer to a #idmef_assessment_t object.
20993 *
20994 * Set @assessment object as a children of @ptr.
20995 * if @ptr already contain an @assessment object, then it is destroyed,
20996 * and updated to point to the provided @assessment object.
20997 */
20998
idmef_alert_set_assessment(idmef_alert_t * ptr,idmef_assessment_t * assessment)20999 void idmef_alert_set_assessment(idmef_alert_t *ptr, idmef_assessment_t *assessment)
21000 {
21001 prelude_return_if_fail(ptr);
21002
21003 if ( ptr->assessment )
21004 idmef_assessment_destroy(ptr->assessment);
21005
21006 ptr->assessment = assessment;
21007 }
21008
21009 /**
21010 * idmef_alert_new_assessment:
21011 * @ptr: pointer to a #idmef_alert_t object.
21012 * @ret: pointer to an address where to store the created #idmef_assessment_t object.
21013 *
21014 * Create a new assessment object, children of #idmef_alert_t.
21015 * If @ptr already contain a #idmef_assessment_t object, then it is destroyed.
21016 *
21017 * Returns: 0 on success, or a negative value if an error occured.
21018 */
idmef_alert_new_assessment(idmef_alert_t * ptr,idmef_assessment_t ** ret)21019 int idmef_alert_new_assessment(idmef_alert_t *ptr, idmef_assessment_t **ret)
21020 {
21021 int retval;
21022
21023 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
21024
21025 if ( ! ptr->assessment ) {
21026 retval = idmef_assessment_new(&ptr->assessment);
21027 if ( retval < 0 )
21028 return retval;
21029 }
21030
21031 *ret = ptr->assessment;
21032 return 0;
21033 }
21034
21035 /**
21036 * idmef_alert_get_next_additional_data:
21037 * @alert: pointer to a #idmef_alert_t object.
21038 * @additional_data_cur: pointer to a #idmef_additional_data_t object.
21039 *
21040 * Get the next #idmef_additional_data_t object listed in @ptr.
21041 * When iterating over the idmef_additional_data_t object listed in @ptr,
21042 * @object should be set to the latest returned #idmef_additional_data_t object.
21043 *
21044 * Returns: the next #idmef_additional_data_t in the list.
21045 */
idmef_alert_get_next_additional_data(idmef_alert_t * alert,idmef_additional_data_t * additional_data_cur)21046 idmef_additional_data_t *idmef_alert_get_next_additional_data(idmef_alert_t *alert, idmef_additional_data_t *additional_data_cur)
21047 {
21048 prelude_list_t *tmp = (additional_data_cur) ? &((prelude_linked_object_t *) additional_data_cur)->_list : NULL;
21049
21050 prelude_return_val_if_fail(alert, NULL);
21051
21052 prelude_list_for_each_continue(&alert->additional_data_list, tmp)
21053 return prelude_linked_object_get_object(tmp);
21054
21055 return NULL;
21056 }
21057
21058
21059 /**
21060 * idmef_alert_set_additional_data:
21061 * @ptr: pointer to a #idmef_alert_t object.
21062 * @object: pointer to a #idmef_additional_data_t object.
21063 * @pos: Position in the list.
21064 *
21065 * Add @object to position @pos of @ptr list of #idmef_additional_data_t object.
21066 *
21067 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
21068 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
21069 */
idmef_alert_set_additional_data(idmef_alert_t * ptr,idmef_additional_data_t * object,int pos)21070 void idmef_alert_set_additional_data(idmef_alert_t *ptr, idmef_additional_data_t *object, int pos)
21071 {
21072 prelude_return_if_fail(ptr);
21073 prelude_return_if_fail(object);
21074
21075 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
21076 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
21077
21078 list_insert(&ptr->additional_data_list, &((prelude_linked_object_t *) object)->_list, pos);
21079 }
21080
21081
21082 /**
21083 * idmef_alert_new_additional_data:
21084 * @ptr: pointer to a #idmef_alert_t object.
21085 * @ret: pointer to an address where to store the created #idmef_additional_data_t object.
21086 * @pos: position in the list.
21087 *
21088 * Create a new #idmef_additional_data_t children of @ptr, and add it to position @pos of
21089 * @ptr list of #idmef_additional_data_t object. The created #idmef_additional_data_t object is
21090 * stored in @ret.
21091 *
21092 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
21093 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
21094 *
21095 * Returns: 0 on success, or a negative value if an error occured.
21096 */
idmef_alert_new_additional_data(idmef_alert_t * ptr,idmef_additional_data_t ** ret,int pos)21097 int idmef_alert_new_additional_data(idmef_alert_t *ptr, idmef_additional_data_t **ret, int pos)
21098 {
21099 int retval;
21100
21101 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
21102
21103 retval = idmef_additional_data_new(ret);
21104 if ( retval < 0 )
21105 return retval;
21106
21107 list_insert(&ptr->additional_data_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
21108
21109 return 0;
21110 }
21111
21112
21113 /**
21114 * idmef_alert_get_type:
21115 * @ptr: pointer to a #idmef_alert_t object.
21116 *
21117 * Access the type children of @ptr.
21118 *
21119 * Returns: a pointer to the #idmef_alert_type_t children, or NULL if it is not set.
21120 */
idmef_alert_get_type(idmef_alert_t * ptr)21121 idmef_alert_type_t idmef_alert_get_type(idmef_alert_t *ptr)
21122 {
21123 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
21124 return ptr->type;
21125 }
21126
21127 /**
21128 * idmef_alert_get_tool_alert:
21129 * @ptr: pointer to a #idmef_alert_t object.
21130 *
21131 * Access the tool_alert children of @ptr.
21132 *
21133 * Returns: a pointer to the #idmef_tool_alert_t children, or NULL if it is not set.
21134 */
idmef_alert_get_tool_alert(idmef_alert_t * ptr)21135 idmef_tool_alert_t *idmef_alert_get_tool_alert(idmef_alert_t *ptr)
21136 {
21137 prelude_return_val_if_fail(ptr, NULL);
21138 return (ptr->type == IDMEF_ALERT_TYPE_TOOL) ? ptr->detail.tool_alert : NULL;
21139 }
21140
21141 /**
21142 * idmef_alert_set_tool_alert:
21143 * @ptr: pointer to a #idmef_alert_t object.
21144 * @tool_alert: pointer to a #idmef_tool_alert_t object.
21145 *
21146 * Set @tool_alert object as a children of @ptr.
21147 * if @ptr already contain a @tool_alert object, then it is destroyed,
21148 * and updated to point to the provided @tool_alert object.
21149 */
idmef_alert_set_tool_alert(idmef_alert_t * ptr,idmef_tool_alert_t * tool_alert)21150 void idmef_alert_set_tool_alert(idmef_alert_t *ptr, idmef_tool_alert_t *tool_alert)
21151 {
21152 prelude_return_if_fail(ptr);
21153
21154 switch ( ptr->type ) {
21155
21156 case IDMEF_ALERT_TYPE_TOOL:
21157 idmef_tool_alert_destroy(ptr->detail.tool_alert);
21158 break;
21159
21160 case IDMEF_ALERT_TYPE_CORRELATION:
21161 idmef_correlation_alert_destroy(ptr->detail.correlation_alert);
21162 break;
21163
21164 case IDMEF_ALERT_TYPE_OVERFLOW:
21165 idmef_overflow_alert_destroy(ptr->detail.overflow_alert);
21166 break;
21167
21168 default:
21169 break;
21170 }
21171
21172 ptr->detail.tool_alert = tool_alert;
21173 ptr->type = (tool_alert) ? IDMEF_ALERT_TYPE_TOOL : 0;
21174 }
21175
21176 /**
21177 * idmef_alert_new_tool_alert:
21178 * @ptr: pointer to a #idmef_alert_t object.
21179 * @ret: pointer where to store the created #idmef_tool_alert_t object.
21180 *
21181 * Create a new idmef_tool_alert_t object, children of #idmef_alert_t.
21182 * If @ptr already contain a #idmef_tool_alert_t object, then it is destroyed.
21183 *
21184 * Returns: 0 on success, or a negative value if an error occured.
21185 */
idmef_alert_new_tool_alert(idmef_alert_t * ptr,idmef_tool_alert_t ** ret)21186 int idmef_alert_new_tool_alert(idmef_alert_t *ptr, idmef_tool_alert_t **ret)
21187 {
21188 int retval;
21189
21190 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
21191
21192 switch ( ptr->type ) {
21193
21194 case IDMEF_ALERT_TYPE_TOOL:
21195 *ret = ptr->detail.tool_alert;
21196 return 0;
21197
21198 case IDMEF_ALERT_TYPE_CORRELATION:
21199 idmef_correlation_alert_destroy(ptr->detail.correlation_alert);
21200 break;
21201
21202 case IDMEF_ALERT_TYPE_OVERFLOW:
21203 idmef_overflow_alert_destroy(ptr->detail.overflow_alert);
21204 break;
21205
21206 default:
21207 break;
21208 }
21209
21210 retval = idmef_tool_alert_new(ret);
21211 if ( retval < 0 )
21212 return retval;
21213
21214 ptr->type = IDMEF_ALERT_TYPE_TOOL;
21215 ptr->detail.tool_alert = *ret;
21216
21217 return 0;
21218 }
21219
21220 /**
21221 * idmef_alert_get_correlation_alert:
21222 * @ptr: pointer to a #idmef_alert_t object.
21223 *
21224 * Access the correlation_alert children of @ptr.
21225 *
21226 * Returns: a pointer to the #idmef_correlation_alert_t children, or NULL if it is not set.
21227 */
idmef_alert_get_correlation_alert(idmef_alert_t * ptr)21228 idmef_correlation_alert_t *idmef_alert_get_correlation_alert(idmef_alert_t *ptr)
21229 {
21230 prelude_return_val_if_fail(ptr, NULL);
21231 return (ptr->type == IDMEF_ALERT_TYPE_CORRELATION) ? ptr->detail.correlation_alert : NULL;
21232 }
21233
21234 /**
21235 * idmef_alert_set_correlation_alert:
21236 * @ptr: pointer to a #idmef_alert_t object.
21237 * @correlation_alert: pointer to a #idmef_correlation_alert_t object.
21238 *
21239 * Set @correlation_alert object as a children of @ptr.
21240 * if @ptr already contain a @correlation_alert object, then it is destroyed,
21241 * and updated to point to the provided @correlation_alert object.
21242 */
idmef_alert_set_correlation_alert(idmef_alert_t * ptr,idmef_correlation_alert_t * correlation_alert)21243 void idmef_alert_set_correlation_alert(idmef_alert_t *ptr, idmef_correlation_alert_t *correlation_alert)
21244 {
21245 prelude_return_if_fail(ptr);
21246
21247 switch ( ptr->type ) {
21248
21249 case IDMEF_ALERT_TYPE_TOOL:
21250 idmef_tool_alert_destroy(ptr->detail.tool_alert);
21251 break;
21252
21253 case IDMEF_ALERT_TYPE_CORRELATION:
21254 idmef_correlation_alert_destroy(ptr->detail.correlation_alert);
21255 break;
21256
21257 case IDMEF_ALERT_TYPE_OVERFLOW:
21258 idmef_overflow_alert_destroy(ptr->detail.overflow_alert);
21259 break;
21260
21261 default:
21262 break;
21263 }
21264
21265 ptr->detail.correlation_alert = correlation_alert;
21266 ptr->type = (correlation_alert) ? IDMEF_ALERT_TYPE_CORRELATION : 0;
21267 }
21268
21269 /**
21270 * idmef_alert_new_correlation_alert:
21271 * @ptr: pointer to a #idmef_alert_t object.
21272 * @ret: pointer where to store the created #idmef_correlation_alert_t object.
21273 *
21274 * Create a new idmef_correlation_alert_t object, children of #idmef_alert_t.
21275 * If @ptr already contain a #idmef_correlation_alert_t object, then it is destroyed.
21276 *
21277 * Returns: 0 on success, or a negative value if an error occured.
21278 */
idmef_alert_new_correlation_alert(idmef_alert_t * ptr,idmef_correlation_alert_t ** ret)21279 int idmef_alert_new_correlation_alert(idmef_alert_t *ptr, idmef_correlation_alert_t **ret)
21280 {
21281 int retval;
21282
21283 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
21284
21285 switch ( ptr->type ) {
21286
21287 case IDMEF_ALERT_TYPE_TOOL:
21288 idmef_tool_alert_destroy(ptr->detail.tool_alert);
21289 break;
21290
21291 case IDMEF_ALERT_TYPE_CORRELATION:
21292 *ret = ptr->detail.correlation_alert;
21293 return 0;
21294
21295 case IDMEF_ALERT_TYPE_OVERFLOW:
21296 idmef_overflow_alert_destroy(ptr->detail.overflow_alert);
21297 break;
21298
21299 default:
21300 break;
21301 }
21302
21303 retval = idmef_correlation_alert_new(ret);
21304 if ( retval < 0 )
21305 return retval;
21306
21307 ptr->type = IDMEF_ALERT_TYPE_CORRELATION;
21308 ptr->detail.correlation_alert = *ret;
21309
21310 return 0;
21311 }
21312
21313 /**
21314 * idmef_alert_get_overflow_alert:
21315 * @ptr: pointer to a #idmef_alert_t object.
21316 *
21317 * Access the overflow_alert children of @ptr.
21318 *
21319 * Returns: a pointer to the #idmef_overflow_alert_t children, or NULL if it is not set.
21320 */
idmef_alert_get_overflow_alert(idmef_alert_t * ptr)21321 idmef_overflow_alert_t *idmef_alert_get_overflow_alert(idmef_alert_t *ptr)
21322 {
21323 prelude_return_val_if_fail(ptr, NULL);
21324 return (ptr->type == IDMEF_ALERT_TYPE_OVERFLOW) ? ptr->detail.overflow_alert : NULL;
21325 }
21326
21327 /**
21328 * idmef_alert_set_overflow_alert:
21329 * @ptr: pointer to a #idmef_alert_t object.
21330 * @overflow_alert: pointer to a #idmef_overflow_alert_t object.
21331 *
21332 * Set @overflow_alert object as a children of @ptr.
21333 * if @ptr already contain a @overflow_alert object, then it is destroyed,
21334 * and updated to point to the provided @overflow_alert object.
21335 */
idmef_alert_set_overflow_alert(idmef_alert_t * ptr,idmef_overflow_alert_t * overflow_alert)21336 void idmef_alert_set_overflow_alert(idmef_alert_t *ptr, idmef_overflow_alert_t *overflow_alert)
21337 {
21338 prelude_return_if_fail(ptr);
21339
21340 switch ( ptr->type ) {
21341
21342 case IDMEF_ALERT_TYPE_TOOL:
21343 idmef_tool_alert_destroy(ptr->detail.tool_alert);
21344 break;
21345
21346 case IDMEF_ALERT_TYPE_CORRELATION:
21347 idmef_correlation_alert_destroy(ptr->detail.correlation_alert);
21348 break;
21349
21350 case IDMEF_ALERT_TYPE_OVERFLOW:
21351 idmef_overflow_alert_destroy(ptr->detail.overflow_alert);
21352 break;
21353
21354 default:
21355 break;
21356 }
21357
21358 ptr->detail.overflow_alert = overflow_alert;
21359 ptr->type = (overflow_alert) ? IDMEF_ALERT_TYPE_OVERFLOW : 0;
21360 }
21361
21362 /**
21363 * idmef_alert_new_overflow_alert:
21364 * @ptr: pointer to a #idmef_alert_t object.
21365 * @ret: pointer where to store the created #idmef_overflow_alert_t object.
21366 *
21367 * Create a new idmef_overflow_alert_t object, children of #idmef_alert_t.
21368 * If @ptr already contain a #idmef_overflow_alert_t object, then it is destroyed.
21369 *
21370 * Returns: 0 on success, or a negative value if an error occured.
21371 */
idmef_alert_new_overflow_alert(idmef_alert_t * ptr,idmef_overflow_alert_t ** ret)21372 int idmef_alert_new_overflow_alert(idmef_alert_t *ptr, idmef_overflow_alert_t **ret)
21373 {
21374 int retval;
21375
21376 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
21377
21378 switch ( ptr->type ) {
21379
21380 case IDMEF_ALERT_TYPE_TOOL:
21381 idmef_tool_alert_destroy(ptr->detail.tool_alert);
21382 break;
21383
21384 case IDMEF_ALERT_TYPE_CORRELATION:
21385 idmef_correlation_alert_destroy(ptr->detail.correlation_alert);
21386 break;
21387
21388 case IDMEF_ALERT_TYPE_OVERFLOW:
21389 *ret = ptr->detail.overflow_alert;
21390 return 0;
21391
21392 default:
21393 break;
21394 }
21395
21396 retval = idmef_overflow_alert_new(ret);
21397 if ( retval < 0 )
21398 return retval;
21399
21400 ptr->type = IDMEF_ALERT_TYPE_OVERFLOW;
21401 ptr->detail.overflow_alert = *ret;
21402
21403 return 0;
21404 }
21405
21406 /**
21407 * idmef_alert_copy:
21408 * @src: Source of the copy.
21409 * @dst: Where to copy the object.
21410 *
21411 * Copy a new #idmef_alert_t object from @src to @dst.
21412 *
21413 * Returns: 0 on success, a negative value if an error occured.
21414 */
idmef_alert_copy(const idmef_alert_t * src,idmef_alert_t * dst)21415 int idmef_alert_copy(const idmef_alert_t *src, idmef_alert_t *dst)
21416 {
21417 int ret;
21418
21419 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
21420 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
21421
21422 ret = 0;
21423
21424 if ( src->messageid ) {
21425 ret = prelude_string_clone(src->messageid, &dst->messageid);
21426 if ( ret < 0 )
21427 return ret;
21428 }
21429
21430 {
21431 prelude_list_t *n, *tmp;
21432 idmef_analyzer_t *entry, *new;
21433
21434 prelude_list_for_each_safe(&src->analyzer_list, tmp, n) {
21435 entry = prelude_linked_object_get_object(tmp);
21436 idmef_analyzer_clone(entry, &new);
21437 prelude_list_add_tail(&dst->analyzer_list, &((prelude_linked_object_t *) new)->_list);
21438 }
21439 }
21440
21441 if ( src->create_time ) {
21442 ret = idmef_time_copy(src->create_time, dst->create_time);
21443 if ( ret < 0 )
21444 return ret;
21445 }
21446
21447 if ( src->classification ) {
21448 ret = idmef_classification_copy(src->classification, dst->classification);
21449 if ( ret < 0 )
21450 return ret;
21451 }
21452
21453 if ( src->detect_time ) {
21454 ret = idmef_time_clone(src->detect_time, &dst->detect_time);
21455 if ( ret < 0 )
21456 return ret;
21457 }
21458
21459 if ( src->analyzer_time ) {
21460 ret = idmef_time_clone(src->analyzer_time, &dst->analyzer_time);
21461 if ( ret < 0 )
21462 return ret;
21463 }
21464
21465 {
21466 prelude_list_t *n, *tmp;
21467 idmef_source_t *entry, *new;
21468
21469 prelude_list_for_each_safe(&src->source_list, tmp, n) {
21470 entry = prelude_linked_object_get_object(tmp);
21471 idmef_source_clone(entry, &new);
21472 prelude_list_add_tail(&dst->source_list, &((prelude_linked_object_t *) new)->_list);
21473 }
21474 }
21475
21476 {
21477 prelude_list_t *n, *tmp;
21478 idmef_target_t *entry, *new;
21479
21480 prelude_list_for_each_safe(&src->target_list, tmp, n) {
21481 entry = prelude_linked_object_get_object(tmp);
21482 idmef_target_clone(entry, &new);
21483 prelude_list_add_tail(&dst->target_list, &((prelude_linked_object_t *) new)->_list);
21484 }
21485 }
21486
21487 if ( src->assessment ) {
21488 ret = idmef_assessment_clone(src->assessment, &dst->assessment);
21489 if ( ret < 0 )
21490 return ret;
21491 }
21492
21493 {
21494 prelude_list_t *n, *tmp;
21495 idmef_additional_data_t *entry, *new;
21496
21497 prelude_list_for_each_safe(&src->additional_data_list, tmp, n) {
21498 entry = prelude_linked_object_get_object(tmp);
21499 idmef_additional_data_clone(entry, &new);
21500 prelude_list_add_tail(&dst->additional_data_list, &((prelude_linked_object_t *) new)->_list);
21501 }
21502 }
21503
21504 switch ( src->type ) {
21505
21506 case IDMEF_ALERT_TYPE_TOOL:
21507 ret = idmef_tool_alert_clone(src->detail.tool_alert, &dst->detail.tool_alert);
21508 break;
21509
21510 case IDMEF_ALERT_TYPE_CORRELATION:
21511 ret = idmef_correlation_alert_clone(src->detail.correlation_alert, &dst->detail.correlation_alert);
21512 break;
21513
21514 case IDMEF_ALERT_TYPE_OVERFLOW:
21515 ret = idmef_overflow_alert_clone(src->detail.overflow_alert, &dst->detail.overflow_alert);
21516 break;
21517
21518 default:
21519 break;
21520 }
21521
21522 if ( ret < 0 )
21523 return ret;
21524
21525 dst->type = src->type;
21526
21527 return 0;
21528 }
21529
21530 /**
21531 * idmef_alert_clone:
21532 * @src: Object to be cloned.
21533 * @dst: Address where to store the pointer to the cloned object.
21534 *
21535 * Create a copy of @src, and store it in @dst.
21536 *
21537 * Returns: 0 on success, a negative value if an error occured.
21538 */
idmef_alert_clone(idmef_alert_t * src,idmef_alert_t ** dst)21539 int idmef_alert_clone(idmef_alert_t *src, idmef_alert_t **dst)
21540 {
21541 int ret;
21542
21543 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
21544
21545 ret = idmef_alert_new(dst);
21546 if ( ret < 0 )
21547 return ret;
21548
21549 return idmef_alert_copy(src, *dst);
21550 }
21551
21552 /**
21553 * idmef_alert_compare:
21554 * @obj1: Object to compare with @obj2.
21555 * @obj2: Object to compare with @obj1.
21556 *
21557 * Compare @obj1 with @obj2.
21558 *
21559 * Returns: 0 on match, a negative value on comparison failure.
21560 */
idmef_alert_compare(const idmef_alert_t * obj1,const idmef_alert_t * obj2)21561 int idmef_alert_compare(const idmef_alert_t *obj1, const idmef_alert_t *obj2)
21562 {
21563 int ret = 0;
21564
21565 if ( obj1 == NULL && obj2 == NULL )
21566 return 0;
21567
21568 else if ( obj1 == NULL || obj2 == NULL )
21569 return -1;
21570
21571 ret = prelude_string_compare(obj1->messageid, obj2->messageid);
21572 if ( ret != 0 )
21573 return ret;
21574
21575 {
21576 prelude_list_t *tmp1, *tmp2;
21577 idmef_analyzer_t *entry1, *entry2;
21578
21579 tmp1 = tmp2 = NULL;
21580 do {
21581 entry1 = entry2 = NULL;
21582
21583 prelude_list_for_each_continue(&obj1->analyzer_list, tmp1) {
21584 entry1 = prelude_linked_object_get_object(tmp1);
21585 break;
21586 }
21587
21588 prelude_list_for_each_continue(&obj2->analyzer_list, tmp2) {
21589 entry2 = prelude_linked_object_get_object(tmp2);
21590 break;
21591 }
21592
21593 ret = idmef_analyzer_compare(entry1, entry2);
21594 if ( ret != 0 )
21595 return ret;
21596
21597 } while ( entry1 && entry2 );
21598 }
21599
21600 ret = idmef_time_compare(obj1->create_time, obj2->create_time);
21601 if ( ret != 0 )
21602 return ret;
21603
21604 ret = idmef_classification_compare(obj1->classification, obj2->classification);
21605 if ( ret != 0 )
21606 return ret;
21607
21608 ret = idmef_time_compare(obj1->detect_time, obj2->detect_time);
21609 if ( ret != 0 )
21610 return ret;
21611
21612 ret = idmef_time_compare(obj1->analyzer_time, obj2->analyzer_time);
21613 if ( ret != 0 )
21614 return ret;
21615
21616 {
21617 prelude_list_t *tmp1, *tmp2;
21618 idmef_source_t *entry1, *entry2;
21619
21620 tmp1 = tmp2 = NULL;
21621 do {
21622 entry1 = entry2 = NULL;
21623
21624 prelude_list_for_each_continue(&obj1->source_list, tmp1) {
21625 entry1 = prelude_linked_object_get_object(tmp1);
21626 break;
21627 }
21628
21629 prelude_list_for_each_continue(&obj2->source_list, tmp2) {
21630 entry2 = prelude_linked_object_get_object(tmp2);
21631 break;
21632 }
21633
21634 ret = idmef_source_compare(entry1, entry2);
21635 if ( ret != 0 )
21636 return ret;
21637
21638 } while ( entry1 && entry2 );
21639 }
21640
21641 {
21642 prelude_list_t *tmp1, *tmp2;
21643 idmef_target_t *entry1, *entry2;
21644
21645 tmp1 = tmp2 = NULL;
21646 do {
21647 entry1 = entry2 = NULL;
21648
21649 prelude_list_for_each_continue(&obj1->target_list, tmp1) {
21650 entry1 = prelude_linked_object_get_object(tmp1);
21651 break;
21652 }
21653
21654 prelude_list_for_each_continue(&obj2->target_list, tmp2) {
21655 entry2 = prelude_linked_object_get_object(tmp2);
21656 break;
21657 }
21658
21659 ret = idmef_target_compare(entry1, entry2);
21660 if ( ret != 0 )
21661 return ret;
21662
21663 } while ( entry1 && entry2 );
21664 }
21665
21666 ret = idmef_assessment_compare(obj1->assessment, obj2->assessment);
21667 if ( ret != 0 )
21668 return ret;
21669
21670 {
21671 prelude_list_t *tmp1, *tmp2;
21672 idmef_additional_data_t *entry1, *entry2;
21673
21674 tmp1 = tmp2 = NULL;
21675 do {
21676 entry1 = entry2 = NULL;
21677
21678 prelude_list_for_each_continue(&obj1->additional_data_list, tmp1) {
21679 entry1 = prelude_linked_object_get_object(tmp1);
21680 break;
21681 }
21682
21683 prelude_list_for_each_continue(&obj2->additional_data_list, tmp2) {
21684 entry2 = prelude_linked_object_get_object(tmp2);
21685 break;
21686 }
21687
21688 ret = idmef_additional_data_compare(entry1, entry2);
21689 if ( ret != 0 )
21690 return ret;
21691
21692 } while ( entry1 && entry2 );
21693 }
21694
21695 if ( obj1->type != obj2->type )
21696 return -1;
21697
21698 switch ( obj1->type ) {
21699
21700 case IDMEF_ALERT_TYPE_TOOL:
21701 ret = idmef_tool_alert_compare(obj1->detail.tool_alert, obj2->detail.tool_alert);
21702 break;
21703
21704 case IDMEF_ALERT_TYPE_CORRELATION:
21705 ret = idmef_correlation_alert_compare(obj1->detail.correlation_alert, obj2->detail.correlation_alert);
21706 break;
21707
21708 case IDMEF_ALERT_TYPE_OVERFLOW:
21709 ret = idmef_overflow_alert_compare(obj1->detail.overflow_alert, obj2->detail.overflow_alert);
21710 break;
21711
21712 default:
21713 break;
21714 }
21715
21716 return ret;
21717 }
21718
21719 /**
21720 * idmef_heartbeat_new:
21721 * @ret: Pointer where to store the created #idmef_heartbeat_t object.
21722 *
21723 * Create a new #idmef_heartbeat_t object.
21724 *
21725 * Returns: 0 on success, a negative value if an error occured.
21726 */
idmef_heartbeat_new(idmef_heartbeat_t ** ret)21727 int idmef_heartbeat_new(idmef_heartbeat_t **ret)
21728 {
21729 *ret = calloc(1, sizeof(**ret));
21730 if ( ! *ret )
21731 return prelude_error_from_errno(errno);
21732
21733 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_HEARTBEAT;
21734
21735 (*ret)->refcount = 1;
21736
21737 prelude_list_init(&(*ret)->analyzer_list);
21738
21739
21740 prelude_list_init(&(*ret)->additional_data_list);
21741
21742
21743 {
21744 int retval = idmef_time_new(&(*ret)->create_time);
21745
21746 if ( retval < 0 ) {
21747 idmef_heartbeat_destroy(*ret);
21748 *ret = NULL;
21749 return retval;
21750 }
21751 }
21752
21753 idmef_time_set_from_gettimeofday((*ret)->create_time);
21754
21755 return 0;
21756
21757 }
21758
21759 /**
21760 * idmef_heartbeat_ref:
21761 * @heartbeat: pointer to a #idmef_heartbeat_t object.
21762 *
21763 * Increase @heartbeat reference count, so that it can be referenced
21764 * multiple time.
21765 *
21766 * Returns: a pointer to @heartbeat.
21767 */
idmef_heartbeat_ref(idmef_heartbeat_t * heartbeat)21768 idmef_heartbeat_t *idmef_heartbeat_ref(idmef_heartbeat_t *heartbeat)
21769 {
21770 prelude_return_val_if_fail(heartbeat, NULL);
21771 heartbeat->refcount++;
21772
21773 return heartbeat;
21774 }
21775
_idmef_heartbeat_get_child(void * p,idmef_class_child_id_t child,void ** childptr)21776 int _idmef_heartbeat_get_child(void *p, idmef_class_child_id_t child, void **childptr)
21777 {
21778 idmef_heartbeat_t *ptr = p;
21779
21780 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
21781 *childptr = NULL;
21782
21783 switch ( child ) {
21784
21785 case 0:
21786 return get_value_from_string((idmef_value_t **) childptr, ptr->messageid, TRUE);
21787 case 1:
21788 *childptr = &ptr->analyzer_list;
21789 return 0;
21790
21791 case 2:
21792 return get_value_from_time((idmef_value_t **) childptr, ptr->create_time, TRUE);
21793 case 3:
21794 return get_value_from_time((idmef_value_t **) childptr, ptr->analyzer_time, TRUE);
21795 case 4:
21796 return (ptr->heartbeat_interval_is_set) ? idmef_value_new_uint32((idmef_value_t **) childptr, ptr->heartbeat_interval) : 0;
21797
21798 case 5:
21799 *childptr = &ptr->additional_data_list;
21800 return 0;
21801
21802 default:
21803 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
21804 }
21805 }
21806
_idmef_heartbeat_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)21807 int _idmef_heartbeat_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
21808 {
21809 idmef_heartbeat_t *ptr = p;
21810
21811 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
21812
21813 switch ( child ) {
21814
21815 case 0:
21816 return idmef_heartbeat_new_messageid(ptr, (prelude_string_t **) ret);
21817
21818 case 1: {
21819 int i = 0;
21820 prelude_list_t *tmp;
21821
21822 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
21823 return idmef_heartbeat_new_analyzer(ptr, (idmef_analyzer_t **) ret, n);
21824
21825 if ( n >= 0 ) {
21826 prelude_list_for_each(&ptr->analyzer_list, tmp) {
21827 if ( i++ == n ) {
21828 *ret = prelude_linked_object_get_object(tmp);
21829 return 0;
21830 }
21831 }
21832
21833 if ( i != n )
21834 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
21835 } else {
21836 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
21837
21838 prelude_list_for_each_reversed(&ptr->analyzer_list, tmp) {
21839 if ( i++ == pos ) {
21840 *ret = prelude_linked_object_get_object(tmp);
21841 return 0;
21842 }
21843 }
21844
21845 if ( i != pos )
21846 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
21847 }
21848
21849 return idmef_heartbeat_new_analyzer(ptr, (idmef_analyzer_t **) ret, n);
21850 }
21851
21852 case 2:
21853 return idmef_heartbeat_new_create_time(ptr, (idmef_time_t **) ret);
21854
21855 case 3:
21856 return idmef_heartbeat_new_analyzer_time(ptr, (idmef_time_t **) ret);
21857
21858 case 4:
21859 return idmef_heartbeat_new_heartbeat_interval(ptr, (uint32_t **) ret);
21860
21861 case 5: {
21862 int i = 0;
21863 prelude_list_t *tmp;
21864
21865 if ( n == IDMEF_LIST_APPEND || n == IDMEF_LIST_PREPEND )
21866 return idmef_heartbeat_new_additional_data(ptr, (idmef_additional_data_t **) ret, n);
21867
21868 if ( n >= 0 ) {
21869 prelude_list_for_each(&ptr->additional_data_list, tmp) {
21870 if ( i++ == n ) {
21871 *ret = prelude_linked_object_get_object(tmp);
21872 return 0;
21873 }
21874 }
21875
21876 if ( i != n )
21877 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
21878 } else {
21879 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
21880
21881 prelude_list_for_each_reversed(&ptr->additional_data_list, tmp) {
21882 if ( i++ == pos ) {
21883 *ret = prelude_linked_object_get_object(tmp);
21884 return 0;
21885 }
21886 }
21887
21888 if ( i != pos )
21889 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
21890 }
21891
21892 return idmef_heartbeat_new_additional_data(ptr, (idmef_additional_data_t **) ret, n);
21893 }
21894
21895 default:
21896 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
21897 }
21898 }
21899
_idmef_heartbeat_destroy_child(void * p,idmef_class_child_id_t child,int n)21900 int _idmef_heartbeat_destroy_child(void *p, idmef_class_child_id_t child, int n)
21901 {
21902 idmef_heartbeat_t *ptr = p;
21903
21904 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
21905
21906 switch ( child ) {
21907
21908 case 0:
21909 if ( ptr->messageid ) {
21910 prelude_string_destroy(ptr->messageid);
21911 ptr->messageid = NULL;
21912 }
21913
21914 return 0;
21915
21916 case 1: {
21917 int i = 0;
21918 prelude_list_t *tmp;
21919
21920 if ( n >= 0 ) {
21921 prelude_list_for_each(&ptr->analyzer_list, tmp) {
21922 if ( i++ == n ) {
21923 void *b = prelude_linked_object_get_object(tmp);
21924 idmef_analyzer_destroy(b);
21925 return 0;
21926 }
21927 }
21928
21929 if ( i != n )
21930 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
21931 } else {
21932 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
21933
21934 prelude_list_for_each_reversed(&ptr->analyzer_list, tmp) {
21935 if ( i++ == pos ) {
21936 void *b = prelude_linked_object_get_object(tmp);
21937 idmef_analyzer_destroy(b);
21938 return 0;
21939 }
21940 }
21941
21942 if ( i != pos )
21943 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
21944 }
21945 }
21946
21947 case 2:
21948 if ( ptr->create_time ) {
21949 idmef_time_destroy(ptr->create_time);
21950 ptr->create_time = NULL;
21951 }
21952
21953 return 0;
21954
21955 case 3:
21956 if ( ptr->analyzer_time ) {
21957 idmef_time_destroy(ptr->analyzer_time);
21958 ptr->analyzer_time = NULL;
21959 }
21960
21961 return 0;
21962
21963 case 4:
21964 ptr->heartbeat_interval_is_set = 0;
21965 return 0;
21966
21967 case 5: {
21968 int i = 0;
21969 prelude_list_t *tmp;
21970
21971 if ( n >= 0 ) {
21972 prelude_list_for_each(&ptr->additional_data_list, tmp) {
21973 if ( i++ == n ) {
21974 void *b = prelude_linked_object_get_object(tmp);
21975 idmef_additional_data_destroy(b);
21976 return 0;
21977 }
21978 }
21979
21980 if ( i != n )
21981 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
21982 } else {
21983 int pos = (-n) - 1; /* With negative value, -1 is the base, translate to 0 */
21984
21985 prelude_list_for_each_reversed(&ptr->additional_data_list, tmp) {
21986 if ( i++ == pos ) {
21987 void *b = prelude_linked_object_get_object(tmp);
21988 idmef_additional_data_destroy(b);
21989 return 0;
21990 }
21991 }
21992
21993 if ( i != pos )
21994 return prelude_error(PRELUDE_ERROR_IDMEF_TREE_INDEX_UNDEFINED);
21995 }
21996 }
21997
21998 default:
21999 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
22000 }
22001 }
22002
idmef_heartbeat_destroy_internal(idmef_heartbeat_t * ptr)22003 static void idmef_heartbeat_destroy_internal(idmef_heartbeat_t *ptr)
22004 {
22005 prelude_return_if_fail(ptr);
22006
22007 if ( ptr->messageid ) {
22008 prelude_string_destroy(ptr->messageid);
22009 ptr->messageid = NULL;
22010 }
22011
22012 {
22013 prelude_list_t *n, *tmp;
22014 idmef_analyzer_t *entry;
22015
22016 prelude_list_for_each_safe(&ptr->analyzer_list, tmp, n) {
22017 entry = prelude_linked_object_get_object(tmp);
22018 prelude_list_del_init(tmp);
22019 idmef_analyzer_destroy(entry);
22020 }
22021 }
22022
22023 if ( ptr->create_time ) {
22024 idmef_time_destroy(ptr->create_time);
22025 ptr->create_time = NULL;
22026 }
22027
22028 if ( ptr->analyzer_time ) {
22029 idmef_time_destroy(ptr->analyzer_time);
22030 ptr->analyzer_time = NULL;
22031 }
22032
22033 {
22034 prelude_list_t *n, *tmp;
22035 idmef_additional_data_t *entry;
22036
22037 prelude_list_for_each_safe(&ptr->additional_data_list, tmp, n) {
22038 entry = prelude_linked_object_get_object(tmp);
22039 prelude_list_del_init(tmp);
22040 idmef_additional_data_destroy(entry);
22041 }
22042 }
22043
22044
22045 /* free() should be done by the caller */
22046 }
22047
22048 /**
22049 * idmef_heartbeat_destroy:
22050 * @ptr: pointer to a #idmef_heartbeat_t object.
22051 *
22052 * Destroy @ptr and all of it's children.
22053 * The objects are only destroyed if their reference count reach zero.
22054 */
22055
idmef_heartbeat_destroy(idmef_heartbeat_t * ptr)22056 void idmef_heartbeat_destroy(idmef_heartbeat_t *ptr)
22057 {
22058 prelude_return_if_fail(ptr);
22059
22060 if ( --ptr->refcount )
22061 return;
22062
22063 idmef_heartbeat_destroy_internal(ptr);
22064 free(ptr);
22065 }
22066
22067 /**
22068 * idmef_heartbeat_get_messageid:
22069 * @ptr: pointer to a #idmef_heartbeat_t object.
22070 *
22071 * Get messageid children of the #idmef_heartbeat_t object.
22072 *
22073 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
22074 */
idmef_heartbeat_get_messageid(idmef_heartbeat_t * ptr)22075 prelude_string_t *idmef_heartbeat_get_messageid(idmef_heartbeat_t *ptr)
22076 {
22077 prelude_return_val_if_fail(ptr, 0); /* FIXME */
22078
22079 return ptr->messageid;
22080 }
22081
22082 /**
22083 * idmef_heartbeat_set_messageid:
22084 * @ptr: pointer to a #idmef_heartbeat_t object.
22085 * @messageid: pointer to a #prelude_string_t object.
22086 *
22087 * Set @messageid object as a children of @ptr.
22088 * if @ptr already contain an @messageid object, then it is destroyed,
22089 * and updated to point to the provided @messageid object.
22090 */
22091
idmef_heartbeat_set_messageid(idmef_heartbeat_t * ptr,prelude_string_t * messageid)22092 void idmef_heartbeat_set_messageid(idmef_heartbeat_t *ptr, prelude_string_t *messageid)
22093 {
22094 prelude_return_if_fail(ptr);
22095
22096 if ( ptr->messageid )
22097 prelude_string_destroy(ptr->messageid);
22098
22099 ptr->messageid = messageid;
22100 }
22101
22102 /**
22103 * idmef_heartbeat_new_messageid:
22104 * @ptr: pointer to a #idmef_heartbeat_t object.
22105 * @ret: pointer to an address where to store the created #prelude_string_t object.
22106 *
22107 * Create a new messageid object, children of #idmef_heartbeat_t.
22108 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
22109 *
22110 * Returns: 0 on success, or a negative value if an error occured.
22111 */
idmef_heartbeat_new_messageid(idmef_heartbeat_t * ptr,prelude_string_t ** ret)22112 int idmef_heartbeat_new_messageid(idmef_heartbeat_t *ptr, prelude_string_t **ret)
22113 {
22114 int retval;
22115
22116 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
22117
22118 if ( ! ptr->messageid ) {
22119 retval = prelude_string_new(&ptr->messageid);
22120 if ( retval < 0 )
22121 return retval;
22122 }
22123
22124 *ret = ptr->messageid;
22125 return 0;
22126 }
22127
22128 /**
22129 * idmef_heartbeat_get_next_analyzer:
22130 * @heartbeat: pointer to a #idmef_heartbeat_t object.
22131 * @analyzer_cur: pointer to a #idmef_analyzer_t object.
22132 *
22133 * Get the next #idmef_analyzer_t object listed in @ptr.
22134 * When iterating over the idmef_analyzer_t object listed in @ptr,
22135 * @object should be set to the latest returned #idmef_analyzer_t object.
22136 *
22137 * Returns: the next #idmef_analyzer_t in the list.
22138 */
idmef_heartbeat_get_next_analyzer(idmef_heartbeat_t * heartbeat,idmef_analyzer_t * analyzer_cur)22139 idmef_analyzer_t *idmef_heartbeat_get_next_analyzer(idmef_heartbeat_t *heartbeat, idmef_analyzer_t *analyzer_cur)
22140 {
22141 prelude_list_t *tmp = (analyzer_cur) ? &((prelude_linked_object_t *) analyzer_cur)->_list : NULL;
22142
22143 prelude_return_val_if_fail(heartbeat, NULL);
22144
22145 prelude_list_for_each_continue(&heartbeat->analyzer_list, tmp)
22146 return prelude_linked_object_get_object(tmp);
22147
22148 return NULL;
22149 }
22150
22151
22152 /**
22153 * idmef_heartbeat_set_analyzer:
22154 * @ptr: pointer to a #idmef_heartbeat_t object.
22155 * @object: pointer to a #idmef_analyzer_t object.
22156 * @pos: Position in the list.
22157 *
22158 * Add @object to position @pos of @ptr list of #idmef_analyzer_t object.
22159 *
22160 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
22161 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
22162 */
idmef_heartbeat_set_analyzer(idmef_heartbeat_t * ptr,idmef_analyzer_t * object,int pos)22163 void idmef_heartbeat_set_analyzer(idmef_heartbeat_t *ptr, idmef_analyzer_t *object, int pos)
22164 {
22165 prelude_return_if_fail(ptr);
22166 prelude_return_if_fail(object);
22167
22168 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
22169 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
22170
22171 list_insert(&ptr->analyzer_list, &((prelude_linked_object_t *) object)->_list, pos);
22172 }
22173
22174
22175 /**
22176 * idmef_heartbeat_new_analyzer:
22177 * @ptr: pointer to a #idmef_heartbeat_t object.
22178 * @ret: pointer to an address where to store the created #idmef_analyzer_t object.
22179 * @pos: position in the list.
22180 *
22181 * Create a new #idmef_analyzer_t children of @ptr, and add it to position @pos of
22182 * @ptr list of #idmef_analyzer_t object. The created #idmef_analyzer_t object is
22183 * stored in @ret.
22184 *
22185 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
22186 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
22187 *
22188 * Returns: 0 on success, or a negative value if an error occured.
22189 */
idmef_heartbeat_new_analyzer(idmef_heartbeat_t * ptr,idmef_analyzer_t ** ret,int pos)22190 int idmef_heartbeat_new_analyzer(idmef_heartbeat_t *ptr, idmef_analyzer_t **ret, int pos)
22191 {
22192 int retval;
22193
22194 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
22195
22196 retval = idmef_analyzer_new(ret);
22197 if ( retval < 0 )
22198 return retval;
22199
22200 list_insert(&ptr->analyzer_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
22201
22202 return 0;
22203 }
22204
22205
22206 /**
22207 * idmef_heartbeat_get_create_time:
22208 * @ptr: pointer to a #idmef_heartbeat_t object.
22209 *
22210 * Get create_time children of the #idmef_heartbeat_t object.
22211 *
22212 * Returns: a pointer to a idmef_time_t object, or NULL if the children object is not set.
22213 */
idmef_heartbeat_get_create_time(idmef_heartbeat_t * ptr)22214 idmef_time_t *idmef_heartbeat_get_create_time(idmef_heartbeat_t *ptr)
22215 {
22216 prelude_return_val_if_fail(ptr, 0); /* FIXME */
22217
22218 return ptr->create_time;
22219 }
22220
22221 /**
22222 * idmef_heartbeat_set_create_time:
22223 * @ptr: pointer to a #idmef_heartbeat_t object.
22224 * @create_time: pointer to a #idmef_time_t object.
22225 *
22226 * Set @create_time object as a children of @ptr.
22227 * if @ptr already contain an @create_time object, then it is destroyed,
22228 * and updated to point to the provided @create_time object.
22229 */
22230
idmef_heartbeat_set_create_time(idmef_heartbeat_t * ptr,idmef_time_t * create_time)22231 void idmef_heartbeat_set_create_time(idmef_heartbeat_t *ptr, idmef_time_t *create_time)
22232 {
22233 prelude_return_if_fail(ptr);
22234
22235 if ( ptr->create_time )
22236 idmef_time_destroy(ptr->create_time);
22237
22238 ptr->create_time = create_time;
22239 }
22240
22241 /**
22242 * idmef_heartbeat_new_create_time:
22243 * @ptr: pointer to a #idmef_heartbeat_t object.
22244 * @ret: pointer to an address where to store the created #idmef_time_t object.
22245 *
22246 * Create a new create_time object, children of #idmef_heartbeat_t.
22247 * If @ptr already contain a #idmef_time_t object, then it is destroyed.
22248 *
22249 * Returns: 0 on success, or a negative value if an error occured.
22250 */
idmef_heartbeat_new_create_time(idmef_heartbeat_t * ptr,idmef_time_t ** ret)22251 int idmef_heartbeat_new_create_time(idmef_heartbeat_t *ptr, idmef_time_t **ret)
22252 {
22253 int retval;
22254
22255 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
22256
22257 if ( ! ptr->create_time ) {
22258 retval = idmef_time_new(&ptr->create_time);
22259 if ( retval < 0 )
22260 return retval;
22261 }
22262
22263 *ret = ptr->create_time;
22264 return 0;
22265 }
22266
22267 /**
22268 * idmef_heartbeat_get_analyzer_time:
22269 * @ptr: pointer to a #idmef_heartbeat_t object.
22270 *
22271 * Get analyzer_time children of the #idmef_heartbeat_t object.
22272 *
22273 * Returns: a pointer to a idmef_time_t object, or NULL if the children object is not set.
22274 */
idmef_heartbeat_get_analyzer_time(idmef_heartbeat_t * ptr)22275 idmef_time_t *idmef_heartbeat_get_analyzer_time(idmef_heartbeat_t *ptr)
22276 {
22277 prelude_return_val_if_fail(ptr, 0); /* FIXME */
22278
22279 return ptr->analyzer_time;
22280 }
22281
22282 /**
22283 * idmef_heartbeat_set_analyzer_time:
22284 * @ptr: pointer to a #idmef_heartbeat_t object.
22285 * @analyzer_time: pointer to a #idmef_time_t object.
22286 *
22287 * Set @analyzer_time object as a children of @ptr.
22288 * if @ptr already contain an @analyzer_time object, then it is destroyed,
22289 * and updated to point to the provided @analyzer_time object.
22290 */
22291
idmef_heartbeat_set_analyzer_time(idmef_heartbeat_t * ptr,idmef_time_t * analyzer_time)22292 void idmef_heartbeat_set_analyzer_time(idmef_heartbeat_t *ptr, idmef_time_t *analyzer_time)
22293 {
22294 prelude_return_if_fail(ptr);
22295
22296 if ( ptr->analyzer_time )
22297 idmef_time_destroy(ptr->analyzer_time);
22298
22299 ptr->analyzer_time = analyzer_time;
22300 }
22301
22302 /**
22303 * idmef_heartbeat_new_analyzer_time:
22304 * @ptr: pointer to a #idmef_heartbeat_t object.
22305 * @ret: pointer to an address where to store the created #idmef_time_t object.
22306 *
22307 * Create a new analyzer_time object, children of #idmef_heartbeat_t.
22308 * If @ptr already contain a #idmef_time_t object, then it is destroyed.
22309 *
22310 * Returns: 0 on success, or a negative value if an error occured.
22311 */
idmef_heartbeat_new_analyzer_time(idmef_heartbeat_t * ptr,idmef_time_t ** ret)22312 int idmef_heartbeat_new_analyzer_time(idmef_heartbeat_t *ptr, idmef_time_t **ret)
22313 {
22314 int retval;
22315
22316 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
22317
22318 if ( ! ptr->analyzer_time ) {
22319 retval = idmef_time_new(&ptr->analyzer_time);
22320 if ( retval < 0 )
22321 return retval;
22322 }
22323
22324 *ret = ptr->analyzer_time;
22325 return 0;
22326 }
22327
22328 /**
22329 * idmef_heartbeat_get_heartbeat_interval:
22330 * @ptr: pointer to a #idmef_heartbeat_t object.
22331 *
22332 * Get heartbeat_interval children of the #idmef_heartbeat_t object.
22333 *
22334 * Returns: a pointer to a uint32_t object, or NULL if the children object is not set.
22335 */
idmef_heartbeat_get_heartbeat_interval(idmef_heartbeat_t * ptr)22336 uint32_t *idmef_heartbeat_get_heartbeat_interval(idmef_heartbeat_t *ptr)
22337 {
22338 prelude_return_val_if_fail(ptr, 0); /* FIXME */
22339
22340 return ptr->heartbeat_interval_is_set ? &ptr->heartbeat_interval : NULL;
22341 }
22342
22343 /**
22344 * idmef_heartbeat_set_heartbeat_interval:
22345 * @ptr: pointer to a #idmef_heartbeat_t object.
22346 * @heartbeat_interval: pointer to a #uint32_t object.
22347 *
22348 * Set @heartbeat_interval object as a children of @ptr.
22349 * if @ptr already contain an @heartbeat_interval object, then it is destroyed,
22350 * and updated to point to the provided @heartbeat_interval object.
22351 */
22352
idmef_heartbeat_set_heartbeat_interval(idmef_heartbeat_t * ptr,uint32_t heartbeat_interval)22353 void idmef_heartbeat_set_heartbeat_interval(idmef_heartbeat_t *ptr, uint32_t heartbeat_interval)
22354 {
22355 prelude_return_if_fail(ptr);
22356 ptr->heartbeat_interval = heartbeat_interval;
22357 ptr->heartbeat_interval_is_set = 1;
22358 }
22359
22360
idmef_heartbeat_unset_heartbeat_interval(idmef_heartbeat_t * ptr)22361 void idmef_heartbeat_unset_heartbeat_interval(idmef_heartbeat_t *ptr)
22362 {
22363 prelude_return_if_fail(ptr);
22364 ptr->heartbeat_interval_is_set = 0;
22365 }
22366
22367
22368 /**
22369 * idmef_heartbeat_new_heartbeat_interval:
22370 * @ptr: pointer to a #idmef_heartbeat_t object.
22371 * @ret: pointer to an address where to store the created #uint32_t object.
22372 *
22373 * Create a new heartbeat_interval object, children of #idmef_heartbeat_t.
22374 * If @ptr already contain a #uint32_t object, then it is destroyed.
22375 *
22376 * Returns: 0 on success, or a negative value if an error occured.
22377 */
idmef_heartbeat_new_heartbeat_interval(idmef_heartbeat_t * ptr,uint32_t ** ret)22378 int idmef_heartbeat_new_heartbeat_interval(idmef_heartbeat_t *ptr, uint32_t **ret)
22379 {
22380 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
22381 ptr->heartbeat_interval_is_set = 1;
22382
22383 *ret = &ptr->heartbeat_interval;
22384 return 0;
22385 }
22386
22387 /**
22388 * idmef_heartbeat_get_next_additional_data:
22389 * @heartbeat: pointer to a #idmef_heartbeat_t object.
22390 * @additional_data_cur: pointer to a #idmef_additional_data_t object.
22391 *
22392 * Get the next #idmef_additional_data_t object listed in @ptr.
22393 * When iterating over the idmef_additional_data_t object listed in @ptr,
22394 * @object should be set to the latest returned #idmef_additional_data_t object.
22395 *
22396 * Returns: the next #idmef_additional_data_t in the list.
22397 */
idmef_heartbeat_get_next_additional_data(idmef_heartbeat_t * heartbeat,idmef_additional_data_t * additional_data_cur)22398 idmef_additional_data_t *idmef_heartbeat_get_next_additional_data(idmef_heartbeat_t *heartbeat, idmef_additional_data_t *additional_data_cur)
22399 {
22400 prelude_list_t *tmp = (additional_data_cur) ? &((prelude_linked_object_t *) additional_data_cur)->_list : NULL;
22401
22402 prelude_return_val_if_fail(heartbeat, NULL);
22403
22404 prelude_list_for_each_continue(&heartbeat->additional_data_list, tmp)
22405 return prelude_linked_object_get_object(tmp);
22406
22407 return NULL;
22408 }
22409
22410
22411 /**
22412 * idmef_heartbeat_set_additional_data:
22413 * @ptr: pointer to a #idmef_heartbeat_t object.
22414 * @object: pointer to a #idmef_additional_data_t object.
22415 * @pos: Position in the list.
22416 *
22417 * Add @object to position @pos of @ptr list of #idmef_additional_data_t object.
22418 *
22419 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
22420 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
22421 */
idmef_heartbeat_set_additional_data(idmef_heartbeat_t * ptr,idmef_additional_data_t * object,int pos)22422 void idmef_heartbeat_set_additional_data(idmef_heartbeat_t *ptr, idmef_additional_data_t *object, int pos)
22423 {
22424 prelude_return_if_fail(ptr);
22425 prelude_return_if_fail(object);
22426
22427 if ( ! prelude_list_is_empty(&((prelude_linked_object_t *) object)->_list) )
22428 prelude_list_del_init(&((prelude_linked_object_t *) object)->_list);
22429
22430 list_insert(&ptr->additional_data_list, &((prelude_linked_object_t *) object)->_list, pos);
22431 }
22432
22433
22434 /**
22435 * idmef_heartbeat_new_additional_data:
22436 * @ptr: pointer to a #idmef_heartbeat_t object.
22437 * @ret: pointer to an address where to store the created #idmef_additional_data_t object.
22438 * @pos: position in the list.
22439 *
22440 * Create a new #idmef_additional_data_t children of @ptr, and add it to position @pos of
22441 * @ptr list of #idmef_additional_data_t object. The created #idmef_additional_data_t object is
22442 * stored in @ret.
22443 *
22444 * If @pos is #IDMEF_LIST_APPEND, @object will be inserted at the tail of the list.
22445 * If @pos is #IDMEF_LIST_PREPEND, @object will be inserted at the head of the list.
22446 *
22447 * Returns: 0 on success, or a negative value if an error occured.
22448 */
idmef_heartbeat_new_additional_data(idmef_heartbeat_t * ptr,idmef_additional_data_t ** ret,int pos)22449 int idmef_heartbeat_new_additional_data(idmef_heartbeat_t *ptr, idmef_additional_data_t **ret, int pos)
22450 {
22451 int retval;
22452
22453 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
22454
22455 retval = idmef_additional_data_new(ret);
22456 if ( retval < 0 )
22457 return retval;
22458
22459 list_insert(&ptr->additional_data_list, &((prelude_linked_object_t *)(*ret))->_list, pos);
22460
22461 return 0;
22462 }
22463
22464
22465 /**
22466 * idmef_heartbeat_copy:
22467 * @src: Source of the copy.
22468 * @dst: Where to copy the object.
22469 *
22470 * Copy a new #idmef_heartbeat_t object from @src to @dst.
22471 *
22472 * Returns: 0 on success, a negative value if an error occured.
22473 */
idmef_heartbeat_copy(const idmef_heartbeat_t * src,idmef_heartbeat_t * dst)22474 int idmef_heartbeat_copy(const idmef_heartbeat_t *src, idmef_heartbeat_t *dst)
22475 {
22476 int ret;
22477
22478 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
22479 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
22480
22481 ret = 0;
22482
22483 if ( src->messageid ) {
22484 ret = prelude_string_clone(src->messageid, &dst->messageid);
22485 if ( ret < 0 )
22486 return ret;
22487 }
22488
22489 {
22490 prelude_list_t *n, *tmp;
22491 idmef_analyzer_t *entry, *new;
22492
22493 prelude_list_for_each_safe(&src->analyzer_list, tmp, n) {
22494 entry = prelude_linked_object_get_object(tmp);
22495 idmef_analyzer_clone(entry, &new);
22496 prelude_list_add_tail(&dst->analyzer_list, &((prelude_linked_object_t *) new)->_list);
22497 }
22498 }
22499
22500 if ( src->create_time ) {
22501 ret = idmef_time_copy(src->create_time, dst->create_time);
22502 if ( ret < 0 )
22503 return ret;
22504 }
22505
22506 if ( src->analyzer_time ) {
22507 ret = idmef_time_clone(src->analyzer_time, &dst->analyzer_time);
22508 if ( ret < 0 )
22509 return ret;
22510 }
22511
22512 dst->heartbeat_interval_is_set = src->heartbeat_interval_is_set;
22513
22514 dst->heartbeat_interval = src->heartbeat_interval;
22515
22516 {
22517 prelude_list_t *n, *tmp;
22518 idmef_additional_data_t *entry, *new;
22519
22520 prelude_list_for_each_safe(&src->additional_data_list, tmp, n) {
22521 entry = prelude_linked_object_get_object(tmp);
22522 idmef_additional_data_clone(entry, &new);
22523 prelude_list_add_tail(&dst->additional_data_list, &((prelude_linked_object_t *) new)->_list);
22524 }
22525 }
22526
22527 return 0;
22528 }
22529
22530 /**
22531 * idmef_heartbeat_clone:
22532 * @src: Object to be cloned.
22533 * @dst: Address where to store the pointer to the cloned object.
22534 *
22535 * Create a copy of @src, and store it in @dst.
22536 *
22537 * Returns: 0 on success, a negative value if an error occured.
22538 */
idmef_heartbeat_clone(idmef_heartbeat_t * src,idmef_heartbeat_t ** dst)22539 int idmef_heartbeat_clone(idmef_heartbeat_t *src, idmef_heartbeat_t **dst)
22540 {
22541 int ret;
22542
22543 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
22544
22545 ret = idmef_heartbeat_new(dst);
22546 if ( ret < 0 )
22547 return ret;
22548
22549 return idmef_heartbeat_copy(src, *dst);
22550 }
22551
22552 /**
22553 * idmef_heartbeat_compare:
22554 * @obj1: Object to compare with @obj2.
22555 * @obj2: Object to compare with @obj1.
22556 *
22557 * Compare @obj1 with @obj2.
22558 *
22559 * Returns: 0 on match, a negative value on comparison failure.
22560 */
idmef_heartbeat_compare(const idmef_heartbeat_t * obj1,const idmef_heartbeat_t * obj2)22561 int idmef_heartbeat_compare(const idmef_heartbeat_t *obj1, const idmef_heartbeat_t *obj2)
22562 {
22563 int ret = 0;
22564
22565 if ( obj1 == NULL && obj2 == NULL )
22566 return 0;
22567
22568 else if ( obj1 == NULL || obj2 == NULL )
22569 return -1;
22570
22571 ret = prelude_string_compare(obj1->messageid, obj2->messageid);
22572 if ( ret != 0 )
22573 return ret;
22574
22575 {
22576 prelude_list_t *tmp1, *tmp2;
22577 idmef_analyzer_t *entry1, *entry2;
22578
22579 tmp1 = tmp2 = NULL;
22580 do {
22581 entry1 = entry2 = NULL;
22582
22583 prelude_list_for_each_continue(&obj1->analyzer_list, tmp1) {
22584 entry1 = prelude_linked_object_get_object(tmp1);
22585 break;
22586 }
22587
22588 prelude_list_for_each_continue(&obj2->analyzer_list, tmp2) {
22589 entry2 = prelude_linked_object_get_object(tmp2);
22590 break;
22591 }
22592
22593 ret = idmef_analyzer_compare(entry1, entry2);
22594 if ( ret != 0 )
22595 return ret;
22596
22597 } while ( entry1 && entry2 );
22598 }
22599
22600 ret = idmef_time_compare(obj1->create_time, obj2->create_time);
22601 if ( ret != 0 )
22602 return ret;
22603
22604 ret = idmef_time_compare(obj1->analyzer_time, obj2->analyzer_time);
22605 if ( ret != 0 )
22606 return ret;
22607
22608 if ( obj1->heartbeat_interval_is_set != obj2->heartbeat_interval_is_set )
22609 return -1;
22610
22611 if ( obj1->heartbeat_interval_is_set && obj1->heartbeat_interval != obj2->heartbeat_interval )
22612 return -1;
22613
22614 {
22615 prelude_list_t *tmp1, *tmp2;
22616 idmef_additional_data_t *entry1, *entry2;
22617
22618 tmp1 = tmp2 = NULL;
22619 do {
22620 entry1 = entry2 = NULL;
22621
22622 prelude_list_for_each_continue(&obj1->additional_data_list, tmp1) {
22623 entry1 = prelude_linked_object_get_object(tmp1);
22624 break;
22625 }
22626
22627 prelude_list_for_each_continue(&obj2->additional_data_list, tmp2) {
22628 entry2 = prelude_linked_object_get_object(tmp2);
22629 break;
22630 }
22631
22632 ret = idmef_additional_data_compare(entry1, entry2);
22633 if ( ret != 0 )
22634 return ret;
22635
22636 } while ( entry1 && entry2 );
22637 }
22638
22639 return ret;
22640 }
22641
22642 /**
22643 * idmef_message_new:
22644 * @ret: Pointer where to store the created #idmef_message_t object.
22645 *
22646 * Create a new #idmef_message_t object.
22647 *
22648 * Returns: 0 on success, a negative value if an error occured.
22649 */
idmef_message_new(idmef_message_t ** ret)22650 int idmef_message_new(idmef_message_t **ret)
22651 {
22652 *ret = calloc(1, sizeof(**ret));
22653 if ( ! *ret )
22654 return prelude_error_from_errno(errno);
22655
22656 (*ret)->_idmef_object_id = IDMEF_CLASS_ID_MESSAGE;
22657
22658 (*ret)->refcount = 1;
22659
22660 {
22661 int retval = prelude_string_new(&(*ret)->version);
22662
22663 if ( retval < 0 ) {
22664 idmef_message_destroy(*ret);
22665 *ret = NULL;
22666 return retval;
22667 }
22668 }
22669
22670 return 0;
22671
22672 }
22673
22674 /**
22675 * idmef_message_ref:
22676 * @message: pointer to a #idmef_message_t object.
22677 *
22678 * Increase @message reference count, so that it can be referenced
22679 * multiple time.
22680 *
22681 * Returns: a pointer to @message.
22682 */
idmef_message_ref(idmef_message_t * message)22683 idmef_message_t *idmef_message_ref(idmef_message_t *message)
22684 {
22685 prelude_return_val_if_fail(message, NULL);
22686 message->refcount++;
22687
22688 return message;
22689 }
22690
_idmef_message_get_child(void * p,idmef_class_child_id_t child,void ** childptr)22691 int _idmef_message_get_child(void *p, idmef_class_child_id_t child, void **childptr)
22692 {
22693 idmef_message_t *ptr = p;
22694
22695 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
22696 *childptr = NULL;
22697
22698 switch ( child ) {
22699
22700 case 0:
22701 return get_value_from_string((idmef_value_t **) childptr, ptr->version, TRUE);
22702 case 1:
22703 *childptr = ( ptr->type == IDMEF_MESSAGE_TYPE_ALERT ) ? ptr->message.alert : NULL;
22704 return 0;
22705
22706 case 2:
22707 *childptr = ( ptr->type == IDMEF_MESSAGE_TYPE_HEARTBEAT ) ? ptr->message.heartbeat : NULL;
22708 return 0;
22709
22710 default:
22711 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
22712 }
22713 }
22714
_idmef_message_new_child(void * p,idmef_class_child_id_t child,int n,void ** ret)22715 int _idmef_message_new_child(void *p, idmef_class_child_id_t child, int n, void **ret)
22716 {
22717 idmef_message_t *ptr = p;
22718
22719 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
22720
22721 switch ( child ) {
22722
22723 case 0:
22724 return idmef_message_new_version(ptr, (prelude_string_t **) ret);
22725
22726 case 1:
22727 return idmef_message_new_alert(ptr, (idmef_alert_t **) ret);
22728
22729 case 2:
22730 return idmef_message_new_heartbeat(ptr, (idmef_heartbeat_t **) ret);
22731
22732 default:
22733 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
22734 }
22735 }
22736
_idmef_message_destroy_child(void * p,idmef_class_child_id_t child,int n)22737 int _idmef_message_destroy_child(void *p, idmef_class_child_id_t child, int n)
22738 {
22739 idmef_message_t *ptr = p;
22740
22741 prelude_return_val_if_fail(p, prelude_error(PRELUDE_ERROR_ASSERTION));
22742
22743 switch ( child ) {
22744
22745 case 0:
22746 if ( ptr->version ) {
22747 prelude_string_destroy(ptr->version);
22748 ptr->version = NULL;
22749 }
22750
22751 return 0;
22752
22753 case 1:
22754 if ( ptr->type != IDMEF_MESSAGE_TYPE_ALERT )
22755 return 0;
22756
22757 idmef_alert_destroy(ptr->message.alert);
22758 ptr->message.alert = NULL;
22759 ptr->type = 0;
22760
22761 return 0;
22762
22763 case 2:
22764 if ( ptr->type != IDMEF_MESSAGE_TYPE_HEARTBEAT )
22765 return 0;
22766
22767 idmef_heartbeat_destroy(ptr->message.heartbeat);
22768 ptr->message.heartbeat = NULL;
22769 ptr->type = 0;
22770
22771 return 0;
22772
22773 default:
22774 return prelude_error(PRELUDE_ERROR_IDMEF_CLASS_UNKNOWN_CHILD);
22775 }
22776 }
22777
idmef_message_destroy_internal(idmef_message_t * ptr)22778 static void idmef_message_destroy_internal(idmef_message_t *ptr)
22779 {
22780 prelude_return_if_fail(ptr);
22781
22782 if ( ptr->version ) {
22783 prelude_string_destroy(ptr->version);
22784 ptr->version = NULL;
22785 }
22786
22787 switch ( ptr->type ) {
22788
22789 case IDMEF_MESSAGE_TYPE_ALERT:
22790 idmef_alert_destroy(ptr->message.alert);
22791 ptr->message.alert = NULL;
22792 break;
22793
22794 case IDMEF_MESSAGE_TYPE_HEARTBEAT:
22795 idmef_heartbeat_destroy(ptr->message.heartbeat);
22796 ptr->message.heartbeat = NULL;
22797 break;
22798
22799 default:
22800 break;
22801 }
22802
22803
22804 /* free() should be done by the caller */
22805 }
22806
22807 /**
22808 * idmef_message_get_version:
22809 * @ptr: pointer to a #idmef_message_t object.
22810 *
22811 * Get version children of the #idmef_message_t object.
22812 *
22813 * Returns: a pointer to a prelude_string_t object, or NULL if the children object is not set.
22814 */
idmef_message_get_version(idmef_message_t * ptr)22815 prelude_string_t *idmef_message_get_version(idmef_message_t *ptr)
22816 {
22817 prelude_return_val_if_fail(ptr, 0); /* FIXME */
22818
22819 return ptr->version;
22820 }
22821
22822 /**
22823 * idmef_message_set_version:
22824 * @ptr: pointer to a #idmef_message_t object.
22825 * @version: pointer to a #prelude_string_t object.
22826 *
22827 * Set @version object as a children of @ptr.
22828 * if @ptr already contain an @version object, then it is destroyed,
22829 * and updated to point to the provided @version object.
22830 */
22831
idmef_message_set_version(idmef_message_t * ptr,prelude_string_t * version)22832 void idmef_message_set_version(idmef_message_t *ptr, prelude_string_t *version)
22833 {
22834 prelude_return_if_fail(ptr);
22835
22836 if ( ptr->version )
22837 prelude_string_destroy(ptr->version);
22838
22839 ptr->version = version;
22840 }
22841
22842 /**
22843 * idmef_message_new_version:
22844 * @ptr: pointer to a #idmef_message_t object.
22845 * @ret: pointer to an address where to store the created #prelude_string_t object.
22846 *
22847 * Create a new version object, children of #idmef_message_t.
22848 * If @ptr already contain a #prelude_string_t object, then it is destroyed.
22849 *
22850 * Returns: 0 on success, or a negative value if an error occured.
22851 */
idmef_message_new_version(idmef_message_t * ptr,prelude_string_t ** ret)22852 int idmef_message_new_version(idmef_message_t *ptr, prelude_string_t **ret)
22853 {
22854 int retval;
22855
22856 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
22857
22858 if ( ! ptr->version ) {
22859 retval = prelude_string_new(&ptr->version);
22860 if ( retval < 0 )
22861 return retval;
22862 }
22863
22864 *ret = ptr->version;
22865 return 0;
22866 }
22867
22868 /**
22869 * idmef_message_get_type:
22870 * @ptr: pointer to a #idmef_message_t object.
22871 *
22872 * Access the type children of @ptr.
22873 *
22874 * Returns: a pointer to the #idmef_message_type_t children, or NULL if it is not set.
22875 */
idmef_message_get_type(idmef_message_t * ptr)22876 idmef_message_type_t idmef_message_get_type(idmef_message_t *ptr)
22877 {
22878 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
22879 return ptr->type;
22880 }
22881
22882 /**
22883 * idmef_message_get_alert:
22884 * @ptr: pointer to a #idmef_message_t object.
22885 *
22886 * Access the alert children of @ptr.
22887 *
22888 * Returns: a pointer to the #idmef_alert_t children, or NULL if it is not set.
22889 */
idmef_message_get_alert(idmef_message_t * ptr)22890 idmef_alert_t *idmef_message_get_alert(idmef_message_t *ptr)
22891 {
22892 prelude_return_val_if_fail(ptr, NULL);
22893 return (ptr->type == IDMEF_MESSAGE_TYPE_ALERT) ? ptr->message.alert : NULL;
22894 }
22895
22896 /**
22897 * idmef_message_set_alert:
22898 * @ptr: pointer to a #idmef_message_t object.
22899 * @alert: pointer to a #idmef_alert_t object.
22900 *
22901 * Set @alert object as a children of @ptr.
22902 * if @ptr already contain a @alert object, then it is destroyed,
22903 * and updated to point to the provided @alert object.
22904 */
idmef_message_set_alert(idmef_message_t * ptr,idmef_alert_t * alert)22905 void idmef_message_set_alert(idmef_message_t *ptr, idmef_alert_t *alert)
22906 {
22907 prelude_return_if_fail(ptr);
22908
22909 switch ( ptr->type ) {
22910
22911 case IDMEF_MESSAGE_TYPE_ALERT:
22912 idmef_alert_destroy(ptr->message.alert);
22913 break;
22914
22915 case IDMEF_MESSAGE_TYPE_HEARTBEAT:
22916 idmef_heartbeat_destroy(ptr->message.heartbeat);
22917 break;
22918
22919 default:
22920 break;
22921 }
22922
22923 ptr->message.alert = alert;
22924 ptr->type = (alert) ? IDMEF_MESSAGE_TYPE_ALERT : 0;
22925 }
22926
22927 /**
22928 * idmef_message_new_alert:
22929 * @ptr: pointer to a #idmef_message_t object.
22930 * @ret: pointer where to store the created #idmef_alert_t object.
22931 *
22932 * Create a new idmef_alert_t object, children of #idmef_message_t.
22933 * If @ptr already contain a #idmef_alert_t object, then it is destroyed.
22934 *
22935 * Returns: 0 on success, or a negative value if an error occured.
22936 */
idmef_message_new_alert(idmef_message_t * ptr,idmef_alert_t ** ret)22937 int idmef_message_new_alert(idmef_message_t *ptr, idmef_alert_t **ret)
22938 {
22939 int retval;
22940
22941 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
22942
22943 switch ( ptr->type ) {
22944
22945 case IDMEF_MESSAGE_TYPE_ALERT:
22946 *ret = ptr->message.alert;
22947 return 0;
22948
22949 case IDMEF_MESSAGE_TYPE_HEARTBEAT:
22950 idmef_heartbeat_destroy(ptr->message.heartbeat);
22951 break;
22952
22953 default:
22954 break;
22955 }
22956
22957 retval = idmef_alert_new(ret);
22958 if ( retval < 0 )
22959 return retval;
22960
22961 ptr->type = IDMEF_MESSAGE_TYPE_ALERT;
22962 ptr->message.alert = *ret;
22963
22964 return 0;
22965 }
22966
22967 /**
22968 * idmef_message_get_heartbeat:
22969 * @ptr: pointer to a #idmef_message_t object.
22970 *
22971 * Access the heartbeat children of @ptr.
22972 *
22973 * Returns: a pointer to the #idmef_heartbeat_t children, or NULL if it is not set.
22974 */
idmef_message_get_heartbeat(idmef_message_t * ptr)22975 idmef_heartbeat_t *idmef_message_get_heartbeat(idmef_message_t *ptr)
22976 {
22977 prelude_return_val_if_fail(ptr, NULL);
22978 return (ptr->type == IDMEF_MESSAGE_TYPE_HEARTBEAT) ? ptr->message.heartbeat : NULL;
22979 }
22980
22981 /**
22982 * idmef_message_set_heartbeat:
22983 * @ptr: pointer to a #idmef_message_t object.
22984 * @heartbeat: pointer to a #idmef_heartbeat_t object.
22985 *
22986 * Set @heartbeat object as a children of @ptr.
22987 * if @ptr already contain a @heartbeat object, then it is destroyed,
22988 * and updated to point to the provided @heartbeat object.
22989 */
idmef_message_set_heartbeat(idmef_message_t * ptr,idmef_heartbeat_t * heartbeat)22990 void idmef_message_set_heartbeat(idmef_message_t *ptr, idmef_heartbeat_t *heartbeat)
22991 {
22992 prelude_return_if_fail(ptr);
22993
22994 switch ( ptr->type ) {
22995
22996 case IDMEF_MESSAGE_TYPE_ALERT:
22997 idmef_alert_destroy(ptr->message.alert);
22998 break;
22999
23000 case IDMEF_MESSAGE_TYPE_HEARTBEAT:
23001 idmef_heartbeat_destroy(ptr->message.heartbeat);
23002 break;
23003
23004 default:
23005 break;
23006 }
23007
23008 ptr->message.heartbeat = heartbeat;
23009 ptr->type = (heartbeat) ? IDMEF_MESSAGE_TYPE_HEARTBEAT : 0;
23010 }
23011
23012 /**
23013 * idmef_message_new_heartbeat:
23014 * @ptr: pointer to a #idmef_message_t object.
23015 * @ret: pointer where to store the created #idmef_heartbeat_t object.
23016 *
23017 * Create a new idmef_heartbeat_t object, children of #idmef_message_t.
23018 * If @ptr already contain a #idmef_heartbeat_t object, then it is destroyed.
23019 *
23020 * Returns: 0 on success, or a negative value if an error occured.
23021 */
idmef_message_new_heartbeat(idmef_message_t * ptr,idmef_heartbeat_t ** ret)23022 int idmef_message_new_heartbeat(idmef_message_t *ptr, idmef_heartbeat_t **ret)
23023 {
23024 int retval;
23025
23026 prelude_return_val_if_fail(ptr, prelude_error(PRELUDE_ERROR_ASSERTION));
23027
23028 switch ( ptr->type ) {
23029
23030 case IDMEF_MESSAGE_TYPE_ALERT:
23031 idmef_alert_destroy(ptr->message.alert);
23032 break;
23033
23034 case IDMEF_MESSAGE_TYPE_HEARTBEAT:
23035 *ret = ptr->message.heartbeat;
23036 return 0;
23037
23038 default:
23039 break;
23040 }
23041
23042 retval = idmef_heartbeat_new(ret);
23043 if ( retval < 0 )
23044 return retval;
23045
23046 ptr->type = IDMEF_MESSAGE_TYPE_HEARTBEAT;
23047 ptr->message.heartbeat = *ret;
23048
23049 return 0;
23050 }
23051
23052 /**
23053 * idmef_message_copy:
23054 * @src: Source of the copy.
23055 * @dst: Where to copy the object.
23056 *
23057 * Copy a new #idmef_message_t object from @src to @dst.
23058 *
23059 * Returns: 0 on success, a negative value if an error occured.
23060 */
idmef_message_copy(const idmef_message_t * src,idmef_message_t * dst)23061 int idmef_message_copy(const idmef_message_t *src, idmef_message_t *dst)
23062 {
23063 int ret;
23064
23065 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
23066 prelude_return_val_if_fail(dst, prelude_error(PRELUDE_ERROR_ASSERTION));
23067
23068 ret = 0;
23069
23070 if ( src->version ) {
23071 ret = prelude_string_copy(src->version, dst->version);
23072 if ( ret < 0 )
23073 return ret;
23074 }
23075
23076 switch ( src->type ) {
23077
23078 case IDMEF_MESSAGE_TYPE_ALERT:
23079 ret = idmef_alert_clone(src->message.alert, &dst->message.alert);
23080 break;
23081
23082 case IDMEF_MESSAGE_TYPE_HEARTBEAT:
23083 ret = idmef_heartbeat_clone(src->message.heartbeat, &dst->message.heartbeat);
23084 break;
23085
23086 default:
23087 break;
23088 }
23089
23090 if ( ret < 0 )
23091 return ret;
23092
23093 dst->type = src->type;
23094
23095 return 0;
23096 }
23097
23098 /**
23099 * idmef_message_clone:
23100 * @src: Object to be cloned.
23101 * @dst: Address where to store the pointer to the cloned object.
23102 *
23103 * Create a copy of @src, and store it in @dst.
23104 *
23105 * Returns: 0 on success, a negative value if an error occured.
23106 */
idmef_message_clone(idmef_message_t * src,idmef_message_t ** dst)23107 int idmef_message_clone(idmef_message_t *src, idmef_message_t **dst)
23108 {
23109 int ret;
23110
23111 prelude_return_val_if_fail(src, prelude_error(PRELUDE_ERROR_ASSERTION));
23112
23113 ret = idmef_message_new(dst);
23114 if ( ret < 0 )
23115 return ret;
23116
23117 return idmef_message_copy(src, *dst);
23118 }
23119
23120 /**
23121 * idmef_message_compare:
23122 * @obj1: Object to compare with @obj2.
23123 * @obj2: Object to compare with @obj1.
23124 *
23125 * Compare @obj1 with @obj2.
23126 *
23127 * Returns: 0 on match, a negative value on comparison failure.
23128 */
idmef_message_compare(const idmef_message_t * obj1,const idmef_message_t * obj2)23129 int idmef_message_compare(const idmef_message_t *obj1, const idmef_message_t *obj2)
23130 {
23131 int ret = 0;
23132
23133 if ( obj1 == NULL && obj2 == NULL )
23134 return 0;
23135
23136 else if ( obj1 == NULL || obj2 == NULL )
23137 return -1;
23138
23139 ret = prelude_string_compare(obj1->version, obj2->version);
23140 if ( ret != 0 )
23141 return ret;
23142
23143 if ( obj1->type != obj2->type )
23144 return -1;
23145
23146 switch ( obj1->type ) {
23147
23148 case IDMEF_MESSAGE_TYPE_ALERT:
23149 ret = idmef_alert_compare(obj1->message.alert, obj2->message.alert);
23150 break;
23151
23152 case IDMEF_MESSAGE_TYPE_HEARTBEAT:
23153 ret = idmef_heartbeat_compare(obj1->message.heartbeat, obj2->message.heartbeat);
23154 break;
23155
23156 default:
23157 break;
23158 }
23159
23160 return ret;
23161 }
23162
23163
_idmef_additional_data_type_is_set(idmef_additional_data_t * ad)23164 int _idmef_additional_data_type_is_set(idmef_additional_data_t *ad)
23165 {
23166 return ad->_type_is_set;
23167 }
23168
23169
idmef_message_set_pmsg(idmef_message_t * message,prelude_msg_t * msg)23170 void idmef_message_set_pmsg(idmef_message_t *message, prelude_msg_t *msg)
23171 {
23172 prelude_return_if_fail(message);
23173 message->pmsg = msg;
23174 }
23175
23176
idmef_message_get_pmsg(idmef_message_t * message)23177 prelude_msg_t *idmef_message_get_pmsg(idmef_message_t *message)
23178 {
23179 prelude_return_val_if_fail(message, NULL);
23180 return message->pmsg;
23181 }
23182
23183
23184 /**
23185 * idmef_message_destroy:
23186 * @ptr: pointer to a #idmef_message_t object.
23187 *
23188 * Destroy @ptr and all of it's children.
23189 * The objects are only destroyed if their reference count reach zero.
23190 */
idmef_message_destroy(idmef_message_t * ptr)23191 void idmef_message_destroy(idmef_message_t *ptr)
23192 {
23193 prelude_return_if_fail(ptr);
23194
23195 if ( --ptr->refcount )
23196 return;
23197
23198 idmef_message_destroy_internal(ptr);
23199
23200 if ( ptr->pmsg )
23201 prelude_msg_destroy(ptr->pmsg);
23202
23203 free(ptr);
23204 }
23205