nmsg 1.1.2
message.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009-2015 by Farsight Security, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef NMSG_MESSAGE_H
18#define NMSG_MESSAGE_H
19
20#include <nmsg/msgmod.h>
21
77nmsg_message_t
78nmsg_message_init(nmsg_msgmod_t mod);
79
96nmsg_message_t
97nmsg_message_from_raw_payload(unsigned vid, unsigned msgtype,
98 uint8_t *data, size_t sz,
99 const struct timespec *ts);
100
123nmsg_message_from_json(const char *json, nmsg_message_t *msg);
124
130void
131nmsg_message_destroy(nmsg_message_t *msg);
132
145nmsg_message_to_pres(nmsg_message_t msg, char **pres, const char *endline);
146
158nmsg_message_to_json(nmsg_message_t msg, char **json);
159
163nmsg_msgmod_t
164nmsg_message_get_msgmod(nmsg_message_t msg);
165
170nmsg_message_add_allocation(nmsg_message_t msg, void *ptr);
171
175void
177
181int32_t
182nmsg_message_get_vid(nmsg_message_t msg);
183
187int32_t
188nmsg_message_get_msgtype(nmsg_message_t msg);
189
195void *
196nmsg_message_get_payload(nmsg_message_t msg);
197
204size_t
206
212void
213nmsg_message_update(nmsg_message_t msg);
214
221void
223
230void
231nmsg_message_get_time(nmsg_message_t msg, struct timespec *ts);
232
240void
241nmsg_message_set_time(nmsg_message_t msg, const struct timespec *ts);
242
247uint32_t
248nmsg_message_get_source(nmsg_message_t msg);
249
254uint32_t
255nmsg_message_get_operator(nmsg_message_t msg);
256
261uint32_t
262nmsg_message_get_group(nmsg_message_t msg);
263
267void
268nmsg_message_set_source(nmsg_message_t msg, uint32_t source);
269
273void
274nmsg_message_set_operator(nmsg_message_t msg, uint32_t operator_);
275
279void
280nmsg_message_set_group(nmsg_message_t msg, uint32_t group);
281
299nmsg_message_get_field(nmsg_message_t msg,
300 const char *field_name,
301 unsigned val_idx,
302 void **data,
303 size_t *len);
304
311 unsigned field_idx,
312 unsigned val_idx,
313 void **data,
314 size_t *len);
315
324nmsg_message_get_field_idx(nmsg_message_t msg,
325 const char *field_name,
326 unsigned *idx);
327
337 unsigned field_idx,
338 const char **field_name);
339
350 const char *field_name,
351 unsigned *flags);
352
359 unsigned field_idx,
360 unsigned *flags);
361
371 const char *field_name,
373
380 unsigned field_idx,
382
390nmsg_message_get_num_fields(nmsg_message_t msg, size_t *n_fields);
391
402 const char *field_name,
403 size_t *n_field_values);
404
415 unsigned field_idx,
416 size_t *n_field_values);
417
430nmsg_message_set_field(nmsg_message_t msg,
431 const char *field_name,
432 unsigned val_idx,
433 const uint8_t *data,
434 size_t len);
435
442 unsigned field_idx,
443 unsigned val_idx,
444 const uint8_t *data,
445 size_t len);
446
456nmsg_message_enum_name_to_value(nmsg_message_t msg, const char *field_name,
457 const char *name, unsigned *value);
458
464nmsg_message_enum_name_to_value_by_idx(nmsg_message_t msg, unsigned field_idx,
465 const char *name, unsigned *value);
466
476nmsg_message_enum_value_to_name(nmsg_message_t msg, const char *field_name,
477 unsigned value, const char **name);
478
484nmsg_message_enum_value_to_name_by_idx(nmsg_message_t msg, unsigned field_idx,
485 unsigned value, const char **name);
486
487#endif /* NMSG_MESSAGE_H */
nmsg_res nmsg_message_add_allocation(nmsg_message_t msg, void *ptr)
Add an allocated object to a message object.
nmsg_message_t nmsg_message_init(nmsg_msgmod_t mod)
Initialize a new, empty message object of a particular type.
nmsg_res nmsg_message_get_field_idx(nmsg_message_t msg, const char *field_name, unsigned *idx)
Get the field index of a named field.
uint32_t nmsg_message_get_operator(nmsg_message_t msg)
Get the operator of a message object.
nmsg_res nmsg_message_get_field_type(nmsg_message_t msg, const char *field_name, nmsg_msgmod_field_type *type)
Get the type of a field.
void nmsg_message_set_time(nmsg_message_t msg, const struct timespec *ts)
Set the timestamp of a message object.
nmsg_res nmsg_message_get_field_name(nmsg_message_t msg, unsigned field_idx, const char **field_name)
Get the name of a field specified by index.
void * nmsg_message_get_payload(nmsg_message_t msg)
WARNING: experts only.
void nmsg_message_set_group(nmsg_message_t msg, uint32_t group)
Set the group of a message object.
nmsg_res nmsg_message_get_field_flags_by_idx(nmsg_message_t msg, unsigned field_idx, unsigned *flags)
Get the flags associated with a field.
nmsg_res nmsg_message_get_field(nmsg_message_t msg, const char *field_name, unsigned val_idx, void **data, size_t *len)
Get the value of a field.
nmsg_message_t nmsg_message_from_raw_payload(unsigned vid, unsigned msgtype, uint8_t *data, size_t sz, const struct timespec *ts)
Initialize a new message object from an opaque payload blob.
size_t nmsg_message_get_payload_size(nmsg_message_t msg)
WARNING: experts only.
int32_t nmsg_message_get_msgtype(nmsg_message_t msg)
Return the message type of a message object.
nmsg_res nmsg_message_enum_value_to_name(nmsg_message_t msg, const char *field_name, unsigned value, const char **name)
Convert a numeric enum value to a symbolic name.
nmsg_res nmsg_message_get_field_by_idx(nmsg_message_t msg, unsigned field_idx, unsigned val_idx, void **data, size_t *len)
Get the value of a field.
nmsg_msgmod_t nmsg_message_get_msgmod(nmsg_message_t msg)
Return the message module object associated with a message object.
int32_t nmsg_message_get_vid(nmsg_message_t msg)
Return the vendor ID of a message object.
nmsg_res nmsg_message_enum_value_to_name_by_idx(nmsg_message_t msg, unsigned field_idx, unsigned value, const char **name)
Convert a numeric enum value to a symbolic name.
nmsg_res nmsg_message_to_json(nmsg_message_t msg, char **json)
Convert a message object to JSON format.
nmsg_res nmsg_message_get_num_field_values(nmsg_message_t msg, const char *field_name, size_t *n_field_values)
Get the total number of field values that a message field contains.
nmsg_res nmsg_message_from_json(const char *json, nmsg_message_t *msg)
Convert a JSON format line to an NMSG payload.
void nmsg_message_compact_payload(nmsg_message_t msg)
WARNING: experts only.
nmsg_res nmsg_message_set_field_by_idx(nmsg_message_t msg, unsigned field_idx, unsigned val_idx, const uint8_t *data, size_t len)
Set a field to the specified value.
nmsg_res nmsg_message_enum_name_to_value(nmsg_message_t msg, const char *field_name, const char *name, unsigned *value)
Convert an enum name to a numeric value.
void nmsg_message_update(nmsg_message_t msg)
WARNING: experts only.
nmsg_res nmsg_message_set_field(nmsg_message_t msg, const char *field_name, unsigned val_idx, const uint8_t *data, size_t len)
Set a field to the specified value.
nmsg_res nmsg_message_get_field_flags(nmsg_message_t msg, const char *field_name, unsigned *flags)
Get the flags associated with a field.
nmsg_res nmsg_message_enum_name_to_value_by_idx(nmsg_message_t msg, unsigned field_idx, const char *name, unsigned *value)
Convert an enum name to a numeric value.
uint32_t nmsg_message_get_group(nmsg_message_t msg)
Get the group of a message object.
void nmsg_message_free_allocations(nmsg_message_t msg)
Free all allocated objects associated with a message object.
nmsg_res nmsg_message_to_pres(nmsg_message_t msg, char **pres, const char *endline)
Convert a message object to presentation format.
uint32_t nmsg_message_get_source(nmsg_message_t msg)
Get the source ID of a message object.
void nmsg_message_get_time(nmsg_message_t msg, struct timespec *ts)
Get the timestamp of a message object.
void nmsg_message_set_operator(nmsg_message_t msg, uint32_t operator_)
Set the operator of a message object.
nmsg_res nmsg_message_get_num_fields(nmsg_message_t msg, size_t *n_fields)
Get the total number of possible fields that a message can contain.
void nmsg_message_set_source(nmsg_message_t msg, uint32_t source)
Set the source ID of a message object.
nmsg_res nmsg_message_get_num_field_values_by_idx(nmsg_message_t msg, unsigned field_idx, size_t *n_field_values)
Get the total number of field values that a message field contains.
nmsg_res nmsg_message_get_field_type_by_idx(nmsg_message_t msg, unsigned field_idx, nmsg_msgmod_field_type *type)
Get the type of a field.
void nmsg_message_destroy(nmsg_message_t *msg)
Destroy a message object and deallocate any resources associated with it.
Message modules.
nmsg_msgmod_field_type
Enum mapping protocol buffer schema types to nmsg-specific types for "transparent" modules.
Definition msgmod.h:72
nmsg_res
nmsg result code
Definition res.h:25