Changeset 301 for branches/branch-1.2/zoo-kernel/service_internal.c
- Timestamp:
- Aug 5, 2011, 3:02:43 PM (13 years ago)
- Location:
- branches/branch-1.2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/branch-1.2
-
branches/branch-1.2/zoo-kernel/service_internal.c
r268 r301 258 258 259 259 JSBool 260 JSUpdateStatus(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)260 JSUpdateStatus(JSContext *cx, uintN argc, jsval *argv1) 261 261 { 262 jsval *argv = JS_ARGV(cx,argv1); 262 263 JS_MaybeGC(cx); 263 264 char *sid; … … 280 281 } 281 282 if(getMapFromMaps(conf,"lenv","status")!=NULL){ 282 if(status!=NULL) 283 fprintf(stderr,"STATUS RETURNED : %s\n",status); 284 if(status!=NULL){ 283 285 setMapInMaps(conf,"lenv","status",status); 286 free(status); 287 } 284 288 else 285 289 setMapInMaps(conf,"lenv","status","15"); … … 367 371 #endif 368 372 int currId=-1; 373 int currNode=-1; 369 374 if(nbNs==0){ 370 375 nbNs++; … … 399 404 } 400 405 nbNs=0; 406 } 407 408 xmlNodePtr soapEnvelope(maps* conf,xmlNodePtr n){ 409 map* soap=getMapFromMaps(conf,"main","isSoap"); 410 if(soap!=NULL && strcasecmp(soap->value,"true")==0){ 411 int lNbNs=nbNs; 412 nsName[lNbNs]=strdup("soap"); 413 usedNs[lNbNs]=xmlNewNs(NULL,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap"); 414 nbNs++; 415 xmlNodePtr nr = xmlNewNode(usedNs[lNbNs], BAD_CAST "Envelope"); 416 nsName[nbNs]=strdup("soap"); 417 usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap"); 418 nbNs++; 419 nsName[nbNs]=strdup("xsi"); 420 usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi"); 421 nbNs++; 422 xmlNsPtr ns_xsi=usedNs[nbNs-1]; 423 xmlNewNsProp(nr,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope"); 424 xmlNodePtr nr1 = xmlNewNode(usedNs[lNbNs], BAD_CAST "Body"); 425 xmlAddChild(nr1,n); 426 xmlAddChild(nr,nr1); 427 return nr; 428 }else 429 return n; 401 430 } 402 431 … … 715 744 xmlAddChild(n,nc1); 716 745 717 xmlDocSetRootElement(doc, n); 746 xmlNodePtr fn=soapEnvelope(m,n); 747 xmlDocSetRootElement(doc, fn); 718 748 //xmlFreeNs(ns); 719 749 free(SERVICE_URL); … … 775 805 addLangAttr(n,m); 776 806 777 xmlDocSetRootElement(doc, n); 807 xmlNodePtr fn=soapEnvelope(m,n); 808 xmlDocSetRootElement(doc, fn); 778 809 779 810 return n; … … 1003 1034 } 1004 1035 } 1036 1005 1037 _tmp=e->supported; 1038 if(_tmp==NULL && (getMap(e->defaults->content,"uom")!=NULL || datatype!=1)) 1039 _tmp=e->defaults; 1040 1006 1041 int hasSupported=-1; 1007 1042 while(_tmp!=NULL){ … … 1082 1117 if(hasDefault!=true && strncmp(type,"Input",5)==0) 1083 1118 xmlAddChild(nc3,xmlNewNode(ns_ows, BAD_CAST "AnyValue")); 1084 xmlFreeNodeList(nc5);1085 xmlFreeNodeList(nc4);1086 1119 } 1087 1120 … … 1093 1126 1094 1127 void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){ 1095 xmlNsPtr ns,ns _ows,ns_xlink,ns_xsi;1128 xmlNsPtr ns,ns1,ns_ows,ns_xlink,ns_xsi; 1096 1129 xmlNodePtr nr,n,nc,nc1,nc2,nc3,pseudor; 1097 1130 xmlDocPtr doc; … … 1100 1133 time_t time1; 1101 1134 time(&time1); 1135 nr=NULL; 1102 1136 /** 1103 1137 * Create the document and its temporary root. … … 1106 1140 int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps"); 1107 1141 ns=usedNs[wpsId]; 1108 1142 1109 1143 n = xmlNewNode(ns, BAD_CAST "ExecuteResponse"); 1144 xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); 1110 1145 int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows"); 1111 1146 ns_ows=usedNs[owsId]; … … 1114 1149 int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); 1115 1150 ns_xsi=usedNs[xsiId]; 1116 xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); 1117 1151 1118 1152 xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_response.xsd"); 1119 1153 … … 1159 1193 sprintf(currentSid,"%s",tmp_lenv->value); 1160 1194 if(tmpm==NULL || strcasecmp(tmpm->value,"false")==0){ 1161 sprintf(url,"%s /?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid);1195 sprintf(url,"%s?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid); 1162 1196 }else{ 1163 1197 if(strlen(tmpm->value)>0) … … 1176 1210 } 1177 1211 if(tmpm1!=NULL) 1178 sprintf(tmp,"%s /",tmpm1->value);1212 sprintf(tmp,"%s",tmpm1->value); 1179 1213 tmpm1=getMapFromMaps(m,"main","TmpPath"); 1180 1214 sprintf(stored_path,"%s/%s_%i.xml",tmpm1->value,service,pid); … … 1312 1346 while(mcursor!=NULL){ 1313 1347 scursor=getElements(serv->outputs,mcursor->name); 1314 printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output"); 1348 if(scursor!=NULL){ 1349 printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output"); 1350 } 1315 1351 mcursor=mcursor->next; 1316 1352 } … … 1320 1356 fprintf(stderr,"printProcessResponse 1 202\n"); 1321 1357 #endif 1322 xmlDocSetRootElement(doc, n); 1358 nr=soapEnvelope(m,n); 1359 xmlDocSetRootElement(doc, nr); 1360 1323 1361 if(hasStoredExecuteResponse==true){ 1324 1362 /* We need to write the ExecuteResponse Document somewhere */ … … 1525 1563 || (tmp2!=NULL && (strncmp(tmp2->value,"image/",6)==0 || 1526 1564 (strncmp(tmp2->value,"application/",12)==0) && 1527 strncmp(tmp2->value,"application/json",16)!=0))) { 1565 strncmp(tmp2->value,"application/json",16)!=0&& 1566 strncmp(tmp2->value,"application/vnd.google-earth.kml",32)!=0) 1567 )) { 1528 1568 map* rs=getMap(m->content,"size"); 1529 1569 bool isSized=true; … … 1531 1571 char tmp1[1024]; 1532 1572 sprintf(tmp1,"%d",strlen(toto->value)); 1533 rs=createMap(" z",tmp1);1573 rs=createMap("size",tmp1); 1534 1574 isSized=false; 1535 1575 } … … 1541 1581 } 1542 1582 } 1543 else if(tmp !=NULL){1544 if(strncmp(tmp ->value,"text/js",4)==0 ||1545 strncmp(tmp ->value,"application/js",14)==0)1583 else if(tmp2!=NULL){ 1584 if(strncmp(tmp2->value,"text/js",7)==0 || 1585 strncmp(tmp2->value,"application/json",16)==0) 1546 1586 xmlAddChild(nc3,xmlNewCDataBlock(doc,BAD_CAST toto->value,strlen(toto->value))); 1547 else 1548 xmlAddChild(nc3,xmlNewText(BAD_CAST toto->value)); 1587 else{ 1588 if(strncmp(tmp2->value,"text/xml",8)==0 || 1589 strncmp(tmp2->value,"application/vnd.google-earth.kml",32)!=0){ 1590 xmlDocPtr doc = 1591 xmlParseMemory(BAD_CAST toto->value,strlen(BAD_CAST toto->value)); 1592 xmlNodePtr ir = xmlDocGetRootElement(doc); 1593 xmlAddChild(nc3,ir); 1594 } 1595 else 1596 xmlAddChild(nc3,xmlNewText(BAD_CAST toto->value)); 1597 } 1549 1598 xmlAddChild(nc2,nc3); 1550 1599 } … … 1764 1813 else if(strcasecmp(mtype->value,"application/json")==0) 1765 1814 ext=createMap("extension","js"); 1815 else if(strncmp(mtype->value,"application/vnd.google-earth.kml",32)!=0) 1816 ext=createMap("extension","kml"); 1766 1817 else 1767 1818 ext=createMap("extension","txt"); … … 1953 2004 elements* tmpInputs=in; 1954 2005 maps* out1=*out; 2006 if(type==1){ 2007 while(out1!=NULL){ 2008 if(getElements(in,out1->name)==NULL) 2009 return out1->name; 2010 out1=out1->next; 2011 } 2012 out1=*out; 2013 } 1955 2014 while(tmpInputs!=NULL){ 1956 2015 maps *tmpMaps=getMaps(out1,tmpInputs->name); … … 2082 2141 else 2083 2142 addToMap(tmpMaps->content,"inRequest","true"); 2143 2084 2144 } 2085 2145 tmpInputs=tmpInputs->next; … … 2236 2296 2237 2297 } 2298 2299 2300 unsigned char* getMd5(char* url){ 2301 EVP_MD_CTX md5ctx; 2302 unsigned char* fresult=(char*)malloc((EVP_MAX_MD_SIZE+1)*sizeof(char)); 2303 unsigned char result[EVP_MAX_MD_SIZE]; 2304 unsigned int len; 2305 EVP_DigestInit(&md5ctx, EVP_md5()); 2306 EVP_DigestUpdate(&md5ctx, url, strlen(url)); 2307 EVP_DigestFinal_ex(&md5ctx,result,&len); 2308 EVP_MD_CTX_cleanup(&md5ctx); 2309 int i; 2310 for(i = 0; i < len; i++){ 2311 if(i>0){ 2312 char *tmp=strdup(fresult); 2313 sprintf(fresult,"%s%02x", tmp,result[i]); 2314 free(tmp); 2315 } 2316 else 2317 sprintf(fresult,"%02x",result[i]); 2318 } 2319 return fresult; 2320 } 2321 2322 /** 2323 * Cache a file for a given request 2324 */ 2325 void addToCache(maps* conf,char* request,char* content,int length){ 2326 map* tmp=getMapFromMaps(conf,"main","cacheDir"); 2327 if(tmp!=NULL){ 2328 unsigned char* md5str=getMd5(request); 2329 char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6)); 2330 sprintf(fname,"%s/%s.zca",tmp->value,md5str); 2331 #ifdef DEBUG 2332 fprintf(stderr,"Cache list : %s\n",fname); 2333 fflush(stderr); 2334 #endif 2335 FILE* fo=fopen(fname,"w+"); 2336 fwrite(content,sizeof(char),length,fo); 2337 fclose(fo); 2338 free(md5str); 2339 free(fname); 2340 } 2341 } 2342 2343 char* isInCache(maps* conf,char* request){ 2344 map* tmpM=getMapFromMaps(conf,"main","cacheDir"); 2345 if(tmpM!=NULL){ 2346 unsigned char* md5str=getMd5(request); 2347 #ifdef DEBUG 2348 fprintf(stderr,"MD5STR : (%s)\n\n",md5str); 2349 #endif 2350 char* fname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+38)); 2351 sprintf(fname,"%s/%s.zca",tmpM->value,md5str); 2352 struct stat f_status; 2353 int s=stat(fname, &f_status); 2354 if(s==0 && f_status.st_size>0){ 2355 free(md5str); 2356 return fname; 2357 } 2358 free(md5str); 2359 free(fname); 2360 } 2361 return NULL; 2362 } 2363 2364 /** 2365 * loadRemoteFile: 2366 * Try to load file from cache or download a remote file if not in cache 2367 */ 2368 void loadRemoteFile(maps* m,map* content,HINTERNET hInternet,char *url){ 2369 HINTERNET res; 2370 char* fcontent; 2371 char* cached=isInCache(m,url); 2372 int fsize; 2373 if(cached!=NULL){ 2374 struct stat f_status; 2375 int s=stat(cached, &f_status); 2376 if(s==0){ 2377 fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1)); 2378 FILE* f=fopen(cached,"r"); 2379 fread(fcontent,sizeof(char),f_status.st_size,f); 2380 fsize=f_status.st_size; 2381 } 2382 }else{ 2383 res=InternetOpenUrl(hInternet,url,NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0); 2384 fcontent=(char*)calloc((res.nDataLen+1),sizeof(char)); 2385 if(fcontent == NULL){ 2386 return errorException(m, _("Unable to allocate memory."), "InternalError"); 2387 } 2388 size_t dwRead; 2389 InternetReadFile(res, (LPVOID)fcontent, res.nDataLen, &dwRead); 2390 fcontent[res.nDataLen]=0; 2391 fsize=res.nDataLen; 2392 } 2393 map* tmpMap=getMapOrFill(content,"value",""); 2394 free(tmpMap->value); 2395 tmpMap->value=(char*)malloc((fsize+1)*sizeof(char)); 2396 memcpy(tmpMap->value,fcontent,(fsize)*sizeof(char)); 2397 char ltmp1[256]; 2398 sprintf(ltmp1,"%d",fsize); 2399 addToMap(content,"size",ltmp1); 2400 if(cached==NULL) 2401 addToCache(m,url,fcontent,fsize); 2402 free(fcontent); 2403 free(cached); 2404 } 2405 2406 int errorException(maps *m, const char *message, const char *errorcode) 2407 { 2408 map* errormap = createMap("text", message); 2409 addToMap(errormap,"code", errorcode); 2410 printExceptionReportResponse(m,errormap); 2411 freeMap(&errormap); 2412 free(errormap); 2413 return -1; 2414 }
Note: See TracChangeset
for help on using the changeset viewer.