Ignore:
Timestamp:
Nov 4, 2016, 4:58:41 PM (7 years ago)
Author:
knut
Message:

Added support for include mechanism in the main.cfg file. An [include] block can be added in main.cfg, like this:

[include]
servicename1 = /my/service/repository/service1.zcfg
servicename2 = /my/service/repository/service2.zcfg
...

The word "include" thus has a special (reserved) meaning, just as "main" does. If necessary, a user may change "include" to something else by redefining the IMPORTSERVICE macro.

The service name (left hand side) should match the [service name] in the config (zcfg) file, but the path/file name (right hand side) may be arbitrary.

When handling requests, Zoo will first check if there is an [include] block, then recursively search the working directory (CWD) and subdirectories as before. If an [include]d service happens to be located in a CWD (sub)directory, it will be published by its [include]d name.

As currently implemented, Zoo will search CWD for the library files of [include]d services if the libPath parameter is not set (note that presently only C and PHP services support the libPath parameter).

Added new function (zoo_path_compare) to check if two path strings refer to the same physical file. It should handle symbolic links (typically, Linux/Unix?) and different path separators (typically, Windows).

Location:
trunk/zoo-project/zoo-kernel
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/server_internal.c

    r785 r789  
    3535#endif
    3636#include <signal.h>
     37
     38// #include <stdlib.h>
     39/*
     40 * Compare two file path strings to see if they refer to the same file.
     41 *
     42 * @param path1 the first file path
     43 * @param path2 the second file path
     44 *
     45 * @return 0 if the files are identical
     46 */
     47#define PATHBUFSIZE 4096
     48int zoo_path_compare(char* path1, char* path2) {
     49
     50  if (path1 == NULL || path2 == NULL) {
     51    return -1;
     52  }
     53
     54  char realpath1[PATHBUFSIZE];
     55  char realpath2[PATHBUFSIZE];
     56
     57#ifdef WIN32
     58  int res1 = GetFullPathName(path1, PATHBUFSIZE, realpath1, NULL);
     59  int res2 = GetFullPathName(path2, PATHBUFSIZE, realpath2, NULL);
     60
     61  if (res1 == 0 || res2 == 0) {
     62    return -1;
     63  }
     64  else {
     65    return strncasecmp(realpath1, realpath2, PATHBUFSIZE);
     66  }
     67#else
     68  char* ptr1 = realpath(path1, realpath1);
     69  char* ptr2 = realpath(path2, realpath2);
     70
     71  if (ptr1 == NULL || ptr2 == NULL) {
     72    return -1;
     73  }
     74  else {
     75    return strncmp(realpath1, realpath2, PATHBUFSIZE);
     76  }
     77#endif
     78}
    3779
    3880/**
  • trunk/zoo-project/zoo-kernel/server_internal.h

    r767 r789  
    2525#ifdef WIN32
    2626#pragma comment(lib, "rpcrt4.lib")
     27#endif
     28
     29#ifndef IMPORTSERVICE
     30#define IMPORTSERVICE "include" // default name of [include] block in main.cfg
    2731#endif
    2832
     
    6670  int createRegistry (maps*,registry **,char *);
    6771
     72  int zoo_path_compare(char* path1, char* path2);
     73
    6874#ifdef WIN32
    6975  char* getMapsAsKVP(maps*,int,int);
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r788 r789  
    287287            memset (tmps1, 0, 1024);
    288288            snprintf (tmps1, 1024, "%s/%s", conf_dir, dp->d_name);
    289             service *s1 = (service *) malloc (SERVICE_SIZE);
    290             if (s1 == NULL)
    291               {
    292                 dup2 (saved_stdout, fileno (stdout));
    293                 errorException (m, _("Unable to allocate memory"),
    294                                 "InternalError", NULL);
    295                 return -1;
    296               }
    297 #ifdef DEBUG
    298             fprintf (stderr, "#################\n%s\n#################\n",
    299                      tmps1);
    300 #endif
     289
    301290            char *tmpsn = zStrdup (dp->d_name);
    302291            tmpsn[strlen (tmpsn) - 5] = 0;
    303             t = readServiceFile (m, tmps1, &s1, tmpsn);
    304             free (tmpsn);
    305             if (t < 0)
    306               {
    307                 map *tmp00 = getMapFromMaps (m, "lenv", "message");
    308                 char tmp01[1024];
    309                 if (tmp00 != NULL)
    310                   sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"),
    311                            dp->d_name, tmp00->value);
    312                 else
    313                   sprintf (tmp01, _("Unable to parse the ZCFG file: %s."),
    314                            dp->d_name);
    315                 dup2 (saved_stdout, fileno (stdout));
    316                 errorException (m, tmp01, "InternalError", NULL);
    317                 return -1;
    318               }
    319 #ifdef DEBUG
    320             dumpService (s1);
    321             fflush (stdout);
    322             fflush (stderr);
    323 #endif
    324             inheritance(r,&s1);
    325             func (r, m, n, s1);
    326             freeService (&s1);
    327             free (s1);
    328             scount++;
     292           
     293            map* import = getMapFromMaps (m, IMPORTSERVICE, tmpsn);
     294            if (import == NULL || import->value == NULL || zoo_path_compare(tmps1, import->value) != 0 ) { // service is not in [include] block
     295              service *s1 = (service *) malloc (SERVICE_SIZE);
     296              if (s1 == NULL)
     297                {
     298                  dup2 (saved_stdout, fileno (stdout));
     299                  errorException (m, _("Unable to allocate memory"),
     300                                  "InternalError", NULL);
     301                  return -1;
     302                }
     303  #ifdef DEBUG
     304              fprintf (stderr, "#################\n%s\n#################\n",
     305                       tmps1);
     306  #endif
     307              t = readServiceFile (m, tmps1, &s1, tmpsn);
     308              free (tmpsn);
     309              if (t < 0)
     310                {
     311                  map *tmp00 = getMapFromMaps (m, "lenv", "message");
     312                  char tmp01[1024];
     313                  if (tmp00 != NULL)
     314                    sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"),
     315                             dp->d_name, tmp00->value);
     316                  else
     317                    sprintf (tmp01, _("Unable to parse the ZCFG file: %s."),
     318                             dp->d_name);
     319                  dup2 (saved_stdout, fileno (stdout));
     320                  errorException (m, tmp01, "InternalError", NULL);
     321                  return -1;
     322                }
     323  #ifdef DEBUG
     324              dumpService (s1);
     325              fflush (stdout);
     326              fflush (stderr);
     327  #endif
     328        inheritance(r,&s1);
     329              func (r, m, n, s1);
     330              freeService (&s1);
     331              free (s1);
     332              scount++;
     333            }
    329334          }
    330335      }
     
    12451250      int saved_stdout = dup (fileno (stdout));
    12461251      dup2 (fileno (stderr), fileno (stdout));
     1252
     1253      maps* imports = getMaps(m, IMPORTSERVICE);
     1254      if (imports != NULL) {       
     1255        map* zcfg = imports->content;
     1256       
     1257        while (zcfg != NULL) {
     1258          if (zcfg->value != NULL) {
     1259            service* svc = (service*) malloc(SERVICE_SIZE);
     1260            if (svc == NULL || readServiceFile(m, zcfg->value, &svc, zcfg->name) < 0) {
     1261              // pass over silently
     1262              zcfg = zcfg->next;
     1263              continue;
     1264            }
     1265            inheritance(zooRegistry, &svc);
     1266            printGetCapabilitiesForProcess(zooRegistry, m, n, svc);
     1267            freeService(&svc);
     1268            free(svc);                             
     1269          }
     1270          zcfg = zcfg->next;
     1271        }           
     1272      }
     1273
    12471274      if (int res =               
    12481275          recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,
     
    13451372            if (strcasecmp ("all", orig) == 0)
    13461373              {
     1374                maps* imports = getMaps(m, IMPORTSERVICE);
     1375                if (imports != NULL) {       
     1376                  map* zcfg = imports->content;
     1377           
     1378                  while (zcfg != NULL) {
     1379                    if (zcfg->value != NULL) {
     1380                      service* svc = (service*) malloc(SERVICE_SIZE);
     1381                      if (svc == NULL || readServiceFile(m, zcfg->value, &svc, zcfg->name) < 0) {
     1382                        // pass over silently
     1383                        zcfg = zcfg->next;
     1384                        continue;
     1385                      }
     1386                      inheritance(zooRegistry, &svc);
     1387                      printDescribeProcessForProcess(zooRegistry, m, n, svc);
     1388                      freeService(&svc);
     1389                      free(svc);                             
     1390                    }
     1391                    zcfg = zcfg->next;
     1392                  }           
     1393                }
     1394 
    13471395                if (int res =
    13481396                    recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,
     
    13611409                    int hasVal = -1;
    13621410                    char *corig = zStrdup (tmps);
    1363                     if (strstr (corig, ".") != NULL)
     1411                    map* import = getMapFromMaps (m, IMPORTSERVICE, corig);   
     1412                    if (import != NULL && import->value != NULL)
     1413                      {
     1414                        s1 = (service *) malloc (SERVICE_SIZE);
     1415                        t = readServiceFile (m, import->value, &s1, import->name);
     1416               
     1417                        if (t < 0) // failure reading zcfg
     1418                          {
     1419                            map *tmp00 = getMapFromMaps (m, "lenv", "message");
     1420                            char tmp01[1024];
     1421                            if (tmp00 != NULL)
     1422                              sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"), import->value, tmp00->value);
     1423                            else
     1424                              sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), import->value);
     1425
     1426                            dup2 (saved_stdout, fileno (stdout));
     1427                            errorException (m, tmp01, "InternalError", NULL);
     1428           
     1429                            freeMaps (&m);
     1430                            free (m);
     1431
     1432                            if(zooRegistry!=NULL){
     1433                              freeRegistry(&zooRegistry);
     1434                              free(zooRegistry);
     1435                            }
     1436                            free (orig);
     1437                            free (REQUEST);
     1438                            closedir (dirp);
     1439                            xmlFreeDoc (doc);
     1440                            xmlCleanupParser ();
     1441                            zooXmlCleanupNs ();
     1442                   
     1443                            return 1;
     1444                          }
     1445#ifdef DEBUG
     1446                        dumpService (s1);
     1447#endif
     1448
     1449                        inheritance(zooRegistry,&s1);
     1450                        printDescribeProcessForProcess (zooRegistry,m, n, s1);
     1451                        freeService (&s1);
     1452                        free (s1);
     1453                        s1 = NULL;
     1454                        scount++;
     1455                        hasVal = 1;               
     1456                    }
     1457                    else if (strstr (corig, ".") != NULL)
    13641458                      {
    13651459
     
    16401734
    16411735  r_inputs = getMap (request_inputs, "Identifier");
    1642   snprintf (tmps1, 1024, "%s/%s.zcfg", conf_dir, r_inputs->value);
    1643 #ifdef DEBUG
    1644   fprintf (stderr, "Trying to load %s\n", tmps1);
    1645 #endif
    1646   if (strstr (r_inputs->value, ".") != NULL)
    1647     {
    1648       char *identifier = zStrdup (r_inputs->value);
    1649       parseIdentifier (m, conf_dir, identifier, tmps1);
    1650       map *tmpMap = getMapFromMaps (m, "lenv", "metapath");
    1651       if (tmpMap != NULL)
    1652         addToMap (request_inputs, "metapath", tmpMap->value);
    1653       free (identifier);
    1654     }
    1655   else
    1656     {
     1736
     1737  map* import = getMapFromMaps (m, IMPORTSERVICE, r_inputs->value);
     1738  if (import != NULL && import->value != NULL) {
     1739      strncpy(tmps1, import->value, 1024);
    16571740      setMapInMaps (m, "lenv", "Identifier", r_inputs->value);
    16581741      setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value);
    1659     }
     1742  }
     1743  else {
     1744    snprintf (tmps1, 1024, "%s/%s.zcfg", conf_dir, r_inputs->value);
     1745#ifdef DEBUG
     1746    fprintf (stderr, "Trying to load %s\n", tmps1);
     1747#endif
     1748    if (strstr (r_inputs->value, ".") != NULL)
     1749      {
     1750        char *identifier = zStrdup (r_inputs->value);
     1751        parseIdentifier (m, conf_dir, identifier, tmps1);
     1752        map *tmpMap = getMapFromMaps (m, "lenv", "metapath");
     1753        if (tmpMap != NULL)
     1754          addToMap (request_inputs, "metapath", tmpMap->value);
     1755        free (identifier);
     1756      }
     1757    else
     1758      {
     1759        setMapInMaps (m, "lenv", "Identifier", r_inputs->value);
     1760        setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value);
     1761      }
     1762  }
    16601763
    16611764  r_inputs = getMapFromMaps (m, "lenv", "Identifier");
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png