summaryrefslogtreecommitdiff
path: root/pjlib-util
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-07-03 22:08:47 +0000
committerBenny Prijono <bennylp@teluu.com>2006-07-03 22:08:47 +0000
commit31d42235239a1291a599b84cc352b7b5b53448b7 (patch)
tree5770b56b29cbd313e47e5067fa3ee4a3b4895240 /pjlib-util
parented98898bb501d02e69093d34961bf1fb46d2ed4d (diff)
Various performance improvements in PJSIP: (1) optimizing for common case to minimize stricmp() calls (header names, method, URI schemes), (2) added functionality in scanner to parse and unescape in-place, (3) etc..
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@583 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib-util')
-rw-r--r--pjlib-util/include/pjlib-util/scanner.h13
-rw-r--r--pjlib-util/src/pjlib-util/scanner.c59
-rw-r--r--pjlib-util/src/pjlib-util/scanner_cis_uint.c2
3 files changed, 74 insertions, 0 deletions
diff --git a/pjlib-util/include/pjlib-util/scanner.h b/pjlib-util/include/pjlib-util/scanner.h
index eb9135fe..57cdced9 100644
--- a/pjlib-util/include/pjlib-util/scanner.h
+++ b/pjlib-util/include/pjlib-util/scanner.h
@@ -332,6 +332,19 @@ PJ_DECL(void) pj_scan_get( pj_scanner *scanner,
/**
+ * Just like #pj_scan_get(), but additionally performs unescaping when
+ * escaped ('%') character is found. The input spec MUST NOT contain the
+ * specification for '%' characted.
+ *
+ * @param scanner The scanner.
+ * @param spec The spec to match input string.
+ * @param out String to store the result.
+ */
+PJ_DECL(void) pj_scan_get_unescape( pj_scanner *scanner,
+ const pj_cis_t *spec, pj_str_t *out);
+
+
+/**
* Get characters between quotes. If current input doesn't match begin_quote,
* syntax error will be thrown. Note that the resulting string will contain
* the enclosing quote.
diff --git a/pjlib-util/src/pjlib-util/scanner.c b/pjlib-util/src/pjlib-util/scanner.c
index 676fd026..cd2a54b2 100644
--- a/pjlib-util/src/pjlib-util/scanner.c
+++ b/pjlib-util/src/pjlib-util/scanner.c
@@ -17,6 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <pjlib-util/scanner.h>
+#include <pj/ctype.h>
#include <pj/string.h>
#include <pj/except.h>
#include <pj/os.h>
@@ -282,6 +283,64 @@ PJ_DEF(void) pj_scan_get( pj_scanner *scanner,
}
+PJ_DEF(void) pj_scan_get_unescape( pj_scanner *scanner,
+ const pj_cis_t *spec, pj_str_t *out)
+{
+ register char *s = scanner->curptr;
+ char *dst = s;
+
+ pj_assert(pj_cis_match(spec,0)==0);
+
+ /* Must not match character '%' */
+ pj_assert(pj_cis_match(spec,'%')==0);
+
+ /* EOF is detected implicitly */
+ if (!pj_cis_match(spec, *s) && *s != '%') {
+ pj_scan_syntax_err(scanner);
+ return;
+ }
+
+ out->ptr = s;
+ do {
+ if (*s == '%') {
+ if (s+3 <= scanner->end) {
+ /* This doesn't check if the hex digits are valid.
+ * If they dont' it will produce garbage characters, but
+ * no harm is done to the application (e.g. no illegal
+ * memory access.
+ */
+ *dst = (pj_uint8_t) ((pj_hex_digit_to_val(*(s+1)) << 4) +
+ pj_hex_digit_to_val(*(s+2)));
+ ++dst;
+ s += 3;
+ } else {
+ *dst++ = *s++;
+ *dst++ = *s++;
+ break;
+ }
+ }
+
+ if (pj_cis_match(spec, *s)) {
+ char *start = s;
+ do {
+ ++s;
+ } while (pj_cis_match(spec, *s));
+
+ if (dst != start) pj_memmove(dst, start, s-start);
+ dst += (s-start);
+ }
+
+ } while (*s == '%');
+
+ scanner->curptr = s;
+ out->slen = (dst - out->ptr);
+
+ if (PJ_SCAN_IS_PROBABLY_SPACE(*s) && scanner->skip_ws) {
+ pj_scan_skip_whitespace(scanner);
+ }
+}
+
+
PJ_DEF(void) pj_scan_get_quote( pj_scanner *scanner,
int begin_quote, int end_quote,
pj_str_t *out)
diff --git a/pjlib-util/src/pjlib-util/scanner_cis_uint.c b/pjlib-util/src/pjlib-util/scanner_cis_uint.c
index 41599835..c12425d5 100644
--- a/pjlib-util/src/pjlib-util/scanner_cis_uint.c
+++ b/pjlib-util/src/pjlib-util/scanner_cis_uint.c
@@ -26,10 +26,12 @@
PJ_DEF(void) pj_cis_buf_init( pj_cis_buf_t *cis_buf)
{
/* Do nothing. */
+ PJ_UNUSED_ARG(cis_buf);
}
PJ_DEF(pj_status_t) pj_cis_init(pj_cis_buf_t *cis_buf, pj_cis_t *cis)
{
+ PJ_UNUSED_ARG(cis_buf);
pj_bzero(cis->cis_buf, sizeof(cis->cis_buf));
return PJ_SUCCESS;
}