Utilities and helpers. More...
#include <stdlib.h>#include <string.h>#include <sys/stat.h>#include <errno.h>#include <fcntl.h>#include <sys/file.h>#include <sys/types.h>#include <unistd.h>#include "utils.h"#include "debug.h"
Functions | |
| gint64 | janus_get_monotonic_time (void) |
| Helper to retrieve the system monotonic time, as Glib's g_get_monotonic_time may not be available (only since 2.28) More... | |
| gint64 | janus_get_real_time (void) |
| Helper to retrieve the system real time, as Glib's g_get_real_time may not be available (only since 2.28) More... | |
| gboolean | janus_is_true (const char *value) |
| Helper to parse yes/no|true/false configuration values. More... | |
| gboolean | janus_strcmp_const_time (const void *str1, const void *str2) |
| Helper to compare strings in constant time. More... | |
| guint32 | janus_random_uint32 (void) |
| Helper to generate random 32-bit unsigned integers (useful for SSRCs, etc.) More... | |
| guint64 | janus_random_uint64 (void) |
| Helper to generate random 64-bit unsigned integers (useful for Janus IDs) More... | |
| guint64 * | janus_uint64_dup (guint64 num) |
| Helper to generate an allocated copy of a guint64 number. More... | |
| void | janus_flags_reset (janus_flags *flags) |
| Janus flags reset method. More... | |
| void | janus_flags_set (janus_flags *flags, uint32_t flag) |
| Janus flags set method. More... | |
| void | janus_flags_clear (janus_flags *flags, uint32_t flag) |
| Janus flags clear method. More... | |
| gboolean | janus_flags_is_set (janus_flags *flags, uint32_t flag) |
| Janus flags check method. More... | |
| char * | janus_string_replace (char *message, const char *old_string, const char *new_string) |
| Helper to replace strings. More... | |
| int | janus_mkdir (const char *dir, mode_t mode) |
| Helper to create a new directory, and recursively create parent directories if needed. More... | |
| int | janus_get_codec_pt (const char *sdp, const char *codec) |
| Ugly and dirty helper to quickly get the payload type associated with a codec in an SDP. More... | |
| const char * | janus_get_codec_from_pt (const char *sdp, int pt) |
| Ugly and dirty helper to quickly get the codec associated with a payload type in an SDP. More... | |
| int | janus_pidfile_create (const char *file) |
| Create and lock a PID file. More... | |
| int | janus_pidfile_remove (void) |
| Unlock and remove a previously created PID file. More... | |
| void | janus_get_json_type_name (int jtype, unsigned int flags, char *type_name) |
| Creates a string describing the JSON type and constraint. More... | |
| gboolean | janus_json_is_valid (json_t *val, json_type jtype, unsigned int flags) |
| Checks whether the JSON value matches the type and constraint. More... | |
Utilities and helpers.
Implementations of a few methods that may be of use here and there in the code.
| void janus_flags_clear | ( | janus_flags * | flags, |
| uint32_t | flag | ||
| ) |
Janus flags clear method.
| [in] | flags | The janus_flags instance to update |
| [in] | flag | The flag to clear |
| gboolean janus_flags_is_set | ( | janus_flags * | flags, |
| uint32_t | flag | ||
| ) |
Janus flags check method.
| [in] | flags | The janus_flags instance to check |
| [in] | flag | The flag to check |
| void janus_flags_reset | ( | janus_flags * | flags | ) |
Janus flags reset method.
| [in] | flags | The janus_flags instance to reset |
| void janus_flags_set | ( | janus_flags * | flags, |
| uint32_t | flag | ||
| ) |
Janus flags set method.
| [in] | flags | The janus_flags instance to update |
| [in] | flag | The flag to set |
| const char* janus_get_codec_from_pt | ( | const char * | sdp, |
| int | pt | ||
| ) |
Ugly and dirty helper to quickly get the codec associated with a payload type in an SDP.
| sdp | The SDP to parse |
| pt | The payload type to look for |
| int janus_get_codec_pt | ( | const char * | sdp, |
| const char * | codec | ||
| ) |
Ugly and dirty helper to quickly get the payload type associated with a codec in an SDP.
| sdp | The SDP to parse |
| codec | The codec to look for |
| void janus_get_json_type_name | ( | int | jtype, |
| unsigned int | flags, | ||
| char * | type_name | ||
| ) |
Creates a string describing the JSON type and constraint.
| jtype | The JSON type, e.g., JSON_STRING | |
| flags | Indicates constraints for the described type | |
| [out] | type_name | The type description, e.g., "a positive integer"; required size is 19 characters |
| gint64 janus_get_monotonic_time | ( | void | ) |
Helper to retrieve the system monotonic time, as Glib's g_get_monotonic_time may not be available (only since 2.28)
| gint64 janus_get_real_time | ( | void | ) |
Helper to retrieve the system real time, as Glib's g_get_real_time may not be available (only since 2.28)
| gboolean janus_is_true | ( | const char * | value | ) |
Helper to parse yes/no|true/false configuration values.
| value | The configuration value to parse |
| gboolean janus_json_is_valid | ( | json_t * | val, |
| json_type | jtype, | ||
| unsigned int | flags | ||
| ) |
Checks whether the JSON value matches the type and constraint.
| val | The JSON value to be checked |
| jtype | The JSON type, e.g., JSON_STRING |
| flags | Indicates constraints for the described type |
| int janus_mkdir | ( | const char * | dir, |
| mode_t | mode | ||
| ) |
Helper to create a new directory, and recursively create parent directories if needed.
| dir | Path to the new folder to create |
| mode | File permissions for the new directory file |
| int janus_pidfile_create | ( | const char * | file | ) |
Create and lock a PID file.
| file | Path to the PID file to use |
| int janus_pidfile_remove | ( | void | ) |
Unlock and remove a previously created PID file.
| guint32 janus_random_uint32 | ( | void | ) |
Helper to generate random 32-bit unsigned integers (useful for SSRCs, etc.)
| guint64 janus_random_uint64 | ( | void | ) |
Helper to generate random 64-bit unsigned integers (useful for Janus IDs)
| gboolean janus_strcmp_const_time | ( | const void * | str1, |
| const void * | str2 | ||
| ) |
Helper to compare strings in constant time.
| str1 | The first string to compare |
| str2 | The second string to compare |
| char* janus_string_replace | ( | char * | message, |
| const char * | old_string, | ||
| const char * | new_string | ||
| ) |
Helper to replace strings.
| message | The string that contains the text to replace, which may be freed if it is too short |
| old_string | The old text to replace |
| new_string | The new text |
| guint64* janus_uint64_dup | ( | guint64 | num | ) |
Helper to generate an allocated copy of a guint64 number.
| num | The guint64 number to duplicate |