Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/script-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Script Tests

# Builds a regular (non unit-test) opensips binary and runs script-level tests
# against it: config parsing and runtime behaviour. See test/script/.
on:
push:
pull_request:
workflow_dispatch:

jobs:
script_tests:
runs-on: ubuntu-latest
container:
image: ubuntu:24.04
env:
COMPILER: gcc
BUILD_OS: ubuntu:24.04
MAKE_TGT: opensips

steps:
- name: Install git
run: |
apt-get update
apt-get install -y git lsb-release gnupg2 wget

- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install dependencies
run: |
sh -x scripts/build/reset_sources.sh
sh -x scripts/build/install_depends.sh

- name: Build
run: sh -x scripts/build/do_build.sh

- name: Run script tests
run: sh test/script/run_all.sh ./opensips

all_done:
needs: script_tests
uses: ./.github/workflows/.notify.yml
with:
job_name: "Script Tests"
job_result: ${{ needs.script_tests.result }}
if: ${{ always() }}
30 changes: 29 additions & 1 deletion action.c
Comment thread
bcnewlin marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,35 @@ int do_action(struct action* a, struct sip_msg* msg)
break;
case XLOG_T:
script_trace("core", "xlog", msg, a->file, a->line) ;
if (a->elem[1].u.data != NULL)
if (a->elem[2].u.data != NULL)
{
if (a->elem[1].type != SCRIPTVAR_ELEM_ST)
{
LM_ALERT("BUG in xlog() type %d\n", a->elem[1].type);
ret=E_BUG;
break;
}
if (a->elem[0].type != STR_ST)
{
LM_ALERT("BUG in xlog() type %d\n", a->elem[0].type);
ret=E_BUG;
break;
}
if (a->elem[2].type != NUMBER_ST)
{
LM_ALERT("BUG in xlog() type %d\n", a->elem[2].type);
ret=E_BUG;
break;
}
ret = xlog_3(msg, a->elem[0].u.data, a->elem[1].u.data,
(enum log_fmt_override)a->elem[2].u.number);
if (ret < 0)
{
LM_ERR("error while printing xlog message\n");
break;
}
}
else if (a->elem[1].u.data != NULL)
{
if (a->elem[1].type != SCRIPTVAR_ELEM_ST)
{
Expand Down
72 changes: 44 additions & 28 deletions cfg.y
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
extern int yylex();
static void yyerror(char* s);
static void yyerrorf(char* fmt, ...);
static enum log_fmt_override parse_xlog_format(char* fmt);
static char* tmp;
static int i_tmp, rc;
static struct socket_id* lst_tmp;
Expand Down Expand Up @@ -1049,20 +1050,9 @@ assign_stm: LOGLEVEL EQUAL snumber { IFOR();
if ((i_tmp = parse_log_format(&s_tmp)) < 0) {
yyerror("unknown log format");
} else {
if (i_tmp != LOG_FORMAT_PLAIN) {
if (init_log_json_buf(0) < 0) {
yyerror("failed to allocate json log buffer");
YYABORT;
}
if (init_log_msg_buf(0) < 0) {
yyerror("failed to allocate msg log buffer");
YYABORT;
}

if (i_tmp == LOG_FORMAT_JSON_CEE && init_log_cee_hostname() < 0) {
yyerror("failed to allocate hostname buffer");
YYABORT;
}
if (init_log_format_bufs(i_tmp) < 0) {
yyerror("failed to allocate log format buffers");
YYABORT;
}

stderr_log_format = i_tmp;
Expand All @@ -1074,20 +1064,9 @@ assign_stm: LOGLEVEL EQUAL snumber { IFOR();
if ((i_tmp = parse_log_format(&s_tmp)) < 0) {
yyerror("unknown log format");
} else {
if (i_tmp != LOG_FORMAT_PLAIN) {
if (init_log_json_buf(0) < 0) {
yyerror("failed to allocate json log buffer");
YYABORT;
}
if (init_log_msg_buf(0) < 0) {
yyerror("failed to allocate msg log buffer");
YYABORT;
}

if (i_tmp == LOG_FORMAT_JSON_CEE && init_log_cee_hostname() < 0) {
yyerror("failed to allocate hostname buffer");
YYABORT;
}
if (init_log_format_bufs(i_tmp) < 0) {
yyerror("failed to allocate log format buffers");
YYABORT;
}

syslog_log_format = i_tmp;
Expand Down Expand Up @@ -2674,6 +2653,10 @@ cmd: ASSERT LPAREN exp COMMA STRING RPAREN {
mk_action2($$, XLOG_T, STR_ST, STR_ST, $3, $5); }
| XLOG LPAREN STRING COMMA folded_string RPAREN {
mk_action2($$, XLOG_T, STR_ST, STR_ST, $3, $5); }
| XLOG LPAREN STRING COMMA STRING COMMA STRING RPAREN {
mk_action3($$, XLOG_T, STR_ST, STR_ST, NUMBER_ST, $3, $5, (void*)(long)parse_xlog_format($7)); }
| XLOG LPAREN STRING COMMA folded_string COMMA STRING RPAREN {
mk_action3($$, XLOG_T, STR_ST, STR_ST, NUMBER_ST, $3, $5, (void*)(long)parse_xlog_format($7)); }
| ASYNC_TOKEN LPAREN async_func COMMA route_name RPAREN {
rt_ref = ref_script_route_by_name( $5, sroutes->request,
RT_NO, REQUEST_ROUTE, 0);
Expand Down Expand Up @@ -2741,6 +2724,39 @@ static void yyerrorf(char *fmt, ...)
}


/* resolve the xlog() per-call format override at parse time, so a typo fails
* config load instead of silently using the configured log format */
static enum log_fmt_override parse_xlog_format(char* fmt)
{
str s;
int fmt_id;

s.s = fmt;
s.len = strlen(fmt);
fmt_id = parse_log_format(&s);

/* the configured stderr/syslog formats may both be plain, in which case
* the json buffers were never allocated - the override needs them too */
if (fmt_id >= 0 && init_log_format_bufs(fmt_id) < 0) {
yyerror("failed to allocate log format buffers");
return LOG_FMT_OVR_NONE;
}

switch (fmt_id) {
case LOG_FORMAT_PLAIN:
return LOG_FMT_OVR_PLAIN;
case LOG_FORMAT_JSON:
return LOG_FMT_OVR_JSON;
case LOG_FORMAT_JSON_CEE:
return LOG_FMT_OVR_JSON_CEE;
default:
yyerrorf("unknown xlog() log format '%s' (expected '%s', '%s' or "
"'%s')", fmt, LOG_PLAIN_NAME, LOG_JSON_NAME, LOG_JSON_CEE_NAME);
return LOG_FMT_OVR_NONE;
}
}


static struct socket_id* mk_listen_id(char* host, enum sip_protos proto,
int port)
{
Expand Down
Loading
Loading