// Asenath.cpp : Defines the entry point for the DLL application. // #include "stdafx.h" #include "httpext.h" #include "corediatheke.h" #include #include BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer) { pVer->dwExtensionVersion = HSE_VERSION; strncpy(pVer->lpszExtensionDesc, "Asenath ISAPI Extension", HSE_MAX_EXT_DLL_NAME_LEN); return TRUE; } void WriteContext(EXTENSION_CONTROL_BLOCK *pECB, const char *pszFormat, ...) { char szBuffer[1024]; va_list arg_ptr; va_start(arg_ptr, pszFormat); vsprintf(szBuffer, pszFormat, arg_ptr); va_end(arg_ptr); DWORD dwSize = strlen(szBuffer); pECB->WriteClient(pECB->ConnID, szBuffer, &dwSize, 0); } void StartContext(EXTENSION_CONTROL_BLOCK *pECB, bool palm) { if (!palm) { WriteContext(pECB, ""); WriteContext(pECB, "Diatheke Interlinear Bible"); WriteContext(pECB, ""); WriteContext(pECB, ""); WriteContext(pECB, ""); WriteContext(pECB, ""); WriteContext(pECB, ""); WriteContext(pECB, ""); WriteContext(pECB, ""); } else { WriteContext(pECB, ""); WriteContext(pECB, "HANDiatheke"); WriteContext(pECB, ""); WriteContext(pECB, ""); WriteContext(pECB, ""); WriteContext(pECB, ""); WriteContext(pECB, ""); } } void EndContext(EXTENSION_CONTROL_BLOCK *pECB, bool palm) { if (palm) { WriteContext(pECB, "
Powered by Diatheke (http://www.crosswire.org/sword/diatheke) and the SWORD Project (http://www.crosswire.org/sword)."); } WriteContext(pECB, "



"); } DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *pECB) { int maxverses = -1; unsigned char outputformat = FMT_CGI, searchtype = ST_NONE, outputencoding = ENC_UTF8; unsigned long optionfilters = OP_NONE; std::string locale, ref, script, range, defversion; signed short variants = 0; bool debugmode = false, palm = false; std::string qstring; std::string savestring = "Asenath.dll?"; std::string val, key; std::list versionlist; string::size_type pos; qstring = pECB->lpszQueryString; unsigned char c; for (int i = 0; i < qstring.length(); i++) { if (qstring[i] == '+') { qstring[i] = ' '; } else if (qstring[i] == '%') { if (qstring[i+1] > 57) { c = 16 * (10 + toupper(qstring[i+1]) - 'A'); } else { c = 16 * (qstring[i+1] - '0'); } if (qstring[i+2] > 57) { c += 10 + toupper(qstring[i+2]) - 'A'; } else { c += qstring[i+2] - '0'; } qstring[i] = c; qstring.erase(i+1, 2); } } while (qstring.length()) { pos = qstring.find("&"); if (pos != string::npos) { key = qstring.substr(0, pos); qstring.erase(0, pos+1); } else { key = qstring; qstring = ""; } pos = key.find("="); if (pos != string::npos) { val = key.substr(pos+1, key.length()-(pos+1)); key.erase(pos, key.length()-pos); } else { val = ""; } if (!stricmp (key.c_str(), "verse")) { ref = val; } else if (!stricmp (key.c_str(), "search")) { if (!stricmp (val.c_str(), "phrase")) { searchtype = ST_PHRASE; savestring += key + "=" + val + "&"; } else if (!stricmp (val.c_str(), "regex")) { searchtype = ST_REGEX; savestring += key + "=" + val + "&"; } else if (!stricmp (val.c_str(), "multiword")) { searchtype = ST_MULTIWORD; savestring += key + "=" + val + "&"; } } else if (!stricmp (key.c_str(), "range")) { range = val; savestring += key + "=" + val + "&"; } else if (!stricmp (key.c_str(), "maxverses")) { maxverses = atoi(val.c_str()); savestring += key + "=" + val + "&"; } else if (!stricmp (key.c_str(), "variants")) { variants = atoi(val.c_str()); savestring += key + "=" + val + "&"; } else if (!stricmp (key.c_str(), "locale")) { locale = val; savestring += key + "=" + val + "&"; } else if (!stricmp (key.c_str(), "debug")) { debugmode = true; savestring += key + "=" + val + "&"; } else if (!stricmp (key.c_str(), "palm")) { palm = true; savestring += key + "=" + val + "&"; } else if (!stricmp (key.c_str(), "defversion")) { defversion = val; savestring += key + "=" + val + "&"; } else if (stricmp (val.c_str(), "off")) { if (!stricmp (key.c_str(), "strongs")) { optionfilters |= OP_STRONGS; savestring += key + "=" + val + "&"; } else if (!stricmp (key.c_str(), "footnotes")) { optionfilters |= OP_FOOTNOTES; savestring += key + "=" + val + "&"; } else if (!stricmp (key.c_str(), "headings")) { optionfilters |= OP_HEADINGS; savestring += key + "=" + val + "&"; } else if (!stricmp (key.c_str(), "morph")) { optionfilters |= OP_MORPH; savestring += key + "=" + val + "&"; } else if (!stricmp (key.c_str(), "hebcant")) { optionfilters |= OP_CANTILLATION; savestring += key + "=" + val + "&"; } else if (!stricmp (key.c_str(), "hebvowels")) { optionfilters |= OP_HEBREWPOINTS; savestring += key + "=" + val + "&"; } else if (!stricmp (key.c_str(), "grkacc")) { optionfilters |= OP_GREEKACCENTS; savestring += key + "=" + val + "&"; } else if (!stricmp (key.c_str(), "lemmas")) { optionfilters |= OP_LEMMAS; savestring += key + "=" + val + "&"; } else if (!stricmp (key.c_str(), "scriprefs")) { optionfilters |= OP_SCRIPREF; savestring += key + "=" + val + "&"; } else if (!stricmp (key.c_str(), "arshape")) { optionfilters |= OP_ARSHAPE; savestring += key + "=" + val + "&"; } else if (!stricmp (key.c_str(), "bidi")) { optionfilters |= OP_BIDI; savestring += key + "=" + val + "&"; } else if (!stricmp (key.c_str(), "redletters")) { optionfilters |= OP_RED; savestring += key + "=" + val + "&"; } else if (!stricmp (key.c_str(), "latinxlit")) { script = "Latin"; savestring += key + "=" + val + "&"; } else versionlist.push_back(string(key)); } } if (!locale.length()) { unsigned long dsize = 2083; char * data = new char[2083]; pECB->GetServerVariable(pECB->ConnID, "ACCEPT_LANGUAGE", data, &dsize); if (dsize) { locale = data; pos = locale.find("_"); if (pos != string::npos) locale = locale.substr(0,pos); } else { locale = "abbr"; } } StartContext(pECB, palm); if (versionlist.size() == 0) if (defversion.length()) versionlist.push_back(defversion); else versionlist.push_back("KJV"); while (versionlist.size() > 0) { ostrstream * output = new ostrstream(); doquery(maxverses, outputformat, outputencoding, optionfilters, searchtype, range.c_str(), versionlist.front().c_str(), locale.c_str(), ref.c_str(), output, script.c_str(), variants); *output << ends; qstring = output->str(); delete output; while ((pos = qstring.find("!DIATHEKE_URL!")) && pos != string::npos) { qstring.replace(pos, 14, savestring.c_str()); } DWORD dwSize = qstring.length(); pECB->WriteClient(pECB->ConnID, (void*)qstring.c_str(), &dwSize, 0); WriteContext(pECB, "

"); versionlist.pop_front(); } EndContext(pECB, palm); return HSE_STATUS_SUCCESS; }