1
/*###################################################################################
3
# Embperl - Copyright (c) 1997-2004 Gerald Richter / ECOS
5
# You may distribute under the terms of either the GNU General Public
6
# License or the Artistic License, as specified in the Perl README file.
8
# THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
9
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10
# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12
# $Id: epcmd2.c,v 1.11 2004/01/23 06:50:54 richter Exp $
14
###################################################################################*/
20
/* ---------------------------------------------------------------------------- */
22
/* Split values in from %fdat */
24
/* ---------------------------------------------------------------------------- */
27
SV * SplitFdat (/*i/o*/ register req * r,
28
/*in*/ SV ** ppSVfdat,
29
/*out*/ SV ** ppSVerg,
40
if (ppSVerg && *ppSVerg && SvTYPE (*ppSVerg))
45
pData = SvPV (*ppSVfdat, dlen) ;
48
if ((p = strchr (s, r -> Config.cMultFieldSep)))
49
{ /* Multiple values -> put them into a hash */
55
hv_store (pHV, s, p - s, &sv_undef, 0) ;
57
p = strchr (s, r -> Config.cMultFieldSep) ;
60
l = dlen - (s - pData) ;
62
hv_store (pHV, s, l, &sv_undef, 0) ;
63
hv_store (r -> pThread -> pFormSplitHash, (char *)pName, nlen, (SV *)pHV, 0) ;
64
if (r -> Component.Config.bDebug & dbgInput)
65
lprintf (r -> pApp, "[%d]INPU: <mult values>\n", r -> pThread -> nPid) ;
70
SvREFCNT_inc (*ppSVfdat) ;
71
hv_store (r -> pThread -> pFormSplitHash, (char *)pName, nlen, *ppSVfdat, 0) ;
72
if (r -> Component.Config.bDebug & dbgInput)
73
lprintf (r -> pApp, "[%d]INPU: value = %s\n", r -> pThread -> nPid, SvPV(*ppSVfdat, na)) ;
78
/* ---------------------------------------------------------------------------- */
80
/* SetRemove Attribute on html tag ... */
82
/* ---------------------------------------------------------------------------- */
86
static void embperlCmd_SetRemove (/*i/o*/ register req * r,
87
/*in*/ tDomTree * pDomTree,
89
/*in*/ tRepeatLevel nRepeatLevel,
90
/*in*/ const char * pName,
92
/*in*/ const char * pVal,
94
/*in*/ const char * sAttrName,
96
/*in*/ int bSetInSource)
101
SV ** ppSV = hv_fetch(r -> pThread -> pFormHash, (char *)pName, nNameLen, 0) ;
102
tNodeData * pNode = Node_selfLevel (r -> pApp, pDomTree, xNode, nRepeatLevel) ;
103
SV * pInputHashValue = NULL ;
107
SV ** ppSVerg = hv_fetch(r -> pThread -> pFormSplitHash, (char *)pName, nNameLen, 0) ;
108
SV * pSV = SplitFdat (r, ppSV, ppSVerg, (char *)pName, nNameLen) ;
110
if (SvTYPE (pSV) == SVt_PVHV)
111
{ /* -> Hash -> check if key exists */
112
nValLen = TransHtml (r, (char *)pVal, nValLen) ;
113
if (hv_exists ((HV *)pSV, (char *)pVal, nValLen))
116
pInputHashValue = newSVpv ((nValLen?((char *)pVal):""), nValLen) ;
122
char * pData = SvPV (pSV, dlen) ;
123
nValLen = TransHtml (r, (char *)pVal, nValLen) ;
124
if ((int)dlen == nValLen && strncmp (pVal, pData, dlen) == 0)
127
pInputHashValue = newSVsv(pSV) ;
133
Element_selfSetAttribut (r -> pApp, pDomTree, pNode, nRepeatLevel, sAttrName, nAttrLen, NULL, 0) ;
134
if (r -> Component.Config.bDebug & dbgInput)
135
lprintf (r -> pApp, "[%d]INPU: Set Attribut: Name: '%*.*s' Value: '%*.*s' Attribute: '%*.*s' nRepeatLevel=%d\n", r -> pThread -> nPid, nNameLen, nNameLen, pName, nValLen, nValLen, pVal, nAttrLen, nAttrLen, sAttrName, nRepeatLevel) ;
139
Element_selfRemoveAttribut (r -> pApp, pDomTree, pNode, nRepeatLevel, sAttrName, nAttrLen) ;
140
if (r -> Component.Config.bDebug & dbgInput)
141
lprintf (r -> pApp, "[%d]INPU: Remove Attribut: Name: '%*.*s' Value: '%*.*s' Attribute: '%*.*s' nRepeatLevel=%d\n", r -> pThread -> nPid, nNameLen, nNameLen, pName, nValLen, nValLen, pVal, nAttrLen, nAttrLen, sAttrName, nRepeatLevel ) ;
146
if (Element_selfGetAttribut (r -> pApp, pDomTree, pNode, sAttrName, nAttrLen))
148
hv_store (r -> pThread -> pInputHash, (char *)pName, nNameLen, newSVpv ((nValLen?((char *)pVal):""), nValLen), 0) ;
149
if (r -> Component.Config.bDebug & dbgInput)
150
lprintf (r -> pApp, "[%d]INPU: Has already Attribut: Name: '%*.*s' Value: '%*.*s' Attribute: '%*.*s' nRepeatLevel=%d\n", r -> pThread -> nPid, nNameLen, nNameLen, pName, nValLen, nValLen, pVal, nAttrLen, nAttrLen, sAttrName, nRepeatLevel ) ;
154
if (r -> Component.Config.bDebug & dbgInput)
155
lprintf (r -> pApp, "[%d]INPU: No value in %%fdat for Attribut: Name: '%*.*s' Value: '%*.*s' Attribute: '%*.*s' nRepeatLevel=%d\n", r -> pThread -> nPid, nNameLen, nNameLen, pName, nValLen, nValLen, pVal, nAttrLen, nAttrLen, sAttrName, nRepeatLevel ) ;
161
hv_store (r -> pThread -> pInputHash, (char *)pName, nNameLen, pInputHashValue, 0) ;
164
if (!hv_exists (r -> pThread -> pInputHash, (char *)pName, nNameLen))
165
hv_store (r -> pThread -> pInputHash, (char *)pName, nNameLen, newSVpv ("", 0), 0) ;
170
/* ---------------------------------------------------------------------------- */
172
/* input checkbox/radio html tag ... */
174
/* ---------------------------------------------------------------------------- */
178
void embperlCmd_InputCheck (/*i/o*/ register req * r,
179
/*in*/ tDomTree * pDomTree,
181
/*in*/ tRepeatLevel nRepeatLevel,
182
/*in*/ const char * pName,
184
/*in*/ const char * pVal,
186
/*in*/ int bSetInSource)
189
embperlCmd_SetRemove (r, pDomTree, xNode, nRepeatLevel, pName, nNameLen, pVal, nValLen, "checked", 7, bSetInSource) ;
193
/* ---------------------------------------------------------------------------- */
195
/* option html tag ... */
197
/* ---------------------------------------------------------------------------- */
200
void embperlCmd_Option (/*i/o*/ register req * r,
201
/*in*/ tDomTree * pDomTree,
203
/*in*/ tRepeatLevel nRepeatLevel,
204
/*in*/ const char * pName,
206
/*in*/ const char * pVal,
208
/*in*/ int bSetInSource)
212
embperlCmd_SetRemove (r, pDomTree, xNode, nRepeatLevel, pName, nNameLen, pVal, nValLen, "selected", 8, bSetInSource) ;
219
/* ---------------------------------------------------------------------------- */
221
/* hidden command ... */
223
/* ---------------------------------------------------------------------------- */
226
int embperlCmd_Hidden (/*i/o*/ register req * r,
227
/*in*/ tDomTree * pDomTree,
229
/*in*/ tRepeatLevel nRepeatLevel,
230
/*in*/ const char * sArg)
237
HV * pAddHash = r -> pThread -> pFormHash ;
238
HV * pSubHash = r -> pThread -> pInputHash ;
248
tNodeData * pNewNode ;
251
EPENTRY (CmdHidden) ;
253
pNode = Node_selfCondCloneNode (r -> pApp, pDomTree, Node_selfLevel (r -> pApp, pDomTree, xNode, nRepeatLevel), nRepeatLevel) ;
257
sArgs = _ep_strdup (r, sArg) ;
258
if (sArgs && *sArgs != '\0')
260
strncpy (sVar, r -> Component.sEvalPackage, sizeof (sVar) - 5) ;
261
sVar[r -> Component.nEvalPackage] = ':' ;
262
sVar[r -> Component.nEvalPackage+1] = ':' ;
263
sVar[sizeof(sVar) - 1] = '\0' ;
264
nMax = sizeof(sVar) - r -> Component.nEvalPackage - 3 ;
266
if ((sVarName = strtok (sArgs, ", \t\n")))
268
if (*sVarName == '%')
271
strncpy (sVar + r -> Component.nEvalPackage + 2, sVarName, nMax) ;
273
if ((pAddHash = perl_get_hv ((char *)sVar, FALSE)) == NULL)
275
strncpy (r -> errdat1, sVar, sizeof (r -> errdat1) - 1) ;
280
if ((sVarName = strtok (NULL, ", \t\n")))
282
if (*sVarName == '%')
285
strncpy (sVar + r -> Component.nEvalPackage + 2, sVarName, nMax) ;
287
if ((pSubHash = perl_get_hv ((char *)sVar, FALSE)) == NULL)
289
strncpy (r -> errdat1, sVar, sizeof (r -> errdat1) - 1) ;
294
if ((sVarName = strtok (NULL, ", \t\n")))
296
if (*sVarName == '@')
299
strncpy (sVar + r -> Component.nEvalPackage + 2, sVarName, nMax) ;
301
if ((pSort = perl_get_av ((char *)sVar, FALSE)) == NULL)
303
strncpy (r -> errdat1, sVar, sizeof (r -> errdat1) - 1) ;
305
return rcArrayError ;
312
pSort = r -> pThread -> pFormArray ;
315
/* oputc (r, '\n') ; */
318
int n = AvFILL (pSort) + 1 ;
321
for (i = 0; i < n; i++)
323
ppsv = av_fetch (pSort, i, 0) ;
324
if (ppsv && (pKey = SvPV(*ppsv, nKey)) && !hv_exists (pSubHash, pKey, nKey))
327
ppsv = hv_fetch (pAddHash, pKey, nKey, 0) ;
329
if (ppsv && (!(r -> Component.Config.bOptions & optNoHiddenEmptyValue) || *SvPV (*ppsv, lppsv)))
334
tNode xInputNode = Node_appendChild (r -> pApp, pDomTree, pNewNode -> xNdx, nRepeatLevel, ntypTag, 0, "input", 5, 0, 0, NULL) ;
335
tNode xAttr = Node_appendChild (r -> pApp, pDomTree, xInputNode, nRepeatLevel, ntypAttr, 0, "type", 4, 0, 0, NULL) ;
336
Node_appendChild (r -> pApp, pDomTree, xAttr, nRepeatLevel, ntypAttrValue, 0, "hidden", 6, 0, 0, NULL) ;
338
xAttr = Node_appendChild (r -> pApp, pDomTree, xInputNode, nRepeatLevel, ntypAttr, 0, "name", 4, 0, 0, NULL) ;
339
Node_appendChild (r -> pApp, pDomTree, xAttr, nRepeatLevel, ntypAttrValue, 0, pKey, nKey, 0, 0, NULL) ;
340
xAttr = Node_appendChild (r -> pApp, pDomTree, xInputNode, nRepeatLevel, ntypAttr, 0, "value", 5, 0, 0, NULL) ;
342
s = SvPV (*ppsv, l) ;
343
sEscapedText = Escape (r, s, l, r -> Component.nCurrEscMode, NULL, '\0') ;
344
s = SV2String (sEscapedText, l) ;
346
Node_appendChild (r -> pApp, pDomTree, xAttr, nRepeatLevel, ntypAttrValue, 0, s, l, 0, 0, NULL) ;
353
hv_iterinit (pAddHash) ;
354
while ((pEntry = hv_iternext (pAddHash)))
357
pKey = hv_iterkey (pEntry, &l) ;
358
nKey = strlen (pKey) ;
359
if (!hv_exists (pSubHash, pKey, nKey))
362
psv = hv_iterval (pAddHash, pEntry) ;
364
if (!(r -> Component.Config.bOptions & optNoHiddenEmptyValue) || *SvPV (psv, lpsv))
369
tNode xInputNode = Node_appendChild (r -> pApp, pDomTree, pNewNode -> xNdx, nRepeatLevel, ntypTag, 0, "input", 5, 0, 0, NULL) ;
370
tNode xAttr = Node_appendChild (r -> pApp, pDomTree, xInputNode, nRepeatLevel, ntypAttr, 0, "type", 4, 0, 0, NULL) ;
371
Node_appendChild (r -> pApp, pDomTree, xAttr, nRepeatLevel, ntypAttrValue, 0, "hidden", 6, 0, 0, NULL) ;
373
xAttr = Node_appendChild (r -> pApp, pDomTree, xInputNode, nRepeatLevel, ntypAttr, 0, "name", 4, 0, 0, NULL) ;
374
Node_appendChild (r -> pApp, pDomTree, xAttr, nRepeatLevel, ntypAttrValue, 0, pKey, nKey, 0, 0, NULL) ;
375
xAttr = Node_appendChild (r -> pApp, pDomTree, xInputNode, nRepeatLevel, ntypAttr, 0, "value", 5, 0, 0, NULL) ;
378
sEscapedText = Escape (r, s, l, r -> Component.nCurrEscMode, NULL, '\0') ;
379
s = SV2String (sEscapedText, l) ;
381
Node_appendChild (r -> pApp, pDomTree, xAttr, nRepeatLevel, ntypAttrValue, 0, s, l, 0, 0, NULL) ;
396
/* ---------------------------------------------------------------------------- */
398
/* ouput data inside a url */
400
/* ---------------------------------------------------------------------------- */
403
SV * Node_replaceChildWithUrlDATA (/*in*/ tReq * r,
404
/*in*/ tIndex xDomTree,
406
/*in*/ tRepeatLevel nRepeatLevel,
415
tDomTree * pDomTree = DomTree_self(xDomTree) ;
417
if (SvTYPE(sText) == SVt_RV && SvTYPE((pAV = (AV *)SvRV(sText))) == SVt_PVAV)
418
{ /* Array reference inside URL */
421
int f = AvFILL(pAV) ;
424
xOldChild = Node_replaceChildWithCDATA (r -> pApp, DomTree_self(xDomTree), xOldChild, nRepeatLevel, "", 0, 4, 0) ;
426
for (i = 0; i <= f; i++)
428
ppSV = av_fetch (pAV, i, 0) ;
431
s = SV2String (*ppSV, l) ;
432
xNode = Node_appendChild (r -> pApp, pDomTree, xOldChild, nRepeatLevel, (tNodeType)((r -> Component.nCurrEscMode & 3)?ntypTextHTML:ntypCDATA), 0, s, l, 0, 0, NULL) ;
433
if (r -> Component.nCurrEscMode & 2)
434
Node_selfLevel (r -> pApp, pDomTree, xNode, nRepeatLevel) -> bFlags |= nflgEscUrl ;
437
Node_appendChild (r -> pApp, pDomTree, xOldChild, nRepeatLevel, ntypCDATA, 0, "=", 1, 0, 0, NULL) ;
439
Node_appendChild (r -> pApp, pDomTree, xOldChild, nRepeatLevel, ntypCDATA, 0, "&", 5, 0, 0, NULL) ;
444
else if (SvTYPE(sText) == SVt_RV && SvTYPE((pHV = (HV *)SvRV(sText))) == SVt_PVHV)
445
{ /* Hash reference inside URL */
453
lprintf (r -> pApp, "xOldChild=%d, rl=%d\n", xOldChild, nRepeatLevel) ;
454
xOldChild = Node_replaceChildWithCDATA (r -> pApp, DomTree_self(xDomTree), xOldChild, nRepeatLevel, "", 0, 4, 0) ;
455
lprintf (r -> pApp, "a xOldChild=%d, rl=%d\n", xOldChild, nRepeatLevel) ;
458
while ((pEntry = hv_iternext (pHV)))
461
Node_appendChild (r -> pApp, pDomTree, xOldChild, nRepeatLevel, ntypCDATA, 0, "&", 5, 0, 0, NULL) ;
462
pKey = hv_iterkey (pEntry, &l32) ;
463
xNode = Node_appendChild (r -> pApp, pDomTree, xOldChild, nRepeatLevel, (tNodeType)((r -> Component.nCurrEscMode & 3)?ntypTextHTML:ntypCDATA), 0, pKey, l32, 0, 0, NULL) ;
464
if (r -> Component.nCurrEscMode & 2)
465
Node_self (pDomTree, xNode) -> bFlags |= nflgEscUrl ;
467
Node_appendChild (r -> pApp, pDomTree, xOldChild, nRepeatLevel, ntypCDATA, 0, "=", 1, 0, 0, NULL) ;
469
pSVValue = hv_iterval (pHV , pEntry) ;
472
s = SV2String (pSVValue, l) ;
473
xNode = Node_appendChild (r -> pApp, pDomTree, xOldChild, nRepeatLevel, (tNodeType)((r -> Component.nCurrEscMode & 3)?ntypTextHTML:ntypCDATA), 0, s, l, 0, 0, NULL) ;
474
if (r -> Component.nCurrEscMode & 2)
475
Node_selfLevel (r -> pApp, pDomTree, xNode, nRepeatLevel) -> bFlags |= nflgEscUrl ;
481
char * s = SV2String (sText, l) ;
482
Node_replaceChildWithCDATA (r -> pApp, DomTree_self(xDomTree), xOldChild, nRepeatLevel, s, l, (r -> Component.nCurrEscMode & 3) == 3?2 + (r -> Component.nCurrEscMode & 4):r -> Component.nCurrEscMode, 0) ;
485
r -> Component.nCurrEscMode = r -> Component.Config.nEscMode ;
486
r -> Component.bEscModeSet = -1 ;
487
/* SvREFCNT_inc (sText) ; */
496
/* ---------------------------------------------------------------------------- */
498
/* AddSessionIdToLink */
500
/* ---------------------------------------------------------------------------- */
503
int embperlCmd_AddSessionIdToLink (/*i/o*/ register req * r,
504
/*in*/ tDomTree * pDomTree,
506
/*in*/ tRepeatLevel nRepeatLevel,
507
/*in*/ char * sAttrName)
513
char * pAttrString = NULL ;
518
if (!r -> sSessionID)
521
pNode = Node_self(pDomTree,xNode) ;
522
nAttrLen = strlen (sAttrName) ;
523
pAttr = Element_selfGetAttribut (r -> pApp, pDomTree, pNode, sAttrName, nAttrLen) ;
525
pAttrValue = Attr_selfValue (r -> pApp, pDomTree, pAttr, nRepeatLevel, &pAttrString) ;
527
sl = strlen (r -> sSessionID) ;
530
l = strlen (pAttrValue) ;
531
StringNew (r -> pApp, &pAttrString, l + 10 + sl) ;
532
StringAdd (r -> pApp, &pAttrString, pAttrValue, l) ;
536
if (strchr(pAttrValue, '?'))
538
StringAdd (r -> pApp, &pAttrString, "&", 1) ;
542
StringAdd (r -> pApp, &pAttrString, "?", 1) ;
544
StringAdd (r -> pApp, &pAttrString, r -> sSessionID, sl) ;
546
Element_selfSetAttribut (r -> pApp, pDomTree, pNode, nRepeatLevel, sAttrName, nAttrLen, pAttrString, ArrayGetSize (r -> pApp, pAttrString)) ;
552
/* ---------------------------------------------------------------------------- */
554
/* AddSessionIdToHidden */
556
/* ---------------------------------------------------------------------------- */
559
int embperlCmd_AddSessionIdToHidden(/*i/o*/ register req * r,
560
/*in*/ tDomTree * pDomTree,
562
/*in*/ tRepeatLevel nRepeatLevel)
565
char * sid = r -> sSessionID ;
568
pNode = Node_self(pDomTree,xNode) ;
571
char * val = strchr (sid, '=') ;
574
tNode xInputNode = Node_appendChild (r -> pApp, pDomTree, pNode -> xNdx, nRepeatLevel, ntypTag, 0, "input", 5, 0, 0, NULL) ;
575
tNode xAttr = Node_appendChild (r -> pApp, pDomTree, xInputNode, nRepeatLevel, ntypAttr, 0, "type", 4, 0, 0, NULL) ;
576
Node_appendChild (r -> pApp, pDomTree, xAttr, nRepeatLevel, ntypAttrValue, 0, "hidden", 6, 0, 0, NULL) ;
578
xAttr = Node_appendChild (r -> pApp, pDomTree, xInputNode, nRepeatLevel, ntypAttr, 0, "name", 4, 0, 0, NULL) ;
579
Node_appendChild (r -> pApp, pDomTree, xAttr, nRepeatLevel, ntypAttrValue, 0, sid, val - sid, 0, 0, NULL) ;
580
xAttr = Node_appendChild (r -> pApp, pDomTree, xInputNode, nRepeatLevel, ntypAttr, 0, "value", 5, 0, 0, NULL) ;
581
Node_appendChild (r -> pApp, pDomTree, xAttr, nRepeatLevel, ntypAttrValue, 0, val+1, strlen(val+1), 0, 0, NULL) ;