Changeset 216 for trunk/zoo-kernel/service_internal.c
- Timestamp:
- May 31, 2011, 3:13:53 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-kernel/service_internal.c
r114 r216 25 25 #include "service_internal.h" 26 26 27 void *addLangAttr(xmlNodePtr n,maps *m){ 27 #ifdef WIN32 28 char * 29 strtok_r (char *s1, const char *s2, char **lasts) 30 { 31 char *ret; 32 if (s1 == NULL) 33 s1 = *lasts; 34 while (*s1 && strchr(s2, *s1)) 35 ++s1; 36 if (*s1 == '\0') 37 return NULL; 38 ret = s1; 39 while (*s1 && !strchr(s2, *s1)) 40 ++s1; 41 if (*s1) 42 *s1++ = '\0'; 43 *lasts = s1; 44 return ret; 45 } 46 #endif 47 48 void addLangAttr(xmlNodePtr n,maps *m){ 28 49 map *tmpLmap=getMapFromMaps(m,"main","language"); 29 50 if(tmpLmap!=NULL) … … 44 65 } 45 66 46 void* unhandleStatus(maps *conf){ 67 #ifdef WIN32 68 69 #include <windows.h> 70 #include <stdio.h> 71 #include <conio.h> 72 #include <tchar.h> 73 74 #define SHMEMSIZE 4096 75 76 static LPVOID lpvMemG = NULL; // pointer to shared memory 77 static HANDLE hMapObjectG = NULL; // handle to file mapping 78 79 void updateStatus(maps *conf){ 80 fprintf(stderr,"OK Final 1 \n"); 81 fflush(stderr); 82 LPWSTR lpszTmp; 83 BOOL fInit; 84 char *s=NULL; 85 map *tmpMap=getMapFromMaps(conf,"lenv","sid"); 86 fprintf(stderr,"OK Final 11 \n"); 87 fflush(stderr); 88 if(hMapObjectG==NULL) 89 hMapObjectG = CreateFileMapping( 90 INVALID_HANDLE_VALUE, // use paging file 91 NULL, // default security attributes 92 PAGE_READWRITE, // read/write access 93 0, // size: high 32-bits 94 SHMEMSIZE, // size: low 32-bits 95 TEXT(tmpMap->value)); // name of map object 96 if (hMapObjectG == NULL){ 97 fprintf(stderr,"Unable to create share memory segment %s !! \n",tmpMap->value); 98 return ; 99 } 100 fprintf(stderr,"OK Final 2 \n"); 101 fflush(stderr); 102 fInit = (GetLastError() != ERROR_ALREADY_EXISTS); 103 if(lpvMemG==NULL) 104 lpvMemG = MapViewOfFile( 105 hMapObjectG, // object to map view of 106 FILE_MAP_WRITE, // read/write access 107 0, // high offset: map from 108 0, // low offset: beginning 109 0); // default: map entire file 110 if (lpvMemG == NULL){ 111 fprintf(stderr,"Unable to create or access the shared memory segment %s !! \n",tmpMap->value); 112 return ; 113 } 114 fprintf(stderr,"OK Final 3 \n"); 115 fflush(stderr); 116 if (fInit) 117 memset(lpvMemG, '\0', SHMEMSIZE); 118 fprintf(stderr,"OK Final 4 \n"); 119 fflush(stderr); 120 tmpMap=getMapFromMaps(conf,"lenv","status"); 121 lpszTmp = (LPWSTR) lpvMemG; 122 for(s=tmpMap->value;*s!=NULL;s++) 123 *lpszTmp++ = *s; 124 *lpszTmp = '\0'; 125 } 126 127 char* getStatus(int pid){ 128 LPWSTR lpszBuf=NULL; 129 LPWSTR lpszTmp=NULL; 130 LPVOID lpvMem = NULL; 131 HANDLE hMapObject = NULL; 132 BOOL fIgnore,fInit; 133 char tmp[100]; 134 sprintf(tmp,"%i",pid); 135 if(hMapObject==NULL) 136 hMapObject = CreateFileMapping( 137 INVALID_HANDLE_VALUE, // use paging file 138 NULL, // default security attributes 139 PAGE_READWRITE, // read/write access 140 0, // size: high 32-bits 141 4096, // size: low 32-bits 142 TEXT(tmp)); // name of map object 143 if (hMapObject == NULL) 144 return FALSE; 145 if((GetLastError() != ERROR_ALREADY_EXISTS)){ 146 fIgnore = UnmapViewOfFile(lpvMem); 147 fIgnore = CloseHandle(hMapObject); 148 return "-1"; 149 } 150 fInit=TRUE; 151 if(lpvMem==NULL) 152 lpvMem = MapViewOfFile( 153 hMapObject, // object to map view of 154 FILE_MAP_READ, // read/write access 155 0, // high offset: map from 156 0, // low offset: beginning 157 0); // default: map entire file 158 if (lpvMem == NULL) 159 return "-1"; 160 lpszTmp = (LPWSTR) lpvMem; 161 while (*lpszTmp!=NULL) 162 *lpszBuf++ = *lpszTmp++; 163 *lpszBuf = '\0'; 164 fIgnore = UnmapViewOfFile(lpvMem); 165 fIgnore = CloseHandle(hMapObject); 166 return (char*)lpszBuf; 167 } 168 169 void unhandleStatus(maps *conf){ 170 BOOL fIgnore; 171 fIgnore = UnmapViewOfFile(lpvMemG); 172 fIgnore = CloseHandle(hMapObjectG); 173 } 174 #else 175 void unhandleStatus(maps *conf){ 47 176 int shmid,i; 48 177 key_t key; … … 69 198 } 70 199 } 200 201 void updateStatus(maps *conf){ 202 int shmid,i; 203 key_t key; 204 char *shm,*s,*s1; 205 map *tmpMap=NULL; 206 tmpMap=getMapFromMaps(conf,"lenv","sid"); 207 if(tmpMap!=NULL){ 208 key=atoi(tmpMap->value); 209 if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) { 210 #ifdef DEBUG 211 fprintf(stderr,"shmget failed to update value\n"); 212 #endif 213 }else{ 214 if ((shm = (char*) shmat(shmid, NULL, 0)) == (char *) -1) { 215 #ifdef DEBUG 216 fprintf(stderr,"shmat failed to update value\n"); 217 #endif 218 } 219 else{ 220 tmpMap=getMapFromMaps(conf,"lenv","status"); 221 s1=shm; 222 for(s=tmpMap->value;s!=NULL;s++) 223 *s1++=*s; 224 shmdt((void *)shm); 225 } 226 } 227 } 228 } 229 230 char* getStatus(int pid){ 231 int shmid,i; 232 key_t key; 233 void *shm; 234 char *s; 235 key=pid; 236 if ((shmid = shmget(key, SHMSZ, 0666)) < 0) { 237 #ifdef DEBUG 238 fprintf(stderr,"shmget failed in getStatus\n"); 239 #endif 240 }else{ 241 if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) { 242 #ifdef DEBUG 243 fprintf(stderr,"shmat failed in getStatus\n"); 244 #endif 245 }else{ 246 return (char*)shm; 247 } 248 } 249 return "-1"; 250 } 251 252 #endif 71 253 72 254 #ifdef USE_JS … … 109 291 #endif 110 292 111 void* updateStatus(maps *conf){112 int shmid,i;113 key_t key;114 char *shm,*s,*s1;115 map *tmpMap=NULL;116 tmpMap=getMapFromMaps(conf,"lenv","sid");117 if(tmpMap!=NULL){118 key=atoi(tmpMap->value);119 if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) {120 #ifdef DEBUG121 fprintf(stderr,"shmget failed to update value\n");122 #endif123 }else{124 if ((shm = (char*) shmat(shmid, NULL, 0)) == (char *) -1) {125 #ifdef DEBUG126 fprintf(stderr,"shmat failed to update value\n");127 #endif128 }129 else{130 tmpMap=getMapFromMaps(conf,"lenv","status");131 s1=shm;132 for(s=tmpMap->value;s!=NULL;s++)133 *s1++=*s;134 shmdt((void *)shm);135 }136 }137 }138 }139 140 char* getStatus(int pid){141 int shmid,i;142 key_t key;143 void *shm;144 char *s;145 key=pid;146 if ((shmid = shmget(key, SHMSZ, 0666)) < 0) {147 #ifdef DEBUG148 fprintf(stderr,"shmget failed in getStatus\n");149 #endif150 }else{151 if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) {152 #ifdef DEBUG153 fprintf(stderr,"shmat failed in getStatus\n");154 #endif155 }else{156 return (char*)shm;157 }158 }159 return "-1";160 }161 293 162 294 … … 1192 1324 int buffersize; 1193 1325 xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, "UTF-8", 1); 1194 fwrite(xmlbuff,1, strlen(xmlbuff)*sizeof(char),output);1326 fwrite(xmlbuff,1,xmlStrlen(xmlbuff)*sizeof(char),output); 1195 1327 xmlFree(xmlbuff); 1196 1328 fclose(output); … … 1204 1336 1205 1337 void printDocument(maps* m, xmlDocPtr doc,int pid){ 1206 rewind(stdout);1207 1338 char *encoding=getEncoding(m); 1208 1339 if(pid==getpid()){ … … 1218 1349 xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); 1219 1350 printf("%s",xmlbuff); 1220 //fflush(stdout);1351 fflush(stdout); 1221 1352 /* 1222 1353 * Free associated memory. … … 1527 1658 maps* tmpMap=getMaps(m,"main"); 1528 1659 1529 int nsid=zooXmlAddNs(NULL, BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST"ows");1660 int nsid=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows"); 1530 1661 ns=usedNs[nsid]; 1531 1662 n = xmlNewNode(ns, BAD_CAST "ExceptionReport"); … … 1757 1888 } 1758 1889 1759 char *base64(const unsignedchar *input, int length)1890 char *base64(const char *input, int length) 1760 1891 { 1761 1892 BIO *bmem, *b64; … … 1779 1910 } 1780 1911 1781 char *base64d( unsignedchar *input, int length,int* red)1912 char *base64d(const char *input, int length,int* red) 1782 1913 { 1783 1914 BIO *b64, *bmem; … … 1788 1919 b64 = BIO_new(BIO_f_base64()); 1789 1920 if(b64){ 1790 bmem = BIO_new_mem_buf( input,length);1921 bmem = BIO_new_mem_buf((unsigned char*)input,length); 1791 1922 bmem = BIO_push(b64, bmem); 1792 1923 *red=BIO_read(bmem, buffer, length); … … 2078 2209 ns_ows=usedNs[owsId]; 2079 2210 n = xmlNewNode(ns_ows, BAD_CAST "BoundingBox"); 2080 xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1", "ows");2211 xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows"); 2081 2212 int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); 2082 2213 ns_xsi=usedNs[xsiId];
Note: See TracChangeset
for help on using the changeset viewer.