espprotocol.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #pragma warning (disable : 4786)
  14. #ifdef _WIN32
  15. #ifdef ESPHTTP_EXPORTS
  16. #define esp_http_decl __declspec(dllexport)
  17. #endif
  18. #endif
  19. #include "platform.h"
  20. #include "espprotocol.hpp"
  21. #include "espbinding.hpp"
  22. #ifdef _USE_OPENLDAP
  23. #include "ldapsecurity.ipp"
  24. #endif
  25. typedef IXslProcessor * (*getXslProcessor_func)();
  26. static atomic_t gActiveRequests;
  27. long ActiveRequests::getCount()
  28. {
  29. return atomic_read(&gActiveRequests);
  30. }
  31. void ActiveRequests::inc()
  32. {
  33. atomic_inc(&gActiveRequests);
  34. }
  35. void ActiveRequests::dec()
  36. {
  37. atomic_dec(&gActiveRequests);
  38. }
  39. CEspApplicationPort::CEspApplicationPort(bool viewcfg) : bindingCount(0), defBinding(-1), viewConfig(viewcfg), rootAuth(false), navWidth(165), navResize(false), navScroll(false)
  40. {
  41. build_ver = getBuildVersion();
  42. hxsl = LoadSharedObject(SharedObjectPrefix "xmllib" SharedObjectExtension, true, false);
  43. if (!hxsl)
  44. DBGLOG("Loading xmllib shared library failed!");
  45. else
  46. {
  47. getXslProcessor_func xslfactory = (getXslProcessor_func) GetSharedProcedure(hxsl, "getXslProcessor");
  48. if (!xslfactory)
  49. DBGLOG("Loading procedure from xmllib shared library failed!");
  50. else
  51. xslp.setown(xslfactory());
  52. }
  53. }
  54. void CEspApplicationPort::appendBinding(CEspBindingEntry* entry, bool isdefault)
  55. {
  56. bindings[bindingCount]=entry;
  57. if (isdefault)
  58. defBinding=bindingCount;
  59. bindingCount++;
  60. EspHttpBinding *httpbind = dynamic_cast<EspHttpBinding *>(entry->queryBinding());
  61. if (httpbind)
  62. {
  63. if (!rootAuth)
  64. rootAuth = httpbind->rootAuthRequired();
  65. int width=0;
  66. bool resizable=false;
  67. bool scroll=false;
  68. httpbind->getNavSettings(width, resizable, scroll);
  69. if (navWidth<width)
  70. navWidth=width;
  71. if (!navResize)
  72. navResize=resizable;
  73. if (!navScroll)
  74. navScroll=scroll;
  75. }
  76. }
  77. const StringBuffer &CEspApplicationPort::getAppFrameHtml(time_t &modified, const char *inner, StringBuffer &html, IEspContext* ctx)
  78. {
  79. if (!xslp)
  80. throw MakeStringException(0,"Error - CEspApplicationPort XSLT processor not initialized");
  81. bool embedded_url=(inner&&*inner);
  82. StringBuffer params;
  83. bool needRefresh = true;
  84. if (!getUrlParams(ctx->queryRequestParameters(), params))
  85. {
  86. if (params.length()==0)
  87. needRefresh = false;
  88. if (ctx->getClientVersion()>0)
  89. {
  90. params.appendf("%cver_=%g", params.length()?'&':'?', ctx->getClientVersion());
  91. needRefresh = true;
  92. }
  93. }
  94. if (needRefresh || embedded_url || !appFrameHtml.length())
  95. {
  96. int passwordDaysRemaining = scPasswordExpired;//-1 means dont display change password screen
  97. #ifdef _USE_OPENLDAP
  98. ISecUser* user = ctx->queryUser();
  99. ISecManager* secmgr = ctx->querySecManager();
  100. if(user && secmgr)
  101. {
  102. passwordDaysRemaining = user->getPasswordDaysRemaining();//-1 if expired, -2 if never expires
  103. int passwordExpirationDays = (int)secmgr->getPasswordExpirationWarningDays();
  104. if (passwordDaysRemaining == scPasswordNeverExpires || passwordDaysRemaining > passwordExpirationDays)
  105. passwordDaysRemaining = scPasswordExpired;
  106. }
  107. #endif
  108. StringBuffer xml;
  109. StringBuffer encoded_inner;
  110. if(inner && *inner)
  111. encodeXML(inner, encoded_inner);
  112. // replace & with &amps;
  113. params.replaceString("&","&amp;");
  114. xml.appendf("<EspApplicationFrame title=\"%s\" navWidth=\"%d\" navResize=\"%d\" navScroll=\"%d\" inner=\"%s\" params=\"%s\" passwordDays=\"%d\"/>",
  115. getESPContainer()->getFrameTitle(), navWidth, navResize, navScroll, (inner&&*inner) ? encoded_inner.str() : "?main", params.str(), passwordDaysRemaining);
  116. Owned<IXslTransform> xform = xslp->createXslTransform();
  117. xform->loadXslFromFile(StringBuffer(getCFD()).append("./xslt/appframe.xsl").str());
  118. xform->setXmlSource(xml.str(), xml.length()+1);
  119. xform->transform( (needRefresh || embedded_url) ? html.clear() : appFrameHtml.clear());
  120. }
  121. if (!needRefresh && !embedded_url)
  122. html.clear().append(appFrameHtml.str());
  123. static time_t startup_time = time(NULL);
  124. modified = startup_time;
  125. return html;
  126. }
  127. const StringBuffer &CEspApplicationPort::getTitleBarHtml(IEspContext& ctx, bool rawXml)
  128. {
  129. if (xslp)
  130. {
  131. StringBuffer titleBarXml;
  132. const char* user = ctx.queryUserId();
  133. if (!user || !*user)
  134. titleBarXml.appendf("<EspHeader><BuildVersion>%s</BuildVersion><ConfigAccess>%d</ConfigAccess>"
  135. "<LoginId>&lt;nobody&gt;</LoginId><NoUser>1</NoUser></EspHeader>", build_ver, viewConfig);
  136. else
  137. titleBarXml.appendf("<EspHeader><BuildVersion>%s</BuildVersion><ConfigAccess>%d</ConfigAccess>"
  138. "<LoginId>%s</LoginId></EspHeader>", build_ver, viewConfig, user);
  139. if (rawXml)
  140. {
  141. titleBarHtml.set(titleBarXml);
  142. }
  143. else
  144. {
  145. Owned<IXslTransform> xform = xslp->createXslTransform();
  146. xform->loadXslFromFile(StringBuffer(getCFD()).append("./xslt/espheader.xsl").str());
  147. xform->setXmlSource(titleBarXml.str(), titleBarXml.length()+1);
  148. xform->transform(titleBarHtml.clear());
  149. }
  150. }
  151. return titleBarHtml;
  152. }
  153. const StringBuffer &CEspApplicationPort::getNavBarContent(IEspContext &context, StringBuffer &content, StringBuffer &contentType, bool rawxml)
  154. {
  155. if (xslp)
  156. {
  157. Owned<IPropertyTree> navtree=createPTree("EspNavigationData");
  158. int count = getBindingCount();
  159. for (int idx = 0; idx<count; idx++)
  160. bindings[idx]->queryBinding()->getNavigationData(context, *navtree.get());
  161. StringBuffer xml;
  162. buildNavTreeXML(navtree.get(), xml);
  163. if (rawxml)
  164. {
  165. content.swapWith(xml);
  166. contentType.clear().append(HTTP_TYPE_APPLICATION_XML_UTF8);
  167. }
  168. else
  169. {
  170. const char* viewType = navtree->queryProp("@viewType");
  171. Owned<IXslTransform> xform = xslp->createXslTransform();
  172. StringBuffer xslsource;
  173. if (viewType && *viewType)
  174. {
  175. xslsource.append(getCFD()).appendf("./xslt/%s.xsl", stricmp(viewType, "tree") != 0 ? viewType: "navigation");
  176. }
  177. else
  178. {
  179. xslsource.append(getCFD()).append("./xslt/nav.xsl");
  180. }
  181. xform->loadXslFromFile(xslsource.str());
  182. xform->setXmlSource(xml.str(), xml.length()+1);
  183. xform->transform(content);
  184. contentType.clear().append("text/html; charset=UTF-8");
  185. }
  186. }
  187. return content;
  188. }
  189. const StringBuffer &CEspApplicationPort::getDynNavData(IEspContext &context, IProperties *params, StringBuffer &content,
  190. StringBuffer &contentType, bool& bVolatile)
  191. {
  192. Owned<IPropertyTree> navtree=createPTree("EspDynNavData");
  193. bVolatile = false;
  194. int count = getBindingCount();
  195. for (int idx = 0; idx<count; idx++)
  196. bindings[idx]->queryBinding()->getDynNavData(context, params, *navtree.get());
  197. if (!bVolatile)
  198. bVolatile = navtree->getPropBool("@volatile", false);
  199. contentType.clear().append(HTTP_TYPE_APPLICATION_XML_UTF8);
  200. return toXML(navtree.get(), content.clear());
  201. }
  202. int CEspApplicationPort::onGetNavEvent(IEspContext &context, IHttpMessage* request, IHttpMessage* response)
  203. {
  204. int handled=0;
  205. int count = getBindingCount();
  206. for (int idx = 0; !handled && idx<count; idx++)
  207. {
  208. handled = bindings[idx]->queryBinding()->onGetNavEvent(context, request, response);
  209. }
  210. return handled;
  211. }
  212. int CEspApplicationPort::onBuildSoapRequest(IEspContext &context, IHttpMessage* ireq, IHttpMessage* iresp)
  213. {
  214. CHttpRequest *request=dynamic_cast<CHttpRequest*>(ireq);
  215. CHttpResponse *response=dynamic_cast<CHttpResponse*>(iresp);
  216. int handled=0;
  217. int count = getBindingCount();
  218. for (int idx = 0; !handled && idx<count; idx++)
  219. {
  220. //if (bindings[idx]->queryBinding()->isValidServiceName(context, ))
  221. }
  222. return handled;
  223. }
  224. void CEspApplicationPort::buildNavTreeXML(IPropertyTree* navtree, StringBuffer& xmlBuf, bool insideFolder)
  225. {
  226. if (!navtree)
  227. return;
  228. //Find out the menu items which do not request a specific position
  229. //Also find out the maximum position being requested
  230. unsigned positionMax = 0;
  231. StringArray itemsGroup1;
  232. Owned<IPropertyTreeIterator> items = navtree->getElements("*");
  233. ForEach(*items)
  234. {
  235. IPropertyTree &item = items->query();
  236. unsigned position = (unsigned) item.getPropInt("@relPosition", 0);
  237. if (position > positionMax)
  238. {
  239. positionMax = position;
  240. }
  241. else if (position < 1)
  242. {//if the item does not request a position, add it to the 'itemsGroup1'.
  243. StringBuffer itemXML;
  244. if (!insideFolder)
  245. buildNavTreeXML(&item, itemXML, true);
  246. else
  247. toXML(&item, itemXML);
  248. itemsGroup1.append(itemXML);
  249. }
  250. }
  251. xmlBuf.appendf("<%s", navtree->queryName());
  252. Owned<IAttributeIterator> attrs = navtree->getAttributes();
  253. ForEach(*attrs)
  254. {
  255. const char *attrname = attrs->queryName()+1;
  256. const char *attrvaluee = attrs->queryValue();
  257. if (attrname && *attrname && attrvaluee && *attrvaluee)
  258. xmlBuf.appendf(" %s=\"%s\"", attrname, attrvaluee);
  259. }
  260. xmlBuf.append(">\n");
  261. unsigned positionInGroup1 = 0;
  262. unsigned itemCountInGroup1 = itemsGroup1.length();
  263. //append the menu items based on the position requested
  264. unsigned position = 1;
  265. while (position <= positionMax)
  266. {
  267. bool foundOne = false;
  268. //process the item(s) which asks for this position
  269. StringBuffer xPath;
  270. xPath.appendf("*[@relPosition=%d]", position);
  271. Owned<IPropertyTreeIterator> items1 = navtree->getElements(xPath.str());
  272. ForEach(*items1)
  273. {
  274. IPropertyTree &item = items1->query();
  275. StringBuffer itemXML;
  276. if (!insideFolder)
  277. buildNavTreeXML(&item, itemXML, true);
  278. else
  279. toXML(&item, itemXML);
  280. xmlBuf.append(itemXML.str());
  281. foundOne = true;
  282. }
  283. //If no one asks for this position, pick one from the itemsGroup1
  284. if (!foundOne && (positionInGroup1 < itemCountInGroup1))
  285. {
  286. StringBuffer itemXML = itemsGroup1.item(positionInGroup1);
  287. xmlBuf.append(itemXML.str());
  288. positionInGroup1++;
  289. }
  290. position++;
  291. }
  292. //Check any item left inside the itemsGroup1 and append it into the xml
  293. while (positionInGroup1 < itemCountInGroup1)
  294. {
  295. StringBuffer itemXML = itemsGroup1.item(positionInGroup1);
  296. xmlBuf.append(itemXML.str());
  297. positionInGroup1++;
  298. }
  299. xmlBuf.appendf("</%s>\n", navtree->queryName());
  300. }
  301. IPropertyTree *CEspBinding::ensureNavFolder(IPropertyTree &root, const char *name, const char *tooltip, const char *menuname, bool sort, unsigned relPosition)
  302. {
  303. StringBuffer xpath;
  304. xpath.appendf("Folder[@name=\"%s\"]", name);
  305. IPropertyTree *ret = root.queryPropTree(xpath.str());
  306. if (!ret)
  307. {
  308. ret=createPTree("Folder");
  309. ret->addProp("@name", name);
  310. ret->addProp("@tooltip", tooltip);
  311. ret->setProp("@menu", menuname);
  312. if (sort)
  313. ret->addPropBool("@sort", true);
  314. ret->addPropInt("@relPosition", relPosition);
  315. root.addPropTree("Folder", ret);
  316. }
  317. return ret;
  318. }
  319. IPropertyTree *CEspBinding::ensureNavMenu(IPropertyTree &root, const char *name)
  320. {
  321. StringBuffer xpath;
  322. xpath.appendf("Menu[@name=\"%s\"]", name);
  323. IPropertyTree *ret = root.queryPropTree(xpath.str());
  324. if (!ret)
  325. {
  326. ret=createPTree("Menu");
  327. ret->addProp("@name", name);
  328. root.addPropTree("Menu", ret);
  329. }
  330. return ret;
  331. }
  332. IPropertyTree *CEspBinding::ensureNavMenuItem(IPropertyTree &root, const char *name, const char *tooltip, const char *action)
  333. {
  334. StringBuffer xpath;
  335. xpath.appendf("MenuItem[@name=\"%s\"]", name);
  336. IPropertyTree *ret = root.queryPropTree(xpath.str());
  337. if (!ret)
  338. {
  339. ret=createPTree("MenuItem");
  340. ret->addProp("@name", name);
  341. ret->addProp("@tooltip", tooltip);
  342. ret->addProp("@action", action);
  343. root.addPropTree("MenuItem", ret);
  344. }
  345. return ret;
  346. }
  347. IPropertyTree *CEspBinding::ensureNavDynFolder(IPropertyTree &root, const char *name, const char *tooltip, const char *params, const char *menuname)
  348. {
  349. StringBuffer xpath;
  350. xpath.appendf("DynamicFolder[@name=\"%s\"]", name);
  351. IPropertyTree *ret = root.queryPropTree(xpath.str());
  352. if (!ret)
  353. {
  354. ret=createPTree("DynamicFolder");
  355. ret->addProp("@name", name);
  356. ret->addProp("@tooltip", tooltip);
  357. ret->addProp("@params", params);
  358. ret->setProp("@menu", menuname);
  359. root.addPropTree("DynamicFolder", ret);
  360. }
  361. return ret;
  362. }
  363. IPropertyTree *CEspBinding::ensureNavLink(IPropertyTree &folder, const char *name, const char *path, const char *tooltip, const char *menuname, const char *navPath, unsigned relPosition, bool force)
  364. {
  365. StringBuffer xpath;
  366. xpath.appendf("Link[@name=\"%s\"]", name);
  367. bool addNew = true;
  368. IPropertyTree *ret = folder.queryPropTree(xpath.str());
  369. if (ret)
  370. {
  371. bool forced = ret->getPropBool("@force");
  372. if (forced || !force)
  373. return ret;
  374. addNew = false;
  375. }
  376. if (addNew)
  377. ret=createPTree("Link");
  378. ret->setProp("@name", name);
  379. ret->setProp("@tooltip", tooltip);
  380. ret->setProp("@path", path);
  381. ret->setProp("@menu", menuname);
  382. ret->setProp("@navPath", navPath);
  383. ret->setPropInt("@relPosition", relPosition);
  384. ret->setPropBool("@force", force);
  385. if (addNew)
  386. folder.addPropTree("Link", ret);
  387. return ret;
  388. }
  389. IPropertyTree *CEspBinding::addNavException(IPropertyTree &folder, const char *message/*=NULL*/, int code/*=0*/, const char *source/*=NULL*/)
  390. {
  391. IPropertyTree *ret = folder.addPropTree("Exception", createPTree());
  392. ret->addProp("@message", message ? message : "Unknown exception");
  393. ret->setPropInt("@code", code);
  394. ret->setProp("@source", source);
  395. return ret;
  396. }
  397. void CEspBinding::getNavigationData(IEspContext &context, IPropertyTree & data)
  398. {
  399. IEspWsdlSections *wsdl = dynamic_cast<IEspWsdlSections *>(this);
  400. if (wsdl)
  401. {
  402. StringBuffer serviceName, params;
  403. wsdl->getServiceName(serviceName);
  404. if (!getUrlParams(context.queryRequestParameters(), params))
  405. {
  406. if (context.getClientVersion()>0)
  407. params.appendf("%cver_=%g", params.length()?'&':'?', context.getClientVersion());
  408. }
  409. IPropertyTree *folder=createPTree("Folder");
  410. folder->addProp("@name", serviceName.str());
  411. folder->addProp("@info", serviceName.str());
  412. StringBuffer encodedparams;
  413. if (params.length())
  414. encodeUtf8XML(params.str(), encodedparams, 0);
  415. folder->addProp("@urlParams", encodedparams);
  416. if (showSchemaLinks())
  417. folder->addProp("@showSchemaLinks", "true");
  418. if (params.length())
  419. params.setCharAt(0,'&'); //the entire params string will follow the initial param: "?form"
  420. MethodInfoArray methods;
  421. wsdl->getQualifiedNames(context, methods);
  422. ForEachItemIn(idx, methods)
  423. {
  424. CMethodInfo &method = methods.item(idx);
  425. IPropertyTree *link=createPTree("Link");
  426. link->addProp("@name", method.m_label.str());
  427. link->addProp("@info", method.m_label.str());
  428. StringBuffer path;
  429. path.appendf("../%s/%s?form%s", serviceName.str(), method.m_label.str(),params.str());
  430. link->addProp("@path", path.str());
  431. folder->addPropTree("Link", link);
  432. }
  433. data.addPropTree("Folder", folder);
  434. }
  435. }
  436. void CEspBinding::getDynNavData(IEspContext &context, IProperties *params, IPropertyTree & data)
  437. {
  438. }
  439. #ifdef _USE_OPENLDAP
  440. void CEspApplicationPort::onUpdatePasswordInput(IEspContext &context, StringBuffer& html)
  441. {
  442. StringBuffer xml;
  443. if (context.queryUserId())
  444. xml.appendf("<UpdatePassword><username>%s</username><Code>-1</Code></UpdatePassword>", context.queryUserId());
  445. else
  446. xml.appendf("<UpdatePassword><Code>2</Code><Massage>Can't find user in esp context. Please check if the user was properly logged in.</Massage></UpdatePassword>");
  447. Owned<IXslTransform> xform = xslp->createXslTransform();
  448. xform->loadXslFromFile(StringBuffer(getCFD()).append("./xslt/passwordupdate.xsl").str());
  449. xform->setXmlSource(xml.str(), xml.length()+1);
  450. xform->transform( html);
  451. return;
  452. }
  453. void CEspApplicationPort::onUpdatePassword(IEspContext &context, IHttpMessage* request, StringBuffer& html)
  454. {
  455. StringBuffer xml, message;
  456. unsigned returnCode = updatePassword(context, request, message);
  457. if (context.queryUserId())
  458. xml.appendf("<UpdatePassword><username>%s</username>", context.queryUserId());
  459. else
  460. xml.appendf("<UpdatePassword><username/>");
  461. xml.appendf("<Code>%d</Code><Message>%s</Message></UpdatePassword>", returnCode, message.str());
  462. Owned<IXslTransform> xform = xslp->createXslTransform();
  463. xform->loadXslFromFile(StringBuffer(getCFD()).append("./xslt/passwordupdate.xsl").str());
  464. xform->setXmlSource(xml.str(), xml.length()+1);
  465. xform->transform( html);
  466. return;
  467. }
  468. unsigned CEspApplicationPort::updatePassword(IEspContext &context, IHttpMessage* request, StringBuffer& message)
  469. {
  470. ISecManager* secmgr = context.querySecManager();
  471. if(!secmgr)
  472. {
  473. message.append("Security manager is not found. Please check if the system authentication is set up correctly.");
  474. return 2;
  475. }
  476. ISecUser* user = context.queryUser();
  477. if(!user)
  478. {
  479. message.append("Can't find user in esp context. Please check if the user was properly logged in.");
  480. return 2;
  481. }
  482. const char* oldpass1 = context.queryPassword();
  483. if (!oldpass1)
  484. {
  485. message.append("Existing password missing from request.");
  486. return 2;
  487. }
  488. CHttpRequest *httpRequest=dynamic_cast<CHttpRequest*>(request);
  489. IProperties *params = httpRequest->getParameters();
  490. if (!params)
  491. {
  492. message.append("No parameter is received. Please check user input.");
  493. return 1;
  494. }
  495. const char* username = params->queryProp("username");
  496. const char* oldpass = params->queryProp("oldpass");
  497. const char* newpass1 = params->queryProp("newpass1");
  498. const char* newpass2 = params->queryProp("newpass2");
  499. if(!username || !streq(username, user->getName()))
  500. {
  501. message.append("Incorrect username has been received.");
  502. return 1;
  503. }
  504. if(!oldpass || !streq(oldpass, oldpass1))
  505. {
  506. message.append("Old password doesn't match credentials in use.");
  507. return 1;
  508. }
  509. if(!streq(newpass1, newpass2))
  510. {
  511. message.append("Password re-entry doesn't match.");
  512. return 1;
  513. }
  514. if(streq(oldpass, newpass1))
  515. {
  516. message.append("New password can't be the same as current password.");
  517. return 1;
  518. }
  519. bool returnFlag = false;
  520. try
  521. {
  522. returnFlag = secmgr->updateUserPassword(*user, newpass1, oldpass);//provide the entered current password, not the cached one
  523. }
  524. catch(IException* e)
  525. {
  526. StringBuffer emsg;
  527. e->errorMessage(emsg);
  528. message.append(emsg.str());
  529. return 2;
  530. }
  531. if(!returnFlag)
  532. {
  533. message.append("Failed in changing password.");
  534. return 2;
  535. }
  536. message.append("Your password has been changed successfully.");
  537. return 0;
  538. }
  539. #endif
  540. CEspProtocol::CEspProtocol()
  541. {
  542. m_viewConfig=false;
  543. m_MaxRequestEntityLength = DEFAULT_MAX_REQUEST_ENTITY_LENGTH;
  544. }
  545. CEspProtocol::~CEspProtocol()
  546. {
  547. clear();
  548. }
  549. bool CEspProtocol::notifySelected(ISocket *sock,unsigned selected)
  550. {
  551. return true;
  552. }
  553. const char * CEspProtocol::getProtocolName()
  554. {
  555. return "ESP Protocol";
  556. }
  557. void CEspProtocol::addBindingMap(ISocket *sock, IEspRpcBinding* binding, bool isdefault)
  558. {
  559. CEspBindingEntry *entry = new CEspBindingEntry(sock, binding);
  560. char name[256];
  561. int port = sock->name(name, 255);
  562. CApplicationPortMap::iterator apport_it = m_portmap.find(port);
  563. CEspApplicationPort *apport=NULL;
  564. if (apport_it!=m_portmap.end())
  565. {
  566. apport = (*apport_it).second;
  567. apport->appendBinding(entry, isdefault);
  568. }
  569. else
  570. {
  571. apport = new CEspApplicationPort(m_viewConfig);
  572. apport->appendBinding(entry, isdefault);
  573. CApplicationPortMap::value_type vt(port, apport);
  574. m_portmap.insert(vt);
  575. }
  576. }
  577. CEspApplicationPort* CEspProtocol::queryApplicationPort(int port)
  578. {
  579. CApplicationPortMap::iterator apport_it = m_portmap.find(port);
  580. return (apport_it != m_portmap.end()) ? (*apport_it).second : NULL;
  581. }