ZOO-Project
service_internal.h
Go to the documentation of this file.
1 /*
2  * Author : GĂ©rald FENOY
3  *
4  * Copyright (c) 2009-2013 GeoLabs SARL
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #ifndef ZOO_SERVICE_INTERNAL_H
26 #define ZOO_SERVICE_INTERNAL_H 1
27 
28 #pragma once
29 
33 #define DEFAULT_SERVICE_URL "http://www.zoo-project.org/"
34 
35 #include <libintl.h>
36 #include <locale.h>
40 #define _(String) dgettext ("zoo-kernel",String)
41 
44 #define _ss(String) dgettext ("zoo-services",String)
45 
49 #define ZOO_LOCK_CREATE_FAILED -4
50 
53 #define ZOO_LOCK_ACQUIRE_FAILED -5
54 
57 #define ZOO_LOCK_RELEASE_FAILED -6
58 
61 #define ZOO_LOCK_MAX_RETRY 180
62 
63 #include <sys/stat.h>
64 #include <sys/types.h>
65 #ifndef WIN32
66 #include <sys/ipc.h>
67 #include <sys/shm.h>
68 #include <sys/sem.h>
69 #else
70 #include <direct.h>
71 #endif
72 #include <stdio.h>
73 #include <time.h>
74 #include <ctype.h>
75 #ifndef USE_RUBY
76 #include <unistd.h>
77 #endif
78 #ifndef WIN32
79 #include <locale.h>
80 #endif
81 
82 #include <fcntl.h>
83 
84 #include "service.h"
85 
86 #if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__))
87 
88 #include <CoreServices/CoreServices.h>
89 #include <SystemConfiguration/SystemConfiguration.h>
90 
91 #endif
92 
93 #ifdef WIN32
94 // fcntl flock definitions
95 #define F_SETLK 8 // Non-Blocking set or clear a lock
96 #define F_SETLKW 9 // Blocking set or clear a lock
97 #define F_GETLK 10
98 #define F_RDLCK 1 // read lock
99 #define F_WRLCK 2 // write lock
100 #define F_UNLCK 3 // remove lock
101 struct flock {
102  short l_type; // F_RDLCK, F_WRLCK, or F_UNLCK
103  short l_whence; // flag to choose starting offset, must be SEEK_SET
104  long l_start; // relative offset, in bytes, must be 0
105  long l_len; // length, in bytes; 0 means lock to EOF, must be 0
106  short l_pid; // unused (returned with the unsupported F_GETLK)
107  short l_xxx; // reserved for future use
108 };
109 #endif
110 
115 typedef struct zooLock{
116  struct flock lock;
117  FILE* lockfile;
118  char* filename;
119 } zooLock;
120 
121 static zooLock** zoo_file_locks=NULL;
122 static int zoo_file_locks_cnt=0;
123 
124 #ifdef __cplusplus
125 extern "C" {
126 #endif
127 
128 
129  ZOO_DLL_EXPORT char *readVSIFile(maps*,const char*);
130  ZOO_DLL_EXPORT bool validateVRT(maps*,const char*);
131  ZOO_DLL_EXPORT int setOutputValue( maps*, const char*, char*, size_t);
132  ZOO_DLL_EXPORT char* getInputValue( maps*,const char*,size_t*);
133 
134  ZOO_DLL_EXPORT struct zooLock* lockFile(maps*,const char*,const char);
135  ZOO_DLL_EXPORT int unlockFile(maps*,struct zooLock*);
136 
139  ZOO_DLL_EXPORT char* _getStatus(maps*,char*);
140  ZOO_DLL_EXPORT char* _getStatusField(maps*,char*,const char*);
141  ZOO_DLL_EXPORT char* _getStatusFile(maps*,char*);
142  ZOO_DLL_EXPORT char* getStatus(int);
143  ZOO_DLL_EXPORT char* getStatusId(maps*,char*);
144 
145  ZOO_DLL_EXPORT int updateStatus( maps*,const int,const char*);
146  ZOO_DLL_EXPORT int removeShmLock(maps*, int);
150 #ifndef WIN32
151 #define semid int
152 #else
153 #include <windows.h>
154 #define semid HANDLE
155 #endif
160 
161  ZOO_DLL_EXPORT char* file_exists(const char* dir, const char* name);
162 
164  ZOO_DLL_EXPORT bool hasDbs(maps*);
165 
166 #ifdef __cplusplus
167 }
168 #endif
169 
170 #endif
_getStatus
ZOO_DLL_EXPORT char * _getStatus(maps *, char *)
Get the ongoing status of a running service.
Definition: service_internal.c:372
zooLock::lock
struct flock lock
The lock.
Definition: service_internal.h:116
updateStatus
ZOO_DLL_EXPORT int updateStatus(maps *, const int, const char *)
Update the status of an ongoing service.
Definition: service_internal.c:846
service.h
hasDbs
ZOO_DLL_EXPORT bool hasDbs(maps *)
Verify if the server rely on database backend.
Definition: service_internal.c:1040
_getStatusField
ZOO_DLL_EXPORT char * _getStatusField(maps *, char *, const char *)
Definition: service_internal.c:1011
lockFile
ZOO_DLL_EXPORT struct zooLock * lockFile(maps *, const char *, const char)
Lock a file for read, write and upload.
Definition: service_internal.c:98
getInputValue
ZOO_DLL_EXPORT char * getInputValue(maps *, const char *, size_t *)
Access an input value.
Definition: service_internal.c:864
readVSIFile
ZOO_DLL_EXPORT char * readVSIFile(maps *, const char *)
Read a file using the GDAL VSI API.
Definition: service_internal.c:934
zooLock::lockfile
FILE * lockfile
The pointer to the lock file.
Definition: service_internal.h:117
zooLock
The lock structure used by the ZOO-Kernel to ensure atomicity of operations.
Definition: service_internal.h:115
acquireLock
ZOO_DLL_EXPORT semid acquireLock(maps *)
Acquire the global lock.
Definition: service_internal.c:265
zooLock::filename
char * filename
The filename to lock.
Definition: service_internal.h:118
getShmLockId
ZOO_DLL_EXPORT semid getShmLockId(maps *, int)
Try to create or access a semaphore set.
Definition: service_internal.c:678
zoo_file_locks
static zooLock ** zoo_file_locks
Definition: service_internal.h:121
maps
linked list of map pointer
Definition: service.h:678
validateVRT
ZOO_DLL_EXPORT bool validateVRT(maps *, const char *)
Validate that the VRT contains only allowed path.
Definition: service_internal.c:886
unlockShm
ZOO_DLL_EXPORT int unlockShm(semid)
_getStatusFile
ZOO_DLL_EXPORT char * _getStatusFile(maps *, char *)
Read the cache file of a running service.
Definition: service_internal.c:304
unlockFile
ZOO_DLL_EXPORT int unlockFile(maps *, struct zooLock *)
Remove a lock.
Definition: service_internal.c:200
_updateStatus
ZOO_DLL_EXPORT int _updateStatus(maps *)
Update the current status of the running service.
Definition: service_internal.c:450
lockShm
ZOO_DLL_EXPORT int lockShm(semid)
zoo_file_locks_cnt
static int zoo_file_locks_cnt
Definition: service_internal.h:122
setOutputValue
ZOO_DLL_EXPORT int setOutputValue(maps *, const char *, char *, size_t)
Set an output value.
Definition: service_internal.c:963
ZOO_DLL_EXPORT
#define ZOO_DLL_EXPORT
Definition: service.h:34
file_exists
ZOO_DLL_EXPORT char * file_exists(const char *dir, const char *name)
Check if file exists in specified folder.
Definition: service_internal.c:991
semid
#define semid
Cross platform type used for Lock identifier.
Definition: service_internal.h:151
removeShmLock
ZOO_DLL_EXPORT int removeShmLock(maps *, int)
Try to remove a semaphore set.
Definition: service_internal.c:750
zooLock
struct zooLock zooLock
The lock structure used by the ZOO-Kernel to ensure atomicity of operations.
getStatusId
ZOO_DLL_EXPORT char * getStatusId(maps *, char *)
Read the sid file attached of a service if any.
Definition: service_internal.c:236
isAsyncCall
ZOO_DLL_EXPORT bool isAsyncCall(maps *)
Verify if an Execute request has been invoked asynchronously.
Definition: service_internal.c:1022
unhandleStatus
ZOO_DLL_EXPORT void unhandleStatus(maps *)
Stop handling status repport.
Definition: service_internal.c:432
getStatus
ZOO_DLL_EXPORT char * getStatus(int)
Get the current status of the running service.
Definition: service_internal.c:812