Ignore:
Timestamp:
May 31, 2011, 3:13:53 AM (13 years ago)
Author:
djay
Message:

Add WIN32 platform support. Fix for values containing @ passed as KVP.

File:
1 edited

Legend:

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

    r114 r216  
    2525#include "service_internal.h"
    2626
    27 void *addLangAttr(xmlNodePtr n,maps *m){
     27#ifdef WIN32
     28char *
     29strtok_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
     48void addLangAttr(xmlNodePtr n,maps *m){
    2849  map *tmpLmap=getMapFromMaps(m,"main","language");
    2950  if(tmpLmap!=NULL)
     
    4465}
    4566
    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
     76static LPVOID lpvMemG = NULL;      // pointer to shared memory
     77static HANDLE hMapObjectG = NULL;  // handle to file mapping
     78
     79void 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
     127char* 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
     169void unhandleStatus(maps *conf){
     170  BOOL fIgnore;
     171  fIgnore = UnmapViewOfFile(lpvMemG);
     172  fIgnore = CloseHandle(hMapObjectG);
     173}
     174#else
     175void unhandleStatus(maps *conf){
    47176  int shmid,i;
    48177  key_t key;
     
    69198  }
    70199}
     200
     201void 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
     230char* 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
    71253
    72254#ifdef USE_JS
     
    109291#endif
    110292
    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 DEBUG
    121       fprintf(stderr,"shmget failed to update value\n");
    122 #endif
    123     }else{
    124       if ((shm = (char*) shmat(shmid, NULL, 0)) == (char *) -1) {
    125 #ifdef DEBUG
    126         fprintf(stderr,"shmat failed to update value\n");
    127 #endif
    128       }
    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 DEBUG
    148     fprintf(stderr,"shmget failed in getStatus\n");
    149 #endif
    150   }else{
    151     if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) {
    152 #ifdef DEBUG
    153       fprintf(stderr,"shmat failed in getStatus\n");
    154 #endif
    155     }else{
    156       return (char*)shm;
    157     }
    158   }
    159   return "-1";
    160 }
    161293
    162294
     
    11921324    int buffersize;
    11931325    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);
    11951327    xmlFree(xmlbuff);
    11961328    fclose(output);
     
    12041336
    12051337void printDocument(maps* m, xmlDocPtr doc,int pid){
    1206   rewind(stdout);
    12071338  char *encoding=getEncoding(m);
    12081339  if(pid==getpid()){
     
    12181349  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
    12191350  printf("%s",xmlbuff);
    1220   //fflush(stdout);
     1351  fflush(stdout);
    12211352  /*
    12221353   * Free associated memory.
     
    15271658  maps* tmpMap=getMaps(m,"main");
    15281659
    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");
    15301661  ns=usedNs[nsid];
    15311662  n = xmlNewNode(ns, BAD_CAST "ExceptionReport");
     
    17571888}
    17581889
    1759 char *base64(const unsigned char *input, int length)
     1890char *base64(const char *input, int length)
    17601891{
    17611892  BIO *bmem, *b64;
     
    17791910}
    17801911
    1781 char *base64d(unsigned char *input, int length,int* red)
     1912char *base64d(const char *input, int length,int* red)
    17821913{
    17831914  BIO *b64, *bmem;
     
    17881919    b64 = BIO_new(BIO_f_base64());
    17891920    if(b64){
    1790       bmem = BIO_new_mem_buf(input,length);
     1921      bmem = BIO_new_mem_buf((unsigned char*)input,length);
    17911922      bmem = BIO_push(b64, bmem);
    17921923      *red=BIO_read(bmem, buffer, length);
     
    20782209  ns_ows=usedNs[owsId];
    20792210  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");
    20812212  int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
    20822213  ns_xsi=usedNs[xsiId];
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