nmsg  0.9.0
message.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2011 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 
67 #include <nmsg.h>
68 
77 nmsg_message_t
78 nmsg_message_init(nmsg_msgmod_t mod);
79 
96 nmsg_message_t
97 nmsg_message_from_raw_payload(unsigned vid, unsigned msgtype,
98  uint8_t *data, size_t sz,
99  const struct timespec *ts);
100 
106 void
107 nmsg_message_destroy(nmsg_message_t *msg);
108 
120 nmsg_res
121 nmsg_message_to_pres(nmsg_message_t msg, char **pres, const char *endline);
122 
126 nmsg_msgmod_t
127 nmsg_message_get_msgmod(nmsg_message_t msg);
128 
132 nmsg_res
133 nmsg_message_add_allocation(nmsg_message_t msg, void *ptr);
134 
138 void
139 nmsg_message_free_allocations(nmsg_message_t msg);
140 
144 int32_t
145 nmsg_message_get_vid(nmsg_message_t msg);
146 
150 int32_t
151 nmsg_message_get_msgtype(nmsg_message_t msg);
152 
158 void *
159 nmsg_message_get_payload(nmsg_message_t msg);
160 
166 void
167 nmsg_message_update(nmsg_message_t msg);
168 
175 void
176 nmsg_message_compact_payload(nmsg_message_t msg);
177 
184 void
185 nmsg_message_get_time(nmsg_message_t msg, struct timespec *ts);
186 
194 void
195 nmsg_message_set_time(nmsg_message_t msg, const struct timespec *ts);
196 
201 uint32_t
202 nmsg_message_get_source(nmsg_message_t msg);
203 
208 uint32_t
209 nmsg_message_get_operator(nmsg_message_t msg);
210 
215 uint32_t
216 nmsg_message_get_group(nmsg_message_t msg);
217 
221 void
222 nmsg_message_set_source(nmsg_message_t msg, uint32_t source);
223 
227 void
228 nmsg_message_set_operator(nmsg_message_t msg, uint32_t operator_);
229 
233 void
234 nmsg_message_set_group(nmsg_message_t msg, uint32_t group);
235 
252 nmsg_res
253 nmsg_message_get_field(nmsg_message_t msg,
254  const char *field_name,
255  unsigned val_idx,
256  void **data,
257  size_t *len);
258 
263 nmsg_res
264 nmsg_message_get_field_by_idx(nmsg_message_t msg,
265  unsigned field_idx,
266  unsigned val_idx,
267  void **data,
268  size_t *len);
269 
277 nmsg_res
278 nmsg_message_get_field_idx(nmsg_message_t msg,
279  const char *field_name,
280  unsigned *idx);
281 
289 nmsg_res
290 nmsg_message_get_field_name(nmsg_message_t msg,
291  unsigned field_idx,
292  const char **field_name);
293 
302 nmsg_res
303 nmsg_message_get_field_flags(nmsg_message_t msg,
304  const char *field_name,
305  unsigned *flags);
306 
311 nmsg_res
312 nmsg_message_get_field_flags_by_idx(nmsg_message_t msg,
313  unsigned field_idx,
314  unsigned *flags);
315 
323 nmsg_res
324 nmsg_message_get_field_type(nmsg_message_t msg,
325  const char *field_name,
326  nmsg_msgmod_field_type *type);
327 
332 nmsg_res
333 nmsg_message_get_field_type_by_idx(nmsg_message_t msg,
334  unsigned field_idx,
335  nmsg_msgmod_field_type *type);
336 
343 nmsg_res
344 nmsg_message_get_num_fields(nmsg_message_t msg, size_t *n_fields);
345 
357 nmsg_res
358 nmsg_message_set_field(nmsg_message_t msg,
359  const char *field_name,
360  unsigned val_idx,
361  const uint8_t *data,
362  size_t len);
363 
368 nmsg_res
369 nmsg_message_set_field_by_idx(nmsg_message_t msg,
370  unsigned field_idx,
371  unsigned val_idx,
372  const uint8_t *data,
373  size_t len);
374 
383 nmsg_res
384 nmsg_message_enum_name_to_value(nmsg_message_t msg, const char *field_name,
385  const char *name, unsigned *value);
386 
391 nmsg_res
392 nmsg_message_enum_name_to_value_by_idx(nmsg_message_t msg, unsigned field_idx,
393  const char *name, unsigned *value);
394 
403 nmsg_res
404 nmsg_message_enum_value_to_name(nmsg_message_t msg, const char *field_name,
405  unsigned value, const char **name);
406 
411 nmsg_res
412 nmsg_message_enum_value_to_name_by_idx(nmsg_message_t msg, unsigned field_idx,
413  unsigned value, const char **name);
414 
415 #endif /* NMSG_MESSAGE_H */
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.
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 symoblic name.
nmsg_res
nmsg result code
Definition: res.h:25
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.
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_compact_payload(nmsg_message_t msg)
WARNING: experts only.
Base nmsg support header.
void nmsg_message_set_group(nmsg_message_t msg, uint32_t group)
Set the group of a message object.
nmsg_msgmod_t nmsg_message_get_msgmod(nmsg_message_t msg)
Return the message module object associated with a message object.
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.
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.
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_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_get_field_type(nmsg_message_t msg, const char *field_name, nmsg_msgmod_field_type *type)
Get the type of a field.
nmsg_msgmod_field_type
Enum mapping protocol buffer schema types to nmsg-specific types for "transparent" modules...
Definition: msgmod.h:73
void nmsg_message_destroy(nmsg_message_t *msg)
Destroy a message object and deallocate any resources associated with it.
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_operator(nmsg_message_t msg)
Get the operator of 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.
void nmsg_message_free_allocations(nmsg_message_t msg)
Free all allocated objects associated with a message object.
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_set_time(nmsg_message_t msg, const struct timespec *ts)
Set the timestamp of a message object.
uint32_t nmsg_message_get_group(nmsg_message_t msg)
Get the group of a message object.
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_res nmsg_message_get_field_flags(nmsg_message_t msg, const char *field_name, unsigned *flags)
Get the flags associated with a field.
void * nmsg_message_get_payload(nmsg_message_t msg)
WARNING: experts only.
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.
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.
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 af ield.
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.
void nmsg_message_set_source(nmsg_message_t msg, uint32_t source)
Set the source ID of a message object.
int32_t nmsg_message_get_msgtype(nmsg_message_t msg)
Return the message type 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_add_allocation(nmsg_message_t msg, void *ptr)
Add an allocated object to a message object.
void nmsg_message_update(nmsg_message_t msg)
WARNING: experts only.