Ignore:
Timestamp:
Feb 12, 2015, 5:01:11 PM (10 years ago)
Author:
djay
Message:

Add initial doxygen comments in some C files, for future documentation generation.

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

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/otbZooWatcher.h

    r558 r579  
    2121#include "service.h"
    2222
     23/**
     24 * Observer used to access the ongoing status of a running OTB Application
     25 */
    2326class /*ITK_EXPORT*/ ZooWatcher : public otb::FilterWatcherBase
    2427{
    2528public:
    2629
    27   /** Constructor. Takes a ProcessObject to monitor and an optional
    28    * comment string that is prepended to each event message. */
     30  /**
     31   * Constructor
     32   * @param process the itk::ProcessObject to monitor
     33   * @param comment comment string that is prepended to each event message
     34   */
    2935  ZooWatcher(itk::ProcessObject* process,
    3036                        const char *comment = "");
    3137
     38  /**
     39   * Constructor
     40   * @param process the itk::ProcessObject to monitor
     41   * @param comment comment string that is prepended to each event message
     42   */
    3243  ZooWatcher(itk::ProcessObject* process,
    3344                        const std::string& comment = "");
     
    3647  ZooWatcher();
    3748
    38   /** Get/Set/Free Configuration maps */
     49  /**
     50   * Copy the original conf in the m_Conf property
     51   *
     52   * @param conf the maps pointer to copy
     53   */
    3954  void SetConf(maps **conf)
    4055  {
    4156    m_Conf=dupMaps(conf);
    4257  }
     58  /** 
     59   * Get Configuration maps (m_Conf)
     60   * @return the m_Conf property
     61   */
    4362  const maps& GetConf() const
    4463  {
    4564    return *m_Conf;
    4665  }
     66  /** 
     67   * Free Configuration maps (m_Conf)
     68   */
    4769  void FreeConf(){
    4870    freeMaps(&m_Conf);
  • trunk/zoo-project/zoo-kernel/service.h

    r576 r579  
    1 /**
     1/*
    22 * Author : Gérald FENOY
    33 *
     
    6060}
    6161#else
     62/**
     63 * The crossplatform strdup alias
     64 */
    6265#define zStrdup strdup
     66/**
     67 * The crossplatform mkdir alias
     68 */
    6369#define zMkdir mkdir
     70/**
     71 * The crossplatform open alias
     72 */
    6473#define zOpen open
     74/**
     75 * The crossplatform write alias
     76 */
    6577#define zWrite write
     78/**
     79 * The crossplatform sleep alias
     80 */
    6681#define zSleep sleep
     82/**
     83 * The crossplatform gettimeofday alias
     84 */
    6785#define zGettimeofday gettimeofday
     86/**
     87 * The crossplatform timeval alias
     88 */
    6889#define ztimeval timeval
    6990#endif
     
    87108#endif
    88109#ifndef true
     110  /**
     111   * Local true definition
     112   */
    89113#define true 1
     114  /**
     115   * Local false definition
     116   */
    90117#define false -1
    91118#endif
    92119#endif
    93120
     121/**
     122 * The global accepted status for a service
     123 */
    94124#define SERVICE_ACCEPTED 0
     125/**
     126 * The global started status for a service
     127 */
    95128#define SERVICE_STARTED 1
     129/**
     130 * The global paused status for a service
     131 */
    96132#define SERVICE_PAUSED 2
     133/**
     134 * The global succeeded status for a service
     135 */
    97136#define SERVICE_SUCCEEDED 3
     137/**
     138 * The global failed status for a service
     139 */
    98140#define SERVICE_FAILED 4
    99141
     142/**
     143 * The memory size to create an elements
     144 */
    100145#define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+sizeof(elements*))
     146/**
     147 * The memory size to create a map
     148 */
    101149#define MAP_SIZE (2*sizeof(char*))+sizeof(NULL)
     150/**
     151 * The memory size to create an iotype
     152 */
    102153#define IOTYPE_SIZE MAP_SIZE+sizeof(NULL)
     154/**
     155 * The memory size to create a maps
     156 */
    103157#define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE
     158/**
     159 * The memory size to create a service
     160 */
    104161#define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*)
    105162
     
    116173
    117174  /**
    118    * \struct map
    119    * \brief KVP linked list
     175   * KVP linked list
    120176   *
    121177   * Deal with WPS KVP (name,value).
     
    138194
    139195  /**
    140    * \struct maps
    141    * \brief linked list of map pointer
     196   * linked list of map pointer
    142197   *
    143198   * Small object to store WPS KVP set.
     
    154209
    155210  /**
    156    * \brief Dump a map on stderr
     211   * Dump a map on stderr
     212   *
     213   * @param t the map to dump
    157214   */
    158215  static void _dumpMap(map* t){
     
    166223  }
    167224
     225  /**
     226   * Dump a map on stderr, see _dumpMap()
     227   *
     228   * @param t the map to dump
     229   */
    168230  static void dumpMap(map* t){
    169231    map* tmp=t;
     
    174236  }
    175237
     238  /**
     239   * Dump a map to a file
     240   *
     241   * @param t the map to dump to file
     242   * @param file the file to store the map
     243   */
    176244  static void dumpMapToFile(map* t,FILE* file){
    177245    map* tmp=t;
     
    185253  }
    186254
     255  /**
     256   * Dump a maps on stderr, see dumpMap().
     257   *
     258   * @param m the map to dump
     259   */
    187260  static void dumpMaps(maps* m){
    188261    maps* tmp=m;
     
    194267  }
    195268
     269  /**
     270   * Dump a maps to a file, see dumpMapToFile().
     271   *
     272   * @param m the map to dump
     273   * @param file_path the full path to the file name to store the map
     274   */
    196275  static void dumpMapsToFile(maps* m,char* file_path){
    197276    FILE* file=fopen(file_path,"w");
     
    205284  }
    206285
     286  /**
     287   * Create a new map
     288   *
     289   * @param name the key to add to the map
     290   * @param value the corresponding value to add to the map
     291   * @return the allocated map
     292   */
    207293  static map* createMap(const char* name,const char* value){
    208294    map* tmp=(map *)malloc(MAP_SIZE);
     
    213299  }
    214300
     301  /**
     302   * Count number of map in a map
     303   *
     304   * @param m the maps to count
     305   * @return number of map in a map
     306   */
    215307  static int count(map* m){
    216308    map* tmp=m;
     
    223315  }
    224316   
     317  /**
     318   * Verify if a key exist in a map
     319   *
     320   * @param m the map to search for the key
     321   * @param key the key to search in the map
     322   * @return true if the key wwas found, false in other case
     323   */
    225324  static bool hasKey(map* m,const char *key){
    226325    map* tmp=m;
     
    236335  }
    237336
     337  /**
     338   * Access a specific maps
     339   *
     340   * @param m the maps to search for the key
     341   * @param key the key to search in the maps
     342   * @return a pointer on the maps found or NULL if not found
     343   */
    238344  static maps* getMaps(maps* m,const char *key){
    239345    maps* tmp=m;
     
    247353  }
    248354
     355  /**
     356   * Access a specific map
     357   *
     358   * @param m the map to search for the key
     359   * @param key the key to search in the map
     360   * @return a pointer on the map found or NULL if not found
     361   */
    249362  static map* getMap(map* m,const char *key){
    250363    map* tmp=m;
     
    259372
    260373
     374  /**
     375   * Access the last map
     376   *
     377   * @param m the map to search for the lastest map
     378   * @return a pointer on the lastest map found or NULL if not found
     379   */
    261380  static map* getLastMap(map* m){
    262381    map* tmp=m;
     
    270389  }
    271390
     391  /**
     392   * Access a specific map from a maps
     393   *
     394   * @param m the maps to search for the key
     395   * @param key the key to search in the maps
     396   * @param subkey the key to search in the map (found for the key, if any)
     397   * @return a pointer on the map found or NULL if not found
     398   */
    272399  static map* getMapFromMaps(maps* m,const char* key,const char* subkey){
    273400    maps* _tmpm=getMaps(m,key);
     
    279406  }
    280407
    281 
     408  /**
     409   * Free allocated memory of a map.
     410   * Require to call free on mo after calling this function.
     411   *
     412   * @param mo the map to free
     413   */
    282414  static void freeMap(map** mo){
    283415    map* _cursor=*mo;
     
    295427  }
    296428
     429  /**
     430   * Free allocated memory of a maps.
     431   * Require to call free on mo after calling this function.
     432   *
     433   * @param mo the maps to free
     434   */
    297435  static void freeMaps(maps** mo){
    298436    maps* _cursor=*mo;
     
    314452
    315453  /**
    316    * \brief Not named linked list
     454   * Not named linked list
    317455   *
    318456   * Used to store informations about formats, such as mimeType, encoding ...
     
    328466
    329467  /**
    330    * \brief Metadata information about input or output.
     468   * Metadata information about input or output.
    331469   *
    332470   * The elements are used to store metadata informations defined in the ZCFG.
    333471   *
    334    * An elements is defined as :
     472   * An elements is defined as:
    335473   *  - a name,
    336474   *  - a content map,
     
    351489  } elements;
    352490
     491  /**
     492   * Metadata informations about a full Service.
     493   *
     494   * An element is defined as:
     495   *  - a name,
     496   *  - a content map,
     497   *  - a metadata map,
     498   *  - an inputs elements
     499   *  - an outputs elements
     500   */
    353501  typedef struct service{
    354502    char* name;
     
    359507  } service;
    360508
     509  /**
     510   * Multiple services chained list.
     511   */
    361512  typedef struct services{
    362513    struct service* content;
     
    364515  } services;
    365516
     517  /**
     518   * Verify if an elements contains a name equal to the given key.
     519   *
     520   * @param e the elements to search for the key
     521   * @param key the elements name to search
     522   * @return true if the elements contains the name, false in other cases.
     523   */
    366524  static bool hasElement(elements* e,const char* key){
    367525    elements* tmp=e;
     
    374532  }
    375533
     534  /**
     535   * Access a specific elements named key.
     536   *
     537   * @param m the elements to search
     538   * @param key the elements name to search
     539   * @return a pointer to the specific element if found, NULL in other case.
     540   */
    376541  static elements* getElements(elements* m,char *key){
    377542    elements* tmp=m;
     
    384549  }
    385550
    386 
     551  /**
     552   * Free allocated memory of an iotype.
     553   * Require to call free on i after calling this function.
     554   *
     555   * @param i the iotype to free
     556   */
    387557  static void freeIOType(iotype** i){
    388558    iotype* _cursor=*i;
     
    397567  }
    398568
     569  /**
     570   * Free allocated memory of an elements.
     571   * Require to call free on e after calling this function.
     572   *
     573   * @param e the iotype to free
     574   */
    399575  static void freeElements(elements** e){
    400576    elements* tmp=*e;
     
    423599  }
    424600
     601  /**
     602   * Free allocated memory of a service.
     603   * Require to call free on e after calling this function.
     604   *
     605   * @param s the service to free
     606   */
    425607  static void freeService(service** s){
    426608    service* tmp=*s;
     
    443625  }
    444626
     627  /**
     628   * Add key value pair to an existing map.
     629   *
     630   * @param m the map to add the KVP
     631   * @param n the key to add
     632   * @param v the corresponding value to add
     633   */
    445634  static void addToMap(map* m,const char* n,const char* v){
    446635    if(hasKey(m,n)==false){
     
    459648  }
    460649
     650  /**
     651   * Add a key and a binary value to an existing map.
     652   *
     653   * @param m the map to add the KVP
     654   * @param n the key to add
     655   * @param v the corresponding value to add
     656   * @param size the size of the given value
     657   */
    461658  static void addToMapWithSize(map* m,const char* n,const char* v,int size){
    462659    if(hasKey(m,n)==false){
     
    479676  }
    480677
     678  /**
     679   * Add a map at the end of another map.
     680   *
     681   * @param mo the map to add mi
     682   * @param mi the map to add to mo
     683   */
    481684  static void addMapToMap(map** mo,map* mi){
    482685    map* tmp=mi;
     
    511714  }
    512715
     716  /**
     717   * Add a map to iotype.
     718   *
     719   * @param io the iotype to add the map
     720   * @param mi the map to add to io
     721   */
    513722  static void addMapToIoType(iotype** io,map* mi){
    514723    iotype* tmp=*io;
     
    522731  }
    523732
     733  /**
     734   * Access a specific map or set its value.
     735   *
     736   * @param m the map to search for the key
     737   * @param key the key to search/add in the map
     738   * @param value the value to add if the key does not exist
     739   * @return a pointer on the map found or NULL if not found
     740   */
    524741  static map* getMapOrFill(map** m,const char *key,const char* value){
    525742    map* tmp=*m;
     
    536753  }
    537754
     755  /**
     756   * Verify if a map is contained in another map.
     757   *
     758   * @param m the map to search for i
     759   * @param i the map to search in m
     760   * @return true if i was found in m, false in other case
     761   */
    538762  static bool contains(map* m,map* i){
    539763    while(i!=NULL){     
     
    552776  }
    553777
     778  /**
     779   * Access a specific iotype from an elements.
     780   *
     781   * @param e the elements to search for the name
     782   * @param name the name to search in the elements e
     783   * @param values the map to verify it was contained in the defaults or
     784   *  supported content of the elements e
     785   * @return a pointer on the iotype found or NULL if not found
     786   */
    554787  static iotype* getIoTypeFromElement(elements* e,char *name, map* values){
    555788    elements* cursor=e;
     
    572805  }
    573806
     807  /**
     808   * Load binary values from a map (in) and add them to another map (out)
     809   *
     810   * @param out the map to add binaries values
     811   * @param in the map containing the binary values to add ti out
     812   * @param pos index of the binary in an array (in case of "MapArray")
     813   */
    574814  static void loadMapBinary(map** out,map* in,int pos){
    575815    map* size=getMap(in,"size");
     
    598838  }
    599839 
     840  /**
     841   * Load binary values from a map (in) and add them to another map (out).
     842   * This function will take care of MapArray.
     843   * @see loadMapBinary
     844   *
     845   * @param out the map to add binaries values
     846   * @param in the map containing the binary values to add ti out
     847   */
    600848  static void loadMapBinaries(map** out,map* in){
    601849    map* size=getMap(in,"size");
     
    613861  }
    614862
     863  /**
     864   * Duplicate a Maps
     865   *
     866   * @param mo the maps to clone
     867   * @return the allocated maps containing a copy of the mo maps
     868   */
    615869  static maps* dupMaps(maps** mo){
    616870    maps* _cursor=*mo;
     
    631885  }
    632886
     887  /**
     888   * Add a maps at the end of another maps.
     889   *
     890   * @see addMapToMap, dupMaps, getMaps
     891   * @param mo the maps to add mi
     892   * @param mi the maps to add to mo
     893   */
    633894  static void addMapsToMaps(maps** mo,maps* mi){
    634895    maps* tmp=mi;
     
    652913  }
    653914
     915  /**
     916   * Access a specific map array element
     917   *
     918   * @param m the map to search for the key
     919   * @param key the key to search in the map
     920   * @param index of the MapArray
     921   * @return a pointer on the map found or NULL if not found
     922   */
    654923  static map* getMapArray(map* m,const char* key,int index){
    655924    char tmp[1024];
     
    670939
    671940
     941  /**
     942   * Add a key value in a MapArray for a specific index
     943   *
     944   * @param m the map to search for the key
     945   * @param key the key to search in the map
     946   * @param index the index of the MapArray
     947   * @param value the value to set in the MapArray
     948   * @return a pointer on the map found or NULL if not found
     949   */
    672950  static void setMapArray(map* m,const char* key,int index,const char* value){
    673951    char tmp[1024];
     
    697975  }
    698976
     977  /**
     978   * Access the map "type"
     979   *
     980   * @param mt the map
     981   * @return a pointer on the map for mimeType/dataType/CRS if found, NULL in
     982   *  other case
     983   */
    699984  static map* getMapType(map* mt){
    700985    map* tmap=getMap(mt,(char *)"mimeType");
     
    711996  }
    712997
     998  /**
     999   * Add a Maps containing a MapArray to a Maps
     1000   *
     1001   * @see getMapType
     1002   * @param mo the maps
     1003   * @param mi the maps
     1004   * @param typ the map "type"
     1005   * @return
     1006   */
    7131007  static int addMapsArrayToMaps(maps** mo,maps* mi,char* typ){
    7141008    maps* tmp=mi;   
     
    7591053  }
    7601054
     1055  /**
     1056   * Set a key value pair to a map contained in a Maps
     1057   *
     1058   * @param m the maps
     1059   * @param key the maps name
     1060   * @param subkey the map name included in the maps corresponding to key
     1061   * @param value the corresponding value to add in the map
     1062   */
    7611063  static void setMapInMaps(maps* m,const char* key,const char* subkey,const char *value){
    7621064    maps* _tmpm=getMaps(m,key);
     
    7871089  }
    7881090
    789 
     1091  /**
     1092   * Dump an elements on stderr
     1093   *
     1094   * @param e the elements to dump
     1095   */
    7901096  static void dumpElements(elements* e){
    7911097    elements* tmp=e;
     
    8181124  }
    8191125
     1126  /**
     1127   * Dump an elements on stderr using the YAML syntaxe
     1128   *
     1129   * @param e the elements to dump
     1130   */
    8201131  static void dumpElementsAsYAML(elements* e){
    8211132    elements* tmp=e;
     
    8891200  }
    8901201
    891 
     1202  /**
     1203   * Duplicate an elements
     1204   *
     1205   * @param e the elements to clone
     1206   * @return the allocated elements containing a copy of the elements e
     1207   */
    8921208  static elements* dupElements(elements* e){
    8931209    elements* cursor=e;
     
    9391255  }
    9401256
     1257  /**
     1258   * Add an elements to another elements.
     1259   *
     1260   * @see dupElements
     1261   * @param m the elements to add the e
     1262   * @param e the elements to be added to m
     1263   */
    9411264  static void addToElements(elements** m,elements* e){
    9421265    elements* tmp=e;
     
    9481271  }
    9491272
     1273  /**
     1274   * Dump a service on stderr
     1275   *
     1276   * @param s the service to dump
     1277   */
    9501278  static void dumpService(service* s){
    9511279    fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",s->name);
     
    9671295  }
    9681296
     1297  /**
     1298   * Dump a service on stderr using the YAML syntaxe
     1299   *
     1300   * @param s the service to dump
     1301   */
    9691302  static void dumpServiceAsYAML(service* s){
    9701303    int i;
     
    9941327  }
    9951328
     1329  /**
     1330   * Convert a maps to a char*** (only used for Fortran support)
     1331   *
     1332   * @param m the maps to convert
     1333   * @param c the resulting array
     1334   */
    9961335  static void mapsToCharXXX(maps* m,char*** c){
    9971336    maps* tm=m;
     
    10241363  }
    10251364
     1365  /**
     1366   * Convert a char*** to a maps (only used for Fortran support)
     1367   *
     1368   * @param c the array to convert
     1369   * @param m the resulting maps
     1370   */
    10261371  static void charxxxToMaps(char*** c,maps**m){
    10271372    maps* trorf=*m;
  • trunk/zoo-project/zoo-kernel/service_internal.c

    r578 r579  
    1 /**
     1/*
    22 * Author : Gérald FENOY
    33 *
     
    4343#define ERROR_MSG_MAX_LENGTH 1024
    4444
     45/**
     46 * Verify if a given language is listed in the lang list defined in the [main]
     47 * section of the main.cfg file.
     48 *
     49 * @param conf the map containing the settings from the main.cfg file
     50 * @param str the specific language
     51 * @return 1 if the specific language is listed, -1 in other case.
     52 */
    4553int isValidLang(maps* conf,const char *str){
    4654  map *tmpMap=getMapFromMaps(conf,"main","lang");
     
    5967}
    6068
     69/**
     70 * Print the HTTP headers based on a map.
     71 *
     72 * @param m the map containing the headers informations
     73 */
    6174void printHeaders(maps* m){
    6275  maps *_tmp=getMaps(m,"headers");
     
    7083}
    7184
     85/**
     86 * Add a land attribute to a XML node
     87 *
     88 * @param n the XML node to add the attribute
     89 * @param m the map containing the language key to add as xml:lang
     90 */
    7291void addLangAttr(xmlNodePtr n,maps *m){
    7392  map *tmpLmap=getMapFromMaps(m,"main","language");
     
    7897}
    7998
    80 /* Converts a hex character to its integer value */
     99/**
     100 * Converts a hex character to its integer value
     101 *
     102 * @param ch the char to convert
     103 * @return the converted char
     104 */
    81105char from_hex(char ch) {
    82106  return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10;
    83107}
    84108
    85 /* Converts an integer value to its hex character*/
     109/**
     110 * Converts an integer value to its hec character
     111 *
     112 * @param code the char to convert
     113 * @return the converted char
     114 */
    86115char to_hex(char code) {
    87116  static char hex[] = "0123456789abcdef";
     
    89118}
    90119
     120/**
     121 * Get the ongoing status of a running service
     122 *
     123 * @param conf the maps containing the setting of the main.cfg file
     124 * @param pid the service identifier (usid key from the [lenv] section)
     125 * @return the reported status char* (MESSAGE|POURCENTAGE)
     126 */
    91127char* _getStatus(maps* conf,int pid){
    92128  char lid[1024];
     
    131167
    132168size_t getKeyValue(maps* conf, char* key, size_t length){
    133  
    134169  if(conf==NULL) {
    135         strncpy(key, "700666", length);
    136         return strlen(key);
     170    strncpy(key, "700666", length);
     171    return strlen(key);
    137172  }
    138173 
     
    148183  }
    149184  return strlen(key);
    150 }
     185}
     186
     187
    151188semid getShmLockId(maps* conf, int nsems){
    152189    semid sem_id;
     
    336373
    337374#else
    338 
     375/**
     376 * Number of time to try to access a semaphores set
     377 * @see getShmLockId
     378 */
    339379#define MAX_RETRIES 10
    340380
     
    347387#endif
    348388
     389/**
     390 * Set in the pre-allocated key the zoo_sem_[SID] string
     391 * where [SID] is the lid (if any) or usid value from the [lenv] section.
     392 *
     393 * @param conf the map containing the setting of the main.cfg file
     394 */
    349395int getKeyValue(maps* conf){
    350396  if(conf==NULL)
     
    359405}
    360406
     407/**
     408 * Try to create or access a semaphore set.
     409 *
     410 * @see getKeyValue
     411 * @param conf the map containing the setting of the main.cfg file
     412 * @param nsems number of semaphores
     413 * @return a semaphores set indentifier on success, -1 in other case
     414 */
    361415int getShmLockId(maps* conf, int nsems){
    362416    int i;
     
    422476}
    423477
     478/**
     479 * Try to remove a semaphore set.
     480 *
     481 * @param conf the map containing the setting of the main.cfg file
     482 * @param nsems number of semaphores
     483 * @return 0 if the semaphore can be removed, -1 in other case.
     484 */
    424485int removeShmLock(maps* conf, int nsems){
    425486  union semun arg;
     
    432493}
    433494
     495/**
     496 * Lock a semaphore set.
     497 *
     498 * @param id the semaphores set indetifier
     499 * @return 0 if the semaphore can be locked, -1 in other case.
     500 */
    434501int lockShm(int id){
    435502  struct sembuf sb;
     
    444511}
    445512
     513/**
     514 * unLock a semaphore set.
     515 *
     516 * @param id the semaphores set indetifier
     517 * @return 0 if the semaphore can be locked, -1 in other case.
     518 */
    446519int unlockShm(int id){
    447520  struct sembuf sb;
     
    456529}
    457530
     531/**
     532 * Stop handling status repport.
     533 *
     534 * @param conf the map containing the setting of the main.cfg file
     535 */
    458536void unhandleStatus(maps *conf){
    459537  int shmid;
     
    481559}
    482560
     561/**
     562 * Update the current of the running service.
     563 *
     564 * @see getKeyValue, getShmLockId, lockShm
     565 * @param conf the map containing the setting of the main.cfg file
     566 * @return 0 on success, -2 if shmget failed, -1 if shmat failed
     567 */
    483568int _updateStatus(maps *conf){
    484569  int shmid;
     
    528613}
    529614
     615/**
     616 * Update the current of the running service.
     617 *
     618 * @see getKeyValue, getShmLockId, lockShm
     619 * @param pid the semaphores
     620 * @return 0 on success, -2 if shmget failed, -1 if shmat failed
     621 */
    530622char* getStatus(int pid){
    531623  int shmid;
     
    594686
    595687
    596 
    597 /* Returns a url-encoded version of str */
    598 /* IMPORTANT: be sure to free() the returned string after use */
     688/**
     689 * URLEncode an url
     690 *
     691 * @param str the url to encode
     692 * @return a url-encoded version of str
     693 * @warning be sure to free() the returned string after use
     694 */
    599695char *url_encode(char *str) {
    600696  char *pstr = str, *buf = (char*) malloc(strlen(str) * 3 + 1), *pbuf = buf;
     
    612708}
    613709
    614 /* Returns a url-decoded version of str */
    615 /* IMPORTANT: be sure to free() the returned string after use */
     710/**
     711 * Decode an URLEncoded url
     712 *
     713 * @param str the URLEncoded url to decode
     714 * @return a url-decoded version of str
     715 * @warning be sure to free() the returned string after use
     716 */
    616717char *url_decode(char *str) {
    617718  char *pstr = str, *buf = (char*) malloc(strlen(str) + 1), *pbuf = buf;
     
    633734}
    634735
     736/**
     737 * Replace the first letter by its upper case version in a new char array
     738 *
     739 * @param tmp the char*
     740 * @return a new char* with first letter in upper case
     741 * @warning be sure to free() the returned string after use
     742 */
    635743char *zCapitalize1(char *tmp){
    636744  char *res=zStrdup(tmp);
     
    640748}
    641749
     750/**
     751 * Replace all letters by their upper case version in a new char array
     752 *
     753 * @param tmp the char*
     754 * @return a new char* with first letter in upper case
     755 * @warning be sure to free() the returned string after use
     756 */
    642757char *zCapitalize(char *tmp){
    643758  int i=0;
     
    649764}
    650765
    651 
     766/**
     767 * Search for an existing XML namespace in usedNS.
     768 *
     769 * @param name the name of the XML namespace to search
     770 * @return the index of the XML namespace found or -1 if not found.
     771 */
    652772int zooXmlSearchForNs(const char* name){
    653773  int i;
     
    661781}
    662782
     783/**
     784 * Add an XML namespace to the usedNS if it was not already used.
     785 *
     786 * @param nr the xmlNodePtr to attach the XML namspace (can be NULL)
     787 * @param url the url of the XML namespace to add
     788 * @param name the name of the XML namespace to add
     789 * @return the index of the XML namespace added.
     790 */
    663791int zooXmlAddNs(xmlNodePtr nr,const char* url,const char* name){
    664792#ifdef DEBUG
     
    683811}
    684812
     813/**
     814 * Free allocated memory to store used XML namespace.
     815 */
    685816void zooXmlCleanupNs(){
    686817  int j;
     
    700831}
    701832
    702 
     833/**
     834 * Add a XML document to the iDocs.
     835 *
     836 * @param value the string containing the XML document
     837 * @return the index of the XML document added.
     838 */
    703839int zooXmlAddDoc(const char* value){
    704840  int currId=0;
     
    709845}
    710846
     847/**
     848 * Free allocated memort to store XML documents
     849 */
    711850void zooXmlCleanupDocs(){
    712851  int j;
     
    716855  nbDocs=0;
    717856}
    718 
    719 
    720 /************************************************************************/
    721 /*                             soapEnvelope()                           */
    722 /************************************************************************/
    723857
    724858/**
     
    755889}
    756890
    757 /************************************************************************/
    758 /*                            printWPSHeader()                          */
    759 /************************************************************************/
    760 
    761891/**
    762892 * Generate a WPS header.
     
    794924  return n;
    795925}
    796 
    797 /************************************************************************/
    798 /*                     printGetCapabilitiesHeader()                     */
    799 /************************************************************************/
    800926
    801927/**
     
    10951221}
    10961222
    1097 
     1223/**
     1224 * Add prefix to the service name.
     1225 *
     1226 * @param conf the conf maps containing the main.cfg settings
     1227 * @param level the map containing the level information
     1228 * @param serv the service structure created from the zcfg file
     1229 */
    10981230void addPrefix(maps* conf,map* level,service* serv){
    10991231  if(level!=NULL){
     
    11281260}
    11291261
     1262/**
     1263 * Generate a wps:Process node for a servie and add it to a given node.
     1264 *
     1265 * @param m the conf maps containing the main.cfg settings
     1266 * @param nc the XML node to add the Process node
     1267 * @param serv the service structure created from the zcfg file
     1268 * @return the generated wps:ProcessOfferings xmlNodePtr
     1269 */
    11301270void printGetCapabilitiesForProcess(maps* m,xmlNodePtr nc,service* serv){
    11311271  xmlNsPtr ns,ns_ows,ns_xlink;
     
    11611301}
    11621302
     1303/**
     1304 * Generate a ProcessDescription node for a servie and add it to a given node.
     1305 *
     1306 * @param m the conf maps containing the main.cfg settings
     1307 * @param nc the XML node to add the Process node
     1308 * @param serv the servive structure created from the zcfg file
     1309 * @return the generated wps:ProcessOfferings xmlNodePtr
     1310 */
    11631311void printDescribeProcessForProcess(maps* m,xmlNodePtr nc,service* serv){
    11641312  xmlNsPtr ns,ns_ows,ns_xlink;
     
    12301378}
    12311379
     1380/**
     1381 * Generate the required XML tree for the detailled metadata informations of
     1382 * inputs or outputs
     1383 *
     1384 * @param in 1 in case of inputs, 0 for outputs
     1385 * @param elem the elements structure containing the metadata informations
     1386 * @param type the name ("Input" or "Output") of the XML node to create
     1387 * @param ns_ows the ows XML namespace
     1388 * @param nc1 the XML node to use to add the created tree
     1389 */
    12321390void printFullDescription(int in,elements *elem,const char* type,xmlNsPtr ns_ows,xmlNodePtr nc1){
    12331391  const char *orderedFields[13];
     
    16861844}
    16871845
     1846/**
     1847 * Generate a wps:Execute XML document.
     1848 *
     1849 * @param m the conf maps containing the main.cfg settings
     1850 * @param request the map representing the HTTP request
     1851 * @param pid the process identifier linked to a service
     1852 * @param serv the serv structure created from the zcfg file
     1853 * @param service the service name
     1854 * @param status the status returned by the service
     1855 * @param inputs the inputs provided
     1856 * @param outputs the outputs generated by the service
     1857 */
    16881858void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){
    16891859  xmlNsPtr ns,ns_ows,ns_xlink;
     
    19662136}
    19672137
    1968 
     2138/**
     2139 * Print a XML document.
     2140 *
     2141 * @param m the conf maps containing the main.cfg settings
     2142 * @param doc the XML document
     2143 * @param pid the process identifier linked to a service
     2144 */
    19692145void printDocument(maps* m, xmlDocPtr doc,int pid){
    19702146  char *encoding=getEncoding(m);
     
    19922168}
    19932169
     2170/**
     2171 * Print a XML document.
     2172 *
     2173 * @param doc the XML document (unused)
     2174 * @param nc the XML node to add the output definition
     2175 * @param ns_wps the wps XML namespace
     2176 * @param ns_ows the ows XML namespace
     2177 * @param e the output elements
     2178 * @param m the conf maps containing the main.cfg settings
     2179 * @param type the type (unused)
     2180 */
    19942181void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,const char* type){
    19952182  xmlNodePtr nc1;
     
    20242211}
    20252212
     2213/**
     2214 * Generate XML nodes describing inputs or outputs metadata.
     2215 *
     2216 * @param doc the XML document
     2217 * @param nc the XML node to add the definition
     2218 * @param ns_wps the wps namespace
     2219 * @param ns_ows the ows namespace
     2220 * @param ns_xlink the xlink namespace
     2221 * @param e the output elements
     2222 * @param m the conf maps containing the main.cfg settings
     2223 * @param type the type
     2224 */
    20262225void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type){
    20272226  xmlNodePtr nc1,nc2,nc3;
     
    22582457}
    22592458
     2459/**
     2460 * Create XML node with basic ows metadata informations (Identifier,Title,Abstract)
     2461 *
     2462 * @param root the root XML node to add the description
     2463 * @param ns_ows the ows XML namespace
     2464 * @param identifier the identifier to use
     2465 * @param amap the map containing the ows metadata informations
     2466 */
    22602467void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,const char* identifier,map* amap){
    22612468  xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier");
     
    22782485}
    22792486
     2487/**
     2488 * Access the value of the encoding key in a maps
     2489 *
     2490 * @param m the maps to search for the encoding key
     2491 * @return the value of the encoding key in a maps if encoding key exists,
     2492 *  "UTF-8" in other case.
     2493 */
    22802494char* getEncoding(maps* m){
    22812495  if(m!=NULL){
     
    22912505}
    22922506
     2507/**
     2508 * Access the value of the version key in a maps
     2509 *
     2510 * @param m the maps to search for the version key
     2511 * @return the value of the version key in a maps if encoding key exists,
     2512 *  "1.0.0" in other case.
     2513 */
    22932514char* getVersion(maps* m){
    22942515  if(m!=NULL){
     
    23042525}
    23052526
    2306 /************************************************************************/
    2307 /*                    printExceptionReportResponse()                    */
    2308 /************************************************************************/
    2309 
    23102527/**
    23112528 * Print an OWS ExceptionReport Document and HTTP headers (when required)
     
    23132530 * Set hasPrinted value to true in the [lenv] section.
    23142531 *
    2315  * @param m the conf maps
     2532 * @param m the maps containing the settings of the main.cfg file
    23162533 * @param s the map containing the text,code,locator keys
    23172534 */
     
    23752592    setMapInMaps(m,"lenv","hasPrinted","true");
    23762593}
    2377 
    2378 /************************************************************************/
    2379 /*                      createExceptionReportNode()                     */
    2380 /************************************************************************/
    23812594
    23822595/**
     
    24482661}
    24492662
    2450 /************************************************************************/
    2451 /*                           errorException()                           */
    2452 /************************************************************************/
    2453 
    24542663/**
    24552664 * Print an OWS ExceptionReport.
     
    24742683}
    24752684
    2476 /************************************************************************/
    2477 /*                          readGeneratedFile()                         */
    2478 /************************************************************************/
    2479 
    24802685/**
    24812686 * Read a file generated by a service.
     
    25112716}
    25122717
     2718/**
     2719 * Generate the output response (RawDataOutput or ResponseDocument)
     2720 *
     2721 * @param s the service structure containing the metadata informations
     2722 * @param request_inputs the inputs provided to the service for execution
     2723 * @param request_outputs the outputs updated by the service execution
     2724 * @param request_inputs1 the map containing the HTTP request
     2725 * @param cpid the process identifier attached to a service execution
     2726 * @param m the conf maps containing the main.cfg settings
     2727 * @param res the value returned by the service execution
     2728 */
    25132729void outputResponse(service* s,maps* request_inputs,maps* request_outputs,
    25142730                    map* request_inputs1,int cpid,maps* m,int res){
     
    27953011}
    27963012
     3013
     3014/**
     3015 * Base64 encoding of a char*
     3016 *
     3017 * @param input the value to encode
     3018 * @param length the value length
     3019 * @return the buffer containing the base64 value
     3020 * @warning make sure to free the returned value
     3021 */
    27973022char *base64(const char *input, int length)
    27983023{
     
    28173042}
    28183043
     3044/**
     3045 * Base64 decoding of a char*
     3046 *
     3047 * @param input the value to decode
     3048 * @param length the value length
     3049 * @param red the value length
     3050 * @return the buffer containing the base64 value
     3051 * @warning make sure to free the returned value
     3052 */
    28193053char *base64d(const char *input, int length,int* red)
    28203054{
     
    28363070}
    28373071
     3072/**
     3073 * Make sure that each value encoded in base64 in a maps is decoded.
     3074 *
     3075 * @param in the maps containing the values
     3076 */
    28383077void ensureDecodedBase64(maps **in){
    28393078  maps* cursor=*in;
     
    28563095}
    28573096
     3097/**
     3098 * Add the default values defined in the zcfg to a maps.
     3099 *
     3100 * @param out the maps containing the inputs or outputs given in the initial
     3101 *  HTTP request
     3102 * @param in the description of all inputs or outputs available for a service
     3103 * @param m the maps containing the settings of the main.cfg file
     3104 * @param type 0 for inputs and 1 for outputs
     3105 * @param err the map to store potential missing mandatory input parameters or
     3106 *  wrong output names depending on the type.
     3107 * @return "" if no error was detected, the name of last input or output causing
     3108 *  an error.
     3109 */
    28583110char* addDefaultValues(maps** out,elements* in,maps* m,int type,map** err){
    28593111  map *res=*err;
     
    30953347
    30963348/**
    3097  * parseBoundingBox : parse a BoundingBox string
    3098  *
    3099  * OGC 06-121r3 : 10.2 Bounding box
    3100  *
    3101  * value is provided as : lowerCorner,upperCorner,crs,dimension
    3102  * exemple : 189000,834000,285000,962000,urn:ogc:def:crs:OGC:1.3:CRS84
    3103  *
    3104  * Need to create a map to store boundingbox informations :
     3349 * Parse a BoundingBox string
     3350 *
     3351 * [OGC 06-121r3](http://portal.opengeospatial.org/files/?artifact_id=20040):
     3352 *  10.2 Bounding box
     3353 *
     3354 *
     3355 * Value is provided as : lowerCorner,upperCorner,crs,dimension
     3356 * Exemple : 189000,834000,285000,962000,urn:ogc:def:crs:OGC:1.3:CRS84
     3357 *
     3358 * A map to store boundingbox informations should contain:
    31053359 *  - lowerCorner : double,double (minimum within this bounding box)
    31063360 *  - upperCorner : double,double (maximum within this bounding box)
     
    31093363 *
    31103364 * Note : support only 2D bounding box.
     3365 *
     3366 * @param value the char* containing the KVP bouding box
     3367 * @return a map containing all the bounding box keys
    31113368 */
    31123369map* parseBoundingBox(const char* value){
     
    31563413
    31573414/**
    3158  * printBoundingBox : fill a BoundingBox node (ows:BoundingBox or
    3159  * wps:BoundingBoxData). Set crs and dimensions attributes, add
    3160  * Lower/UpperCorner nodes to a pre-existing XML node.
     3415 * Create required XML nodes for boundingbox and update the current XML node
     3416 *
     3417 * @param ns_ows the ows XML namespace
     3418 * @param n the XML node to update
     3419 * @param boundingbox the map containing the boundingbox definition
    31613420 */
    31623421void printBoundingBox(xmlNsPtr ns_ows,xmlNodePtr n,map* boundingbox){
     
    31913450}
    31923451
     3452/**
     3453 * Print an ows:BoundingBox XML document
     3454 *
     3455 * @param m the maps containing the settings of the main.cfg file
     3456 * @param boundingbox the maps containing the boundingbox definition
     3457 * @param file the file to print the BoundingBox (if NULL then print on stdout)
     3458 * @see parseBoundingBox, printBoundingBox
     3459 */
    31933460void printBoundingBoxDocument(maps* m,maps* boundingbox,FILE* file){
    31943461  if(file==NULL)
     
    32433510}
    32443511
    3245 
     3512/**
     3513 * Compute md5
     3514 *
     3515 * @param url the char*
     3516 * @return a char* representing the md5 of the url
     3517 * @warning make sure to free ressources returned by this function
     3518 */
    32463519char* getMd5(char* url){
    32473520  EVP_MD_CTX md5ctx;
     
    32673540
    32683541/**
    3269  * Cache a file for a given request
     3542 * Cache a file for a given request.
     3543 * For each cached file, the are two files stored, a .zca and a .zcm containing
     3544 * the downloaded content and the mimeType respectively.
     3545 *
     3546 * @param conf the maps containing the settings of the main.cfg file
     3547 * @param request the url used too fetch the content
     3548 * @param content the downloaded content
     3549 * @param mimeType the content mimeType
     3550 * @param length the content size
    32703551 */
    32713552void addToCache(maps* conf,char* request,char* content,char* mimeType,int length){
     
    33003581}
    33013582
     3583/**
     3584 * Verify if a url is available in the cache
     3585 *
     3586 * @param conf the maps containing the settings of the main.cfg file
     3587 * @param request the url
     3588 * @return the full name of the cached file if any, NULL in other case
     3589 * @warning make sure to free ressources returned by this function (if not NULL)
     3590 */
    33023591char* isInCache(maps* conf,char* request){
    33033592  map* tmpM=getMapFromMaps(conf,"main","cacheDir");
     
    33213610}
    33223611
     3612/**
     3613 * Effectively run all the HTTP requests in the queue
     3614 *
     3615 * @param m the maps containing the settings of the main.cfg file
     3616 * @param inputs the maps containing the inputs (defined in the requests+added
     3617 *  per default based on the zcfg file)
     3618 * @param hInternet the HINTERNET pointer
     3619 * @return 0 on success
     3620 */
    33233621int runHttpRequests(maps** m,maps** inputs,HINTERNET* hInternet){
    33243622  if(hInternet->nb>0){
     
    34273725
    34283726/**
    3429  * loadRemoteFile:
    34303727 * Try to load file from cache or download a remote file if not in cache
     3728 *
     3729 * @param m the maps containing the settings of the main.cfg file
     3730 * @param content the map to update
     3731 * @param hInternet the HINTERNET pointer
     3732 * @param url the url to fetch
     3733 * @return 0
    34313734 */
    34323735int loadRemoteFile(maps** m,map** content,HINTERNET* hInternet,char *url){
     
    35233826}
    35243827
     3828/**
     3829 * Read a file using the GDAL VSI API
     3830 *
     3831 * @param conf the maps containing the settings of the main.cfg file
     3832 * @param dataSource the datasource name to read
     3833 * @warning make sure to free ressources returned by this function
     3834 */
    35253835char *readVSIFile(maps* conf,const char* dataSource){
    35263836    VSILFILE * fichier=VSIFOpenL(dataSource,"rb");
     
    35423852}
    35433853
     3854/**
     3855 * Extract the service identifier from the full service identifier
     3856 * ie:
     3857 *  - Full service name: OTB.BandMath
     3858 *  - Service name: BandMath
     3859 *
     3860 * @param conf the maps containing the settings of the main.cfg file
     3861 * @param conf_dir the full path to the ZOO-Kernel directory
     3862 * @param identifier the full service name (potentialy including a prefix, ie:
     3863 *  Prefix.MyService)
     3864 * @param buffer the resulting service identifier (without any prefix)
     3865 */
    35443866void parseIdentifier(maps* conf,char* conf_dir,char *identifier,char* buffer){
    35453867  setMapInMaps(conf,"lenv","oIdentifier",identifier);
     
    36073929}
    36083930
     3931/**
     3932 * Update the status of an ongoing service
     3933 *
     3934 * @param conf the maps containing the settings of the main.cfg file
     3935 * @param percentCompleted percentage of completude of execution of the service
     3936 * @param message information about the current step executed
     3937 * @return the value of _updateStatus
     3938 * @see _updateStatus
     3939 */
    36093940int updateStatus( maps* conf, const int percentCompleted, const char* message ){
    36103941  char tmp[4];
     
    36153946}
    36163947
     3948/**
     3949 * Access an input value
     3950 *
     3951 * @param inputs the maps to search for the input value
     3952 * @param parameterName the input name to fetch the value
     3953 * @param numberOfBytes the resulting size of the value to add (for binary
     3954 *  values), -1 for basic char* data
     3955 * @return a pointer to the input value if found, NULL in other case.
     3956 */
    36173957char* getInputValue( maps* inputs, const char* parameterName, size_t* numberOfBytes){
    36183958  map* res=getMapFromMaps(inputs,parameterName,"value");
     
    36303970}
    36313971
     3972/**
     3973 * Set an output value
     3974 *
     3975 * @param outputs the maps to define the output value
     3976 * @param parameterName the output name to set the value
     3977 * @param data the value to set
     3978 * @param numberOfBytes size of the value to add (for binary values), -1 for
     3979 *  basic char* data
     3980 * @return 0
     3981 */
    36323982int  setOutputValue( maps* outputs, const char* parameterName, char* data, size_t numberOfBytes ){
    36333983  if(numberOfBytes==-1){
     
    36493999}
    36504000
    3651 /************************************************************************/
    3652 /*                           checkValidValue()                          */
    3653 /************************************************************************/
    3654 
    36554001/**
    36564002 * Verify if a parameter value is valid.
     
    36584004 * @param request the request map
    36594005 * @param res the error map potentially generated
     4006 * @param toCheck the parameter to use
    36604007 * @param avalues the acceptable values (or null if testing only for presence)
    36614008 * @param mandatory verify the presence of the parameter if mandatory > 0
     
    37404087}
    37414088
    3742 /*
    3743  * The character string returned from getLastErrorMessage resides
     4089/**
     4090 * Access the last error message returned by the OS when trying to dynamically
     4091 * load a shared library.
     4092 *
     4093 * @return the last error message
     4094 * @warning The character string returned from getLastErrorMessage resides
    37444095 * in a static buffer. The application should not write to this
    37454096 * buffer or attempt to free() it.
    37464097 */
    3747 char* getLastErrorMessage() {                                                                                                                                                   
    3748 #ifdef WIN32   
    3749         LPVOID lpMsgBuf;
    3750         DWORD errCode = GetLastError();
    3751         static char msg[ERROR_MSG_MAX_LENGTH];
    3752         size_t i;
    3753 
    3754         DWORD length = FormatMessage(
    3755                                          FORMAT_MESSAGE_ALLOCATE_BUFFER |
    3756                                          FORMAT_MESSAGE_FROM_SYSTEM |
    3757                                          FORMAT_MESSAGE_IGNORE_INSERTS,
    3758                                          NULL,
    3759                                          errCode,
    3760                                          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    3761                                          (LPTSTR) &lpMsgBuf,
    3762                                          0, NULL );     
    3763        
    3764         #ifdef UNICODE         
    3765                 wcstombs_s( &i, msg, ERROR_MSG_MAX_LENGTH,
    3766                                         (wchar_t*) lpMsgBuf, _TRUNCATE );
    3767         #else
    3768                 strcpy_s( msg, ERROR_MSG_MAX_LENGTH,
    3769                       (char *) lpMsgBuf );             
    3770         #endif 
    3771         LocalFree(lpMsgBuf);
    3772        
    3773         return msg;
     4098char* getLastErrorMessage() {                                             
     4099#ifdef WIN32
     4100  LPVOID lpMsgBuf;
     4101  DWORD errCode = GetLastError();
     4102  static char msg[ERROR_MSG_MAX_LENGTH];
     4103  size_t i;
     4104 
     4105  DWORD length = FormatMessage(
     4106                               FORMAT_MESSAGE_ALLOCATE_BUFFER |
     4107                               FORMAT_MESSAGE_FROM_SYSTEM |
     4108                               FORMAT_MESSAGE_IGNORE_INSERTS,
     4109                               NULL,
     4110                               errCode,
     4111                               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
     4112                               (LPTSTR) &lpMsgBuf,
     4113                               0, NULL );       
     4114 
     4115#ifdef UNICODE         
     4116  wcstombs_s( &i, msg, ERROR_MSG_MAX_LENGTH,
     4117              (wchar_t*) lpMsgBuf, _TRUNCATE );
    37744118#else
    3775         return dlerror();
    3776 #endif
    3777 }
     4119  strcpy_s( msg, ERROR_MSG_MAX_LENGTH,
     4120            (char *) lpMsgBuf );               
     4121#endif 
     4122  LocalFree(lpMsgBuf);
     4123 
     4124  return msg;
     4125#else
     4126  return dlerror();
     4127#endif
     4128}
  • trunk/zoo-project/zoo-kernel/service_internal.h

    r578 r579  
    1 /**
     1/*
    22 * Author : Gérald FENOY
    33 *
     
    2828#pragma once
    2929
     30/**
     31 * The default service url (overriden by serverAddress)
     32 */
    3033#define DEFAULT_SERVICE_URL "http://www.zoo-project.org/"
     34/**
     35 * The time size
     36 */
    3137#define TIME_SIZE 40
    3238
    3339#include <libintl.h>
    3440#include <locale.h>
     41/**
     42 * ZOO-Kernel internal messages translation function
     43 */
    3544#define _(String) dgettext ("zoo-kernel",String)
     45/**
     46 * ZOO-Services messages translation function
     47 */
    3648#define _ss(String) dgettext ("zoo-services",String)
    3749
     50/**
     51 * ZOO-Kernel was unable to create a lock
     52 */
    3853#define ZOO_LOCK_CREATE_FAILED -4
     54/**
     55 * ZOO-Kernel was unable to acquire a lock
     56 */
    3957#define ZOO_LOCK_ACQUIRE_FAILED -5
     58/**
     59 * ZOO-Kernel was unable to release a lock
     60 */
    4061#define ZOO_LOCK_RELEASE_FAILED -6
    4162
     
    89110#include <libxml/xpath.h>
    90111
     112  /**
     113   * Maximum number of XML namespaces
     114   */
     115#define ZOO_NS_MAX 10
     116  /**
     117   * Maximum number of XML docs
     118   */
     119#define ZOO_DOC_MAX 20
     120
     121  /**
     122   * Global char* to store the serverAddress value of the mmmmmain section
     123   */
    91124  static char* SERVICE_URL;
    92   static xmlNsPtr usedNs[10];
    93   static char* nsName[10];
    94   static xmlDocPtr iDocs[10];
     125  /**
     126   * Array of xmlNsPtr storing all used XML namespace
     127   */
     128  static xmlNsPtr usedNs[ZOO_NS_MAX];
     129  /**
     130   * Array storing names of the used XML namespace
     131   */
     132  static char* nsName[ZOO_NS_MAX];
     133  /**
     134   * Number of XML namespaces
     135   */
    95136  static int nbNs=0;
     137  /**
     138   * Array of xmlDocPtr storing XML docs
     139   */
     140  static xmlDocPtr iDocs[ZOO_DOC_MAX];
     141  /**
     142   * Number of XML docs
     143   */
    96144  static int nbDocs=0;
    97145
     
    107155  char* getStatus(int);
    108156  int removeShmLock(maps*, int);
     157  /**
     158   * Cross platform type used for Lock identifier
     159   */
    109160#ifndef WIN32
    110161#define semid int
  • trunk/zoo-project/zoo-kernel/service_internal_ms.c

    r550 r579  
    1 /**
     1/*
    22 * Author : Gérald FENOY
    33 *
  • trunk/zoo-project/zoo-kernel/service_internal_ms.h

    r379 r579  
    1 /**
     1/*
    22 * Author : Gérald FENOY
    33 *
  • trunk/zoo-project/zoo-kernel/service_internal_python.c

    r576 r579  
    1 /**
     1/*
    22 * Author : Gérald FENOY
    33 *
     
    2525#include "service_internal_python.h"
    2626
     27/**
     28 * The state for the zoo Python module
     29 */
    2730struct module_state {
    28     PyObject *error;
     31   PyObject *error;
    2932};
    3033
     
    4346#endif
    4447
     48/**
     49 * The exception for the zoo Python module
     50 */
    4551static PyObject* ZooError;
    4652
     53/**
     54 * Function definitions for the zoo Python Module
     55 *
     56 * Define the following functions available from a service loaded and running
     57 * from the ZOO-Kernel Python environment:
     58 *  - "_" corresponding to the PythonTranslate function
     59 *  - "updte_status" corresponding to the PythonUpdateStatus function
     60 * @see PythonTranslate, PythonUpdateStatus
     61 */
    4762PyMethodDef zooMethods[] = {
    4863  {"_", PythonTranslate, METH_VARARGS, "Translate a string using the zoo-services textdomain."},
     
    7691#endif
    7792
     93/**
     94 * Function to create and initialize the zoo Python module
     95 *
     96 * @return the Python module (for Python versions < 3, nothing for version >=3)
     97 */
    7898PyMODINIT_FUNC init_zoo(){
    7999  PyObject *tmp,*d;
     
    115135}
    116136
     137/**
     138 * Loading a Python module then run the function corresponding to the service
     139 * by passing the conf, inputs and outputs parameters by reference.
     140 *
     141 * @param main_conf the conf maps containing the main.cfg settings
     142 * @param request the map containing the HTTP request
     143 * @param s the service structure
     144 * @param real_inputs the maps containing the inputs
     145 * @param real_outputs the maps containing the outputs
     146 */
    117147int zoo_python_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){
    118148  char *pythonpath;
     
    271301}
    272302
     303/**
     304 * Repport Python error which may occur on loading the Python module or at
     305 * runtime.
     306 *
     307 * @param m the conf maps containing the main.cfg settings
     308 * @param module the service name
     309 * @param load 1 if the Python module was not loaded yet
     310 */
    273311void PythonZooReport(maps* m,const char* module,int load){
    274312  PyObject *pName, *pModule, *pFunc;
     
    335373}
    336374
     375/**
     376 * Convert a maps to a Python dictionary
     377 *
     378 * @param t the maps to convert
     379 * @return a new PyDictObject containing the converted maps
     380 * @see PyDict_FromMap
     381 * @warning make sure to free ressources returned by this function
     382 */
    337383PyDictObject* PyDict_FromMaps(maps* t){
    338384  PyObject* res=PyDict_New( );
     
    351397}
    352398
     399/**
     400 * Convert a map to a Python dictionary
     401 *
     402 * @param t the map to convert
     403 * @return a new PyDictObject containing the converted maps
     404 * @warning make sure to free ressources returned by this function
     405 */
    353406PyDictObject* PyDict_FromMap(map* t){
    354407  PyObject* res=PyDict_New( );
     
    461514}
    462515
     516/**
     517 * Convert a Python dictionary to a maps
     518 *
     519 * @param t the PyDictObject to convert
     520 * @return a new maps containing the converted PyDictObject
     521 * @warning make sure to free ressources returned by this function
     522 */
    463523maps* mapsFromPyDict(PyDictObject* t){
    464524  maps* res=NULL;
     
    501561}
    502562
     563/**
     564 * Convert a Python dictionary to a map
     565 *
     566 * @param t the PyDictObject to convert
     567 * @return a new map containing the converted PyDictObject
     568 * @warning make sure to free ressources returned by this function
     569 */
    503570map* mapFromPyDict(PyDictObject* t){
    504571  map* res=NULL;
     
    540607}
    541608
     609/**
     610 * Use the ZOO-Services messages translation function  from the Python
     611 * environment
     612 *
     613 * @param self the Python object on which we can run the method
     614 * @param args the Python arguments given from the Python environment
     615 * @return a new Python string containing the translated value to the Python
     616 *  environment
     617 * @see _ss
     618 */
    542619PyObject*
    543620PythonTranslate(PyObject* self, PyObject* args)
     
    553630}
    554631
     632/**
     633 * Update the ongoing status of a running service from the Python environment
     634 *
     635 * @param self the Python object on which we can run the method
     636 * @param args the Python arguments given from the Python environment
     637 * @return None to the Python environment
     638 * @see _updateStatus
     639 */
    555640PyObject*
    556641PythonUpdateStatus(PyObject* self, PyObject* args)
  • trunk/zoo-project/zoo-kernel/service_internal_python.h

    r576 r579  
    1 /**
     1/*
    22 * Author : Gérald FENOY
    33 *
     
    4040
    4141maps* mapsFromPyDict(PyDictObject* t);
    42 void createMapsFromPyDict(maps**,PyDictObject*);
    4342map* mapFromPyDict(PyDictObject* t);
    4443
  • trunk/zoo-project/zoo-kernel/ulinet.c

    r539 r579  
    1 /**
     1/*
    22 *  ulinet.c
    33 *
    44 * Author : Gérald FENOY
    55 *
    6  * Copyright (c) 2008-2010 GeoLabs SARL
     6 * Copyright (c) 2008-2015 GeoLabs SARL
    77 *
    88 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    3030#include "ulinet.h"
    3131#include <assert.h>
    32  
     32
     33/**
     34 * Write the downloaded content to a _HINTERNET structure
     35 *
     36 * @param buffer the buffer to read
     37 * @param size size of each member
     38 * @param nmemb number of element to read
     39 * @param data the _HINTERNET structure to write in
     40 * @return the size red, -1 if buffer is NULL
     41 */
    3342size_t write_data_into(void *buffer, size_t size, size_t nmemb, void *data){
    3443  size_t realsize = size * nmemb;
     
    5867}
    5968
     69/**
     70 * In case of presence of "Set-Cookie" in the headers red, store the cookie
     71 * identifier in CCookie
     72 *
     73 * @param buffer the buffer to read
     74 * @param size size of each member
     75 * @param nmemb number of element to read
     76 * @param data the _HINTERNET structure to write in
     77 * @return the size red, -1 if buffer is NULL
     78 * @see CCookie
     79 */
    6080size_t header_write_data(void *buffer, size_t size, size_t nmemb, void *data){
    6181  if(strncmp("Set-Cookie: ",(char*)buffer,12)==0){
     
    82102};
    83103
    84 
     104/**
     105 * Define the proxy to use for a CURL handler
     106 *
     107 * @param handle the CURL handler
     108 * @param host the proxy host (including http://)
     109 * @param port the proxy port
     110 */
    85111void setProxy(CURL* handle,char* host,long port){
     112  char* proxyDef=(char*)malloc((strlen(host)+10+2)*sizeof(char));
     113  sprintf(proxyDef,"%s:%ld",host,port);
     114  curl_easy_setopt(handle,CURLOPT_PROXY,proxyDef);
     115  free(proxyDef);
    86116}
    87117
     
    154184#else
    155185/**
    156  * Linux (Gnome)
     186 * Should autodetect the proxy configuration (do nothing on linux)
     187 *
     188 * @param handle a CURL handle
     189 * @param proto the protocol requiring the use of a proxy
    157190 */
    158191bool setProxiesForProtcol(CURL* handle,const char *proto){
     
    164197#endif
    165198
     199/**
     200 * Create a HINTERNET
     201 *
     202 * @param lpszAgent the HTPP User-Agent to use to send requests
     203 * @param  dwAccessType type of access required
     204 * @param  lpszProxyName the name of the proxy server(s) to use
     205 * @param  lpszProxyBypass ip address or host names which should not be routed
     206 *  through the proxy
     207 * @param  dwFlags Options (INTERNET_FLAG_ASYNC,INTERNET_FLAG_FROM_CACHE,INTERNET_FLAG_OFFLINE)
     208 * @return the created HINTERNET
     209 */
    166210HINTERNET InternetOpen(char* lpszAgent,int dwAccessType,char* lpszProxyName,char* lpszProxyBypass,int dwFlags){
    167211  HINTERNET ret;
     
    173217}
    174218
     219/**
     220 * Close a HINTERNET connection and free allocated ressources
     221 *
     222 * @param handle0 the HINTERNET connection to close
     223 */
    175224void InternetCloseHandle(HINTERNET* handle0){
    176225  int i=0;
     
    200249}
    201250
     251/**
     252 * Create a new element in the download queue
     253 *
     254 * @param hInternet the HINTERNET connection to add the download link
     255 * @param lpszUrl the url to download
     256 * @param lpszHeaders the additional headers to be sent to the HTTP server
     257 * @param dwHeadersLength the size of the additional headers
     258 * @param dwFlags desired download mode (INTERNET_FLAG_NO_CACHE_WRITE for not using cache file)
     259 * @param dwContext not used
     260 */
    202261HINTERNET InternetOpenUrl(HINTERNET* hInternet,LPCTSTR lpszUrl,LPCTSTR lpszHeaders,size_t dwHeadersLength,size_t dwFlags,size_t dwContext){
    203262
     
    289348};
    290349
     350/**
     351 * Download all opened urls in the queue
     352 *
     353 * @param hInternet the HINTERNET structure containing the queue
     354 * @return 0
     355 */
    291356int processDownloads(HINTERNET* hInternet){
    292357  int still_running=0;
     
    307372}
    308373
     374/**
     375 * Initialize the CCookie for a specific index (hInternet.nb)
     376 *
     377 * @param hInternet the HINTERNET structure to know the CCookie index to reset
     378 * @return 1
     379 * @see HINTERNET
     380 */
    309381int freeCookieList(HINTERNET hInternet){
    310382  memset(&CCookie[hInternet.nb][0],0,1024);
     
    315387}
    316388
     389/**
     390 * Copy a downloaded content
     391 *
     392 * @param hInternet the _HINTERNET structure
     393 * @param lpBuffer the memory space to copy the downloaded content
     394 * @param dwNumberOfBytesToRead the size of lpBuffer
     395 * @param lpdwNumberOfBytesRead number of bytes red
     396 * @return 1 on success, 0 if failure
     397 */
    317398int InternetReadFile(_HINTERNET hInternet,LPVOID lpBuffer,int dwNumberOfBytesToRead, size_t *lpdwNumberOfBytesRead){
    318399  int dwDataSize;
  • trunk/zoo-project/zoo-kernel/ulinet.h

    r554 r579  
    1 /**
     1/*
    22 * Author : Gérald FENOY
    33 *
     
    5656static char CCookie[MAX_REQ][1024];
    5757#else
    58 extern char HEADER[MAX_REQ][3072];
     58/**
     59 * The cookies found
     60 */
    5961extern char CCookie[MAX_REQ][1024];
    6062#endif
     
    6466#endif
    6567
    66   //static pthread_mutex_t hMutexConnect = PTHREAD_MUTEX_INITIALIZER;
    67 
    68 static char* waitingRequests[MAX_REQ];
    69 
    7068struct MemoryStruct {
    71   char *memory;
    72   size_t size;
     69  char *memory; //!< the memory space to store data
     70  size_t size; //!< side of the memory space
    7371};
    7472
     73  /**
     74   * Individual CURL handler
     75   */
    7576typedef struct {
    76   CURL *handle;
    77   struct curl_slist *header;
    78   char* filename;
    79   FILE* file;
    80   size_t size;
    81   unsigned char *pabyData;
    82   char *mimeType;
    83   int hasCacheFile;
    84   int nDataLen;
    85   int nDataAlloc;
    86   int id;
     77  CURL *handle; //!< the CURL handler
     78  struct curl_slist *header; //!< the headers to send
     79  char* filename; //!< the cached file name
     80  FILE* file; //!< the file pointer
     81  unsigned char *pabyData; //!< the downloaded content
     82  char *mimeType; //!< the mimeType returned by the server
     83  int hasCacheFile; //!< 1 if we used a cache file
     84  int nDataLen; //!< the length of the downloaded content
     85  int nDataAlloc; //!<
     86  int id; //!< The position of the element in the queue
    8787} _HINTERNET;
    8888
     89  /**
     90   * Multiple CURL handlers
     91   */
    8992typedef struct {
    90   CURLM *handle;
    91   _HINTERNET ihandle[MAX_REQ];
    92   char *waitingRequests[MAX_REQ];
    93   char *agent;
    94   int nb;
     93  CURLM *handle; //!< the CURLM handler
     94  _HINTERNET ihandle[MAX_REQ]; //!< individual handlers in the queue
     95  char *waitingRequests[MAX_REQ]; //!< request in the queue
     96  char *agent; //!< The User-Agent to use for HTTP request
     97  int nb; //!< number of element in the queue
    9598} HINTERNET;
    9699
    97100size_t write_data_into(void *buffer, size_t size, size_t nmemb, void *data);
    98101
    99 size_t content_write_data(void *buffer, size_t size, size_t nmemb, void *data);
    100 
    101102size_t header_write_data(void *buffer, size_t size, size_t nmemb, void *data);
    102103
    103 
    104104void setProxy(CURL* handle,char* host,long port);
    105 
    106105
    107106#if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__))
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r578 r579  
    26812681                      {
    26822682              /**
    2683                * Get every attribute from a Output node
     2683               * Get every attribute from an Output node
    26842684               * mimeType, encoding, schema, uom, asReference
    26852685               */
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