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

Last change on this file since 512 was 512, checked in by david, 9 years ago

-loading files configuration on startup
-devel version with probably a lot of leak
-using temporarily glib to store services

File size: 6.0 KB
RevLine 
[512]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  for (l = serviceCfgList; l; l = l->next)
127    {
128      if (strcasecmp (identifier, ((service *) (l->data))->identifier) == 0)
129        return (service *) l->data;
130    }
131  return NULL;
132}
133
134
135void
136XML_CapabilitiesAllProcess (maps * m, xmlNodePtr nc)
137{
138  GList *l;
139  for (l = serviceCfgList; l; l = l->next)
140    {
141
142      service *serv = (service *) l->data;
143
144      xmlNsPtr ns, ns_ows, ns_xlink;
145      xmlNodePtr n = NULL, nc1, nc2;
146  /**
147   * Initialize or get existing namspaces
148   */
149      int wpsId =
150        zooXmlAddNs (NULL, "http://www.opengis.net/wps/1.0.0", "wps");
151      ns = usedNs[wpsId];
152      int owsId = zooXmlAddNs (NULL, "http://www.opengis.net/ows/1.1", "ows");
153      ns_ows = usedNs[owsId];
154      int xlinkId = zooXmlAddNs (n, "http://www.w3.org/1999/xlink", "xlink");
155      ns_xlink = usedNs[xlinkId];
156
157      map *tmp1;
158      if (serv->content != NULL)
159        {
160          nc1 = xmlNewNode (ns, BAD_CAST "Process");
161          tmp1 = getMap (serv->content, "processVersion");
162          if (tmp1 != NULL)
163            xmlNewNsProp (nc1, ns, BAD_CAST "processVersion",
164                          BAD_CAST tmp1->value);
165          //map *tmp3 = getMapFromMaps (m, "lenv", "level");
166          //addPrefix (m, tmp3, serv);
167          printDescription (nc1, ns_ows, serv->identifier, serv->content);
168          tmp1 = serv->metadata;
169          while (tmp1 != NULL)
170            {
171              nc2 = xmlNewNode (ns_ows, BAD_CAST "Metadata");
172              xmlNewNsProp (nc2, ns_xlink, BAD_CAST tmp1->name,
173                            BAD_CAST tmp1->value);
174              xmlAddChild (nc1, nc2);
175              tmp1 = tmp1->next;
176            }
177          xmlAddChild (nc, nc1);
178        }
179    }
180}
181
182void
183XML_Describe_Process (maps * m, xmlNodePtr nc, char *identifiers)
184{
185  if (strcasecmp ("all", identifiers) == 0)
186    {
187      GList *l;
188      for (l = serviceCfgList; l; l = l->next)
189        {
190          service *serv = (service *) l->data;
191          printDescribeProcessForProcess (m, nc, serv);
192        }
193    }
194  else
195    {
196      char *save_ptr_strtok;
197      char *token = strtok_r (identifiers, ",", &save_ptr_strtok);
198      while (token != NULL)
199        {
200          service *serv = search_service (token);
201          if (serv != NULL)
202            printDescribeProcessForProcess (m, nc, serv);
203          token = strtok_r (NULL, ",", &save_ptr_strtok);
204        }
205    }
206}
Note: See TracBrowser for help on using the repository browser.

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