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

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