Previous approach based on the strhash used
to support an upper case variant of "cli" command.
Just preserve it.
Current NG_COMMANDS based macro generation, uses
only lower cases based on the command name from
the table, so not mess things more, just add
one exception for the "CLI".
Change-Id: I0bb373a50f56a44c13921a24fddf9534379b8e0d
For the following arrays:
- `ng_command_strings`
- `ng_command_strings_esc`
- `ng_command_strings_short`
Because there are still external users of them,
which should be reworked in the future to use the
`ng_command_defs` instead.
Change-Id: I4086513e295b00cc23ee035b004e896a83294bf9
With the newly introduced `ng_command_find()` lookup func.
Add the local `ng_command_def` and maintain via it.
Check whether:
- the handler has been defined
- the handler gets properly selected
- the command is defined (known)
Accordingly update the opmode of the command context.
By default define as `OP_OTHER` always.
For the case when no handler has been defined, introduce
the error reply "No handler found".
Accordingly trigger selected handler after
the command was found.
The main payoff here is that the command processing
flow becomes quite transparent and easy to maintain:
- parse command string
- lookup command definition
- set opmode from table
- call uniform handler
- shared error/success reply handling for all commands
Deprecate strhash based `__csh_lookup()`/`CSH_LOOKUP()`.
Accordingly adap the daemons's and tests Makefile,
remove the strhash objects with the normal control_ng one.
Additionally:
introduce the special `resultstr = "pong"` for the
ping command case, because all other commands have "ok".
Change-Id: Ifff7d7f61ae4d25fd220460f4485d794c9a7cbd5
Instead of the previous approach using the strhash,
introduce if-based lookup from `NG_COMMANDS`.
The usage of strhash is deprecated because it:
- forses string literals in switch cases, hence gives
no possibility to use variables
- makes then shortcuts using macro not possible to be used
- it makes the part with the command find and
actual commands definition duplicate, because
one has to maintain both of them when adding/removing commands
- switch is redundant and feels heavy, meanwhile the same
thing can be generated using marco based on `NG_COMMANDS`
introduced before, which are the main source of the truth
Newer approach:
- avoid usage of for/while cycles (because CPU consuming)
- sorts the lookup based on the cmd name (string) length,
what makes the command find efficient, because exlcludes
unnecessary comparisons
- uses the `memcmp()` at the very last
- for example, for the "offer" command it may run the `memcmp()`
only two times, because there are only two commands with
the length 5 our of supported 35 commands in list now
Additionally:
include `string.h` for `memcmp()` operations.
Change-Id: Iae70de87b88cd444ae162ba2b7c6aa7690731ee3
Introduce a common NG commands table `ng_command_defs`
for all type of things: OP enum, name, escaped name,
short name and most important the handler.
This table operates on and returns a dedicated struct `ng_command_def`,
which has all the information required on the command (like
all type of things mentioned above) and may have either
single-parameter or double-parameter signature (for cases with
the `addr` requiring commands such as the offer command).
Also add unified signatures for X and XA handlers,
they will be used later accordingly. Most of those use single-parameter,
and those exceptional use the second one.
Also add dummy plug-functions for ping and block/unblock silence media.
The ping one doesn't have any particular handler, but because a new
structure of NG commands wants to see a real declaration of the func
handler, just give it. For the block/unblock silence media, there aren't
even handling of commands in the control NG, they are just dummy OPs,
so fulfill the actual NG commands structure, and give them dummy funcs.
Change-Id: I2064ddca1595079959a6c6843119556a8b6bf5d5
Keep enum `ng_opmode` generated from the command list,
and also keep `ng_command_strings[]`, `ng_command_strings_esc[]`
and `ng_command_strings_short[]`.
And add the wrapper func name into the array, to be able
to appeal to it later, when processing any coming NG command.
Change-Id: I6aa725679d2405277f4497db46c3a8010d9ccd56
The `OP_...` enum is meant to only represent commands list.
Then make the list from the NG commands macro
the actual source of truth for the enum count.
This eliminates human mistakes, when introducing a new command,
because no more need to update enum manually.
Additionally:
- move the command list macro to the header
- existing extern declarations remain untouched
- `OP_OTHER` remains sentinel
- eventually replace the manual enum with macro based one
Change-Id: I33d928367fe0a254571cb0b7d4aafe4445b30b77
Instead of keeping separate arrays (essentially it's
a duplication) for command strings, escaped strings
or short version of commands, just create one single
macro pattern, which keeps these as an array.
And then using designated array initializers,
use the marco pattern to generate accordingly
an array of the required type (usual strings,
those escaped or the short version of them).
This prevents the human mistakes, or at least
makes them less possible in case of new command
introduction.
Change-Id: I27271ed4852f95760424552ce66fc8bc340c76a3
The dict pretty printer advances from key to value
by `chld = chld->sibling` and then prints the `chld`.
If a malformed dict ever reaches this func
with an odd number of child nodes, this can dereference NULL.
Just add guard against NULL.
Change-Id: Ia24671a5eba06dda8c48515fd9dc45fe7a9ec371
In order to understand whether is must be initialized.
And use a given parser pointer to do so. This can be native or
json parser.
Remove previously introduced bool param, which was used
for differentiation.
Change-Id: I6d0bb083fe4dea5625d40175c8978fffaca6d34f
There is a dedicated JSON parser, so use this.
Also leave some TODO'ers to think about adding own
`parser_arg` for JSON-like formatted data.
Change-Id: I5399ffb6ec74e88887b52fd63b96a8e44428c495
If already having the local ptr, then why not to use it,
instead of using directly the globally visible object.
In the `control_ng_process_payload()` add a pointer
to the `ng_parser_json` parser.
Change-Id: I9d656733991e2d99c18aa1cc6d705ed053f57f0a
When preparing a response, especially for the case of error,
we already make sure to init the resp ctx. So just add
a helper for this, because same routine used.
Also optionally init parser as native (dict) if required.
Some of the cases like data is <= 0 length, or
there has been not dict or JSON format spotted,
then init as native.
Change-Id: I7d13669075525b754e1950e3212b79800b20f85a
In case the data length is <= 0, or there has been
no dictionary-like or json-like format spotted in the
NG incoming control message, then treat parser
as native (so dict) by default.
Otherwise not possible to initilize the command context,
and hence the error treatment wouldn't be
able to prepare the response properly.
Change-Id: I99b9c571a9112a25e474dfc39e21cce15fc5f634
If any caller passes NULL for item callback and
then receives a JSON with a nested object/list/int, this can crash.
Change-Id: I69fbb9fec76305f6e1ed9ea5b25a50a7ee85c454
Allocate dict enough in-time for the `command_ctx.resp`,
because a plenty of the `err_send` gotos, having this alias
appending something to the dict, will use it uninitialized.
Change-Id: I9114e7b02437e47de256b8fc88faf993329f083f
Resolve file name conflicts between different components
Ensure shared log levels are identical across components
Encapsulates lib/*
Change-Id: If848d6fa0e4cd8eac88ce9e63ee77fc5a7a481fd
New NG protocol commands that mix audio from a source participant
into a destination participant's stream without a full offer/answer
exchange.
- inject start: creates one-way subscription with audio_player mixing
- inject stop: removes injection and restores original codec routing
- Supports cross-call injection via source-call-id (merges calls internally)
- inject attribute persisted through Redis for HA failover
- Audio-only; matches media by media-id, index, then type fallback
Closes#2082
Change-Id: Ib88113b021a4b76bf98892eb1af60c0b36c0d6d3
Simply take the xmlrpc-callback address as string and don't try to parse
it out. Store it in the call object as string as well.
Obsolete `created_from_addr`. The string form `created_from` is all we
need.
Change `created_from` to `str` as well.
Change-Id: Ib67b57b1d2d474d7b033f56ef8be59f71e44641b
The GLib slice allocator has been obsoleted. Having a mixture of two
allocators can lead to hidden issues on systems that use different
implementations. Take the leap and replace everything with g_new/g_free.
Change-Id: I025c8383ef47b2c2472573360407fd6a6ca339b3
Change old code to directly return `str` objects instead of pointers to
allocated ones. Largely a no-op change but makes some code easier and
eliminates some old kludges.
Change-Id: I2be19dd24bb7ff046d86cc32a3af235283e65dd0
Make the macro return the appropriate pointer type, and make sure the
free function takes an argument of the same type. This also eliminates
some boilerplate type-casting code.
Change-Id: I3094271fa2c53ec93b9ff9f837d461cf422e0f12
The opmode is already determined uniquely when processing the NG
command. There is no need to explicitly set it again elsewhere. Simply
carry along the originally determined opmode.
Change-Id: I16924264b0337423aff6763c70a4b2c6dd3687db
There is enough overlap between the two enums that it doesn't make sense
to carry along both. Unify.
Change-Id: I9de8fbdb8d78a2002d8c1b62cea57188c937d61d