Convert percent entities to set the type and value of the supplied atom. Here the percent entity is supplied in isolation. The ConvertText function (which calls this function), is used where percent entities can appear as part of a larger string (that is otherwise to be used verbatim).
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hdsApp::PcEntConv | (hzAtom&,hzString&,hzHttpEvent*,) |
Declared in file: hzDissemino.h
Defined in file : hdsSystem.cpp
Function Logic:
Function body:
hzEcode hdsApp::PcEntConv (hzAtom& atom)hzString& v, hzHttpEvent* pE,
{
// Convert percent entities to set the type and value of the supplied atom. Here the percent entity is supplied in isolation. The ConvertText function
// (which calls this function), is used where percent entities can appear as part of a larger string (that is otherwise to be used verbatim).
//
// Arguments: 1) atom The hzAtom to be set with the variable's value
// 2) v The percent entity
// 3) pE HTTP event pointer
//
// Returns: E_FORMAT If the supplied percent entity string is invalid
// E_NOTFOUND If the supplied percent entity is not matched
// E_OK If the supplied percent entity string is valid
_hzfunc("hdsApp::PcEntConv") ;
const hdbMember* pMbr ; // Class member
hzChain W ; // Variable name buffer
hdsInfo* pInfo ; // User session if applicable
hdsFormref* pFormref ; // From the event context
hdsFormdef* pFormdef ; // From the form reference
hdsField* pFld ; // Selected by name from the form
const hdbEnum* pSlct ; // Selector (for conversion of ints to strings)
hdbObjRepos* pRepos = 0; // Repository
const char* i ; // Used to iterate input value
hzString w_val ; // Constructed variable name
hzString extn ; // Variable extension for binaries and documents (eg ->addr, ->data)
hzString val ; // Variable value
uint32_t nTest ; // Category of percent directive
char buf[12]; // Buffer for random init code
hzEcode rc = E_OK ; // Return code
if (!pE)
hzexit(E_ARGUMENT, "%s: No HTTP event supplied for input=%s", *m_Appname, *v) ;
atom.Clear() ;
if (!v)
return E_OK ;
m_pLog->Log("PcEntConv processing %s\n", *v) ;
// If nothing to convert
if (v[0]!= CHAR_PERCENT)
{
atom = v ;
return E_OK ;
}
// All percent entities must have colon after the percent and the source directive
if (v[2]!= CHAR_COLON)
return E_FORMAT ;
// Get the variable type and name component
i = *v ;
for (i += 3; *i && *i != CHAR_SCOLON && IsAlpha(*i) ; i++)
W.AddByte(*i) ;
w_val = W ;
W.Clear() ;
if (*i == CHAR_PERIOD)
{
for (i++ ; *i && *i != CHAR_SCOLON && IsAlpha(*i) ; i++)
W.AddByte(*i) ;
extn = W ;
W.Clear() ;
}
if (*i == CHAR_SCOLON)
i++ ;
// If there is a sesssion - this affects many percent entities
pInfo = (hdsInfo*) pE->Session() ;
// Lookup variable and determine its value
switch (v[1])
{
case ''x'': // SYSTEM VALUES
if (w_val == "count")
{
// Count is of objects in a class
pRepos = m_ADP.GetObjRepos(extn) ;
if (!pRepos)
{ rc = E_NOTFOUND ; m_pLog->Log("Cannot Xlate. Repository not found: %s\n", *extn) ; }
else
atom = pRepos->Count() ;
}
else if (w_val == "objid")
{
pRepos = m_ADP.GetObjRepos(extn) ;
if (!pRepos)
{ rc = E_NOTFOUND ; m_pLog->Log("Cannot Xlate. Repository not found: %s\n", *extn) ; }
else
{
if (pE->m_ObjIds.Exists(extn))
atom = pE->m_ObjIds[extn] ;
else
{ rc = E_NOTFOUND ; m_pLog->Log("Cannot Xlate. Event entry not found: %s\n", *extn) ; }
}
}
else if (w_val == "date") atom = pE->m_Occur.Date() ;
else if (w_val == "time") atom = pE->m_Occur.Time() ;
else if (w_val == "datetime") atom = pE->m_Occur ;
else if (w_val == "referer") atom.SetValue(BASETYPE_STRING, pE->Referer()) ; // .Resource()) ;
else if (w_val == "usecs") atom = pE->m_Occur.uSec() ;
else if (w_val == "uid") atom = (uint32_t) (pInfo ? pInfo->m_UserId : 0);
else if (w_val == "random") { sprintf(buf, "%06d", pE->m_Occur.uSec()) ; atom.SetValue(BASETYPE_STRING, buf) ; }
else
{ rc = E_NOTFOUND ; m_pLog->Log("Cannot Xlate. Unknown parameter: %s\n", *w_val) ; }
break ;
case ''e'': // HTTP EVENT VARIABLES
pSlct = m_ADP.GetDataEnum(w_val) ;
if (pSlct)
// if (m_ADP.mapEnums.Exists(w_val))
{
// If a selector, values returned in form submissions will be integers
val = pE->m_mapStrings[w_val] ;
if (IsPosint(nTest, *val))
{
// pSlct = m_ADP.mapEnums[w_val] ;
val = pSlct->GetStr(nTest) ;
rc = atom.SetValue(BASETYPE_STRING, val) ;
break ;
}
}
if (pE->m_Uploads.Exists(w_val))
{
// Find an entry in m_Files paart of the HTTP event - then give either the file name or the file data
hzHttpFile& hf = pE->m_Uploads[w_val] ;
if (extn == "name")
rc = atom.SetValue(BASETYPE_STRING, hf.m_filename) ;
else if (extn == "data")
{
if (hf.m_file.Size())
{ rc = E_OK ; atom = hf.m_file ; }
else
rc = E_NODATA ;
m_pLog->Log("Have file %s of %d bytes\n", *hf.m_filename, hf.m_file.Size()) ;
}
else
rc = E_BADVALUE ;
break ;
}
if (w_val == g_Errmsg)
{
if (pE->m_appError)
atom = pE->m_appError ;
break ;
}
if (w_val == "resarg")
{
atom.SetValue(BASETYPE_STRING, pE->m_Resarg) ;
break ;
}
if (pE->m_mapStrings.Exists(w_val))
{
val = pE->m_mapStrings[w_val] ;
if (pE->m_pContextForm)
{
pFormref = (hdsFormref*) pE->m_pContextForm ;
pFormdef = m_FormDefs[pFormref->m_Formname] ;
if (!pFormdef->m_mapFlds.Exists(w_val))
{
m_pLog->Log("Case 1: Using string context value %s = %s\n", *w_val, *val) ;
rc = atom.SetValue(BASETYPE_STRING, val) ;
}
else
{
pFld = pFormdef->m_mapFlds[w_val] ;
if (pFld)
{
m_pLog->Log("Case 2: Using string context value %s = %s %s\n", *w_val, Basetype2Txt(pFld->m_Fldspec.m_pType->Basetype()), *val) ;
rc = atom.SetValue(pFld->m_Fldspec.m_pType->Basetype(), val) ;
}
else
{
m_pLog->Log("Case 3: Using string context value %s = %s\n", *w_val, *val) ;
rc = atom.SetValue(BASETYPE_STRING, val) ;
}
}
}
else
{
m_pLog->Log("Using context-less value %s\n", *val) ;
rc = atom.SetValue(BASETYPE_STRING, val) ;
}
break ;
}
if (pE->m_mapChains.Exists(w_val))
{
val = pE->m_mapChains[w_val] ;
if (pE->m_pContextForm)
{
pFormref = (hdsFormref*) pE->m_pContextForm ;
pFormdef = m_FormDefs[pFormref->m_Formname] ;
if (!pFormdef->m_mapFlds.Exists(w_val))
{
m_pLog->Log("Case 1: Using chain context value %s = %s\n", *w_val, *val) ;
rc = atom.SetValue(BASETYPE_STRING, val) ;
}
else
{
m_pLog->Log("Case 2: Using chain context value %s = %s\n", *w_val, *val) ;
pFld = pFormdef->m_mapFlds[w_val] ;
rc = atom.SetValue(pFld->m_Fldspec.m_pType->Basetype(), val) ;
}
}
else
{
m_pLog->Log("Using context-less value %s\n", *val) ;
rc = atom.SetValue(BASETYPE_STRING, val) ;
}
break ;
}
rc = E_NOTFOUND ;
break ;
case ''s'': // SESSION VARIABLES
rc = E_NOTFOUND ;
if (pInfo && pInfo->m_Sessvals.Count())
{
if (pInfo->m_Sessvals.Exists(w_val))
{
atom = pInfo->m_Sessvals[w_val] ;
rc = E_OK ;
}
break ;
}
m_pLog->Log("Warning: No such session value [%s]\n", *w_val) ;
break ;
case ''i'': // IN-SITU OBJECT MEMBERS
rc = E_NOTFOUND ;
if (!pInfo)
break ;
if (!pInfo->m_CurrRepos)
break ;
if (!pInfo->m_CurrObj)
break ;
// pRepos = m_ADP.m_arrRepositories[pInfo->m_CurrRepos] ;
pRepos = m_ADP.GetObjRepos(pInfo->m_CurrRepos) ;
// if (pRepos)
// pCache = dynamic_cast<hdbObjCache*>(pRepos) ;
if (pRepos)
pMbr = pRepos->GetMember(w_val) ;
if (pMbr)
{
hdbObject obj ;
hzChain Z ;
rc = pRepos->Fetch(obj, pInfo->m_CurrObj) ;
if (rc != E_OK)
break ;
if (pMbr->Basetype() == BASETYPE_BINARY || pMbr->Basetype() == BASETYPE_TXTDOC)
{
if (extn == "addr")
{
m_pLog->Log("Fetching address %s\n", *w_val) ;
// rc = pRepos->Fetchval(atom, w_val, pInfo->m_CurrObj) ;
obj.GetValue(atom, pMbr) ;
}
if (extn == "data")
{
m_pLog->Log("Fetching binary body %s\n", *w_val) ;
// rc = pRepos->Fetchbin(atom, w_val, pInfo->m_CurrObj) ;
rc = obj.GetBinary(Z, pMbr) ;
atom = Z ;
}
}
else
{
m_pLog->Log("Fetching ord %s\n", *w_val) ;
// rc = pRepos->Fetchval(atom, w_val, pInfo->m_CurrObj) ;
rc = obj.GetValue(atom, pMbr) ;
}
}
break ;
case ''v'': // CURRENT OBJECT MEMBERS
break ;
case ''u'': // CURRENT USER-INFO MEMBERS (also user dirs and files)
rc = E_NOTFOUND ;
if (!pInfo)
break ;
m_pLog->Log("Fetching item %s for subscriber id %d\n", *w_val, pInfo->m_SubId) ;
if (w_val == "username")
{
// if (m_Allusers)
// rc = m_Allusers->Fetchval(atom, SUBSCRIBER_USERNAME, pInfo->m_SubId) ;
// m_pLog->Log("Fetched item %s\n", *atom.Str()) ;
atom = pInfo->m_Username ;
break ;
}
if (pInfo->m_CurrRepos && pInfo->m_UserId > 0)
{
// pRepos = m_ADP.m_arrRepositories[pInfo->m_CurrRepos] ;
pRepos = m_ADP.GetObjRepos(pInfo->m_CurrRepos) ;
// if (pRepos)
// pRepos = dynamic_cast<hdbObjCache*>(pRepos) ;
if (pRepos)
pMbr = pRepos->GetMember(w_val) ;
if (!pMbr)
break ;
hdbObject obj ;
hzChain Z ;
rc = pRepos->Fetch(obj, pInfo->m_CurrObj) ;
if (rc != E_OK)
break ;
if (pMbr->Basetype() == BASETYPE_BINARY || pMbr->Basetype() == BASETYPE_TXTDOC)
{
if (extn == "addr")
{
m_pLog->Out("Fetching address %s\n", *w_val) ;
// rc = pRepos->Fetchval(atom, w_val, pInfo->m_UserId) ;
rc = obj.GetValue(atom, pMbr) ;
}
if (extn == "data")
{
m_pLog->Out("Fetching binary body %s\n", *w_val) ;
// rc = pRepos->Fetchbin(atom, w_val, pInfo->m_UserId) ;
rc = obj.GetBinary(Z, pMbr) ;
atom = Z ;
}
}
else
{
m_pLog->Out("Fetching ord %s\n", *w_val) ;
// rc = pRepos->Fetchval(atom, w_val, pInfo->m_UserId) ;
rc = obj.GetValue(atom, pMbr) ;
}
}
break ;
default:
rc = hzerr(E_FORMAT, "Invalid Percent Entity Category (%c)", v[1]);
}
return rc ;
}