presence.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. /**
  13. * IM Presence plug-in
  14. */
  15. #include <stdio.h>
  16. #include <ctype.h>
  17. #include <string.h>
  18. #include "portable.h"
  19. #include "nspr.h"
  20. #include "slapi-plugin.h"
  21. #include "slapi-private.h"
  22. #include "vattr_spi.h"
  23. #include "plhash.h"
  24. #include "ldif.h"
  25. #include "http_client.h"
  26. #include <sys/stat.h>
  27. /*** from ldaplog.h ***/
  28. /* edited ldaplog.h for LDAPDebug()*/
  29. #ifndef _LDAPLOG_H
  30. #define _LDAPLOG_H
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. #ifdef __cplusplus
  35. }
  36. #endif
  37. #endif /* _LDAP_H */
  38. #define PRESENCE_PLUGIN_SUBSYSTEM "presence-plugin"
  39. #define PRESENCE_PLUGIN_VERSION 0x00050050
  40. /**
  41. * this may become unnecessary when we are able to get
  42. * the plug-in DN dynamically (pete?)
  43. */
  44. #define PRESENCE_DN "cn=Presence,cn=plugins,cn=config" /* temporary */
  45. #define PRESENCE_SUCCESS 0
  46. #define PRESENCE_FAILURE -1
  47. /**
  48. * Presence vendor specific config parameters
  49. */
  50. #define NS_IM_ID "nsIM-ID"
  51. #define NS_IM_URL_TEXT "nsIM-URLText"
  52. #define NS_IM_URL_GRAPHIC "nsIM-URLGraphic"
  53. #define NS_IM_ON_VALUE_MAP_TEXT "nsIM-OnValueMapText"
  54. #define NS_IM_OFF_VALUE_MAP_TEXT "nsIM-OffValueMapText"
  55. #define NS_IM_ON_VALUE_MAP_GRAPHIC "nsIM-OnValueMapGraphic"
  56. #define NS_IM_OFF_VALUE_MAP_GRAPHIC "nsIM-OffValueMapGraphic"
  57. #define NS_IM_DISABLED_VALUE_MAP_GRAPHIC "nsIM-disabledValueMapGraphic"
  58. #define NS_IM_REQUEST_METHOD "nsIM-RequestMethod"
  59. #define NS_IM_URL_TEXT_RETURN_TYPE "nsIM-URLTextReturnType"
  60. #define NS_IM_URL_GRAPHIC_RETURN_TYPE "nsIM-URLGraphicReturnType"
  61. #define NS_IM_STATUS_TEXT "nsIM-StatusText"
  62. #define NS_IM_STATUS_GRAPHIC "nsIM-StatusGraphic"
  63. #define PRESENCE_STRING 1
  64. #define PRESENCE_BINARY 2
  65. #define PRESENCE_TEXT_RETURN_TYPE "TEXT"
  66. #define PRESENCE_BINARY_RETURN_TYPE "BINARY"
  67. #define PRESENCE_REQUEST_METHOD_GET "GET"
  68. #define PRESENCE_REQUEST_METHOD_REDIRECT "REDIRECT"
  69. #define PRESENCE_RETURNED_ON_TEXT "ONLINE"
  70. #define PRESENCE_RETURNED_OFF_TEXT "OFFLINE"
  71. #define PRESENCE_RETURNED_ERROR_TEXT "ERROR"
  72. static Slapi_PluginDesc pdesc = { "IM Presence",
  73. VENDOR,
  74. DS_PACKAGE_VERSION,
  75. "presence plugin" };
  76. /**
  77. * struct used to pass the argument to PL_Enumerator Callback
  78. */
  79. struct _vattrtypes
  80. {
  81. Slapi_Entry *entry;
  82. vattr_type_list_context *context;
  83. };
  84. /**
  85. * This structure holds the mapping between the virtual attributes and
  86. * the IM IDs. This information is used to find out whether this plugin
  87. * should service the attributes it was asked to. Also, it stores the
  88. * syntax of the attribute. 1 is String and 2 is binary.
  89. */
  90. struct _vattrmap {
  91. char *imID;
  92. int syntax;
  93. };
  94. typedef struct _vattrmap _Vmap;
  95. /**
  96. * struct to store the config values for each presence vendor
  97. */
  98. struct _defs {
  99. char *textURL;
  100. char *graphicURL;
  101. char *onTextMap;
  102. char *offTextMap;
  103. Slapi_Attr *onGraphicMap;
  104. Slapi_Attr *offGraphicMap;
  105. Slapi_Attr *disabledGraphicMap;
  106. char *requestMethod;
  107. char *textReturnType;
  108. char *graphicReturnType;
  109. };
  110. typedef struct _defs _ConfigEntry;
  111. static vattr_sp_handle *_VattrHandle = NULL;
  112. static void *_PluginID = NULL;
  113. static char *_PluginDN = NULL;
  114. static PLHashTable *_IdVattrMapTable = NULL;
  115. static PLHashTable *_IdConfigMapTable = NULL;
  116. static void **_HttpAPI = NULL;
  117. /**
  118. *
  119. * Presence plug-in management functions
  120. *
  121. */
  122. int presence_init(Slapi_PBlock *pb);
  123. int presence_start(Slapi_PBlock *pb);
  124. int presence_close(Slapi_PBlock *pb);
  125. /**
  126. *
  127. * Vattr operation callbacks functions
  128. *
  129. */
  130. static int presence_vattr_get(vattr_sp_handle *handle, vattr_context *c, Slapi_Entry *e, char *type, Slapi_ValueSet** results,int *type_name_disposition, char** actual_type_name, int flags, int *free_flags, void *hint);
  131. static int presence_vattr_compare(vattr_sp_handle *handle, vattr_context *c, Slapi_Entry *e, char *type, Slapi_Value *test_this, int* result, int flags, void *hint);
  132. static int presence_vattr_types(vattr_sp_handle *handle,Slapi_Entry *e,vattr_type_list_context *type_context,int flags);
  133. /**
  134. *
  135. * Local operation functions
  136. *
  137. */
  138. static int loadPluginConfig(void);
  139. static int parseConfigEntry(Slapi_Entry *e);
  140. static int imIDExists(Slapi_Entry *e, char *type, char **value, _Vmap **map, _ConfigEntry **entry);
  141. static int makeHttpRequest(char *id, _Vmap *map, _ConfigEntry *info, char **buf, int *size);
  142. static char * replaceIdWithValue(char *str, char *id, char *value);
  143. static int setIMStatus(char *id, _Vmap *map, _ConfigEntry *info, char *returnedBUF, int size, Slapi_ValueSet **results);
  144. static int setTypes(PLHashEntry *he, PRIntn i, void *arg);
  145. static void deleteMapTables(void);
  146. static PRIntn destroyHashEntry(PLHashEntry *he, PRIntn index, void *arg);
  147. static void logGraphicAttributeValue( Slapi_Attr *attr, const char *attrname );
  148. static void toLowerCase(char* str);
  149. /**
  150. * utility function
  151. */
  152. void printMapTable(void);
  153. PRIntn printIdVattrMapTable(PLHashEntry *he, PRIntn i, void *arg);
  154. PRIntn printIdConfigMapTable(PLHashEntry *he, PRIntn i, void *arg);
  155. /**
  156. *
  157. * Get the presence plug-in version
  158. *
  159. */
  160. int presence_version(void)
  161. {
  162. return PRESENCE_PLUGIN_VERSION;
  163. }
  164. /**
  165. * Plugin identity mgmt
  166. */
  167. void setPluginID(void * pluginID)
  168. {
  169. _PluginID=pluginID;
  170. }
  171. void * getPluginID(void)
  172. {
  173. return _PluginID;
  174. }
  175. void setPluginDN(char *pluginDN)
  176. {
  177. _PluginDN = pluginDN;
  178. }
  179. char * getPluginDN(void)
  180. {
  181. return _PluginDN;
  182. }
  183. /*
  184. presence_init
  185. -------------
  186. adds our callbacks to the list
  187. */
  188. int presence_init( Slapi_PBlock *pb )
  189. {
  190. int status = PRESENCE_SUCCESS;
  191. char * plugin_identity=NULL;
  192. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM,"presence_init - BEGIN\n");
  193. /**
  194. * Store the plugin identity for later use.
  195. * Used for internal operations
  196. */
  197. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &plugin_identity);
  198. PR_ASSERT (plugin_identity);
  199. setPluginID(plugin_identity);
  200. if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  201. SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  202. slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN,
  203. (void *) presence_start ) != 0 ||
  204. slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN,
  205. (void *) presence_close ) != 0 ||
  206. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  207. (void *)&pdesc ) != 0 )
  208. {
  209. slapi_log_error(SLAPI_LOG_ERR, PRESENCE_PLUGIN_SUBSYSTEM,
  210. "presence_init - Failed to register plugin\n" );
  211. status = PRESENCE_FAILURE;
  212. }
  213. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "presence_init -- END\n");
  214. return status;
  215. }
  216. /*
  217. presence_start
  218. --------------
  219. This function registers the computed attribute evaluator
  220. and loads the configuration parameters in the local cache.
  221. It is called after presence_init.
  222. */
  223. int presence_start( Slapi_PBlock *pb )
  224. {
  225. char * plugindn = NULL;
  226. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "presence_start - BEGIN\n");
  227. if(slapi_apib_get_interface(HTTP_v1_0_GUID, &_HttpAPI))
  228. {
  229. /**
  230. * error cannot proceeed
  231. */
  232. return PRESENCE_FAILURE;
  233. }
  234. /**
  235. * register our vattr callbacks
  236. */
  237. if (slapi_vattrspi_register((vattr_sp_handle **)&_VattrHandle,
  238. presence_vattr_get,
  239. presence_vattr_compare,
  240. presence_vattr_types) != 0)
  241. {
  242. slapi_log_error(SLAPI_LOG_ERR, PRESENCE_PLUGIN_SUBSYSTEM,
  243. "presence_start - Cannot register as service provider\n" );
  244. return PRESENCE_FAILURE;
  245. }
  246. /**
  247. * Get the plug-in target dn from the system
  248. * and store it for future use. This should avoid
  249. * hardcoding of DN's in the code.
  250. */
  251. slapi_pblock_get(pb, SLAPI_TARGET_DN, &plugindn);
  252. if (plugindn == NULL || strlen(plugindn) == 0)
  253. {
  254. /**
  255. * This is not required as the above statement
  256. * should work and give you a valid DN for this
  257. * plugin. ??? remove it later
  258. */
  259. plugindn = PRESENCE_DN;
  260. }
  261. setPluginDN(plugindn);
  262. /**
  263. * Load the config info for our plug-in in memory
  264. * In the 6.0 release this information will be stored
  265. * statically and if any change is done to this info a server
  266. * restart is necessary :-(. Probably if time permits then
  267. * state change plug-in would be used to notify the state
  268. * change. We also register the virtual attributes we are
  269. * interested in here.
  270. */
  271. if (loadPluginConfig() != PRESENCE_SUCCESS)
  272. {
  273. slapi_log_error(SLAPI_LOG_ERR, PRESENCE_PLUGIN_SUBSYSTEM,
  274. "presence_start - Unable to load plug-in configuration\n" );
  275. return PRESENCE_FAILURE;
  276. }
  277. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "presence_start - Ready for service\n");
  278. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "presence_start - END\n");
  279. return PRESENCE_SUCCESS;
  280. }
  281. /*
  282. presence_close
  283. --------------
  284. closes down the cache
  285. */
  286. int presence_close( Slapi_PBlock *pb )
  287. {
  288. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "--> presence_close\n");
  289. deleteMapTables();
  290. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "<-- presence_close\n");
  291. return PRESENCE_SUCCESS;
  292. }
  293. static int presence_vattr_get(vattr_sp_handle *handle,
  294. vattr_context *c,
  295. Slapi_Entry *e,
  296. char *type,
  297. Slapi_ValueSet** results,
  298. int *type_name_disposition,
  299. char** actual_type_name,
  300. int flags,
  301. int *free_flags,
  302. void *hint)
  303. {
  304. int status = PRESENCE_SUCCESS;
  305. char *id = NULL;
  306. char *returnedBUF = NULL;
  307. int size = 0;
  308. _Vmap *map = NULL;
  309. _ConfigEntry *info = NULL;
  310. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "--> presence_vattr_get \n");
  311. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "presence_vattr_get - Type=[%s] \n",type);
  312. if (imIDExists(e, type, &id, &map, &info) != PRESENCE_SUCCESS)
  313. {
  314. /**
  315. * we didn't find any valid matching nsimid in this
  316. * entry so since we cannot process a request without
  317. * a valid nsimid we just return.
  318. */
  319. status = PRESENCE_FAILURE;
  320. goto cleanup;
  321. }
  322. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "presence_vattr_get - ID=[%s] \n",id);
  323. /**
  324. * Now since we got a valid id we do a quick schema check
  325. * if schema checking is on to make sure that there is no
  326. * schema violation ?
  327. */
  328. /* do_schema_check() */
  329. /**
  330. * At this stage we have a valid attribute and we have to
  331. * get its value from the IM Server. so make an Http request
  332. * depending on whether it is a request for Text or Graphic
  333. */
  334. status = makeHttpRequest(id, map, info, &returnedBUF, &size);
  335. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "presence_vattr_get - size=[%d] \n",size);
  336. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "presence_vattr_get - buffer=[%s]\n",(returnedBUF) ? returnedBUF : "NULL");
  337. if(status == PRESENCE_SUCCESS)
  338. {
  339. status = setIMStatus(id, map, info, returnedBUF, size, results);
  340. }
  341. else
  342. {
  343. /**
  344. * Report all HTTP failures as a single predefined value of the
  345. * attribute
  346. */
  347. Slapi_Value *value =
  348. slapi_value_new_string(PRESENCE_RETURNED_ERROR_TEXT);
  349. if (!*results) {
  350. *results = slapi_valueset_new();
  351. }
  352. slapi_valueset_add_value(*results, value);
  353. slapi_value_free(&value); /* slapi_valueset_add_value copies value */
  354. /**
  355. * It's a success only in the sense that we are returning a value
  356. */
  357. status = PRESENCE_SUCCESS;
  358. }
  359. if(status == PRESENCE_SUCCESS)
  360. {
  361. *free_flags = SLAPI_VIRTUALATTRS_RETURNED_COPIES;
  362. *actual_type_name = slapi_ch_strdup(type);
  363. *type_name_disposition = SLAPI_VIRTUALATTRS_TYPE_NAME_MATCHED_EXACTLY_OR_ALIAS;
  364. }
  365. cleanup:
  366. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "presence_vattr_get - Processed ID=[%s] \n",id);
  367. if (id != NULL ) {
  368. slapi_ch_free((void **)&id);
  369. }
  370. if (returnedBUF != NULL ) {
  371. PR_Free(returnedBUF);
  372. }
  373. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "<-- presence_vattr_get \n");
  374. return status;
  375. }
  376. static int presence_vattr_compare(vattr_sp_handle *handle, vattr_context *c, Slapi_Entry *e, char *type, Slapi_Value *test_this, int* result, int flags, void *hint)
  377. {
  378. int status = PRESENCE_SUCCESS;
  379. /**
  380. * not yet implemented ???
  381. */
  382. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "--> presence_vattr_compare - does nothing \n");
  383. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "<-- presence_vattr_compare \n");
  384. return status;
  385. }
  386. static int presence_vattr_types(vattr_sp_handle *handle,Slapi_Entry *e,vattr_type_list_context *type_context,int flags)
  387. {
  388. int status = PRESENCE_SUCCESS;
  389. struct _vattrtypes args;
  390. args.entry = e;
  391. args.context = type_context;
  392. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "--> presence_vattr_types\n");
  393. PL_HashTableEnumerateEntries(_IdVattrMapTable, setTypes, &args);
  394. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "<-- presence_vattr_types\n");
  395. return status;
  396. }
  397. static int loadPluginConfig(void)
  398. {
  399. int status = PRESENCE_SUCCESS;
  400. int result;
  401. int i;
  402. Slapi_PBlock *search_pb;
  403. Slapi_Entry **entries = NULL;
  404. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "--> loadPluginConfig\n");
  405. search_pb = slapi_pblock_new();
  406. slapi_search_internal_set_pb(search_pb, PRESENCE_DN, LDAP_SCOPE_ONELEVEL,
  407. "objectclass=*", NULL, 0, NULL, NULL, getPluginID(), 0);
  408. slapi_search_internal_pb(search_pb);
  409. slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
  410. if (status != PRESENCE_SUCCESS)
  411. {
  412. slapi_log_error(SLAPI_LOG_ERR, PRESENCE_PLUGIN_SUBSYSTEM,
  413. "loadPluginConfig - Error getting level1 presence configurations<%s>\n", getPluginDN());
  414. status = PRESENCE_FAILURE;
  415. goto cleanup;
  416. }
  417. slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
  418. if (NULL == entries || entries[0] == NULL)
  419. {
  420. slapi_log_error(SLAPI_LOG_ERR, PRESENCE_PLUGIN_SUBSYSTEM,
  421. "loadPluginConfig - No entries found for <%s>\n", getPluginDN());
  422. status = PRESENCE_FAILURE;
  423. goto cleanup;
  424. }
  425. _IdVattrMapTable = PL_NewHashTable( 0,
  426. PL_HashString,
  427. PL_CompareStrings,
  428. PL_CompareValues,
  429. NULL,
  430. NULL
  431. );
  432. _IdConfigMapTable = PL_NewHashTable(0,
  433. PL_HashString,
  434. PL_CompareStrings,
  435. PL_CompareValues,
  436. NULL,
  437. NULL
  438. );
  439. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "--> parseConfigEntry \n");
  440. for (i = 0; (entries[i] != NULL); i++)
  441. {
  442. status = parseConfigEntry(entries[i]);
  443. if (status != PRESENCE_SUCCESS)
  444. {
  445. deleteMapTables();
  446. goto cleanup;
  447. }
  448. }
  449. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "<-- parseConfigEntry \n");
  450. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "<-- loadPluginConfig\n");
  451. cleanup:
  452. slapi_free_search_results_internal(search_pb);
  453. slapi_pblock_destroy(search_pb);
  454. return status;
  455. }
  456. static int parseConfigEntry(Slapi_Entry *e)
  457. {
  458. char *key = NULL;
  459. char *value = NULL;
  460. _ConfigEntry *entry = NULL;
  461. _Vmap *map = NULL;
  462. Slapi_Attr *attr = NULL;
  463. key = slapi_entry_attr_get_charptr(e, NS_IM_ID);
  464. if (!key) {
  465. /**
  466. * IM Id not defined in the config, unfortunately
  467. * cannot do anything without it so better not to
  468. * load the plug-in.
  469. */
  470. return PRESENCE_FAILURE;
  471. }
  472. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "parseConfigEntry - key [%s] \n",key);
  473. /**
  474. * Now create the config entry which will hold all the
  475. * attributes of a presence vendor
  476. */
  477. entry = (_ConfigEntry*) slapi_ch_calloc(1, sizeof(_ConfigEntry));
  478. /**
  479. * Next 2 are the virtual attributes for which this plug-in
  480. * is responsible. Register them with the vattr system so
  481. * that the system can call us whenever their
  482. * values are requested. Also update these entries in the
  483. * map table for later access.
  484. */
  485. value = slapi_entry_attr_get_charptr(e, NS_IM_STATUS_TEXT);
  486. if (value) {
  487. slapi_vattrspi_regattr(_VattrHandle, value, "", NULL);
  488. map = (_Vmap*) slapi_ch_calloc(1, sizeof(_Vmap));
  489. map->imID = key;
  490. map->syntax = PRESENCE_STRING;
  491. toLowerCase(value);
  492. PL_HashTableAdd(_IdVattrMapTable, value, map);
  493. }
  494. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "parseConfigEntry - nsIMStatusText [%s] \n",value);
  495. value = slapi_entry_attr_get_charptr(e, NS_IM_STATUS_GRAPHIC);
  496. if (value) {
  497. slapi_vattrspi_regattr(_VattrHandle, value, "", NULL);
  498. map = (_Vmap*) slapi_ch_calloc(1, sizeof(_Vmap));
  499. map->imID = key;
  500. map->syntax = PRESENCE_BINARY;
  501. toLowerCase(value);
  502. PL_HashTableAdd(_IdVattrMapTable, value, map);
  503. }
  504. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "parseConfigEntry - nsIMStatusGraphic [%s] \n",value);
  505. value = slapi_entry_attr_get_charptr(e, NS_IM_URL_TEXT);
  506. if (value) {
  507. entry->textURL = value;
  508. }
  509. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "parseConfigEntry - nsIMURLText [%s] \n",value);
  510. value = slapi_entry_attr_get_charptr(e, NS_IM_URL_GRAPHIC);
  511. if (value) {
  512. entry->graphicURL = value;
  513. }
  514. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "parseConfigEntry - nsIMStatusGraphic [%s] \n",value);
  515. value = slapi_entry_attr_get_charptr(e, NS_IM_ON_VALUE_MAP_TEXT);
  516. if (value) {
  517. entry->onTextMap = value;
  518. }
  519. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "parseConfigEntry - nsIMOnValueMapText [%s] \n",value);
  520. value = slapi_entry_attr_get_charptr(e, NS_IM_OFF_VALUE_MAP_TEXT);
  521. if (value) {
  522. entry->offTextMap = value;
  523. }
  524. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "parseConfigEntry - nsIMOffValueMapText [%s] \n",value);
  525. /**
  526. * Next 3 are binary syntax types so needs special handling
  527. */
  528. slapi_entry_attr_find(e, NS_IM_ON_VALUE_MAP_GRAPHIC, &attr);
  529. if (attr) {
  530. entry->onGraphicMap = slapi_attr_dup(attr);
  531. logGraphicAttributeValue(attr,NS_IM_ON_VALUE_MAP_GRAPHIC);
  532. }
  533. slapi_entry_attr_find(e, NS_IM_OFF_VALUE_MAP_GRAPHIC, &attr);
  534. if (attr) {
  535. entry->offGraphicMap = slapi_attr_dup(attr);
  536. logGraphicAttributeValue(attr,NS_IM_OFF_VALUE_MAP_GRAPHIC);
  537. }
  538. slapi_entry_attr_find(e, NS_IM_DISABLED_VALUE_MAP_GRAPHIC, &attr);
  539. if (attr) {
  540. entry->disabledGraphicMap = slapi_attr_dup(attr);
  541. logGraphicAttributeValue(attr,NS_IM_DISABLED_VALUE_MAP_GRAPHIC);
  542. }
  543. value = slapi_entry_attr_get_charptr(e, NS_IM_REQUEST_METHOD);
  544. if (value) {
  545. entry->requestMethod = value;
  546. }
  547. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "parseConfigEntry - nsIMRequestMethod [%s] \n",value);
  548. value = slapi_entry_attr_get_charptr(e, NS_IM_URL_TEXT_RETURN_TYPE);
  549. if (value) {
  550. entry->textReturnType = value;
  551. }
  552. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "parseConfigEntry - nsIMURLTextReturnType [%s] \n",value);
  553. value = slapi_entry_attr_get_charptr(e, NS_IM_URL_GRAPHIC_RETURN_TYPE);
  554. if (value) {
  555. entry->graphicReturnType = value;
  556. }
  557. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "parseConfigEntry - nsIMURLGraphicReturnType [%s] \n",value);
  558. /**
  559. * Finally add the entry to the map table
  560. */
  561. PL_HashTableAdd(_IdConfigMapTable, key, entry);
  562. return PRESENCE_SUCCESS;
  563. }
  564. /**
  565. * this function goes thru the valid stored ids
  566. * and return the correct one for which we have to
  567. * do further processing
  568. */
  569. static int imIDExists(Slapi_Entry *e, char *type, char **value, _Vmap **map, _ConfigEntry **entry)
  570. {
  571. int status = PRESENCE_SUCCESS;
  572. char *tValue = NULL;
  573. _ConfigEntry *tEntry = NULL;
  574. _Vmap *tMap = NULL;
  575. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "--> imIDExists \n",0,0,0);
  576. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "imIDExists - Type [%s] \n",type,0,0);
  577. /**
  578. * The public function PL_HashTableLookup modifies the
  579. * the table while reading. so using this private function
  580. * which just does a lookup and doesn't modifies the
  581. * hashtable
  582. */
  583. toLowerCase(type);
  584. tMap = PL_HashTableLookupConst(_IdVattrMapTable, type);
  585. if (!tMap)
  586. {
  587. /**
  588. * this should not happen but no harm we just return
  589. */
  590. status = PRESENCE_FAILURE;
  591. slapi_log_error(SLAPI_LOG_ERR, PRESENCE_PLUGIN_SUBSYSTEM,
  592. "imIDExists - No hashtable for vattr types\n");
  593. goto bail;
  594. }
  595. /**
  596. * We found a matching id in the map table
  597. * now see if that id exists in the Slapi_Entry
  598. */
  599. tValue = slapi_entry_attr_get_charptr(e, tMap->imID);
  600. if (!tValue)
  601. {
  602. /**
  603. * we don't do anything here but just return
  604. */
  605. status = PRESENCE_FAILURE;
  606. goto bail;
  607. }
  608. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "-imIDExists - Value [%s] \n",tValue,0,0);
  609. tEntry = PL_HashTableLookupConst(_IdConfigMapTable, tMap->imID);
  610. *value = tValue;
  611. *entry = tEntry;
  612. *map = tMap;
  613. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "<-- imIDExists \n");
  614. bail:
  615. return status;
  616. }
  617. static int makeHttpRequest(char *id, _Vmap *map, _ConfigEntry *info, char **BUF, int *size)
  618. {
  619. int status = PRESENCE_SUCCESS;
  620. char *buf = NULL;
  621. char *url = NULL;
  622. char *urltosend = NULL;
  623. int bytesRead;
  624. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "--> makeHttpRequest\n");
  625. if (map->syntax == PRESENCE_STRING) {
  626. url = info->textURL;
  627. } else {
  628. url = info->graphicURL;
  629. }
  630. if (url == NULL) {
  631. status = PRESENCE_FAILURE;
  632. goto bail;
  633. }
  634. urltosend = replaceIdWithValue(url, map->imID, id);
  635. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "makeHttpRequest - URL [%s] \n",urltosend);
  636. /**
  637. * make an actual HTTP call now
  638. */
  639. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "makeHttpRequest - RequestMethod [%s] \n", info->requestMethod);
  640. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "makeHttpRequest - Syntax [%d] \n", map->syntax);
  641. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "makeHttpRequest - TextReturnType [%s] \n", info->textReturnType);
  642. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "makeHttpRequest - GraphicReturnType [%s] \n", info->graphicReturnType);
  643. if (!strcasecmp(info->requestMethod, PRESENCE_REQUEST_METHOD_GET)) {
  644. if (map->syntax == PRESENCE_STRING) {
  645. if (!strcasecmp(info->textReturnType, PRESENCE_TEXT_RETURN_TYPE)) {
  646. status = http_get_text(_HttpAPI, urltosend, &buf, &bytesRead);
  647. } else {
  648. status = http_get_binary(_HttpAPI, urltosend, &buf, &bytesRead);
  649. }
  650. } else {
  651. if (!strcasecmp(info->graphicReturnType, PRESENCE_TEXT_RETURN_TYPE)) {
  652. status = http_get_text(_HttpAPI, urltosend, &buf, &bytesRead);
  653. } else {
  654. status = http_get_binary(_HttpAPI, urltosend, &buf, &bytesRead);
  655. }
  656. }
  657. } else if (!strcasecmp(info->requestMethod, PRESENCE_REQUEST_METHOD_REDIRECT)) {
  658. status = http_get_redirected_uri(_HttpAPI, urltosend, &buf, &bytesRead);
  659. } else {
  660. /**
  661. * error : unknown method
  662. * probably we should check at the time of loading
  663. * of the plugin itself that the config values are
  664. * properly checked and throw warning/errors in case
  665. * of any invalid entry
  666. */
  667. slapi_log_error(SLAPI_LOG_ERR, PRESENCE_PLUGIN_SUBSYSTEM,
  668. "makeHttpRequest - Unknown request type <%s>\n", info->requestMethod);
  669. status = PRESENCE_FAILURE;
  670. goto bail;
  671. }
  672. if (buf && status == PRESENCE_SUCCESS)
  673. {
  674. *BUF = buf;
  675. *size = bytesRead;
  676. }
  677. bail:
  678. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "<-- makeHttpRequest:: <%d>\n",status,0,0);
  679. slapi_ch_free((void**)&urltosend);
  680. return status;
  681. }
  682. /**
  683. * This function replaces the occurrence of $ns[<vendor>]imid with its
  684. * actual value
  685. * e.g.
  686. * URL : http://opi.yahoo.com/online?u=$nsyimid
  687. * after replacing
  688. * newURL : http://opi.yahoo.com/online?u=srajam
  689. */
  690. static char * replaceIdWithValue(char *str, char *id, char *value)
  691. {
  692. int i=0;
  693. int k=0;
  694. char *newstr = NULL;
  695. char c;
  696. if (!str || !id || !value)
  697. {
  698. return NULL;
  699. }
  700. /* extra space for userids */
  701. newstr = (char *)slapi_ch_malloc(strlen(str) + strlen(value));
  702. while ((c=str[i]) != '\0')
  703. {
  704. if (c == '$')
  705. {
  706. int j = 0;
  707. i++; /*skip one char */
  708. /**
  709. * we found the begining of the string to be
  710. * substituted. Now skip the chars we want to replace
  711. */
  712. while (str[i] != '\0' && id[j] != '\0' &&
  713. (toupper(str[i]) == toupper(id[j])))
  714. {
  715. i++;
  716. j++;
  717. }
  718. j=0;
  719. while (value[j] != '\0')
  720. {
  721. newstr[k++] = value[j++];
  722. }
  723. }
  724. else
  725. {
  726. newstr[k++]=c;
  727. i++;
  728. }
  729. }
  730. newstr[k] = '\0';
  731. return newstr;
  732. }
  733. static int setIMStatus(char *id, _Vmap *map, _ConfigEntry *info,
  734. char *returnedBUF, int size, Slapi_ValueSet **results)
  735. {
  736. int status = PRESENCE_SUCCESS;
  737. char *ontxtmap = NULL;
  738. char *offtxtmap = NULL;
  739. Slapi_Value *value = NULL;
  740. Slapi_Value *value1 = NULL;
  741. Slapi_Value *value2 = NULL;
  742. struct berval bval;
  743. Slapi_Attr *attr = NULL;
  744. const struct berval *tmp = NULL;
  745. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "--> setIMStatus \n");
  746. /**
  747. * we got some data back so lets try to map it to
  748. * the existing set of on/off data
  749. *
  750. * first we need to take a look at the
  751. * returned type and depending upon that parse
  752. * the data
  753. */
  754. if (map->syntax == PRESENCE_STRING) {
  755. /**
  756. * we had send a request for text
  757. * but chances are we might end up
  758. * getting an image back. So we need
  759. * to compare it to existing set of
  760. * images that we have in store ???
  761. */
  762. if (!strcasecmp(info->textReturnType, PRESENCE_TEXT_RETURN_TYPE)) {
  763. /* return value is in text format */
  764. ontxtmap = replaceIdWithValue(info->onTextMap, map->imID, id);
  765. offtxtmap = replaceIdWithValue(info->offTextMap, map->imID, id);
  766. if (!strcasecmp(ontxtmap, returnedBUF)) {
  767. /**
  768. * set the on value
  769. */
  770. value = slapi_value_new_string(PRESENCE_RETURNED_ON_TEXT);
  771. } else if (!strcasecmp(offtxtmap, returnedBUF)) {
  772. /**
  773. * set the off value
  774. */
  775. value = slapi_value_new_string(PRESENCE_RETURNED_OFF_TEXT);
  776. } else {
  777. value = slapi_value_new_string(PRESENCE_RETURNED_ERROR_TEXT);
  778. }
  779. } else if (!strcasecmp(info->textReturnType, PRESENCE_BINARY_RETURN_TYPE)) {
  780. /**
  781. * call binary compare method
  782. */
  783. bval.bv_len = size;
  784. bval.bv_val = returnedBUF;
  785. value1 = slapi_value_new_berval(&bval);
  786. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "setIMStatus - returned size [%d] \n", bval.bv_len);
  787. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "setIMStatus - returned value [%s] \n", bval.bv_val);
  788. attr = info->onGraphicMap;
  789. if (attr) {
  790. slapi_attr_first_value(attr, &value2);
  791. tmp = slapi_value_get_berval(value2);
  792. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "setIMStatus - Stored size [%d] \n", tmp->bv_len);
  793. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "setIMStatus - Stored value [%s] \n", tmp->bv_val);
  794. if (!slapi_value_compare(attr, value1, value2)) {
  795. value = slapi_value_new_string(PRESENCE_RETURNED_ON_TEXT);
  796. }
  797. }
  798. if (!value) {
  799. attr = info->offGraphicMap;
  800. if (attr) {
  801. slapi_attr_first_value(attr, &value2);
  802. if (!slapi_value_compare(attr, value1, value2)) {
  803. value = slapi_value_new_string(PRESENCE_RETURNED_OFF_TEXT);
  804. }
  805. }
  806. }
  807. if (!value) {
  808. attr = info->disabledGraphicMap;
  809. if (attr) {
  810. slapi_attr_first_value(attr, &value2);
  811. if (!slapi_value_compare(attr, value1, value2)) {
  812. value = slapi_value_new_string(PRESENCE_RETURNED_OFF_TEXT);
  813. }
  814. }
  815. }
  816. if (!value) {
  817. /* some error */
  818. value = slapi_value_new_string(PRESENCE_RETURNED_ERROR_TEXT);
  819. }
  820. } else {
  821. /**
  822. * set the error condition
  823. */
  824. value = slapi_value_new_string(PRESENCE_RETURNED_ERROR_TEXT);
  825. }
  826. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "setIMStatus - value [%s] \n", returnedBUF);
  827. } else {
  828. /**
  829. * we had send a request for image
  830. * so whatever we get back we just
  831. * return instead of analyzing it
  832. */
  833. if (!strcasecmp(info->graphicReturnType, PRESENCE_TEXT_RETURN_TYPE)) {
  834. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "setIMStatus - value [%s] \n", returnedBUF);
  835. if (!strcasecmp(info->requestMethod, PRESENCE_REQUEST_METHOD_REDIRECT)) {
  836. /**
  837. * a redirect case in which we should probably have a
  838. * gif in store so return that value
  839. *
  840. * for now
  841. */
  842. ontxtmap = replaceIdWithValue(info->onTextMap, map->imID, id);
  843. offtxtmap = replaceIdWithValue(info->offTextMap, map->imID, id);
  844. if (!strcasecmp(ontxtmap, returnedBUF)) {
  845. /**
  846. * set the on value
  847. */
  848. attr = info->onGraphicMap;
  849. } else if (!strcasecmp(offtxtmap, returnedBUF)) {
  850. /**
  851. * set the off value
  852. */
  853. attr = info->offGraphicMap;
  854. } else {
  855. attr = info->disabledGraphicMap;
  856. }
  857. if (attr) {
  858. slapi_attr_first_value(attr, &value);
  859. }
  860. } else {
  861. /**
  862. * for now just set the returned value
  863. * should not happen in our case
  864. * ERROR
  865. */
  866. }
  867. } else {
  868. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "setIMStatus - value [%s] \n", returnedBUF);
  869. bval.bv_len = size;
  870. bval.bv_val = returnedBUF;
  871. value = slapi_value_new_berval(&bval);
  872. }
  873. }
  874. if (!*results) {
  875. *results = slapi_valueset_new();
  876. }
  877. slapi_valueset_add_value(*results, value);
  878. if (ontxtmap) {
  879. slapi_ch_free((void **)&ontxtmap);
  880. }
  881. if (offtxtmap) {
  882. slapi_ch_free((void **)&offtxtmap);
  883. }
  884. if (value && map->syntax == PRESENCE_STRING) {
  885. slapi_value_free(&value);
  886. }
  887. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "<-- setIMStatus \n");
  888. return status;
  889. }
  890. static int setTypes(PLHashEntry *he, PRIntn i, void *arg)
  891. {
  892. int status;
  893. int props = SLAPI_ATTR_FLAG_OPATTR;
  894. Slapi_ValueSet *results = NULL;
  895. int type_name_disposition = 0;
  896. char *actual_type_name = 0;
  897. int free_flags = 0;
  898. struct _vattrtypes *args = arg;
  899. char *type = (char *)he->key;
  900. _Vmap *map = (_Vmap *)he->value;
  901. char *id = map->imID;
  902. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "--> setTypes \n");
  903. status = slapi_vattr_values_get_sp(NULL, args->entry, id, &results, &type_name_disposition, &actual_type_name, 0, &free_flags);
  904. if(status == PRESENCE_SUCCESS)
  905. {
  906. /* entry contains this attr */
  907. vattr_type_thang thang = {0};
  908. thang.type_name = type;
  909. thang.type_flags = props;
  910. slapi_vattrspi_add_type(args->context,&thang,0);
  911. slapi_vattr_values_free(&results, &actual_type_name, free_flags);
  912. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "setTypes - ID [%s] Type[%s]\n", actual_type_name,type);
  913. }
  914. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "<-- setTypes \n");
  915. return HT_ENUMERATE_NEXT;
  916. }
  917. static void
  918. logGraphicAttributeValue( Slapi_Attr *attr, const char *attrname )
  919. {
  920. Slapi_Value *val = NULL;
  921. const struct berval *v = NULL;
  922. if ( LDAPDebugLevelIsSet( LDAP_DEBUG_PLUGIN )) {
  923. slapi_attr_first_value(attr, &val);
  924. v = slapi_value_get_berval(val);
  925. if (v) {
  926. char *ldifvalue;
  927. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "logGraphicAttributeValue - %s size [%d] \n",
  928. attrname,v->bv_len);
  929. ldifvalue = ldif_type_and_value_with_options(
  930. (char *)attrname, /* XXX: had to cast away const */
  931. v->bv_val, v->bv_len, 0 );
  932. if ( NULL != ldifvalue ) {
  933. slapi_log_error(SLAPI_LOG_PLUGIN, PRESENCE_PLUGIN_SUBSYSTEM, "logGraphicAttributeValue - %s value [\n%s]\n",
  934. attrname,ldifvalue);
  935. slapi_ch_free_string( &ldifvalue );
  936. }
  937. }
  938. }
  939. }
  940. static void deleteMapTables(void)
  941. {
  942. PL_HashTableEnumerateEntries(_IdConfigMapTable, destroyHashEntry, 0);
  943. if (_IdConfigMapTable)
  944. {
  945. PL_HashTableDestroy(_IdConfigMapTable);
  946. }
  947. PL_HashTableEnumerateEntries(_IdVattrMapTable, destroyHashEntry, 0);
  948. if (_IdVattrMapTable)
  949. {
  950. PL_HashTableDestroy(_IdVattrMapTable);
  951. }
  952. return;
  953. }
  954. static PRIntn destroyHashEntry(PLHashEntry *he, PRIntn index, void *arg)
  955. {
  956. void *value = NULL;
  957. if (he == NULL)
  958. {
  959. return HT_ENUMERATE_NEXT;
  960. }
  961. value = he->value;
  962. if (value)
  963. {
  964. slapi_ch_free(&value);
  965. }
  966. return HT_ENUMERATE_REMOVE;
  967. }
  968. static void toLowerCase(char* str)
  969. {
  970. if (str) {
  971. char* lstr = str;
  972. for(; (*lstr != '\0'); ++lstr) {
  973. *lstr = tolower(*lstr);
  974. }
  975. }
  976. }
  977. /**
  978. * utility function to print the array
  979. */
  980. void printMapTable(void)
  981. {
  982. PL_HashTableEnumerateEntries(_IdVattrMapTable, printIdVattrMapTable, 0);
  983. PL_HashTableEnumerateEntries(_IdConfigMapTable, printIdConfigMapTable, 0);
  984. }
  985. PRIntn printIdVattrMapTable(PLHashEntry *he, PRIntn i, void *arg)
  986. {
  987. char *key = (char *)he->key;
  988. _Vmap *map = (_Vmap *)he->value;
  989. printf("<---- Key -------> %s\n", key);
  990. printf("<---- ImId ------> %s\n", map->imID);
  991. printf("<---- syntax ----> %d\n", map->syntax);
  992. return HT_ENUMERATE_NEXT;
  993. }
  994. PRIntn printIdConfigMapTable(PLHashEntry *he, PRIntn i, void *arg)
  995. {
  996. char *key = (char *)he->key;
  997. _ConfigEntry *value = (_ConfigEntry *)he->value;
  998. printf("<- Key ---------------------> %s\n", key);
  999. printf("<---- text_url -------------> %s\n", value->textURL);
  1000. printf("<---- graphic_url ----------> %s\n", value->graphicURL);
  1001. printf("<---- on_text_map ----------> %s\n", value->onTextMap);
  1002. printf("<---- off_text_map ---------> %s\n", value->offTextMap);
  1003. printf("<---- request_method -------> %s\n", value->requestMethod);
  1004. printf("<---- text_return_type -----> %s\n", value->textReturnType);
  1005. printf("<---- graphic_return_type --> %s\n", value->graphicReturnType);
  1006. return HT_ENUMERATE_NEXT;
  1007. }