Skip to content

Commit

Permalink
added msForceTmpFileBase and -tmpbase mapserv switch
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/mapserver/trunk@4399 7532c77e-422f-0410-93f4-f0b67bdd69e2
  • Loading branch information
warmerdam committed Feb 9, 2005
1 parent 2286126 commit dc00d8a
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 35 deletions.
4 changes: 4 additions & 0 deletions HISTORY.TXT
Expand Up @@ -16,6 +16,10 @@ the CVS logs is updated daily at the following URL:
Version 4.5
-----------

- Added msForceTmpFileBase() and mapserv -tmpbase switch to allow overriding
temporary file naming conventions. Mainly intended to make writing
testscripts using mapserv easier. FrankW.

- maporaclespatil.c: Bug fix for: #1109, #1110, #1111, #1112, #1136,
#1210, #1211, #1212, #1213.
Support for compound polygons, fixed internal sql to stay more accurate
Expand Down
5 changes: 5 additions & 0 deletions map.h
Expand Up @@ -28,6 +28,9 @@
******************************************************************************
*
* $Log$
* Revision 1.395 2005/02/09 21:51:17 frank
* added msForceTmpFileBase and -tmpbase mapserv switch
*
* Revision 1.394 2005/02/09 20:43:49 assefa
* Add SVG utility function msSaveImagetoFpSVG.
*
Expand Down Expand Up @@ -1665,6 +1668,8 @@ MS_DLL_EXPORT pointObj *msGetMeasureUsingPoint(shapeObj *shape, pointObj *point)

MS_DLL_EXPORT char **msGetAllGroupNames(mapObj* map, int *numTok);
MS_DLL_EXPORT char *msTmpFile(const char *mappath, const char *tmppath, const char *ext);
MS_DLL_EXPORT void msForceTmpFileBase( const char *new_base );


MS_DLL_EXPORT imageObj *msImageCreate(int width, int height, outputFormatObj *format, char *imagepath, char *imageurl, mapObj *map);

Expand Down
89 changes: 58 additions & 31 deletions mapserv.c
Expand Up @@ -27,6 +27,9 @@
******************************************************************************
*
* $Log$
* Revision 1.144 2005/02/09 21:51:17 frank
* added msForceTmpFileBase and -tmpbase mapserv switch
*
* Revision 1.143 2005/01/28 06:16:54 sdlime
* Applied patch to make function prototypes ANSI C compliant. Thanks to Petter Reinholdtsen. This fixes but 1181.
*
Expand Down Expand Up @@ -1042,6 +1045,9 @@ void returnCoordinate(pointObj pnt)
writeError();
}

/************************************************************************/
/* FastCGI cleanup functions. */
/************************************************************************/
#ifndef WIN32
void msCleanupOnSignal( int nInData )

Expand Down Expand Up @@ -1075,49 +1081,65 @@ void msCleanupOnExit( void )

// FIX: need to consider 5% shape extent expansion

