summaryrefslogtreecommitdiffstats
path: root/include/osmocom/core/utils.h
Commit message (Collapse)AuthorAgeFilesLines
* utils: add helper wrapper for osmo_strlcpy()Max2018-02-051-0/+3
| | | | | | | | | | Add wrapper for osmo_strlcpy() which uses sizeof() to automatically determine buffer's size and use it for GSMTAP logging. This is pretty common use case for osmo_strlcpy() so it's a good idea to save some typing by using generic define. Related: OS#2864 Change-Id: I03d0d3d32a8d572ad573d03c603e14cdc27a3f7b
* utils: add osmo_escape_str()Neels Hofmeyr2017-12-181-0/+3
| | | | | | | | | | | | | To report invalid characters in identifiers, it is desirable to escape any weird characters. Otherwise we might print stray newlines or control characters in the log output. ctrl_test.c already uses a print_escaped() function, which will be replaced by osmo_escape_str() in a subsequent patch. control_cmd.c will use osmo_escape_str() to log invalid identifiers. Change-Id: Ic685eb63dead3967d01aaa4f1e9899e5461ca49a
* utils: add osmo_separated_identifiers_valid()Neels Hofmeyr2017-12-171-0/+1
| | | | | | | | For validating CTRL input, we want to verify that an input variable is a series of valid osmo_identifier_valid() separated by dots. Allow validating any additional chars with identifiers, for CTRL vars will be just ".". Change-Id: I13dfd02c8c870620f937d789873ad84c6b1c45de
* logging vty: describe 'logging set-log-mask' command, add OSMO_STRINGIFY_VAL()Neels Hofmeyr2017-12-121-0/+2
| | | | Change-Id: I73ac5873ede858da44e1486d8a5c81da1ed5b19f
* comment: utils: more accurately describe OSMO_STRINGIFY macroNeels Hofmeyr2017-12-101-1/+3
| | | | Change-Id: I7b057c026f9df90608b7cbd12481ab9e7a41d88c
* Introduce osmo_identifier_valid() function to check validity of identifierHarald Welte2017-10-241-0/+3
| | | | | | | | | We define the notion of an 'osmocom identifier' which is basically a 7-bit US-ASCII without any special characters beyond "-_:@". We introduce a function to verify if an identifier consists only of the permitted characters. Change-Id: I96a8d345c5a69238a12d040f39b70c485a5c421c
* add osmo_talloc_asprintf() and ctrl_cmd_reply_printf()Neels Hofmeyr2017-10-241-0/+18
| | | | | | | | | | | | | | | | Add macro to append to a CTRL commands' reply string, ctrl_cmd_reply_printf(). The talloc_asprintf() part of it is generic enough to qualify for a separate macro, osmo_talloc_asprintf(). The idea is to not have to decide for each bit added to a string whether the string is already allocated or not, but simply be able to issue printf commands and let the macro worry about initial allocation or reallocation. This originally came from osmo-hlr change I1bd62ae0d4eefde7e1517db15a2155640a1bab58, where it was requested to move this bit to libosmocore. Change-Id: Ic9dba0e4a1eb5a7dc3cee2f181b9024ed4fc7005
* utils: add osmo_is_hexstr(), add unit testNeels Hofmeyr2017-10-091-0/+5
| | | | | | Will be used by OsmoHLR to validate VTY and CTRL input. Change-Id: Idf75946eb0a84e145adad13fc7c78bb7a267aa0a
* doxygen: unify use of \file across the boardNeels Hofmeyr2017-06-231-3/+1
| | | | | | | | | | | | | | | | | Considering the various styles and implications found in the sources, edit scores of files to follow the same API doc guidelines around the doxygen grouping and the \file tag. Many files now show a short description in the generated API doc that was so far only available as C comment. The guidelines and reasoning behind it is documented at https://osmocom.org/projects/cellular-infrastructure/wiki/Guidelines_for_API_documentation In some instances, remove file comments and add to the corresponding group instead, to be shared among several files (e.g. bitvec). Change-Id: Ifa70e77e90462b5eb2b0457c70fd25275910c72b
* doxygen: enable AUTOBRIEF, drop \briefNeels Hofmeyr2017-06-231-9/+9
| | | | | | | | | | Especially for short descriptions, it is annoying to have to type \brief for every single API doc. Drop all \brief and enable the AUTOBRIEF feature of doxygen, which always takes the first sentence of an API doc as the brief description. Change-Id: I11a8a821b065a128108641a2a63fb5a2b1916e87
* Move NUM_BYTES macro to core libraryMax2017-06-191-0/+2
| | | | | | | | | It's universally useful so it make sense to have it in the shared core: * move macro from libosmocoding to libosmocore * add OSMO_ prefix * add doxygen docs Change-Id: I5386ba3e1f1cc153ba96c29dc71c9075a052aa02
* fix OSMO_VALUE_STRING macro: don't use OSMO_STRINGIFY()Neels Hofmeyr2017-03-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | To be able to use OSMO_VALUE_STRING() on a #defined constant, don't use OSMO_STRINGIFY(): the second indirection resolves the #define to its value, so for example OSMO_VALUE_STRING(GSM48_PDISC_MM) would resolve to { 0x05, "0x05" } When using '#x' directly, this becomes the desired { 0x05, "GSM48_PDISC_MM" } With enum values as we've used until now, this problem does not appear, because enum values are not resolved by the preprocessor. Keep OSMO_STRINGIFY() because it is used directly in openbsc (composing FSM state names). Change-Id: I91ecfcef61be8cf73d59ea821cc4fd9d2ad5c9c7
* utils.h: #include <stdio.h> as we use fprintf()Harald Welte2017-01-231-0/+1
| | | | Change-Id: I911c7f4bcadde414ce0b384e13a3a9a4a953e2fb
* utils.h: add OSMO_STRINGIFY and OSMO_VALUE_STRING macrosNeels Hofmeyr2016-12-211-0/+4
| | | | | | | | | | | | | | OSMO_STRINGIFY particularly allows putting port numbers from a #define into VTY doc strings, like: #define FOO_PORT 2342 DEFUN(..., "Foo UDP port (default: " OSMO_STRINGIFY(FOO_PORT) ")\n") OSMO_VALUE_STRING creates value_string items with the string being exactly the enum value's name. Replaces a similar macro def in fsm.c Change-Id: I857af45ae602bb9a647ba26cf8b0d1b23403b54c
* Introduce osmo_strlcpy() function so we can stop using strncpy()Harald Welte2016-11-261-0/+2
| | | | | | | | | | | | | | | | I'm aware of the existing criticism on stlrcpy(), but I think it is still better than what we have now: stnrcpy(), sometimes with Coverity warnings and sometimes with a manual setting of the termination byte. The implementation follows the linux kernel strlcpy() which is claimed to be BSD compatible. We could of course link against libbsd on Linux instead, but I think it's reasonably small and simple to provide our own implementation. Future versions of libosmocore could use some autoconf magic and preprocessor macros to use the system-provided strlcpy() if it exists. Change-Id: Ifdc99b0e3b8631f1e771e58acaf9efb00a9cd493
* Mark input string to osmo_talloc_replace_string() as constHarald Welte2016-07-281-1/+1
| | | | | | | This allows us to pass in strings that are 'const', which for the source of a copy should be the normal/regular case anyway. Change-Id: Icee6a5f88babd3a4e30bf0886f0f8d3b865d80ce
* add get_value_string_or_null() to handle unknown itemsNeels Hofmeyr2016-06-131-0/+2
| | | | | | | | | | | | | | | | | Add get_value_string_or_null() to return NULL in case the given value is not found in the list of strings, to be able to cleanly fall back to another list of strings. Absorb the lookup loop from get_value_string(). Context: in osmo-bts, I want to look up an RSL message name in rsl_msgt_names and fall back to rsl_ipac_msgt_names if not found, because the IPAC PDCH ACT and DEACT messages are sent in a standard ABIS_RSL_MDISC_DED_CHAN. In a subsequent commit, get_value_string_or_null() will be used by new rsl_or_ipac_msg_name(). Change-Id: I1fa3907e28d528d2758bc3eae9d19e6c1168f5e5 Reviewed-on: https://gerrit.osmocom.org/230 Reviewed-by: Harald Welte <laforge@gnumonks.org> Tested-by: Jenkins Builder
* logging: Use __BASE_FILE__ instead of __FILE__Harald Welte2016-05-121-1/+1
| | | | | | | | | | | | | | Apparently __FILE__ expands to nasty '../../..' paths when BUILDDIR != SRCDIR. This in turn leads to ugly log lines like: <0000> ../../../../osmo-bts/src/common/rsl.c:1642 (bts=0,trx=0,ts=0,ss=0) Handing RLL msg UNIT_DATA_IND from LAPDm to MEAS REP Where we certainly wouldn't want the "../../../../osmo-bts" part. Change-Id: If6d2de33c3b6bb2943954bbd81eff261dc279d58 Reviewed-on: https://gerrit.osmocom.org/38 Tested-by: Jenkins Builder Reviewed-by: Harald Welte <laforge@gnumonks.org>
* Import osmo_{encode,decode}_big_endian() from openbscHarald Welte2016-05-051-0/+4
|
* Update doxygen annotations in libosmocoreHarald Welte2016-05-051-0/+9
| | | | | This adds and improves doxygen API descriptions all over libosmocore, reducing the 'white spots' that don't have any documentation.
* osmo_static_assert: Put back the typedef in the codeHolger Hans Peter Freyther2015-04-131-1/+1
| | | | | | | | In OSX the int declares linkage and for libosmo-abis we have two static asserts with the same name in two different compilation units. When adding the "unused" attribute I removed the typedef. I verified with a gcc 4.9.2 that no new warnings will be shown when compiling libosmo-abis.
* libctrl: remove reference to bsc_replace_string()Harald Welte2014-08-211-0/+7
| | | | | ... and rather introduce a general osmo_talloc_replace_string() to libosmocore.
* include: Switch to #pragma once patternSylvain Munaut2014-06-161-4/+1
| | | | Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
* utils.h: we need to include utils.h for osmo_generate_backtrace()Harald Welte2013-07-061-0/+2
| | | | | this causes compiler warnings in user code ever since commit 55cf02221f0654a3f48888f3b13766b671a120f0
* misc: Fix compiler warnings about the static_assert macro with gcc 4.8Holger Hans Peter Freyther2013-07-011-1/+1
| | | | | | | | | | | | | The modified macro is still working on a gcc 4.7 and gcc 4.8 after the removal of the typedef and addition of the unused attribute. include/osmocom/core/msgb.h: In function ‘msgb_alloc_headroom’: include/osmocom/core/utils.h:40:51: warning: typedef ‘dummyheadroom_bigger’ locally defined but not used [-Wunused-local-typedefs] #define osmo_static_assert(exp, name) typedef int dummy##name [(exp) ? 1 : -1]; ^ include/osmocom/core/msgb.h:386:2: note: in expansion of macro ‘osmo_static_assert’ osmo_static_assert(size > headroom, headroom_bigger); ^
* utils: Use fprintf to print the assertion and generate a backtraceKaterina Barone-Adesi2013-03-251-1/+2
| | | | | | | | | This is changing the semantic of the assert. The regression tests now either need to check the stderr result, the exit status or print a message when all tests are completed. This is not that bad as the osmo_generate_backtrace is printing to the stdout right now.
* utils: Introduce OSMO_ASSERT in the utils and use it in the unit testsKaterina Barone-Adesi2013-03-091-0/+7
| | | | | The tests should unconditionally assert, regardless of debug settings. This uses the OSMO_ prefix as it's in the global namespace.
* utils: Change semantic of OSMO_MAX/OSMO_MIN to match semantic of a functionHolger Hans Peter Freyther2012-08-151-2/+2
| | | | | | | Add parentheses around the OSMO_MAX and OSMO_MIN macro to match the behaviour of calling a function. The current version does not evaluate to what is expected. (OSMO_MAX(3, 2) + 13) currently results in 3 and not 16.
* doc: Fix the Doxygen section endingsSylvain Munaut2012-04-181-1/+1
| | | | Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
* utils: Add declaration back for osmo_osmo_hexdump_nospcSylvain Munaut2011-11-131-0/+1
| | | | | | | | As it turns out, if a project uses the old name but without a declaration, it'll causes a segfault on 64 bits platform (because of the implicit int return type which doesn't apply since here it's a pointer). Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
* utils: Fix a bad double osmo_ prefix for osmo_hexdump_nospcSylvain Munaut2011-11-101-1/+1
| | | | | | Hopefully no project where using them it seems Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
* doxygen: add doxygen module 'utils'Harald Welte2011-08-171-54/+7
|
* start to add doxygen documentation to libosmocore headersHarald Welte2011-08-161-2/+63
|
* add definition of OSMO_MIN macro, similar to OSMO_MAXHarald Welte2011-07-271-0/+1
|
* add MAX() macro as OSMO_MAXHarald Welte2011-06-261-0/+1
|
* utils: use namespace prefix osmo_*Pablo Neira Ayuso2011-05-071-7/+7
| | | | | | | | | | | | Summary of changes: s/bcd2char/osmo_bcd2char/g s/char2bcd/osmo_char2bcd/g s/hexparse/osmo_hexparse/g s/hexdump/osmo_hexdump/g s/hexdump_nospc/osmo_hexdump_nospc/g s/ubit_dump/osmo_ubit_dump/g s/static_assert/osmo_static_assert/g
* utils: move OSMO_SNPRINT_RET() macro definition to osmocom/core/utils.hPablo Neira Ayuso2011-03-281-0/+9
| | | | | This is used by the logging to vty conversion functions by now, but it may be of help for other functions that plan to use snprintf().
* include: reorganize headers file to include/osmocom/[gsm|core]Pablo Neira Ayuso2011-03-231-0/+30
This patch moves all GSM-specific definitions to include/osmocom/gsm. Moreover, the headers in include/osmocore/ have been moved to include/osmocom/core. This has been proposed by Harald Welte and Sylvain Munaunt. Tested with `make distcheck'. Signed-off-by: Pablo Neira Ayuso <pablo@gnumonks.org>