Ignore:
Timestamp:
Jul 26, 2011, 5:37:58 PM (13 years ago)
Author:
djay
Message:

Base of SOAP Envelope support. Primitive cache system. Solving bugs #45, #46, #47, #48, #50

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-kernel/zoo_service_loader.c

    r277 r280  
    493493  textdomain("zoo-services");
    494494
     495  map* lsoap=getMap(request_inputs,"soap");
     496  if(lsoap!=NULL && strcasecmp(lsoap->value,"true")==0)
     497    setMapInMaps(m,"main","isSoap","true");
     498  else
     499    setMapInMaps(m,"main","isSoap","false");
    495500
    496501  /**
     
    10411046              fprintf(stderr,"REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",tmpv1+1);
    10421047#endif
     1048              char *tmpx=url_encode(tmpv1+1);
     1049              addToMap(tmpmaps->content,tmpn1,tmpx);
     1050             
    10431051#ifndef WIN32
    10441052              if(CHECK_INET_HANDLE(hInternet))
    10451053#endif
    10461054                {
    1047                   res=InternetOpenUrl(hInternet,tmpv1+1,NULL,0,
    1048                                       INTERNET_FLAG_NO_CACHE_WRITE,0);
    1049 #ifdef DEBUG
    1050                   fprintf(stderr,"(%s) content-length : %d,,res.nDataAlloc %d \n",
    1051                           tmpv1+1,res.nDataAlloc,res.nDataLen);
    1052 #endif
    1053                   char* tmpContent=(char*)calloc((res.nDataLen+1),sizeof(char));
    1054                   if(tmpContent == NULL){
    1055                     return errorException(m, _("Unable to allocate memory."), "InternalError");
     1055                  char* cached=isInCache(m,tmpv1+1);
     1056                  if(cached!=NULL){
     1057                    fprintf(stderr,"Use cached file: %s\n",cached);
     1058                    struct stat f_status;
     1059                    int s=stat(cached, &f_status);
     1060                    if(s==0){
     1061                      map* tmpMap=getMap(tmpmaps->content,"value");
     1062                      char* fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
     1063                      FILE* f=fopen(cached,"r");
     1064                      fread(fcontent,sizeof(char),f_status.st_size,f);
     1065                      free(tmpMap->value);
     1066                      tmpMap->value=(char*)malloc((f_status.st_size+1)*sizeof(char));
     1067                      memmove(tmpMap->value,fcontent,(f_status.st_size)*sizeof(char));
     1068                      free(fcontent);
     1069                    }
     1070                  }else{
     1071                    res=InternetOpenUrl(hInternet,tmpv1+1,NULL,0,
     1072                                        INTERNET_FLAG_NO_CACHE_WRITE,0);
     1073#ifdef DEBUG
     1074                    fprintf(stderr,"(%s) content-length : %d,,res.nDataAlloc %d \n",
     1075                            tmpv1+1,res.nDataAlloc,res.nDataLen);
     1076#endif
     1077                    char* tmpContent=(char*)calloc((res.nDataLen+1),sizeof(char));
     1078                    if(tmpContent == NULL){
     1079                      return errorException(m, _("Unable to allocate memory."), "InternalError");
     1080                    }
     1081                    size_t dwRead;
     1082                    InternetReadFile(res, (LPVOID)tmpContent,res.nDataLen, &dwRead);
     1083                    map* tmpMap=getMap(tmpmaps->content,"value");
     1084                    if(tmpMap!=NULL){
     1085                      free(tmpMap->value);
     1086                      tmpMap->value=(char*)malloc((res.nDataLen+1)*sizeof(char));
     1087                      memmove(tmpMap->value,tmpContent,(res.nDataLen)*sizeof(char));
     1088                      tmpMap->value[res.nDataLen]=0;
     1089                      if(strlen(tmpContent)!=res.nDataLen){
     1090                        char tmp[256];
     1091                        sprintf(tmp,"%d",res.nDataLen*sizeof(char));
     1092                        addToMap(tmpmaps->content,"size",tmp);
     1093                      }
     1094                      addToCache(m,tmpv1+1,tmpContent,res.nDataLen);
     1095                    }
     1096                    free(tmpContent);
    10561097                  }
    1057                   size_t dwRead;
    1058                   InternetReadFile(res, (LPVOID)tmpContent,res.nDataLen, &dwRead);
    1059                   map* tmpMap=getMap(tmpmaps->content,"value");
    1060                   if(tmpMap!=NULL){
    1061                     free(tmpMap->value);
    1062                     tmpMap->value=(char*)malloc((res.nDataLen+1)*sizeof(char));
    1063                     memmove(tmpMap->value,tmpContent,(res.nDataLen)*sizeof(char));
    1064                     tmpMap->value[res.nDataLen]=0;
    1065                     if(strlen(tmpContent)!=res.nDataLen){
    1066                       char tmp[256];
    1067                       sprintf(tmp,"%d",res.nDataLen*sizeof(char));
    1068                       addToMap(tmpmaps->content,"size",tmp);
    1069                     }
    1070                   }
    1071                   free(tmpContent);
    10721098                }
    1073               char *tmpx=url_encode(tmpv1+1);
    1074               addToMap(tmpmaps->content,tmpn1,tmpx);
    1075               free(tmpx);
     1099              char *tmpx1=url_encode(tmpv1+1);
     1100              addToMap(tmpmaps->content,tmpn1,tmpx1);
     1101              free(tmpx1);
    10761102              addToMap(tmpmaps->content,"Reference",tmpv1+1);
    10771103            }
     
    14131439                    else
    14141440                      tmpmaps->content=createMap(list[l],(char*)val);
     1441#ifdef DEBUG
     1442                    fprintf(stderr,"%s\n",val);
     1443#endif
    14151444                  }
    1416 #ifdef DEBUG
    1417                   fprintf(stderr,"%s\n",val);
    1418 #endif
    14191445                  xmlFree(val);
    1420                   free(list[l]);
     1446                  free(list[l]);                 
    14211447                }
    14221448              }
     
    14321458                for(int l=0;l<3;l++){
    14331459#ifdef DEBUG
    1434                   fprintf(stderr,"*** ComplexData %s ***",coms[l]);
     1460                  fprintf(stderr,"*** ComplexData %s ***\n",coms[l]);
    14351461#endif
    14361462                  xmlChar *val=xmlGetProp(cur4,BAD_CAST coms[l]);
     
    14401466                    else
    14411467                      tmpmaps->content=createMap(coms[l],(char*)val);
     1468#ifdef DEBUG
     1469                    fprintf(stderr,"%s\n",val);
     1470#endif
    14421471                  }
    1443 #ifdef DEBUG
    1444                   fprintf(stderr,"%s\n",val);
    1445 #endif
    14461472                  xmlFree(val);
    14471473                }
    14481474              }
     1475
    14491476              map* test=getMap(tmpmaps->content,"encoding");
    1450               if(test==NULL || strcasecmp(test->value,"base64")!=0){
     1477              if(test==NULL){
     1478                if(tmpmaps->content!=NULL)
     1479                  addToMap(tmpmaps->content,"encoding","utf-8");
     1480                else
     1481                  tmpmaps->content=createMap("encoding","utf-8");
     1482                test=getMap(tmpmaps->content,"encoding");
     1483              }
     1484
     1485              if(strcasecmp(test->value,"base64")!=0){
    14511486                xmlChar* mv=xmlNodeListGetString(doc,cur4->xmlChildrenNode,1);
    1452                 if(mv==NULL){
     1487                map* ltmp=getMap(tmpmaps->content,"mimeType");
     1488                if(mv==NULL ||
     1489                   (xmlStrcasecmp(cur4->name, BAD_CAST "ComplexData")==0 &&
     1490                    (ltmp==NULL || strncasecmp(ltmp->value,"text/xml",8)==0) )){
    14531491                  xmlDocPtr doc1=xmlNewDoc(BAD_CAST "1.0");
    14541492                  int buffersize;
    1455                   xmlDocSetRootElement(doc1,cur4->xmlChildrenNode);
     1493                  xmlNodePtr cur5=cur4->children;
     1494                  while(cur5!=NULL &&cur5->type!=XML_ELEMENT_NODE)
     1495                    cur5=cur5->next;
     1496                  xmlDocSetRootElement(doc1,cur5);
    14561497                  xmlDocDumpFormatMemoryEnc(doc1, &mv, &buffersize, "utf-8", 1);
    14571498                  char size[1024];
     
    15781619        xmlNodePtr cur1=cur->children;
    15791620        while(cur1){
    1580           if(xmlStrncasecmp(cur1->name,BAD_CAST "Output",xmlStrlen(cur1->name))==0){
     1621          /**
     1622           * Indentifier
     1623           */
     1624          if(xmlStrncasecmp(cur1->name,BAD_CAST "Identifier",xmlStrlen(cur1->name))==0){
     1625            xmlChar *val=
     1626              xmlNodeListGetString(doc,cur1->xmlChildrenNode,1);
     1627            if(tmpmaps==NULL){
     1628              tmpmaps=(maps*)calloc(1,MAPS_SIZE);
     1629              if(tmpmaps == NULL){
     1630                return errorException(m, _("Unable to allocate memory."), "InternalError");
     1631              }
     1632              tmpmaps->name=strdup((char*)val);
     1633              tmpmaps->content=NULL;
     1634              tmpmaps->next=NULL;
     1635            }
     1636            else
     1637              tmpmaps->name=strdup((char*)val);;
     1638            xmlFree(val);
     1639          }
     1640          /**
     1641           * Title, Asbtract
     1642           */
     1643          else if(xmlStrncasecmp(cur1->name,BAD_CAST "Title",xmlStrlen(cur1->name))==0 ||
     1644                  xmlStrncasecmp(cur1->name,BAD_CAST "Abstract",xmlStrlen(cur1->name))==0){
     1645            xmlChar *val=
     1646              xmlNodeListGetString(doc,cur1->xmlChildrenNode,1);
     1647            if(tmpmaps==NULL){
     1648              tmpmaps=(maps*)calloc(1,MAPS_SIZE);
     1649              if(tmpmaps == NULL){
     1650                return errorException(m, _("Unable to allocate memory."), "InternalError");
     1651              }
     1652              tmpmaps->name=strdup("missingIndetifier");
     1653              tmpmaps->content=createMap((char*)cur1->name,(char*)val);
     1654              tmpmaps->next=NULL;
     1655            }
     1656            else{
     1657              if(tmpmaps->content!=NULL)
     1658                addToMap(tmpmaps->content,
     1659                         (char*)cur1->name,(char*)val);
     1660              else
     1661                tmpmaps->content=
     1662                  createMap((char*)cur1->name,(char*)val);
     1663            }
     1664            xmlFree(val);
     1665          }
     1666          else if(xmlStrncasecmp(cur1->name,BAD_CAST "Output",xmlStrlen(cur1->name))==0){
    15811667            /**
    15821668             * Get every attribute from a Output node
     
    16821768  dumpMaps(request_output_real_format);
    16831769  dumpMap(request_inputs);
     1770  fprintf(stderr,"\n%i\n",i);
    16841771#endif
    16851772
     
    16891776   */
    16901777  char *dfv=addDefaultValues(&request_input_real_format,s1->inputs,m,0);
    1691   if(strcmp(dfv,"")!=0){
     1778  char *dfv1=addDefaultValues(&request_output_real_format,s1->outputs,m,1);
     1779  if(strcmp(dfv1,"")!=0 || strcmp(dfv,"")!=0){
    16921780    char tmps[1024];
    1693     snprintf(tmps,1024,_("The <%s> argument was not specified in DataInputs but defined as requested in ZOO ServicesProvider configuration file, please correct your query or the ZOO Configuration file."),dfv);
     1781    if(strcmp(dfv,"")!=0){
     1782      snprintf(tmps,1024,_("The <%s> argument was not specified in DataInputs but defined as requested in ZOO ServicesProvider configuration file, please correct your query or the ZOO Configuration file."),dfv);
     1783    }
     1784    else if(strcmp(dfv1,"")!=0){
     1785      snprintf(tmps,1024,_("The <%s> argument was specified as Output identifier but not defined in the ZOO Configuration File. Please, correct your query or the ZOO Configuration File."),dfv1);
     1786    }
    16941787    map* tmpe=createMap("text",tmps);
    16951788    addToMap(tmpe,"code","MissingParameterValue");
     
    17111804    return 1;
    17121805  }
    1713   addDefaultValues(&request_output_real_format,s1->outputs,m,1);
    17141806
    17151807  ensureDecodedBase64(&request_input_real_format);
     
    18051897  addToMap(_tmpMaps->content,"status","0");
    18061898  addToMap(_tmpMaps->content,"cwd",ntmp);
     1899  map* ltmp=getMap(request_inputs,"soap");
     1900  if(ltmp!=NULL)
     1901    addToMap(_tmpMaps->content,"soap",ltmp->value);
     1902  else
     1903    addToMap(_tmpMaps->content,"soap","false");
    18071904  if(cgiCookie!=NULL && strlen(cgiCookie)>0){
    18081905    addToMap(_tmpMaps->content,"sessid",strstr(cgiCookie,"=")+1);
Note: See TracChangeset for help on using the changeset viewer.

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