1 | /** |
---|
2 | * Author : Gérald FENOY |
---|
3 | * |
---|
4 | * Copyright 2015 GeoLabs SARL. All rights reserved. |
---|
5 | * |
---|
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
7 | * of this software and associated documentation files (the "Software"), to deal |
---|
8 | * in the Software without restriction, including without limitation the rights |
---|
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
10 | * copies of the Software, and to permit persons to whom the Software is |
---|
11 | * furnished to do so, subject to the following conditions: |
---|
12 | * |
---|
13 | * The above copyright notice and this permission notice shall be included in |
---|
14 | * all copies or substantial portions of the Software. |
---|
15 | * |
---|
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
22 | * THE SOFTWARE. |
---|
23 | */ |
---|
24 | |
---|
25 | #include "service.h" |
---|
26 | #include "service_internal.h" |
---|
27 | #include "server_internal.h" |
---|
28 | #include "response_print.h" |
---|
29 | |
---|
30 | #include <libxml/tree.h> |
---|
31 | #include <libxml/parser.h> |
---|
32 | #include <libxml/xpath.h> |
---|
33 | #include <libxml/xpathInternals.h> |
---|
34 | |
---|
35 | #include <libxslt/xslt.h> |
---|
36 | #include <libxslt/xsltInternals.h> |
---|
37 | #include <libxslt/transform.h> |
---|
38 | #include <libxslt/xsltutils.h> |
---|
39 | |
---|
40 | #include <dirent.h> |
---|
41 | extern "C" { |
---|
42 | |
---|
43 | /** |
---|
44 | * GetFromRegistry ZOO Service : |
---|
45 | * This service is used in the ZOO-Project to browse the profiles registry. |
---|
46 | */ |
---|
47 | #ifdef WIN32 |
---|
48 | __declspec(dllexport) |
---|
49 | #endif |
---|
50 | int GetFromRegistry(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
51 | const char *params[4 + 1]; |
---|
52 | int xmlLoadExtDtdDefaultValue; |
---|
53 | map* tmpMap=NULL,*tmpMmap=NULL, *tmpTmap=NULL; |
---|
54 | |
---|
55 | map* reg = getMapFromMaps (conf, "main", "registry"); |
---|
56 | registry* zooRegistry=NULL; |
---|
57 | if(reg!=NULL){ |
---|
58 | int saved_stdout = dup (fileno (stdout)); |
---|
59 | dup2 (fileno (stderr), fileno (stdout)); |
---|
60 | createRegistry (conf,&zooRegistry,reg->value); |
---|
61 | dup2 (saved_stdout, fileno (stdout)); |
---|
62 | close(saved_stdout); |
---|
63 | }else{ |
---|
64 | setMapInMaps(conf,"lenv","message",_ss("No registry defined")); |
---|
65 | return SERVICE_FAILED; |
---|
66 | } |
---|
67 | tmpMap=getMapFromMaps(inputs,"id","value"); |
---|
68 | if(strstr(tmpMap->value,"/")==NULL){ |
---|
69 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse your registry identifier")); |
---|
70 | return SERVICE_FAILED; |
---|
71 | } |
---|
72 | char* tmp=zStrdup(tmpMap->value); |
---|
73 | char* tmp1=zStrdup(strstr(tmpMap->value,"/")+1); |
---|
74 | tmp[strlen(tmp)-strlen(tmp1)-1]=0; |
---|
75 | service* inherited=getServiceFromRegistry(zooRegistry,tmp,tmp1); |
---|
76 | if(inherited!=NULL){ |
---|
77 | dumpService(inherited); |
---|
78 | xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0"); |
---|
79 | xmlNodePtr n = printWPSHeader(doc,conf,"DescribeProcess", |
---|
80 | root_nodes[1][1],"2.0.0",1); |
---|
81 | setMapInMaps(conf,"main","rversion","2.0.0"); |
---|
82 | printDescribeProcessForProcess(zooRegistry,conf,n,inherited); |
---|
83 | setMapInMaps(conf,"main","rversion","1.0.0"); |
---|
84 | |
---|
85 | |
---|
86 | xmlNodePtr n1 = xmlFirstElementChild(xmlFirstElementChild(n)); |
---|
87 | |
---|
88 | |
---|
89 | xmlDocPtr doc1 = xmlNewDoc (BAD_CAST "1.0"); |
---|
90 | int vid=1; |
---|
91 | char *tmp=(char*) malloc((86+strlen("DescribeProcess")+1)*sizeof(char)); |
---|
92 | sprintf(tmp,schemas[vid][4],schemas[vid][2],schemas[vid][3],"DescribeProcess"); |
---|
93 | xmlNewProp(n1,BAD_CAST "xsi:schemaLocation",BAD_CAST tmp); |
---|
94 | free(tmp); |
---|
95 | |
---|
96 | n1->ns=xmlCopyNamespaceList(n->ns); |
---|
97 | n1->nsDef=xmlCopyNamespaceList(n->nsDef); |
---|
98 | |
---|
99 | xmlDocSetRootElement(doc1, n1); |
---|
100 | |
---|
101 | xmlChar *xmlbuff; |
---|
102 | int buffersize; |
---|
103 | xmlDocDumpFormatMemoryEnc(doc1, &xmlbuff, &buffersize, "utf-8", 1); |
---|
104 | setMapInMaps(outputs,"Result","value",(char*)xmlbuff); |
---|
105 | xmlFree(xmlbuff); |
---|
106 | xmlFreeDoc(doc); |
---|
107 | xmlFreeDoc(doc1); |
---|
108 | return SERVICE_SUCCEEDED; |
---|
109 | }else{ |
---|
110 | if(strcasecmp(tmp,"concept")==0){ |
---|
111 | char *file_path=(char*)malloc((strlen(reg->value)+strlen(tmpMap->value)+5)*sizeof(char)); |
---|
112 | sprintf(file_path,"%s/%s.txt",reg->value,tmpMap->value); |
---|
113 | FILE* f=fopen(file_path,"r"); |
---|
114 | if(f!=NULL){ |
---|
115 | fseek(f, 0, SEEK_END); |
---|
116 | long count = ftell(f); |
---|
117 | fseek(f, 0, SEEK_SET); |
---|
118 | setMapInMaps(outputs,"Result","value",""); |
---|
119 | map* tmpMap=getMapFromMaps(outputs,"Result","value"); |
---|
120 | free(tmpMap->value); |
---|
121 | tmpMap->value=(char*) malloc((count+1)*sizeof(char)); |
---|
122 | fread(tmpMap->value,1,count,f); |
---|
123 | tmpMap->value[count]=0; |
---|
124 | fclose(f); |
---|
125 | setMapInMaps(outputs,"Result","mimeType","text/plain"); |
---|
126 | return SERVICE_SUCCEEDED; |
---|
127 | }else{ |
---|
128 | setMapInMaps(conf,"lenv","message",_ss("Unable to access this item in the registry.")); |
---|
129 | return SERVICE_FAILED; |
---|
130 | } |
---|
131 | } |
---|
132 | setMapInMaps(conf,"lenv","message",_ss("Unable to access this item in the registry.")); |
---|
133 | return SERVICE_FAILED; |
---|
134 | } |
---|
135 | return SERVICE_SUCCEEDED; |
---|
136 | } |
---|
137 | |
---|
138 | } |
---|