Changeset 889 for trunk/zoo-project


Ignore:
Timestamp:
Jan 3, 2019, 12:44:57 PM (6 years ago)
Author:
knut
Message:

Added some new logging functionality (function logMessage(), macros zooLog, zooLogMsg). Added utility functions setErrorMessage(), hasvalue(), and nonempty() in service.c. Added enum WPSException and arrays WPSExceptionText and WPSExceptionCode (see also function setErrorMessage). New conditional definition of type bool in service.c (to fix issue with bool). Null pointer check in function addToMap. Added missing return values and explicit type casts in some functions. Removed Windows-specific code in function dumpBackFinalFile (zoo_service_loader.c) that may cause error for async raw data output in formats other than XML.

Location:
trunk/zoo-project/zoo-kernel
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/request_parser.c

    r870 r889  
    628628                          if (l == 4 )
    629629                            {
    630                               if ((ltmp==NULL || strncmp (ltmp->value, "POST",4) != 0))
     630                              if ((ltmp==NULL || strncasecmp (ltmp->value, "POST",4) != 0)) //
     631                              //if ((ltmp==NULL || strncmp (ltmp->value, "POST",4) != 0))
    631632                                {
    632633                                  if (loadRemoteFile
     
    11681169    }
    11691170  }
     1171  return 0;
    11701172}
    11711173
     
    14681470
    14691471  xmlInitParser ();
    1470   xmlDocPtr doc = xmlReadMemory (post, cgiContentLength, "input_request.xml", NULL, XML_PARSE_RECOVER);
     1472  //xmlDocPtr doc = xmlReadMemory (post, cgiContentLength, "input_request.xml", NULL, XML_PARSE_RECOVER);
     1473  xmlDocPtr doc = xmlReadMemory (post, cgiContentLength, "input_request.xml", NULL, XML_PARSE_RECOVER | XML_PARSE_HUGE); //
    14711474
    14721475  /**
  • trunk/zoo-project/zoo-kernel/response_print.c

    r820 r889  
    26112611    map* tmpIV=getMap(request_inputs1,"RawDataOutput");
    26122612    if(tmpIV!=NULL){
    2613       tmpI=getMaps(request_outputs,tmpIV->value);
     2613      tmpI=getMaps(request_outputs,tmpIV->value);         
    26142614    }
    26152615    if(tmpI==NULL)
    26162616      tmpI=request_outputs;
     2617
    26172618    elements* e=getElements(s->outputs,tmpI->name);
    26182619    if(e!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){
     
    26212622      map *gfile=getMap(tmpI->content,"generated_file");
    26222623      if(gfile!=NULL){
    2623         gfile=getMap(tmpI->content,"expected_generated_file");
     2624        gfile=getMap(tmpI->content,"expected_generated_file"); 
    26242625        if(gfile==NULL){
    26252626          gfile=getMap(tmpI->content,"generated_file");
     
    26272628        readGeneratedFile(m,tmpI->content,gfile->value);
    26282629      }
    2629       toto=getMap(tmpI->content,"value");
     2630      toto=getMap(tmpI->content,"value");       
    26302631      if(toto==NULL){
    26312632        char tmpMsg[1024];
     
    26332634        errorException(m,tmpMsg,"InvalidParameterValue","RawDataOutput");
    26342635        return;
    2635       }
    2636       map* fname=getMapFromMaps(tmpI,tmpI->name,"filename");
     2636      }   
     2637      map* fname=getMapFromMaps(tmpI,tmpI->name,"filename");             
    26372638      if(fname!=NULL)
    26382639        printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value);
  • trunk/zoo-project/zoo-kernel/server_internal.c

    r820 r889  
    942942    (char *)
    943943    malloc ((strlen (r_inputs->value) + strlen (pid) + 7) * sizeof (char));
    944   sprintf (fbkpid, "%s/%s.pid", r_inputs->value, pid);
     944  sprintf (fbkpid, "%s/%s.pid", r_inputs->value, pid); 
    945945  FILE* f0 = fopen (fbkpid, "r");
    946946  if(f0!=NULL){
     
    970970  }else{
    971971    map* statusInfo=createMap("JobID",pid);
    972     if(isRunning(conf,pid)>0){
     972    if(isRunning(conf,pid)>0){         
    973973      if(strncasecmp(req,"GetResult",strlen(req))==0){
    974974        errorException (conf, _("The result for the requested JobID has not yet been generated. "),
  • trunk/zoo-project/zoo-kernel/service.c

    r868 r889  
    2525#include "service.h"
    2626
     27// knut: time utilities required for new log function (logMessage)
     28#include <ctime>
     29#include <chrono>
     30#include <process.h>
    2731
    2832#if defined(_MSC_VER) && _MSC_VER < 1800
     
    450454 */
    451455void addToMap(map* m,const char* n,const char* v){
    452   if(hasKey(m,n)==false){
    453     map* _cursor=m;
    454     while(_cursor->next!=NULL){
    455       _cursor=_cursor->next;
    456     }
    457     _cursor->next=createMap(n,v);
    458   }
    459   else{
    460     map *tmp=getMap(m,n);
    461     if(tmp->value!=NULL)
    462       free(tmp->value);
    463     tmp->value=zStrdup(v);
     456  if (m != NULL) { // knut: add NULL-pointer check
     457    if(hasKey(m,n)==false){
     458      map* _cursor=m;
     459      while(_cursor->next!=NULL){
     460        _cursor=_cursor->next;
     461      }
     462      _cursor->next=createMap(n,v);
     463    }
     464    else{
     465      map *tmp=getMap(m,n);
     466      if(tmp->value!=NULL)
     467        free(tmp->value);
     468      tmp->value=zStrdup(v);
     469    }
    464470  }
    465471}
     
    15971603}
    15981604
     1605/**
     1606 * Verify that a map has a value
     1607 *
     1608 * @param map pointer to map that should be checked
     1609 * @return true if map has a value or false if value is missing/empty/NULL
     1610 */
     1611bool nonempty( map* map ) {
     1612    return ( map != NULL && map->value != NULL && strlen(map->value) > 0 && strcmp(map->value, "NULL") != 0 );
     1613}
     1614
     1615/**
     1616 * Verify that a particular map value exists in a maps
     1617 * data structure, and obtain that value
     1618 *
     1619 * @param source pointer to maps structure
     1620 * @param node name of maps node to search
     1621 * @param key name of map node to find
     1622 * @param address to the map* if it exists, otherwise NULL
     1623 * @return true if map has a value or false if value is missing/NULL
     1624 */
     1625bool hasvalue( maps* source, const char* node, const char* key, map** kvp ) {
     1626    *kvp = getMapFromMaps(source, node, key);
     1627    return ( *kvp != NULL && (*kvp)->value != NULL &&
     1628             strlen((*kvp)->value) > 0 && strcmp((*kvp)->value, "NULL") != 0 );
     1629}
     1630
     1631/*
     1632 * Set error message in configuration maps
     1633 *
     1634 * @param conf reference to configuration maps
     1635 * @param service name of service
     1636 * @param exc WPSException code
     1637 * @param message exception text (default: exception text in WPS specification)
     1638 */
     1639void setErrorMessage( maps*& conf, const char* service, WPSException exc, const char* message ) {
     1640 
     1641  if (message == NULL) {
     1642    message = WPSExceptionText[exc];
     1643  }
     1644
     1645        size_t len = strlen( service ) + strlen(": ") + strlen( message ) + strlen(": ") + strlen(WPSExceptionCode[exc]) + 16;
     1646        char* msg = (char*) malloc( len * sizeof(char) );
     1647
     1648        if (msg != NULL) {
     1649                snprintf( msg, len*sizeof(char), "\n%s: %s: %s\n", service, message, WPSExceptionCode[exc] );
     1650                setMapInMaps( conf, "lenv", "message", msg );
     1651                free( msg );
     1652        }       
     1653}
     1654
     1655void logMessage(const char* source, const char* function, int line, const char* file, const char* message) { //, const char* source, const char* function, int line) {
     1656 
     1657  size_t msglen = 512;
     1658  const char empty[] = "";
     1659 
     1660  FILE* log;
     1661 
     1662  // system time, process time [nanoseconds]   
     1663  unsigned long long sys_t, proc_t;
     1664 
     1665  // processor time consumed by the program:
     1666  clock_t t = clock();
     1667   
     1668  // system time:
     1669  std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
     1670 
     1671  std::time_t now_t = std::chrono::system_clock::to_time_t( now );
     1672  std::tm* tm = localtime( &now_t );
     1673        char* str = asctime(tm);
     1674  str[strlen(str)-1] = '\0'; // remove newline
     1675 
     1676  sys_t = std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count();
     1677  //proc_t = (unsigned long long)(1.0e9*t/CLOCKS_PER_SEC);
     1678  proc_t = t;
     1679 
     1680  if ( message != NULL ) {
     1681     msglen += strlen(message);
     1682  } 
     1683  else {
     1684    message = empty;
     1685  }
     1686  //getLastErrorMessage(); // cgiScriptName 
     1687  char* text = (char*) malloc( sizeof(char)*msglen );
     1688 
     1689  snprintf( text, msglen, "pid: %d %s line %d %s() %s systime: %lld ns ticks: %lld %s\n",
     1690    _getpid(), source, line, function, str, sys_t, proc_t, message ); // __FILE__ __LINE__ __func__ //
     1691 
     1692  if ( file != NULL && (log = fopen( file, "a+" )) != NULL ) {
     1693    fputs( text, log );
     1694    fclose( log );
     1695  }
     1696  else {
     1697    #ifdef MSG_LOG_FILE
     1698    if ( (log = fopen( MSG_LOG_FILE, "a+" )) != NULL ) {
     1699      fputs( text, log );
     1700      fclose( log );
     1701    }     
     1702    #endif
     1703  }
     1704 
     1705  if ( text != NULL ) free( text );
     1706}
     1707
     1708// knut:
     1709// Example:
     1710// zooLog;
     1711// zooLogMsg(NULL, getLastErrorMessage());
     1712// zooLogMsg(log.txt, getLastErrorMessage());
     1713
    15991714#ifdef WIN32
    16001715#ifndef USE_MS
  • trunk/zoo-project/zoo-kernel/service.h

    r847 r889  
    4040#endif
    4141
     42// knut: add bool if necessary
     43#ifndef __cplusplus
     44  #ifndef WIN32
     45    #include <stdbool.h>
     46  #else
     47    typedef int bool;
     48    #define false 0
     49    #define true 1     
     50  #endif
     51#endif
     52#ifndef __bool_true_false_are_defined
     53  #define __bool_true_false_are_defined 1
     54#endif
     55
    4256#ifdef WIN32
    4357#define strncasecmp _strnicmp
     
    4761#define snprintf _snprintf
    4862#endif
     63/* knut: see new definition of bool above
    4964#if defined(_MSC_VER) && _MSC_VER < 1800
    5065#define false 0
     
    5267#define bool int
    5368#endif
     69*/
    5470#define zStrdup _strdup
    5571#define zMkdir _mkdir
     
    124140#ifndef WIN32
    125141#include <ctype.h>
    126 #include <stdbool.h>
     142//#include <stdbool.h> // knut: see new definition of bool above
    127143#endif
    128144
     
    274290    struct registry* next; //!< the next registry pointer
    275291  } registry;
     292 
     293  // knut
     294  enum WPSException {
     295    /*
     296    * StatusOK is not a WPS exception, it is added
     297    * here for convenience.
     298    */     
     299    StatusOK,                 
     300    /*
     301    * See WPS 1.0 specification, Table 38 and Table 62.
     302    */
     303    MissingParameterValue,   
     304    InvalidParameterValue,
     305    NoApplicableCode,
     306    NotEnoughStorage,
     307    ServerBusy,
     308    FileSizeExceeded,
     309    StorageNotSupported,
     310    VersionNegotiationFailed,
     311    /*
     312    * See WPS 2.0 specification, Tables 41, 46, 48, and 50.
     313    */
     314    NoSuchProcess,
     315    NoSuchMode,
     316    NoSuchInput,
     317    NoSuchOutput,
     318    DataNotAccessible,
     319    SizeExceeded,
     320    TooManyInputs,
     321    TooManyOutputs,
     322    NoSuchFormat,
     323    WrongInputData,
     324    InternalServerError,
     325    NoSuchJob,
     326    ResultNotReady
     327  };
     328 
     329  static const char* const WPSExceptionCode[] = {
     330    "StatusOK",
     331    "MissingParameterValue",
     332    "InvalidParameterValue",
     333    "NoApplicableCode",
     334    "NotEnoughStorage",
     335    "ServerBusy",
     336    "FileSizeExceeded",
     337    "StorageNotSupported",
     338    "VersionNegotiationFailed",
     339    "NoSuchProcess",
     340    "NoSuchMode",
     341    "NoSuchInput",
     342    "NoSuchOutput",
     343    "DataNotAccessible",
     344    "SizeExceeded",
     345    "TooManyInputs",
     346    "TooManyOutputs",
     347    "NoSuchFormat",
     348    "WrongInputData",
     349    "InternalServerError",
     350    "NoSuchJob",
     351    "ResultNotReady"   
     352  };     
     353
     354  static const char* const WPSExceptionText[] = {
     355    "No problem detected",
     356    "Operation request does not include a parameter value, and this server did not declare a default value for that parameter.",
     357    "Operation request contains an invalid parameter value.",
     358    "No other exceptionCode specified by this service and server applies to this exception.",
     359    "The server does not have enough space available to store the inputs and outputs associated with the request.",
     360    "The server is too busy to accept and queue the request at this time.",
     361    "The file size of one of the input parameters was too large for this process to handle.",
     362    "Execute operation request included transmission=”reference” for one of the outputs, but storage is not offered by this server.",
     363    "Service version for a ComplexData xlink:href input was not supported by the referenced server, and version negotiation failed.",
     364    "One of the identifiers passed does not match with any of the processes offered by this server.",
     365    "The process does not permit the desired execution mode.",
     366    "One or more of the input identifiers passed does not match with any of the input identifiers of this process.",
     367    "One or more of the output identifiers passed does not match with any of the input identifiers of this process.",
     368    "One of the referenced input data sets was inaccessible.",
     369    "The size of one of the input parameters was too large for this process to handle.",
     370    "Too many input items have been specified.",
     371    "Too many output items have been specified.",
     372    "One or more of the input or output formats specified in the request did not match with any of the formats defined for that particular input or output.",
     373    "One or more of inputs for which the service was able to retrieve the data but could not read it.",
     374    "",
     375    "The JobID from the request does not match any of the Jobs running on this server.",
     376    "The result for the requested JobID has not yet been generated."
     377  };
    276378
    277379  ZOO_DLL_EXPORT void _dumpMap(map*);
     
    340442  ZOO_DLL_EXPORT int snprintf(char *buffer, size_t n, const char *format, ...);
    341443#endif
     444
     445  // knut: some new utility functions; logMessage is primarily intended for debugging   
     446  ZOO_DLL_EXPORT bool nonempty(map* map);
     447  ZOO_DLL_EXPORT bool hasvalue(maps* source, const char* node, const char* key, map** kvp);
     448  ZOO_DLL_EXPORT void setErrorMessage(maps*& conf, const char* service, WPSException exc, const char* message = NULL);
     449  ZOO_DLL_EXPORT void logMessage(const char* source, const char* function, int line, const char* file = NULL, const char* message = NULL); 
     450  #define zooLogMsg(file,message) logMessage(__FILE__, __func__, __LINE__, (file), (message))
     451  #define zooLog logMessage(__FILE__, __func__, __LINE__) 
     452 
    342453#ifdef __cplusplus
    343454}
  • trunk/zoo-project/zoo-kernel/service_internal.c

    r788 r889  
    243243 * @param conf the map containing the setting of the main.cfg file
    244244 */
    245 void unhandleStatus(maps *conf){
     245void unhandleStatus(maps *conf){       
    246246  map* r_inputs = getMapFromMaps (conf, "main", "tmpPath");
    247247  map* usid = getMapFromMaps (conf, "lenv", "usid");
  • trunk/zoo-project/zoo-kernel/service_internal_ms.h

    r586 r889  
    3838#endif
    3939
     40
    4041#include <mapserver.h>
    4142
  • trunk/zoo-project/zoo-kernel/ulinet.c

    r841 r889  
    9191        ;
    9292#endif
    93     tmp=strtok(buffer,";");
     93    tmp=strtok((char*) buffer,";"); // knut: added cast to char*
    9494    cnt=0;
    9595    psInternet=(_HINTERNET *)data;
     
    247247  char *token, *saveptr;
    248248  int cnt;
    249   char* host; 
    250   token = strtok_r (url, "//", &saveptr);
     249  char* host;
     250 
     251  // knut: make a copy of url since strtok family modifies first argument and cannot be used on constant strings 
     252  char* urlcpy = (char*) malloc(sizeof(char)*(strlen(url)+1));
     253  urlcpy = strncpy(urlcpy, url, strlen(url)+1); // since count > strlen(url), a null character is properly appended
     254 
     255  //token = strtok_r (url, "//", &saveptr);
     256  token = strtok_r (urlcpy, "//", &saveptr);   // knut
    251257  cnt=0;
    252258  while(token!=NULL && cnt<=1){
     
    257263    if(cnt==1 && strstr(protectedHosts,token)!=NULL){
    258264      fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,strstr(protectedHosts,token));
     265      free(urlcpy);
    259266      return 1;
    260267    }
     
    262269    cnt+=1;
    263270  }
     271  free(urlcpy);
    264272  return 0;
    265273}
  • trunk/zoo-project/zoo-kernel/ulinet.h

    r834 r889  
    4444#include "jsapi.h"
    4545#endif
     46/* knut: see new definition of bool in service.h
    4647#ifndef bool
    4748#define bool int
     
    5152#define false 0
    5253#endif
     54*/
    5355
    5456#define MAX_REQ 50
     
    151153  typedef size_t* LPDWORD;
    152154#endif
     155/* knut: see new definition of bool in service.h
    153156#ifndef bool
    154157#define bool int
    155158#endif
     159*/
    156160
    157161#  define CHECK_INET_HANDLE(h) (h.handle != 0)
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r844 r889  
    159159  lockShm (lid);
    160160#endif
    161   FILE *f3 = fopen (fbkp, "wb+");
    162   free (fbkp);
     161  FILE *f3 = fopen (fbkp, "wb+"); 
     162  free (fbkp); 
    163163  fseek (f2, 0, SEEK_END);
    164164  long flen = ftell (f2);
    165165  fseek (f2, 0, SEEK_SET);
    166166  char *tmps1 = (char *) malloc ((flen + 1) * sizeof (char));
    167   fread (tmps1, flen, 1, f2);
     167  fread (tmps1, flen, 1, f2); 
    168168#ifdef WIN32
    169   char *pchr=strrchr(tmps1,'>');
    170   flen=strlen(tmps1)-strlen(pchr)+1;
    171   tmps1[flen]=0;
    172 #endif
     169  /* knut: I think this block can be dropped; pchr may be NULL if result is not in XML format
     170  char *pchr=strrchr(tmps1,'>');   
     171  flen=strlen(tmps1)-strlen(pchr)+1; 
     172  tmps1[flen]=0; 
     173  */
     174#endif 
    173175  fwrite (tmps1, 1, flen, f3);
     176  free(tmps1);
    174177  fclose (f2);
    175   fclose (f3);
     178  fclose (f3); 
    176179  return 1;
    177180}
     
    22182221          addToMap(bmap->content,"sid",tmpm->value);
    22192222          addIntToMap(bmap->content,"pid",getpid());
    2220          
     2223                 
    22212224          // Create PID file referencing the OS process identifier
    22222225          fbkpid =
     
    23092312            if(dumpBackFinalFile(m,fbkp,fbkp1)<0)
    23102313              return -1;
    2311             unlink (fbkpid);
     2314            unlink (fbkpid);           
    23122315            unhandleStatus (m);
    23132316            freeMaps (&m);
     
    23642367  signal (SIGABRT, donothing);
    23652368#endif
    2366 
    23672369  if (((int) getpid ()) != cpid || cgiSid != NULL)
    2368     {
     2370    {     
    23692371      fclose (stdout);
    23702372      fclose (stderr);
     
    23722374      fclose (f0);
    23732375      fclose (f1);
    2374 
    2375       if(dumpBackFinalFile(m,fbkp,fbkp1)<0)
    2376         return -1;
    2377       unlink (fbkpid);
     2376         
     2377          if (dumpBackFinalFile(m, fbkp, fbkp1) < 0)
     2378                  return -1;
     2379       
     2380      unlink (fbkpid);   
    23782381      switch(eres){
    23792382      default:
     
    23872390        break;
    23882391      }     
    2389 #ifndef RELY_ON_DB
     2392#ifndef RELY_ON_DB       
    23902393      dumpMapsToFile(bmap,fbkpres,1);
    23912394      removeShmLock (m, 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