Changeset 607 for trunk/zoo-project/zoo-kernel/zoo_service_loader.c
- Timestamp:
- Mar 12, 2015, 3:14:52 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/zoo_service_loader.c
r605 r607 1 /* *1 /* 2 2 * Author : Gérald FENOY 3 3 * … … 120 120 #endif 121 121 122 /** 123 * Translation function for zoo-kernel 124 */ 122 125 #define _(String) dgettext ("zoo-kernel",String) 126 /** 127 * Translation function for zoo-service 128 */ 123 129 #define __(String) dgettext ("zoo-service",String) 124 130 … … 131 137 extern int getServiceFromFile (maps *, const char *, service **); 132 138 139 /** 140 * Parse the service file using getServiceFromFile or use getServiceFromYAML 141 * if YAML support was activated. 142 * 143 * @param conf the conf maps containing the main.cfg settings 144 * @param file the file name to parse 145 * @param service the service to update witht the file content 146 * @param name the service name 147 * @return true if the file can be parsed or false 148 * @see getServiceFromFile, getServiceFromYAML 149 */ 133 150 int 134 151 readServiceFile (maps * conf, char *file, service ** service, char *name) … … 144 161 } 145 162 163 /** 164 * Replace a char by another one in a string 165 * 166 * @param str the string to update 167 * @param toReplace the char to replace 168 * @param toReplaceBy the char that will be used 169 */ 146 170 void 147 171 translateChar (char *str, char toReplace, char toReplaceBy) … … 156 180 157 181 /** 158 * Create (or append to) an array valued maps 159 * value = "["",""]" 182 * Create (or append to) an array valued maps value = "["",""]" 183 * 184 * @param m the conf maps containing the main.cfg settings 185 * @param mo the map to update 186 * @param mi the map to append 187 * @param elem the elements containing default definitions 188 * @return 0 on success, -1 on failure 160 189 */ 161 190 int … … 237 266 } 238 267 268 /** 269 * Create the profile registry. 270 * 271 * The profile registry is optional (created only if the registry key is 272 * available in the [main] section of the main.cfg file) and can be used to 273 * store the profiles hierarchy. The registry is a directory which should 274 * contain the following sub-directories: 275 * * concept: direcotry containing .html files describing concept 276 * * generic: directory containing .zcfg files for wps:GenericProcess 277 * * implementation: directory containing .zcfg files for wps:Process 278 * 279 * @param m the conf maps containing the main.cfg settings 280 * @param r the registry to update 281 * @param reg_dir the resgitry 282 * @param saved_stdout the saved stdout identifier 283 * @return 0 if the resgitry is null or was correctly updated, -1 on failure 284 */ 239 285 int 240 recursReaddirF (maps * m, xmlNodePtr n, char *conf_dir, char *prefix, 286 createRegistry (maps* m,registry ** r, char *reg_dir, int saved_stdout) 287 { 288 struct dirent *dp; 289 int scount = 0; 290 291 if (reg_dir == NULL) 292 return 0; 293 DIR *dirp = opendir (reg_dir); 294 if (dirp == NULL) 295 { 296 return -1; 297 } 298 while ((dp = readdir (dirp)) != NULL){ 299 if ((dp->d_type == DT_DIR || dp->d_type == DT_LNK) && dp->d_name[0] != '.') 300 { 301 302 char * tmpName = 303 (char *) malloc ((strlen (reg_dir) + strlen (dp->d_name) + 2) * 304 sizeof (char)); 305 sprintf (tmpName, "%s/%s", reg_dir, dp->d_name); 306 307 DIR *dirp1 = opendir (tmpName); 308 struct dirent *dp1; 309 while ((dp1 = readdir (dirp1)) != NULL){ 310 char* extn = strstr(dp1->d_name, ".zcfg"); 311 if(dp1->d_name[0] != '.' && extn != NULL && strlen(extn) == 5) 312 { 313 int t; 314 char *tmps1= 315 (char *) malloc ((strlen (tmpName) + strlen (dp1->d_name) + 2) * 316 sizeof (char)); 317 sprintf (tmps1, "%s/%s", tmpName, dp1->d_name); 318 char *tmpsn = zStrdup (dp1->d_name); 319 tmpsn[strlen (tmpsn) - 5] = 0; 320 service* s1 = (service *) malloc (SERVICE_SIZE); 321 if (s1 == NULL) 322 { 323 dup2 (saved_stdout, fileno (stdout)); 324 errorException (m, _("Unable to allocate memory."), 325 "InternalError", NULL); 326 return -1; 327 } 328 t = readServiceFile (m, tmps1, &s1, tmpsn); 329 free (tmpsn); 330 if (t < 0) 331 { 332 map *tmp00 = getMapFromMaps (m, "lenv", "message"); 333 char tmp01[1024]; 334 if (tmp00 != NULL) 335 sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"), 336 dp1->d_name, tmp00->value); 337 else 338 sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), 339 dp1->d_name); 340 dup2 (saved_stdout, fileno (stdout)); 341 errorException (m, tmp01, "InternalError", NULL); 342 return -1; 343 } 344 #ifdef DEBUG 345 dumpService (s1); 346 fflush (stdout); 347 fflush (stderr); 348 #endif 349 if(strncasecmp(dp->d_name,"implementation",14)==0){ 350 inheritance(*r,&s1); 351 } 352 addServiceToRegistry(r,dp->d_name,s1); 353 freeService (&s1); 354 free (s1); 355 scount++; 356 } 357 } 358 (void) closedir (dirp1); 359 } 360 } 361 (void) closedir (dirp); 362 return 0; 363 } 364 365 /** 366 * Recursivelly parse zcfg starting from the ZOO-Kernel cwd. 367 * Call the func function given in arguments after parsing the ZCFG file. 368 * 369 * @param m the conf maps containing the main.cfg settings 370 * @param r the registry containing profiles hierarchy 371 * @param n the root XML Node to add the sub-elements 372 * @param conf_dir the location of the main.cfg file (basically cwd) 373 * @param prefix the current prefix if any, or NULL 374 * @param saved_stdout the saved stdout identifier 375 * @param level the current level (number of sub-directories to reach the 376 * current path) 377 * @see inheritance, readServiceFile 378 */ 379 int 380 recursReaddirF (maps * m, registry *r, xmlNodePtr n, char *conf_dir, char *prefix, 241 381 int saved_stdout, int level, void (func) (maps *, xmlNodePtr, 242 382 service *)) … … 287 427 setMapInMaps (m, "lenv", "level", levels1); 288 428 res = 289 recursReaddirF (m, n, tmp, prefix, saved_stdout, level + 1,429 recursReaddirF (m, r, n, tmp, prefix, saved_stdout, level + 1, 290 430 func); 291 431 sprintf (levels1, "%d", level); … … 346 486 fflush (stderr); 347 487 #endif 488 inheritance(r,&s1); 348 489 func (m, n, s1); 349 490 freeService (&s1); … … 356 497 } 357 498 499 /** 500 * Apply XPath Expression on XML document. 501 * 502 * @param doc the XML Document 503 * @param search the XPath expression 504 * @return xmlXPathObjectPtr containing the resulting nodes set 505 */ 358 506 xmlXPathObjectPtr 359 507 extractFromDoc (xmlDocPtr doc, const char *search) … … 367 515 } 368 516 517 /** 518 * Signal handling function which simply call exit(0). 519 * 520 * @param sig the signal number 521 */ 369 522 void 370 523 donothing (int sig) … … 376 529 } 377 530 531 /** 532 * Signal handling function which create an ExceptionReport node containing the 533 * information message corresponding to the signal number. 534 * 535 * @param sig the signal number 536 */ 378 537 void 379 538 sig_handler (int sig) … … 416 575 } 417 576 577 /** 578 * Load a service provider and run the service function. 579 * 580 * @param myMap the conf maps containing the main.cfg settings 581 * @param s1 the service structure 582 * @param request_inputs map storing all the request parameters 583 * @param inputs the inputs maps 584 * @param ioutputs the outputs maps 585 * @param eres the result returned by the service execution 586 */ 418 587 void 419 588 loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs, … … 876 1045 #endif 877 1046 1047 /** 1048 * Process the request. 1049 * 1050 * @param inputs the request parameters map 1051 * @return 0 on sucess, other value on failure 1052 * @see conf_read,recursReaddirF 1053 */ 878 1054 int 879 1055 runRequest (map ** inputs) … … 1113 1289 SERVICE_URL = zStrdup (DEFAULT_SERVICE_URL); 1114 1290 1291 1292 1115 1293 service *s1; 1116 1294 int scount = 0; … … 1129 1307 else 1130 1308 snprintf (conf_dir, 1024, "%s", ntmp); 1309 1310 map* reg = getMapFromMaps (m, "main", "registry"); 1311 registry* zooRegistry=NULL; 1312 if(reg!=NULL){ 1313 int saved_stdout = dup (fileno (stdout)); 1314 dup2 (fileno (stderr), fileno (stdout)); 1315 createRegistry (m,&zooRegistry,reg->value,saved_stdout); 1316 dup2 (saved_stdout, fileno (stdout)); 1317 } 1131 1318 1132 1319 if (strncasecmp (REQUEST, "GetCapabilities", 15) == 0) … … 1146 1333 dup2 (fileno (stderr), fileno (stdout)); 1147 1334 if (int res = 1148 recursReaddirF (m, n, conf_dir, NULL, saved_stdout, 0,1335 recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0, 1149 1336 printGetCapabilitiesForProcess) < 0) 1150 1337 { 1151 1338 freeMaps (&m); 1152 1339 free (m); 1340 if(zooRegistry!=NULL){ 1341 freeRegistry(&zooRegistry); 1342 free(zooRegistry); 1343 } 1153 1344 free (REQUEST); 1154 1345 free (SERVICE_URL); … … 1160 1351 freeMaps (&m); 1161 1352 free (m); 1353 if(zooRegistry!=NULL){ 1354 freeRegistry(&zooRegistry); 1355 free(zooRegistry); 1356 } 1162 1357 free (REQUEST); 1163 1358 free (SERVICE_URL); … … 1177 1372 freeMaps (&m); 1178 1373 free (m); 1374 if(zooRegistry!=NULL){ 1375 freeRegistry(&zooRegistry); 1376 free(zooRegistry); 1377 } 1179 1378 free (REQUEST); 1180 1379 free (SERVICE_URL); … … 1200 1399 { 1201 1400 if (int res = 1202 recursReaddirF (m, n, conf_dir, NULL, saved_stdout, 0,1401 recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0, 1203 1402 printDescribeProcessForProcess) < 0) 1204 1403 return res; … … 1245 1444 freeMaps (&m); 1246 1445 free (m); 1446 if(zooRegistry!=NULL){ 1447 freeRegistry(&zooRegistry); 1448 free(zooRegistry); 1449 } 1247 1450 free (REQUEST); 1248 1451 free (corig); … … 1259 1462 dumpService (s1); 1260 1463 #endif 1464 inheritance(zooRegistry,&s1); 1261 1465 printDescribeProcessForProcess (m, n, s1); 1262 1466 freeService (&s1); … … 1321 1525 freeMaps (&m); 1322 1526 free (m); 1527 if(zooRegistry!=NULL){ 1528 freeRegistry(&zooRegistry); 1529 free(zooRegistry); 1530 } 1323 1531 free (orig); 1324 1532 free (REQUEST); … … 1332 1540 dumpService (s1); 1333 1541 #endif 1542 inheritance(zooRegistry,&s1); 1334 1543 printDescribeProcessForProcess (m, n, s1); 1335 1544 freeService (&s1); … … 1358 1567 freeMaps (&m); 1359 1568 free (m); 1569 if(zooRegistry!=NULL){ 1570 freeRegistry(&zooRegistry); 1571 free(zooRegistry); 1572 } 1360 1573 free (orig); 1361 1574 free (REQUEST); … … 1379 1592 freeMaps (&m); 1380 1593 free (m); 1594 if(zooRegistry!=NULL){ 1595 freeRegistry(&zooRegistry); 1596 free(zooRegistry); 1597 } 1381 1598 free (REQUEST); 1382 1599 free (SERVICE_URL); … … 1396 1613 freeMaps (&m); 1397 1614 free (m); 1615 if(zooRegistry!=NULL){ 1616 freeRegistry(&zooRegistry); 1617 free(zooRegistry); 1618 } 1398 1619 free (REQUEST); 1399 1620 free (SERVICE_URL); … … 1410 1631 freeMaps (&m); 1411 1632 free (m); 1633 if(zooRegistry!=NULL){ 1634 freeRegistry(&zooRegistry); 1635 free(zooRegistry); 1636 } 1412 1637 free (REQUEST); 1413 1638 free (SERVICE_URL); … … 1447 1672 dup2 (fileno (stderr), fileno (stdout)); 1448 1673 t = readServiceFile (m, tmps1, &s1, r_inputs->value); 1674 inheritance(zooRegistry,&s1); 1675 if(zooRegistry!=NULL){ 1676 freeRegistry(&zooRegistry); 1677 free(zooRegistry); 1678 } 1449 1679 fflush (stdout); 1450 1680 dup2 (saved_stdout, fileno (stdout));
Note: See TracChangeset
for help on using the changeset viewer.