From 474877b9d7912a3d2abc2a350dbc41e4c3b050e4 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Fri, 29 Mar 2013 16:04:21 +0100 Subject: permit substring extraction relative to end-of-string in templates --- runtime/msg.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'runtime/msg.c') diff --git a/runtime/msg.c b/runtime/msg.c index 32a02424..9afd46cf 100644 --- a/runtime/msg.c +++ b/runtime/msg.c @@ -3017,13 +3017,20 @@ uchar *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe, uchar *pSb; iFrom = pTpe->data.field.iFromPos; iTo = pTpe->data.field.iToPos; - /* need to zero-base to and from (they are 1-based!) */ - if(iFrom > 0) - --iFrom; - if(iTo > 0) - --iTo; if(bufLen == -1) bufLen = ustrlen(pRes); +dbgprintf("DDDD: orginal iFrom %u, iTo %u, len %u\n", iFrom, iTo, bufLen); + if(pTpe->data.field.options.bFromPosEndRelative) { + iFrom = (bufLen < iFrom) ? 0 : bufLen - iFrom; + iTo = (bufLen < iTo)? 0 : bufLen - iTo; +dbgprintf("DDDD: now iFrom %u, iTo %u\n", iFrom, iTo); + } else { + /* need to zero-base to and from (they are 1-based!) */ + if(iFrom > 0) + --iFrom; + if(iTo > 0) + --iTo; + } if(iFrom == 0 && iTo >= bufLen) { /* in this case, the requested string is a superset of what we already have, * so there is no need to do any processing. This is a frequent case for size-limited -- cgit v1.2.3 From f6da383e1c9d3ccfc5742d972c23dc3c718a0b88 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Fri, 29 Mar 2013 16:10:50 +0100 Subject: cleanup --- runtime/msg.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'runtime/msg.c') diff --git a/runtime/msg.c b/runtime/msg.c index 1e61e632..a5c52810 100644 --- a/runtime/msg.c +++ b/runtime/msg.c @@ -3232,11 +3232,9 @@ uchar *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe, iTo = pTpe->data.field.iToPos; if(bufLen == -1) bufLen = ustrlen(pRes); -dbgprintf("DDDD: orginal iFrom %u, iTo %u, len %u\n", iFrom, iTo, bufLen); if(pTpe->data.field.options.bFromPosEndRelative) { iFrom = (bufLen < iFrom) ? 0 : bufLen - iFrom; iTo = (bufLen < iTo)? 0 : bufLen - iTo; -dbgprintf("DDDD: now iFrom %u, iTo %u\n", iFrom, iTo); } else { /* need to zero-base to and from (they are 1-based!) */ if(iFrom > 0) -- cgit v1.2.3