source: branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/service_zcfg.c @ 531

Last change on this file since 531 was 531, checked in by david, 9 years ago
  • remove metapath parameter for python and js support
  • use conf in memory for C,python and js services
File size: 6.1 KB
Line 
1#include <string.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <glib.h>
5#include <sys/stat.h>
6#include "service.h"
7#include "service_internal.h"
8#include <libxml/tree.h>
9#include <libxml/xmlmemory.h>
10#include <libxml/parser.h>
11#include <libxml/xpath.h>
12#include <libxml/xpathInternals.h>
13
14
15
16static int SCAN_DEPTH = 7;
17
18
19static GList *serviceCfgList;
20
21static int
22scanServiceCfg (char *rootDir, GList ** serviceList, int level)
23{
24  if (level >= SCAN_DEPTH)
25    return 1;
26  struct dirent *d;
27  DIR *dir = opendir (rootDir);
28  if (dir != NULL)
29    {
30      while ((d = readdir (dir)))
31        {
32          if ((d->d_type == DT_DIR || d->d_type == DT_LNK)
33              && d->d_name[0] != '.' && strstr (d->d_name, ".") == NULL)
34            {
35              char *name =
36                (char *) malloc (strlen (rootDir) + strlen (d->d_name) + 2);
37              name[0] = '\0';
38              strncat (name, rootDir, strlen (rootDir));
39              strncat (name, "/", strlen ("/"));
40              strncat (name, d->d_name, strlen (d->d_name));
41              scanServiceCfg (name, serviceList, level + 1);
42            }
43          else
44            {
45              if (d->d_name[0] != '.')
46                if (strstr (d->d_name, ".zcfg") != NULL)
47                  {
48                    char *name =
49                      (char *) malloc (strlen (rootDir) + strlen (d->d_name) +
50                                       2);
51                    name[0] = '\0';
52                    strncat (name, rootDir, strlen (rootDir));
53                    strncat (name, "/", strlen ("/"));
54                    strncat (name, d->d_name, strlen (d->d_name));
55                    *serviceList = g_list_append (*serviceList, name);
56                  }
57            }
58        }
59    }
60  free (d);
61  closedir (dir);
62  return 1;
63}
64
65static int
66get_identifier (char *root_dir, char *zcfg_path, char **identifier)
67{
68  // On extrait le repertoire racine ainsi que l'extention .zcfg pour contruire l'identifiant
69  // root_dir = /var/www/zoo/cgi-bin/ zcfg_path=/var/www/zoo/cgi-bin/gdal/ndvi/ExtractNDVI.zcfg  ===>  gdal.ndvi.ExtractNDVI
70  char *identifier_tmp =
71    (char *) malloc ((strlen (zcfg_path) + 1) * sizeof (char));
72  identifier_tmp[0] = '\0';
73  int ext_len = strlen (".zcfg");
74  int s_tmp_len = strlen (zcfg_path) - ext_len - strlen (root_dir);
75  if (s_tmp_len > 1)
76    {
77      char *s_tmp = (char *) malloc ((s_tmp_len + 1) * sizeof (char));
78      int j;
79      for (j = 0; j < s_tmp_len; j++)
80        s_tmp[j] = zcfg_path[strlen (root_dir) + j];
81      s_tmp[s_tmp_len] = '\0';
82      char *save_ptr_strtok;
83      char *token = strtok_r (s_tmp, "/", &save_ptr_strtok);
84      strncat (identifier_tmp, token, strlen (token));
85      while (token != NULL)
86        {
87          token = strtok_r (NULL, "/", &save_ptr_strtok);
88          if (token != NULL)
89            {
90              strncat (identifier_tmp, ".", strlen ("."));
91              strncat (identifier_tmp, token, strlen (token));
92            }
93
94        }
95      *identifier =
96        (char *) malloc ((strlen (identifier_tmp) + 1) * sizeof (char));
97      strncpy (*identifier, identifier_tmp, strlen (identifier_tmp) + 1);
98      free (identifier_tmp);
99      free (s_tmp);
100    }
101  return 1;
102}
103
104void
105init_services_conf (char *rootDir)
106{
107  maps *m = (maps *) malloc (MAP_SIZE);
108  GList *L = NULL;
109  scanServiceCfg (rootDir, &L, 0);
110  GList *l = NULL;
111  for (l = L; l; l = l->next)
112    {
113      service *s1 = (service *) malloc (SERVICE_SIZE);
114      get_identifier (rootDir, (char *) (l->data), &(s1->identifier));
115      s1->zcfg = (char *) (l->data);
116      readServiceFile (m, (char *) l->data, &s1, s1->identifier);
117      serviceCfgList = g_list_append (serviceCfgList, s1);
118    }
119}
120
121
122service *
123search_service (char *identifier)
124{
125  GList *l;
126  int i = 0;
127  for (l = serviceCfgList; l; l = l->next)
128    {
129#ifdef DEBUG
130      fprintf (stderr, "%d ### %s ###\n", i,
131               ((service *) (l->data))->identifier);
132      i++;
133#endif
134      if (strcasecmp (identifier, ((service *) (l->data))->identifier) == 0)
135        return (service *) l->data;
136    }
137  return NULL;
138}
139
140
141void
142XML_CapabilitiesAllProcess (maps * m, xmlNodePtr nc)
143{
144  GList *l;
145  for (l = serviceCfgList; l; l = l->next)
146    {
147
148      service *serv = (service *) l->data;
149
150      xmlNsPtr ns, ns_ows, ns_xlink;
151      xmlNodePtr n = NULL, nc1, nc2;
152  /**
153   * Initialize or get existing namspaces
154   */
155      int wpsId =
156        zooXmlAddNs (NULL, "http://www.opengis.net/wps/1.0.0", "wps");
157      ns = usedNs[wpsId];
158      int owsId = zooXmlAddNs (NULL, "http://www.opengis.net/ows/1.1", "ows");
159      ns_ows = usedNs[owsId];
160      int xlinkId = zooXmlAddNs (n, "http://www.w3.org/1999/xlink", "xlink");
161      ns_xlink = usedNs[xlinkId];
162
163      map *tmp1;
164      if (serv->content != NULL)
165        {
166          nc1 = xmlNewNode (ns, BAD_CAST "Process");
167          tmp1 = getMap (serv->content, "processVersion");
168          if (tmp1 != NULL)
169            xmlNewNsProp (nc1, ns, BAD_CAST "processVersion",
170                          BAD_CAST tmp1->value);
171          //map *tmp3 = getMapFromMaps (m, "lenv", "level");
172          //addPrefix (m, tmp3, serv);
173          printDescription (nc1, ns_ows, serv->identifier, serv->content);
174          tmp1 = serv->metadata;
175          while (tmp1 != NULL)
176            {
177              nc2 = xmlNewNode (ns_ows, BAD_CAST "Metadata");
178              xmlNewNsProp (nc2, ns_xlink, BAD_CAST tmp1->name,
179                            BAD_CAST tmp1->value);
180              xmlAddChild (nc1, nc2);
181              tmp1 = tmp1->next;
182            }
183          xmlAddChild (nc, nc1);
184        }
185    }
186}
187
188void
189XML_Describe_Process (maps * m, xmlNodePtr nc, char *identifiers)
190{
191  if (strcasecmp ("all", identifiers) == 0)
192    {
193      GList *l;
194      for (l = serviceCfgList; l; l = l->next)
195        {
196          service *serv = (service *) l->data;
197          printDescribeProcessForProcess (m, nc, serv);
198        }
199    }
200  else
201    {
202      char *save_ptr_strtok;
203      char *token = strtok_r (identifiers, ",", &save_ptr_strtok);
204      while (token != NULL)
205        {
206          service *serv = search_service (token);
207          if (serv != NULL)
208            printDescribeProcessForProcess (m, nc, serv);
209          token = strtok_r (NULL, ",", &save_ptr_strtok);
210        }
211    }
212}
Note: See TracBrowser for help on using the repository browser.

Search

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