util.cc File Reference

#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <ctype.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdexcept>
#include "BaseType.h"
#include "Str.h"
#include "Url.h"
#include "Sequence.h"
#include "Error.h"
#include "parser.h"
#include "util.h"
#include "GNURegex.h"
#include "debug.h"

Include dependency graph for util.cc:

Go to the source code of this file.

Functions

void append_double_to_string (const double &num, string &str)
void append_long_to_string (long val, int base, string &str_val)
string dap_version ()
string double_to_string (const double &num)
void downcase (string &s)
string file_to_string (FILE *fp)
FILE * get_temp_file (char *temp)
char * get_tempfile_template (char *file_template)
const char * libdap_name ()
const char * libdap_root ()
const char * libdap_version ()
string long_to_string (long val, int base)
string path_to_filename (string path)
string prune_spaces (const string &name)
string systime ()
bool unique_names (vector< BaseType * > l, const string &var_name, const string &type_name, string &msg)
Security functions
bool pathname_ok (const string &path, bool strict)
 Does the string name a potentailly valid pathname? Test the given pathname to verfiy that it is a valid name. We define this as: Contains only printable characters; and Is less then 256 characters. If strict is true, test that the pathname consists of only letters, digits, and underscore, dash and dot characters instead of the more general case where a pathname can be composed of any printable characters.
bool size_ok (uint sz, uint nelem)
 sanitize the size of an array. Test for integer overflow when dynamically allocating an array.


Function Documentation

void append_double_to_string ( const double &  num,
string &  str 
)

Definition at line 439 of file util.cc.

Referenced by double_to_string().

void append_long_to_string ( long  val,
int  base,
string &  str_val 
)

Definition at line 402 of file util.cc.

References append_long_to_string().

Referenced by append_long_to_string(), InternalErr::InternalErr(), long_to_string(), and parse_error().

Here is the call graph for this function:

string dap_version (  ) 

Get the version of the DAP library.

Definition at line 461 of file util.cc.

References libdap_version().

Here is the call graph for this function:

string double_to_string ( const double &  num  ) 

Definition at line 450 of file util.cc.

References append_double_to_string().

Referenced by GeoConstraint::set_bounding_box().

Here is the call graph for this function:

void downcase ( string &  s  ) 

Definition at line 373 of file util.cc.

Referenced by is_keyword(), and String_to_AttrType().

string file_to_string ( FILE *  fp  ) 

Read stuff from a file and dump it into a string. This assumes the file holds character data only. Intended for testing...

Parameters:
fp Read from this file
Returns:
Returns a string which holds the character data.

Definition at line 575 of file util.cc.

FILE* get_temp_file ( char *  temp  ) 

Intended for testing, this may have other uses. The template should be the pathname of the temporary file ending in 'XXXXXX' (as for mkstemp) and will be modified.

Parameters:
temp Pathname, ending in 'XXXXXX'
Returns:
A FILE pointer opened for update.

Definition at line 560 of file util.cc.

char* get_tempfile_template ( char *  file_template  ) 

Build a template for a temporary file suitable for use with mkstemp. Look around for a reasonable place to put a temporary file. Check first the value of the TMPDIR env var. If that does not yield a path that's writable (as defined by access(..., W_OK|R_OK)) then look at P_tmpdir (as defined in stdio.h. If both come up empty, then use `./'.

This function allocates storage using new. The caller must delete the char array.

Parameters:
file_template A template suitable for use with mkstemp (so it has to have six extra chars at its end. This is combined with the path to some temporary directory (see above).
Returns:
A writable char[] that holds the fully qualified filename/template to use with mkstemp.

Definition at line 504 of file util.cc.

References size_ok().

Referenced by get_temp_file().

Here is the call graph for this function:

const char* libdap_name (  ) 

Definition at line 188 of file util.cc.

References PACKAGE_NAME.

const char* libdap_root (  ) 

Definition at line 166 of file util.cc.

References LIBDAP_ROOT, and libdap_root().

Referenced by libdap_root().

Here is the call graph for this function:

const char* libdap_version (  ) 

Return the version string for this package.

Note:
This function has C linkage so that it can be found using autoconf tests.
Returns:
The version string.

Definition at line 181 of file util.cc.

References PACKAGE_VERSION.

Referenced by dap_version().

string long_to_string ( long  val,
int  base 
)

Definition at line 431 of file util.cc.

References append_long_to_string().

Referenced by AISDatabaseParser::aisError(), AISDatabaseParser::aisFatalError(), AISDatabaseParser::aisWarning(), build_btp_args(), DDXParser::ddx_fatal_error(), RCReader::get_proxy_server_host_url(), SignalHandler::register_handler(), save_str(), and libdap::set_array_using_double().

Here is the call graph for this function:

string path_to_filename ( string  path  ) 

Get the filename part from a path. This function can be used to return a string that has the directory components stripped from a path. This is useful when building error message strings.

If WIN32 is defined, use '\' as the path separator, otherwise use '/' as the path separator.

Returns:
A string containing only the filename given a path.

Definition at line 483 of file util.cc.

bool pathname_ok ( const string &  path,
bool  strict 
)

Note:
Using this function does not guarentee that the path is valid, only that the path could be valid. The intent is foil attacks where an exploit is encoded in a string then passed to a library function. This code does not address whether the pathname references a valid resource.
Parameters:
path The pathname to test
strict Apply more restrictive tests (true by default)
Returns:
true if the pathname consists of legal characters and is of legal size, false otherwise.

Definition at line 616 of file util.cc.

string prune_spaces ( const string &  name  ) 

Removed spaces from the front of a URL and also from the front of the CE. This function assumes that there are no holes in both the URL and the CE. It will remove leading space, but not other spaces.

Todo:
Is this still needed? This function may predate the switch from libwww to libcurl and the latter may not need to have spaces removed.
Parameters:
name The URL to process
Returns:
Returns a new string object that contains the pruned URL.

Definition at line 94 of file util.cc.

Referenced by Connect::Connect(), and is_keyword().

bool size_ok ( uint  sz,
uint  nelem 
)

Parameters:
nelem Number of elements.
sz size of each element.
Returns:
True if the nelem elements of sz size will overflow an array.

Definition at line 594 of file util.cc.

Referenced by build_btp_args(), and get_tempfile_template().

string systime (  ) 

Definition at line 360 of file util.cc.

bool unique_names ( vector< BaseType * >  l,
const string &  var_name,
const string &  type_name,
string &  msg 
)

Definition at line 117 of file util.cc.

References DBG.

Referenced by Structure::check_semantics(), Sequence::check_semantics(), Grid::check_semantics(), and DDS::check_semantics().


Generated on Fri Nov 30 10:50:21 2007 for libdap++ by  doxygen 1.5.1