mirror of
https://github.com/kenzok8/small.git
synced 2025-01-07 03:26:39 +08:00
update 2024-05-18 20:12:38
This commit is contained in:
parent
fcbd3d6538
commit
b00a07b02b
@ -1,6 +1,6 @@
|
|||||||
--- a/server/server.c
|
--- a/server/server.c
|
||||||
+++ b/server/server.c
|
+++ b/server/server.c
|
||||||
@@ -1942,11 +1942,11 @@ main(int argc, char **argv)
|
@@ -1942,12 +1942,12 @@
|
||||||
text = (char*)malloc(strlen(protocol) - 11);
|
text = (char*)malloc(strlen(protocol) - 11);
|
||||||
memcpy(text, protocol, strlen(protocol) - 11);
|
memcpy(text, protocol, strlen(protocol) - 11);
|
||||||
int length = strlen(protocol) - 11;
|
int length = strlen(protocol) - 11;
|
||||||
@ -9,7 +9,8 @@
|
|||||||
memset(protocol, 0x00, length);
|
memset(protocol, 0x00, length);
|
||||||
memcpy(protocol, text, length);
|
memcpy(protocol, text, length);
|
||||||
LOGI("protocol compatible enable, %s", protocol);
|
LOGI("protocol compatible enable, %s", protocol);
|
||||||
+ free(protocol);
|
|
||||||
free(text);
|
free(text);
|
||||||
|
+ free(protocol);
|
||||||
protocol_compatible = 1;
|
protocol_compatible = 1;
|
||||||
}
|
}
|
||||||
|
}
|
@ -105,7 +105,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_pthread.m4 \
|
|||||||
$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
|
$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
|
||||||
$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
|
$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
|
||||||
$(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/mbedtls.m4 \
|
$(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/mbedtls.m4 \
|
||||||
$(top_srcdir)/m4/openssl.m4 $(top_srcdir)/m4/pcre.m4 \
|
$(top_srcdir)/m4/openssl.m4 $(top_srcdir)/m4/pcre2.m4 \
|
||||||
$(top_srcdir)/m4/polarssl.m4 \
|
$(top_srcdir)/m4/polarssl.m4 \
|
||||||
$(top_srcdir)/m4/stack-protector.m4 $(top_srcdir)/m4/zlib.m4 \
|
$(top_srcdir)/m4/stack-protector.m4 $(top_srcdir)/m4/zlib.m4 \
|
||||||
$(top_srcdir)/libev/libev.m4 $(top_srcdir)/configure.ac
|
$(top_srcdir)/libev/libev.m4 $(top_srcdir)/configure.ac
|
||||||
|
@ -82,14 +82,28 @@ int
|
|||||||
init_rule(rule_t *rule)
|
init_rule(rule_t *rule)
|
||||||
{
|
{
|
||||||
if (rule->pattern_re == NULL) {
|
if (rule->pattern_re == NULL) {
|
||||||
const char *reerr;
|
int errornumber;
|
||||||
int reerroffset;
|
PCRE2_SIZE erroroffset;
|
||||||
|
rule->pattern_re = pcre2_compile(
|
||||||
|
(PCRE2_SPTR)rule->pattern, /* the pattern */
|
||||||
|
PCRE2_ZERO_TERMINATED, /* indicates pattern is zero-terminated */
|
||||||
|
0, /* default options */
|
||||||
|
&errornumber, /* for error number */
|
||||||
|
&erroroffset, /* for error offset */
|
||||||
|
NULL); /* use default compile context */
|
||||||
|
|
||||||
rule->pattern_re =
|
|
||||||
pcre_compile(rule->pattern, 0, &reerr, &reerroffset, NULL);
|
|
||||||
if (rule->pattern_re == NULL) {
|
if (rule->pattern_re == NULL) {
|
||||||
LOGE("Regex compilation of \"%s\" failed: %s, offset %d",
|
PCRE2_UCHAR errbuffer[512];
|
||||||
rule->pattern, reerr, reerroffset);
|
pcre2_get_error_message(errornumber, errbuffer, sizeof(errbuffer));
|
||||||
|
LOGE("PCRE2 regex compilation failed at offset %d: %s\n", (int)erroroffset,
|
||||||
|
errbuffer);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
rule->pattern_re_match_data = pcre2_match_data_create_from_pattern(rule->pattern_re, NULL);
|
||||||
|
|
||||||
|
if (rule->pattern_re_match_data == NULL) {
|
||||||
|
ERROR("PCRE2: the memory for the block could not be obtained");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,8 +123,15 @@ lookup_rule(const struct cork_dllist *rules, const char *name, size_t name_len)
|
|||||||
|
|
||||||
cork_dllist_foreach_void(rules, curr, next) {
|
cork_dllist_foreach_void(rules, curr, next) {
|
||||||
rule_t *rule = cork_container_of(curr, rule_t, entries);
|
rule_t *rule = cork_container_of(curr, rule_t, entries);
|
||||||
if (pcre_exec(rule->pattern_re, NULL,
|
if (pcre2_match(
|
||||||
name, name_len, 0, 0, NULL, 0) >= 0)
|
rule->pattern_re, /* the compiled pattern */
|
||||||
|
(PCRE2_SPTR)name, /* the subject string */
|
||||||
|
name_len, /* the length of the subject */
|
||||||
|
0, /* start at offset 0 in the subject */
|
||||||
|
0, /* default options */
|
||||||
|
rule->pattern_re_match_data, /* block for storing the result */
|
||||||
|
NULL /* use default match context */
|
||||||
|
) >= 0)
|
||||||
return rule;
|
return rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +152,13 @@ free_rule(rule_t *rule)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
ss_free(rule->pattern);
|
ss_free(rule->pattern);
|
||||||
if (rule->pattern_re != NULL)
|
if (rule->pattern_re != NULL) {
|
||||||
pcre_free(rule->pattern_re);
|
pcre2_code_free(rule->pattern_re); /* data and the compiled pattern. */
|
||||||
|
rule->pattern_re = NULL;
|
||||||
|
}
|
||||||
|
if (rule->pattern_re_match_data != NULL) {
|
||||||
|
pcre2_match_data_free(rule->pattern_re_match_data); /* Release memory used for the match */
|
||||||
|
rule->pattern_re_match_data = NULL;
|
||||||
|
}
|
||||||
ss_free(rule);
|
ss_free(rule);
|
||||||
}
|
}
|
||||||
|
@ -33,17 +33,27 @@
|
|||||||
|
|
||||||
#include <libcork/ds.h>
|
#include <libcork/ds.h>
|
||||||
|
|
||||||
#ifdef HAVE_PCRE_H
|
/*
|
||||||
#include <pcre.h>
|
* The PCRE2_CODE_UNIT_WIDTH macro must be defined before including pcre2.h.
|
||||||
#elif HAVE_PCRE_PCRE_H
|
* For a program that uses only one code unit width, setting it to 8, 16, or 32
|
||||||
#include <pcre/pcre.h>
|
* makes it possible to use generic function names such as pcre2_compile(). Note
|
||||||
#endif
|
* that just changing 8 to 16 (for example) is not sufficient to convert this
|
||||||
|
* program to process 16-bit characters. Even in a fully 16-bit environment, where
|
||||||
|
* string-handling functions such as strcmp() and printf() work with 16-bit
|
||||||
|
* characters, the code for handling the table of named substrings will still need
|
||||||
|
* to be modified.
|
||||||
|
*/
|
||||||
|
/* we only need to support ASCII chartable, thus set it to 8 */
|
||||||
|
#define PCRE2_CODE_UNIT_WIDTH 8
|
||||||
|
|
||||||
|
#include <pcre2.h>
|
||||||
|
|
||||||
typedef struct rule {
|
typedef struct rule {
|
||||||
char *pattern;
|
char *pattern;
|
||||||
|
|
||||||
/* Runtime fields */
|
/* Runtime fields */
|
||||||
pcre *pattern_re;
|
pcre2_code *pattern_re;
|
||||||
|
pcre2_match_data *pattern_re_match_data;
|
||||||
|
|
||||||
struct cork_dllist_item entries;
|
struct cork_dllist_item entries;
|
||||||
} rule_t;
|
} rule_t;
|
||||||
|
Loading…
Reference in New Issue
Block a user