Rework the payload to be a string instead of the raw char array.
This eliminates cases when we actually need to track that this char array
is indeed null-terminated and deprives us from doing other tricks to
properly maintain this char array.
Also no need to return const of payload anymore, because simply copied
during return. Data protection ensured by not giving a reference to the payload,
modifiable still during the first time setting this payload.
Rework also other users, such as nested call into AmSdp provided `parse()`.
Now `parse()` takes a string, and already in a local scope handles a char array
copy of this given string. This is only because the `parse_sdp_line_ex()` still
requires a refactor to be working with strings instead of char array.
Additionally: move parser helpers of AmSdp to const char pointers,
instead of working on a plain char pointer. This is because the SDP body
parser has been moved from the referenced pointer `char *&`
to the `const char *` pointer. This allows to not have additionally
heap allocated SDP body C-string for parsing purposes.
No functional change.
Change-Id: Ic3ee6c349b62e7e5e0cd4de722f9ed923862a7cb
Preamble: no functional changes.
AmSdp::parse() mixes int values with bool,
what makes the behavior not really clear, not defined
and can lead to the unpredicted result (even though the
compiler *should* actually fix that, but one ought to
not rely on this).
Hence make the parse method only be working with bool values.
Then, reverse the return value so that it's clear
that wrongly parsed is `false`, and good parsed is `true`.
Refactor all users accordingly.
Also rework those users, who indeed need `int` value
be returned, e.g. when having -1.
Do the same thing with the `parse_sdp_line_ex()` helper,
whereas parse() is the only user of it. And also reverse
the interpretation of true/false.
Then, make `parse()` working with a plain `char*`, so not a const.
Because doing a tricks like:
cast `char*` to const (user level) -> cast `const char*` to non-const
in a function (in a old C-like manner), has really no sense.
Refactor everything accordingly.
Other than that, refactor AmMimeBody:
Refactor it to work with a plain `char *` pointer instead of working
with `unsigned char *`, which nowadays has really no sense and
rather is a rudiment of C-like code base coming from the past.
Convert `payload` from `unsigned char*` to `char *` accordingly.
Refactor everything in AmMimeBody implementation accordingly.
Remove rudiment C-like casting everywhere, where possible.
Update `parseMultipart()` to work with a plain `const char *`
instead of `const unsigned char*`
P.S.: leave a list of TODO's for further rework, which
is not directly related to this scope of rework.
Change-Id: Ie1e132429245e0d2cc740d5b1c1fc17cf037a820
Instead of copying the FilterEntry mf, do the move.
Fixes defect:
329 vector<string> elems = explode(value, ",");
330 for (vector<string>::iterator it=elems.begin(); it != elems.end(); it++)
331 {
332 mf.filter_list.insert(*it);
333 }
334 mf.filter_type = Undefined;
>>> CID 550235: Performance inefficiencies (COPY_INSTEAD_OF_MOVE)
>>> "mf" is copied and then passed-by-reference as parameter to STL insertion function
"std::vector<FilterEntry, std::allocator<FilterEntry> >::push_back(
std::vector<FilterEntry, std::allocator<FilterEntry> >::value_type const &)",
when it could be moved instead.
335 profile->messagefilter.push_back(mf);
336 DBG("message_list set to '%s'\n", value.c_str());
337 EXEC_ACTION_STOP;
338 }
339
340 }
Change-Id: If6d04432f7004993fb1c70a0a026799805ed2a1a
Update the AmArg argument to const as these functions never change it,
and it may come from a const source. (The `string` counterpart in the
other overload is already const qualified.)
Change-Id: I1e527425a70e0c6468b8b59de7e4a20fa1f5c218
When dereferencing it (after creating a new context before)
make sure it's not NULL even when just checking for
a connection error, as it might still be NULL and hence
will just seg.fault in this case.
Fixes:
Dereference before null check (REVERSE_INULL)
check_after_deref: Null-checking this->redis_context suggests
that it may be null, but it has already been dereferenced on all paths leading to the check.
Change-Id: I67f88f1dfccef66751298b1c26e85efba0458c1f
size_t will always be true against `>=` because
it's a typedef for unsigned long.
Makes no sense to check it, just log what it is.
Fixes: Unsigned compared against 0 (NO_EFFECT)
unsigned_compare: This greater-than-or-equal-to-zero comparison
of an unsigned value is always true. reply->len >= 0UL.
Change-Id: I75803cbe0760a1b5c4a0d056af86bc992ea0a110
Add a default case for `handle_redis_reply()`.
Fixes:
Dereference after null check (FORWARD_NULL)
4. var_deref_op: Dereferencing null pointer reply.
Change-Id: I22edbc3cb14f7e8662efe4c607e1502fbb8c56b6
Instead of using the `tmpnam()` which doesn't exclude
race conditions on the system (same filenames created
simultaneously), because it doesn't open/reserve the file,
just use the `mkstemp()` which actually genereates a filename
and creates the file for the process.
Upon creating the file, close the FD, as not needed atm.
This file can be then later opened using `SCPopenAction`
or anything alike.
Current new implementation does not unlink the file from
the filesystem and a user of it has to explicitly do that
later with for example the `sys.unlink()` from this same
library.
Additionally: to be able to have excplicit file path (so dir),
add a second parameter to this function to provide a directory.
Fixes:
warning: the use of `tmpnam' is dangerous, better use `mkstemp'
Change-Id: Ib5e89461b2d2288be77d5f1a899e5293b76ebf90
Fixes:
CID 542433: (#1 of 1): Uninitialized scalar variable (UNINIT)
34. uninit_use_in_call: Using uninitialized value mf.
Field mf.filter_type is uninitialized when calling push_back.
Change-Id: Ia5c2c2ebb08f1632f973ef0d08d4dca0c5b8934b
Don't do an extra job many times checking
what is the `profile_param`, just catch this once.
Hence conditions must be self-excluding.
Change-Id: I6d98a082e50777c995538fd6303eb0fe527b301b
If a channel has been allocated with
`ConferenceJoinChannel()` then remember to transfer
the ownership over it to the DSM sessions's
"garbage collector" which later takes care to
deallocate it.
Fixes:
CID 542153: (#1 of 1): Resource leak (RESOURCE_LEAK)
10. leaked_storage: Variable chan going out of scope leaks the storage it points to.
Change-Id: Icdc2c67cf2a349ec70fd83f1cf6a43ecfcf69547
Instead of copying string parameter, just pass via reference.
Fixes:
Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE)
Change-Id: I872cd9631bbadc746aea12e7ae5840670fa16e8f
Fixes:
Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE)
copy_constructor_call: varname is passed-by-value as parameter
to std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > const &), when it could be moved instead.
Do the move operation also for the rvalue beign assigned,
as it is a locally allocated pair.
Change-Id: Iba8e349f13c4f83bcd10e229fb101e7b26872f0e
For the local usage of AmArg (`AmArg var_struct;`),
in case when when a custom string to array convertor
is used, ensure that the `var_struct` was actually
set to something reasonable (non-Undef).
Change-Id: Ic5208a60a028788d7c61d8b9e731d6c6f982fcb1
If import of the DSM module fails, close previously
allocated handler for dynamic linking.
Fixes:
CID 542305: (#1 of 1): Resource leak (RESOURCE_LEAK)
13. leaked_storage: Variable h_dl going out of scope leaks the storage it points to.
Change-Id: I426188a2d819c320862ad7de64a01e5ad08e3725
Just initialize to NULL before going forward.
Fixes:
CID 542426: (#1 of 1): Uninitialized pointer read (UNINIT)
21. uninit_use_in_call: Using uninitialized value script_config.diags when calling operator =
Change-Id: I4ed97e4fbeb371f04f0496565fa03b7b4a302e02
These are all instances of an object being put into a container just
before it goes out of scope. Use move semantics to avoid copying.
Change-Id: I9c40a56c4a67df2b8e244d51f068b50ec286f5bf
Warned-by: Coverity
Classes that inherit from both AmThread and AmEventHandler must inherit
from AmEventQueue first and from AmThread after. This is needed so that
the AmThread dtor is called first, which will trigger the thread to shut
down, which in turn makes sure nothing is waiting on the AmEventQueue's
condition variable.
Otherwise, if AmEventQueue is destroyed first while the corresponding
thread is still running and waiting on the condition variable, it will
be a deadlock.
With this, sems finally can shut down cleanly without having to be
killed by systemd.
Change-Id: I914455763b517c96561acb0b64fce26f127f44bc
Use a manual lock to make read/write operations
to the `std::map<DSMModule*, void*> mods_hdls` safer.
Change-Id: I45fb46bab603e2817bd98cd99267ed813122e548
Just add the following flags,
which are affecting the usage in our newer functionality:
- ssl
- crypto
Change-Id: Ia3edf1b77316fd64f7f55a5d2600fee730a285b4
Take into account that par2, used to pass N-th
amount of parameters, is properly exploded into
separate string objects having no spaces and
escaped double-quotes. Otherwise resolution fails.
Fixes:
[runactions, DSMStateEngine.cpp:334] DEBUG: executing 'utils.playRingTone(0, $config.rbt_on, $config.rbt_off, $config.rbt_f, $config.rbt_f2)'
[str2int, AmUtils.cpp:353] DEBUG: str2i: unexpected char 0x24 in $config.rbt_off
[execute, ModUtils.cpp:554] WARNING: could not decipher ringtone parameter 1: ' $config.rbt_off', using default
[str2int, AmUtils.cpp:353] DEBUG: str2i: unexpected char 0x24 in $config.rbt_f
[execute, ModUtils.cpp:554] WARNING: could not decipher ringtone parameter 2: ' $config.rbt_f', using default
[str2int, AmUtils.cpp:353] DEBUG: str2i: unexpected char 0x24 in $config.rbt_f2
[execute, ModUtils.cpp:554] WARNING: could not decipher ringtone parameter 3: ' $config.rbt_f2', using default
[execute, ModUtils.cpp:560] DEBUG: Playing ringtone length 0, on 1000, off 4000, f 440, f2 480
Change-Id: Ifed353478464d8071b5ca64959a7d4de6c877c8f
New functions introduced for DSM API (mod_utils):
- encryptCodeAes128CBC()
- decryptCodeAes128CBC()
Will be used by the voucher DSM application to encrypt/decrypt
the code given by a subscriber when filling up the balance.
OpenSSL AES128 CBC is used as an algorithm.
(with default AES key size 16 bytes)
Required things to let it be working:
- base64 encoding/decoding (of binary raw data)
- padding based on default AES key size (16)
Change-Id: I4b47f49ebf4b61157c3a4631cd8302565c660bc3
Use overloading for the various flavours of str2int functions. This has
the benefit of automatically choosing the appropriate function for
aliased types that may be one or the other underlying type, such as
size_t.
Do a mass renaming of all relevant instances.
Change-Id: I7abb6b9031ee53332d2b04a6cba4a6cc667a4807
Fixes:
Uninitialized pointer field (UNINIT_CTOR)
Non-static class member current_diag is not initialized
in this constructor nor in any functions that it calls.
Change-Id: I80fd5175edb68079e7b7da7a336bcc7f0e882016
Don't use the `B2BgetHeaderReply()`, it's based on
last received positive reply (200OK), so quite useless
for provisional replies processing (18X).
Thus e.g. for 180 Ringing handling it will never
return anything, because it has no data to parse.
Instead cast event into B2BSipReplyEvent and
parse headers from there.
Change-Id: I4bc4ad5d3aebd7b9ea497bcd53f63736e89d61db
Replace occurences of escaped CRLF used in
the hdrs value passed to the function.
This allows to pass multiple headers to the function,
whereas each header has `\r\n` at the end
(but the DSM script will always make it escaped,
hence the code must take care of it).
Change-Id: Ie76b44ff0f2d76105691aad6dbb5eb8d7dfb628a
This function replaces escaped `\r\n` occurences
into normal its view: `\r\n`.
Make this a function, to let it be reusable
for other DSM implementations.
Change-Id: Ica737df259fbf136b9a6855bc9439cbe005be6c1
When OA generates own SDP body (e.g. case with
accepted invite in DSP), save it as established_body
for this leg, in order to be able to re-invite
this leg later.
It can happen there is still no SDP seen from the
callee side (other side), and in case we want to
send established re-invite towards this leg,
this will fail, since no SDP body seen yet.
Change-Id: Ifd9f0fb70d27deac871de4eed1648f7c152813f3
Save last reply gotten and processed with
`DSMCallCalleeSession::onSipReply()`.
E.g. 18X are getting processed for DSM sessions there.
Change-Id: Ie0c44b1ddc8acd3fb07e01c6353eb2dce7a45a6e
Use `b2b_mark_dsm_for_updates` DSM session variable
to let updates towards caller have `P-DSM-App:`
header with a given value.
Change-Id: I4bc92f8ec9e2ec51bae70550c294a40581f92443
If requested by `b2b_build_pai_from_hdr` DSM parameter,
then get the value of PAI using this parameter and pass
it further for `B2BSipReplyEvent` processing.
Use event params to pass the value.
`b2b_build_pai_from_hdr` keeps the name of header
coming in the latest reply, from which the PAI's value
is to be built.
Update the `reinviteCaller()` function's signature,
to pass headers towards `dlg->sendRequest()`.
Change-Id: Ic6e66e326f26a830c3ed06c19a6ab7be4ebe0135
Re-use previously offered SDP body, when processing
a call session with an involvement of DSM, and getting
newer SIP invite having no SDP offer.
This affects applications using the B2B `connectCollee()`
functionality and doesn't actually touch the B2B core itself.
(Which would be wrong if changed in a usual core SDP
processing, whereas original request can be empty and
an offer/answer is postponed to 200OK/ACK exchange)
(Re)invites towards DSM applications technically must
not be empty, because DSMs don't support late offering.
In order to overcome that just pretend that empty
re-INVITEs are using previous body version.
Change-Id: I252eb9f32e7dc073454a2258b176f77bf15d35c9