/*
**
** Start of main program
**
*/
/************************************************************************/
/* main() */
/************************************************************************/
int main(int argc, char *argv[]) {
int i,j;
int i,j, iArg;
char buffer[1024];
imageObj *img=NULL;
int status;

if(argc > 1 && strcmp(argv[1], "-v") == 0) {
printf("%s\n", msGetVersion());
fflush(stdout);
exit(0);
}
else if(argc > 2 && strcmp(argv[1], "-t") == 0)
/* -------------------------------------------------------------------- */
/* Process arguments. In normal use as a cgi-bin there are no */
/* commandline switches, but we provide a few for test/debug */
/* purposes, and to query the version info. */
/* -------------------------------------------------------------------- */
for( iArg = 1; iArg < argc; iArg++ )
{
char **tokens;
int numtokens=0;
if ((tokens=msTokenizeMap(argv[2], &numtokens)) != NULL)
{
int i;
for(i=0; i<numtokens; i++)
printf("%s\n", tokens[i]);
msFreeCharArray(tokens, numtokens);
if( strcmp(argv[iArg],"-v") == 0 ) {
printf("%s\n", msGetVersion());
fflush(stdout);
exit(0);
}
else if( iArg < argc-1 && strcmp(argv[iArg], "-tmpbase") == 0) {
msForceTmpFileBase( argv[++iArg] );
}
else if( iArg < argc-1 && strcmp(argv[iArg], "-t") == 0) {
char **tokens;
int numtokens=0;
if ((tokens=msTokenizeMap(argv[iArg+1], &numtokens)) != NULL)
{
int i;
for(i=0; i<numtokens; i++)
printf("%s\n", tokens[i]);
msFreeCharArray(tokens, numtokens);
}
else
{
writeError();
}

exit(0);
}
else if ( strncmp(argv[iArg], "QUERY_STRING=", 13) == 0) {
/* Debugging hook... pass "QUERY_STRING=..." on the command-line */
char *buf;
buf = strdup("REQUEST_METHOD=GET");
putenv(buf);
buf = strdup(argv[1]);
putenv(buf);
}
else
{
writeError();
/* we don't produce a usage message as some web servers pass
junk arguments */
}

exit(0);
}
else if (argc > 1 && strncmp(argv[1], "QUERY_STRING=", 13) == 0) {
/* Debugging hook... pass "QUERY_STRING=..." on the command-line */
char *buf;
buf = strdup("REQUEST_METHOD=GET");
putenv(buf);
buf = strdup(argv[1]);
putenv(buf);
}

/* -------------------------------------------------------------------- */
/* Setup cleanup magic, mainly for FastCGI case. */
/* -------------------------------------------------------------------- */
#ifndef WIN32
signal( SIGUSR1, msCleanupOnSignal );
signal( SIGTERM, msCleanupOnSignal );
Expand All @@ -1130,10 +1152,15 @@ int main(int argc, char *argv[]) {
atexit( msCleanupOnExit );
#endif

// In FastCGI case we loop accepting multiple requests. In normal CGI
// use we only accept and process one request.
while( FCGI_Accept() >= 0 )
{
#endif /* def USE_FASTCGI */

/* -------------------------------------------------------------------- */
/* Process a request. */
/* -------------------------------------------------------------------- */
msObj = msAllocMapServObj();

sprintf(msObj->Id, "%ld%d",(long)time(NULL),(int)getpid()); // asign now so it can be overridden
Expand Down
53 changes: 49 additions & 4 deletions maputil.c
Expand Up @@ -27,6 +27,9 @@
******************************************************************************
*
* $Log$
* Revision 1.174 2005/02/09 21:51:17 frank
* added msForceTmpFileBase and -tmpbase mapserv switch
*
* Revision 1.173 2005/02/09 20:43:50 assefa
* Add SVG utility function msSaveImagetoFpSVG.
*
Expand Down Expand Up @@ -1000,21 +1003,62 @@ char **msGetAllGroupNames(mapObj *map, int *numTok)
return papszGroups;
}

/************************************************************************/
/* msForceTmpFileBase() */
/************************************************************************/

static int tmpCount = -1;
static char *ForcedTmpBase = NULL;

void msForceTmpFileBase( const char *new_base )
{
/* -------------------------------------------------------------------- */
/* Clear previous setting, if any. */
/* -------------------------------------------------------------------- */
if( ForcedTmpBase != NULL )
{
free( ForcedTmpBase );
ForcedTmpBase = NULL;
}

tmpCount = -1;

if( new_base == NULL )
return NULL;

/* -------------------------------------------------------------------- */
/* Record new base. */
/* -------------------------------------------------------------------- */
ForcedTmpBase = strdup( new_base );
tmpCount = 0;
}

/**********************************************************************
* msTmpFile()
*
* Generate a Unique temporary filename using PID + timestamp + extension
* char* returned must be freed by caller
* Generate a Unique temporary filename using:
*
* PID + timestamp + sequence# + extension
*
* If msForceTmpFileBase() has been call to control the temporary filename
* then the filename will be:
*
* TmpBase + sequence# + extension
*
* Returns char* which must be freed by caller.
**********************************************************************/
char *msTmpFile(const char *mappath, const char *tmppath, const char *ext)
{
char *tmpFname;
char szPath[MS_MAXPATHLEN];
const char *fullFname;
static char tmpId[128]; /* big enough for time + pid + ext */
static int tmpCount = -1;

if (tmpCount == -1)
if( ForcedTmpBase != NULL )
{
strncpy( tmpId, ForcedTmpBase, sizeof(tmpId) );
}
else if (tmpCount == -1)
{
/* We'll use tmpId and tmpCount to generate unique filenames */
sprintf(tmpId, "%ld%d",(long)time(NULL),(int)getpid());
Expand Down Expand Up @@ -1210,6 +1254,7 @@ extern void lexer_cleanup(void);

void msCleanup()
{
msForceTmpFileBase( NULL );
msConnPoolFinalCleanup();
lexer_cleanup();
#ifdef USE_OGR
Expand Down

0 comments on commit dc00d8a

Please sign in to comment.