188
188
* new parameter escapeMode is 0 - standard sql, 1 - "smart" engines
189
189
* 2005-09-22 rgerhards
191
void doSQLEscape(uchar **pp, size_t *pLen, unsigned short *pbMustBeFreed, int escapeMode)
192
doSQLEscape(uchar **pp, size_t *pLen, unsigned short *pbMustBeFreed, int escapeMode)
197
cstr_t *pStrB = NULL;
196
198
uchar *pszGenerated;
198
200
assert(pp != NULL);
210
212
/* when we get out of the loop, we are either at the
211
213
* string terminator or the first \'. */
213
return; /* nothing to do in this case! */
215
FINALIZE; /* nothing to do in this case! */
217
if(rsCStrConstruct(&pStrB) != RS_RET_OK) {
218
/* oops - no mem ... Do emergency... */
219
doSQLEmergencyEscape(p, escapeMode);
219
CHKiRet(rsCStrConstruct(&pStrB));
225
if(rsCStrAppendChar(pStrB, (escapeMode == 0) ? '\'' : '\\') != RS_RET_OK) {
226
doSQLEmergencyEscape(*pp, escapeMode);
227
rsCStrDestruct(&pStrB);
223
CHKiRet(rsCStrAppendChar(pStrB, (escapeMode == 0) ? '\'' : '\\'));
230
224
iLen++; /* reflect the extra character */
231
225
} else if((escapeMode == 1) && (*p == '\\')) {
232
if(rsCStrAppendChar(pStrB, '\\') != RS_RET_OK) {
233
doSQLEmergencyEscape(*pp, escapeMode);
234
rsCStrDestruct(&pStrB);
226
CHKiRet(rsCStrAppendChar(pStrB, '\\'));
237
227
iLen++; /* reflect the extra character */
239
if(rsCStrAppendChar(pStrB, *p) != RS_RET_OK) {
240
doSQLEmergencyEscape(*pp, escapeMode);
241
rsCStrDestruct(&pStrB);
229
CHKiRet(rsCStrAppendChar(pStrB, *p));
247
if(rsCStrConvSzStrAndDestruct(pStrB, &pszGenerated, 0) != RS_RET_OK) {
248
doSQLEmergencyEscape(*pp, escapeMode);
232
CHKiRet(rsCStrFinish(pStrB));
233
CHKiRet(rsCStrConvSzStrAndDestruct(pStrB, &pszGenerated, 0));
252
235
if(*pbMustBeFreed)
253
236
free(*pp); /* discard previous value */
385
377
if((pTpe = tpeConstruct(pTpl)) == NULL) {
386
378
/* OK, we are out of luck. Let's invalidate the
387
379
* entry and that's it.
388
* TODO: add panic message once we have a mechanism for this
390
381
pTpe->eEntryType = UNDEFINED;
453
444
pTpe->data.field.eCaseConv = tplCaseConvLower;
454
445
} else if(!strcmp((char*)Buf, "uppercase")) {
455
446
pTpe->data.field.eCaseConv = tplCaseConvUpper;
447
} else if(!strcmp((char*)Buf, "sp-if-no-1st-sp")) {
448
pTpe->data.field.options.bSPIffNo1stSP = 1;
456
449
} else if(!strcmp((char*)Buf, "escape-cc")) {
457
450
pTpe->data.field.options.bEscapeCC = 1;
458
451
} else if(!strcmp((char*)Buf, "drop-cc")) {
510
503
pTpe->eEntryType = FIELD;
512
505
while(*p && *p != '%' && *p != ':') {
513
rsCStrAppendChar(pStrB, *p++);
506
rsCStrAppendChar(pStrB, tolower(*p));
507
++p; /* do NOT do this in tolower()! */
516
510
/* got the name*/
1021
1015
if(pTpe->data.field.options.bSpaceCC) {
1022
1016
dbgprintf("[replace control-characters with space] ");
1018
if(pTpe->data.field.options.bSecPathDrop) {
1019
dbgprintf("[slashes are dropped] ");
1021
if(pTpe->data.field.options.bSecPathReplace) {
1022
dbgprintf("[slashes are replaced by '_'] ");
1024
if(pTpe->data.field.options.bSPIffNo1stSP) {
1025
dbgprintf("[SP iff no first SP] ");
1024
1027
if(pTpe->data.field.options.bDropLastLF) {
1025
1028
dbgprintf("[drop last LF in msg] ");