summaryrefslogtreecommitdiff
path: root/accel-pppd/cli
diff options
context:
space:
mode:
authorSergey V. Lobanov <sergey@lobanov.in>2024-09-01 08:59:09 +0000
committerSergey V. Lobanov <sergey@lobanov.in>2024-09-02 12:42:58 +0000
commitcbfa3efe7ae135b4ae8890485701677f56087f50 (patch)
tree3541b071ebfdb37699043e7c55b02ca6c230304e /accel-pppd/cli
parent0c021f60244a7fd992916a882fb4ed7277f5cba8 (diff)
downloadaccel-ppp-cbfa3efe7ae135b4ae8890485701677f56087f50.tar.gz
accel-ppp-cbfa3efe7ae135b4ae8890485701677f56087f50.zip
migrate from pcre to pcre2
PCRE is not supported anymore and removed from several distros
Diffstat (limited to 'accel-pppd/cli')
-rw-r--r--accel-pppd/cli/cli.c64
-rw-r--r--accel-pppd/cli/cli.h8
-rw-r--r--accel-pppd/cli/show_sessions.c19
-rw-r--r--accel-pppd/cli/std_cmd.c20
4 files changed, 42 insertions, 69 deletions
diff --git a/accel-pppd/cli/cli.c b/accel-pppd/cli/cli.c
index 7d440727..6b71cb04 100644
--- a/accel-pppd/cli/cli.c
+++ b/accel-pppd/cli/cli.c
@@ -63,51 +63,6 @@ void __export cli_register_simple_cmd2(
va_end(ap);
}
-void __export cli_register_regexp_cmd(struct cli_regexp_cmd_t *cmd)
-{
- int err;
- int erroffset;
- const char *errptr;
-
- if (cmd->exec == NULL) {
- log_emerg("cli: impossible to register regexp command"
- " without an execution callback function\n");
- _exit(EXIT_FAILURE);
- }
- if (cmd->pattern == NULL) {
- log_emerg("cli: impossible to register regexp command"
- " without pattern\n");
- _exit(EXIT_FAILURE);
- }
- cmd->re = pcre_compile2(cmd->pattern, cmd->options, &err,
- &errptr, &erroffset, NULL);
- if (!cmd->re) {
- log_emerg("cli: failed to compile regexp \"%s\": %s (error %i)"
- " at positon %i (unprocessed characters: \"%s\")\n",
- cmd->pattern, errptr, err, erroffset,
- cmd->pattern + erroffset);
- _exit(EXIT_FAILURE);
- }
-
- if (cmd->h_pattern) {
- cmd->h_re = pcre_compile2(cmd->h_pattern, cmd->h_options, &err,
- &errptr, &erroffset, NULL);
- if (!cmd->h_re) {
- log_emerg("cli: failed to compile help regexp \"%s\":"
- " %s (error %i) at position %i (unprocessed"
- " characters: \"%s\")\n",
- cmd->h_pattern, errptr, err, erroffset,
- cmd->h_pattern + erroffset);
- _exit(EXIT_FAILURE);
- }
- } else {
- cmd->h_re = NULL;
- cmd->h_pattern = NULL;
- }
-
- list_add_tail(&cmd->entry, &regexp_cmd_list);
-}
-
int __export cli_send(void *client, const char *data)
{
struct cli_client_t *cln = (struct cli_client_t *)client;
@@ -189,13 +144,15 @@ static int cli_process_help_cmd(struct cli_client_t *cln)
cmd_found = 1;
list_for_each_entry(recmd, &regexp_cmd_list, entry) {
+ pcre2_match_data *match_data = pcre2_match_data_create(0, NULL);
if (cmd[0] == '\0'
- || pcre_exec(recmd->h_re, NULL, cmd, strlen(cmd),
- 0, 0, NULL, 0) >= 0) {
+ || pcre2_match(recmd->h_re, (PCRE2_SPTR)cmd, strlen(cmd),
+ 0, 0, match_data, NULL) >= 0) {
cmd_found = 1;
if (recmd->help)
recmd->help(cmd, cln);
}
+ pcre2_match_data_free(match_data);
}
nb_items = split(cmd, items);
@@ -230,14 +187,19 @@ static int cli_process_regexp_cmd(struct cli_client_t *cln, int *err)
int res;
cmd = skip_space(cmd);
- list_for_each_entry(recmd, &regexp_cmd_list, entry)
- if (pcre_exec(recmd->re, NULL, cmd, strlen(cmd),
- 0, 0, NULL, 0) >= 0) {
+ list_for_each_entry(recmd, &regexp_cmd_list, entry) {
+ pcre2_match_data *match_data = pcre2_match_data_create(0, NULL);
+ if (pcre2_match(recmd->re, (PCRE2_SPTR)cmd, strlen(cmd),
+ 0, 0, match_data, NULL) >= 0) {
found = 1;
res = recmd->exec(cmd, cln);
- if (res != CLI_CMD_OK)
+ if (res != CLI_CMD_OK) {
+ pcre2_match_data_free(match_data);
break;
+ }
}
+ pcre2_match_data_free(match_data);
+ }
if (found)
*err = res;
diff --git a/accel-pppd/cli/cli.h b/accel-pppd/cli/cli.h
index 6eda5d3f..3d8069b3 100644
--- a/accel-pppd/cli/cli.h
+++ b/accel-pppd/cli/cli.h
@@ -1,7 +1,8 @@
#ifndef __CLI_H
#define __CLI_H
-#include <pcre.h>
+#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>
#include "list.h"
@@ -23,11 +24,11 @@ struct cli_simple_cmd_t
struct cli_regexp_cmd_t
{
struct list_head entry;
- pcre *re;
+ pcre2_code *re;
const char *pattern;
int options;
int (*exec)(const char *cmd, void *client);
- pcre *h_re;
+ pcre2_code *h_re;
const char *h_pattern;
int h_options;
int (*help)(const char *cmd, void *client);
@@ -42,7 +43,6 @@ void cli_register_simple_cmd2(
int hdr_len,
...
);
-void cli_register_regexp_cmd(struct cli_regexp_cmd_t *cmd);
void cli_show_ses_register(const char *name, const char *desc, void (*print)(struct ap_session *ses, char *buf));
int cli_send(void *client, const char *data);
diff --git a/accel-pppd/cli/show_sessions.c b/accel-pppd/cli/show_sessions.c
index 22f5318a..ca2ec68d 100644
--- a/accel-pppd/cli/show_sessions.c
+++ b/accel-pppd/cli/show_sessions.c
@@ -128,9 +128,9 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
struct column_t *match_key = NULL;
char *match_pattern = NULL;
struct column_t *order_key = NULL;
- pcre *re = NULL;
- const char *pcre_err;
- int pcre_offset;
+ pcre2_code *re = NULL;
+ int pcre_err;
+ PCRE2_SIZE pcre_offset;
struct column_t *column;
struct col_t *col;
struct row_t *row;
@@ -169,9 +169,11 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
}
if (match_key) {
- re = pcre_compile2(match_pattern, 0, NULL, &pcre_err, &pcre_offset, NULL);
+ re = pcre2_compile((PCRE2_SPTR)match_pattern, PCRE2_ZERO_TERMINATED, 0, &pcre_err, &pcre_offset, NULL);
if (!re) {
- cli_sendv(cli, "match: %s at %i\r\n", pcre_err, pcre_offset);
+ PCRE2_UCHAR err_msg[64];
+ pcre2_get_error_message(pcre_err, err_msg, sizeof(err_msg));
+ cli_sendv(cli, "match: %s at %i\r\n", err_msg, (int)pcre_offset);
return CLI_CMD_OK;
}
}
@@ -262,10 +264,13 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
row = list_entry(t_list.next, typeof(*row), entry);
list_del(&row->entry);
if (match_key) {
- if (pcre_exec(re, NULL, row->match_key, strlen(row->match_key), 0, 0, NULL, 0) < 0) {
+ pcre2_match_data *match_data = pcre2_match_data_create(0, NULL);
+ if (pcre2_match(re, (PCRE2_SPTR)row->match_key, strlen(row->match_key), 0, 0, match_data, NULL) < 0) {
free_row(row);
+ pcre2_match_data_free(match_data);
continue;
}
+ pcre2_match_data_free(match_data);
}
if (order_key)
insert_row(&r_list, row);
@@ -362,7 +367,7 @@ out:
}
if (re)
- pcre_free(re);
+ pcre2_code_free(re);
return CLI_CMD_OK;
diff --git a/accel-pppd/cli/std_cmd.c b/accel-pppd/cli/std_cmd.c
index fc073526..ace48391 100644
--- a/accel-pppd/cli/std_cmd.c
+++ b/accel-pppd/cli/std_cmd.c
@@ -123,9 +123,9 @@ static int terminate_exec1(char * const *f, int f_cnt, void *cli)
{
struct ap_session *ses;
int hard = 0;
- pcre *re;
- const char *pcre_err;
- int pcre_offset;
+ pcre2_code *re;
+ int pcre_err;
+ PCRE2_SIZE pcre_offset;
if (f_cnt == 5) {
if (!strcmp(f[4], "hard"))
@@ -135,9 +135,11 @@ static int terminate_exec1(char * const *f, int f_cnt, void *cli)
} else if (f_cnt != 4)
return CLI_CMD_SYNTAX;
- re = pcre_compile2(f[3], 0, NULL, &pcre_err, &pcre_offset, NULL);
+ re = pcre2_compile((PCRE2_SPTR)f[3], PCRE2_ZERO_TERMINATED, 0, &pcre_err, &pcre_offset, NULL);
if (!re) {
- cli_sendv(cli, "match: %s at %i\r\n", pcre_err, pcre_offset);
+ PCRE2_UCHAR err_msg[64];
+ pcre2_get_error_message(pcre_err, err_msg, sizeof(err_msg));
+ cli_sendv(cli, "match: %s at %i\r\n", err_msg, (int)pcre_offset);
return CLI_CMD_OK;
}
@@ -145,8 +147,12 @@ static int terminate_exec1(char * const *f, int f_cnt, void *cli)
list_for_each_entry(ses, &ses_list, entry) {
if (!ses->username)
continue;
- if (pcre_exec(re, NULL, ses->username, strlen(ses->username), 0, 0, NULL, 0) < 0)
+ pcre2_match_data *match_data = pcre2_match_data_create(0, NULL);
+ if (pcre2_match(re, (PCRE2_SPTR)ses->username, strlen(ses->username), 0, 0, match_data, NULL) < 0) {
+ pcre2_match_data_free(match_data);
continue;
+ }
+ pcre2_match_data_free(match_data);
if (hard)
triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_hard, ses);
else
@@ -154,7 +160,7 @@ static int terminate_exec1(char * const *f, int f_cnt, void *cli)
}
pthread_rwlock_unlock(&ses_lock);
- pcre_free(re);
+ pcre2_code_free(re);
return CLI_CMD_OK;
}