aboutsummaryrefslogtreecommitdiffstats
path: root/src/msgb.c
AgeCommit message (Collapse)AuthorFilesLines
2019-06-04make all library-internal static buffers thread-localHarald Welte1-1/+1
We have a number of library-internal static global buffers which are mainly used for various stringification functions. This worked as all of the related Osmocom programs were strictly single-threaded. Let's make those buffers at least thread-local. This way every thread gets their own set of buffers, and it's safe for multiple threads to execute the same functions once. They're of course still not re-entrant. If you need re-entrancy, you will need to use the _c() or _buf() suffix version of those functions and work with your own (stack or heap) buffers. Change-Id: I50eb2436a7c1261d79a9d2955584dce92780ca07
2019-04-12Fix incorrect buffer size calculationVadim Yanitskiy1-2/+3
Calling sizeof() on a pointer to dynamically allocated memory would result in getting size of the pointer (usually 4 or 8 bytes) itself, but not the size of allocated memory. Change-Id: I8ffda4dea2b7f9b4b76dfeecad1fab6384c5a62c Fixes: CID#197629, CID#197628, CID#197627 Fixes: CID#197626, CID#197625, CID#197624
2019-04-10Add _c versions of functions that otherwise return static buffersHarald Welte1-7/+50
We have a habit of returning static buffers from some functions, particularly when generating some kind of string values. This is convenient in terms of memory management, but it comes at the expense of not being thread-safe, and not allowing for two calls of the related function within one printf() statement. Let's introduce _c suffix versions of those functions where the caller passes in a talloc context from which the output buffer shall be allocated. Change-Id: I8481c19b68ff67cfa22abb93c405ebcfcb0ab19b
2019-04-03Add _buf() functions to bypass static string buffersHarald Welte1-14/+24
We have a number of static buffers in use in libosmo*. This means the related functions are not usable in a thread-safe way. While we so far don't have many multi-threaded programs in the osmocom universe, the static buffers also prevent us from calling the same e.g. string-ify function twice within a single printf() call. Let's make sure there's an alternative function in all those cases, where the user can pass in a caller-allocated buffer + size, and make the 'classic' function with the static buffer a wrapper around that _buf() variant. Change-Id: Ibf85f79e93244f53b2684ff6f1095c5b41203e05
2019-03-27src/msgb.c: fix Doxygen documentation for msgb_printf()Vadim Yanitskiy1-2/+3
This change fixes the following Doxygen warnings: src/msgb.c:479: warning: argument 'msg' of command @param is not found in the argument list of msgb_printf(struct msgb *msgb, const char *format,...) core/msgb.h:708: warning: The following parameters of msgb_printf(struct msgb *msgb, const char *format,...) are not documented: parameter 'msgb' parameter 'format' As a bonus, it dot-terminates all sentences. Change-Id: Ib708664336eef06f748d408ae02a13c754b6647a
2019-01-09msgb: fix debug printMax1-1/+1
Since osmo_hexdump() use static buffers we can't re-use pointers to it after subsequent osmo_hexdump() calls. Let's print data used for comparison directly instead. Change-Id: I24dc3fad6f64ef788da9b7d790f9d5f689190c42
2018-12-12msgb: add test helpersMax1-0/+92
It's often handy to compare certain msgb layer to a given array and print the position where they differ. Add simple pretty-printer and corresponding L* wrappers. Change-Id: I3bc95f2f5ab6e3f4b502647fb3e0aaaf1f7c4cf5
2018-03-09src/msgb.c: avoid using internal talloc APIVadim Yanitskiy1-2/+4
An internal symbol '_talloc_zero' of talloc library was used during a msgb allocation. This is not actually good because: - it may be removed or modified by talloc developers; - the behaviour may be changed by talloc developers; - it's marked as internal using 'underscore'; - there is public API to do the same. So, let's use the public API. Change-Id: I1080c9071e997944cc0f9fc3716129e9395437ad
2018-03-09src/msgb.c: print an error if msgb allocation failedVadim Yanitskiy1-1/+3
Printing an error message when msgb allocation failed was initially intended, but have been commented out for years. This would facilitate the bug hunting process, especially on embedded platforms with limited resources (e.g. amount of RAM). The GLOBAL logging subsystem with FATAL level is used for printing such messages. Change-Id: I3e2d1beabd6936fc28a1ad664c083ff1698bb644
2018-03-08src/msgb.c: remove dead includes from OpenBSCVadim Yanitskiy1-3/+0
The MSGB API is not a part of OpenBSC anymore, so let's remove dead includes, which were probably left here during the migration process. Change-Id: Ief562a6e5b220a84902f95862d67279f953ee726
2018-03-08src/msgb.c: cosmetic: fix spelling mistakesVadim Yanitskiy1-3/+3
Change-Id: I6b473aadaa22d95f2a8cc87580c638ccd7e531a4
2017-11-13Fix/Update copyright notices; Add SPDX annotationHarald Welte1-0/+2
Let's fix some erroneous/accidential references to wrong license, update copyright information where applicable and introduce a SPDX-License-Identifier to all files. Change-Id: I39af26c6aaaf5c926966391f6565fc5936be21af
2017-10-22add function msgb_printf() to print formatted text into msg bufPhilipp Maier1-0/+48
In ASCII string based protocols it a printf() version that prints directly to the message buffer may be useful. Add function msgb_printf(), make sure that msg buffer bounderies are not exceeded. If the end of the tail buffer is hit, return with an error code. Change-Id: I15e1af68616309555d0ed9ac5da027c9833d42e3
2017-06-23doxygen: unify use of \file across the boardNeels Hofmeyr1-2/+3
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
2017-06-23doxygen: enable AUTOBRIEF, drop \briefNeels Hofmeyr1-13/+13
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
2017-06-12update/extend doxygen documentationHarald Welte1-2/+27
It's a pity that even with this patch we still are fare away from having the whole API documented. However, at least we have a more solid foundation. Updates not only extend the documentation, but also make sure it is rendered properly in the doxygen HTML. Change-Id: I1344bd1a6869fb00de7c1899a8db93bba9bafce3
2016-09-27msgb: add msgb_talloc_ctx_init(), deprecate msgb_set_talloc_ctx()Neels Hofmeyr1-1/+20
So far each and every main() scope creates a msgb talloc context and either passes it to msgb_set_talloc_ctx() or sets tall_msgb_ctx directly (by defining it extern first). Remove some code duplication: add one central function that creates the "msgb" talloc context for all. Most users of msgb employ a talloc_named_const(), but osmo-bts uses a talloc_pool() instead. Offer both ways by means of the pool_size argument, and for both ways make sure the context is called "msgb". Suggest that msgb users should move to this new function: deprecate msgb_set_talloc_ctx(). To be able to do so, include core/defs.h in msgb.h. There's a tradeoff between hiding the msgb talloc context behind API that tries to guess all use cases versus avoiding code dup. This patch opts against code dup and boldly assumes that all future use is covered. Also, the new function suggests to not access tall_msgb_ctx directly, which can be considered a style improvement. It seems that not all main scopes that use msgb actually initialize the msgb ctx. As a fallback for these, explicitly initialize tall_msgb_ctx to NULL. Change-Id: I747fbbf977c4d2c868c8dead64cfc5fd86eb8d4c
2016-06-23Fix potential segfault in msg_dequeueMax1-3/+6
Change-Id: I06e9c5ba3e00c73a4e52d2583ce3492f236275ce
2016-05-05Update doxygen annotations in libosmocoreHarald Welte1-0/+1
This adds and improves doxygen API descriptions all over libosmocore, reducing the 'white spots' that don't have any documentation.
2015-12-24Fix some recently added formats on 64bitNeels Hofmeyr1-3/+5
86ec311896dd5d4 adds compiler warnings on 64bit. The build is clean otherwise, so let's keep it that way.
2015-12-21msgb: Let msgb_hexdump be more tolerantJacob Erlbeck1-7/+39
This patch makes msgb_hexdump accept out of range lXh pointers and shows info about them instead of aborting the dump entirely. Sponsored-by: On-Waves ehf
2015-12-21msgb: Add msgb_resize_area and msgb_copyJacob Erlbeck1-0/+91
These functions originate from openbsc/src/gprs but are generic msgb helper functions. msgb_copy: This function allocates a new msgb, copies the data buffer of msg, and adjusts the pointers (incl. l1h-l4h) accordingly. msgb_resize_area: This resizes a sub area of the msgb data and adjusts the pointers (incl. l1h-l4h) accordingly. Sponsored-by: On-Waves ehf
2014-03-04msgb: Add msgb_hexdump() functionJacob Erlbeck1-0/+49
This function works like osmo_hexdump() and returns a static buffer containing hex bytes along with markers for the layers. Note that it uses osmo_hexdump() internally, thus a call to msgb_hexdump() invalidates the buffer that has been returned by an earlier call to osmo_hexdump(). In short: don't mix them in a single call printf(). Sponsored-by: On-Waves ehf
2013-02-15misc: Doxygen tweaks: fixed some typos and minor errorsKaterina Barone-Adesi1-3/+3
Doxygen generates quite a lot of warnings on libosmocore. Some of them are obvious typos - this patch aims to fix such low-hanging fruit.
2012-04-18doc: Fix the Doxygen section endingsSylvain Munaut1-1/+1
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2011-08-17some more doxygen work (include the notion of modules)Harald Welte1-0/+51
2011-06-29add msgb_set_talloc_ctx() to set the talloc context for msgb allocationsHarald Welte1-0/+5
2011-04-18misc: Remove the sys/types.h include from various filesHolger Hans Peter Freyther1-1/+0
We used this include for the u_int{8,16,32}_t types but we do not need this anymore.
2011-03-23include: reorganize headers file to include/osmocom/[gsm|core]0.2.0Pablo Neira Ayuso1-2/+2
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>
2010-10-18msgb: Add non-inlined helper functions to ease with language bindingsHolger Hans Peter Freyther1-0/+11
It is easier from languages that dlopen libosmocore to have a function to access this data than to poke at the bytes of the struct directly. Add copyright for this method and the reset method I did earlier this year.
2010-05-01msgb: initialize cb[] to zero during msgb_reset()0.1.5Harald Welte1-0/+2
2010-04-30msgb: remove smsh, llch, tlli and gmmhHarald Welte1-1/+1
This is a lot of GSM/GPRS specific stuff in struct msgb which we want to avoid. The 'control buffer' will replace them.
2010-04-30remove the unneeded bts_link pointer from msgbHarald Welte1-1/+0
2010-02-24msgb.c: Style cleanup in initializationSylvain Munaut1-13/+4
Don't assign the same var twice & init all from the same source.
2010-02-20intial checkin of the libosmocore projectHarald Welte1-0/+98