view src/util.h @ 500:614a3177b15c noffle tip

Add mail-from option. Some modern mail systems will try and ensure the sender email is a legitimate address. Which will fail if there isn't such an address.
author Jim Hague <jim.hague@acm.org>
date Wed, 14 Aug 2013 12:04:39 +0100
parents 95697d7c97a1
children
line wrap: on
line source

/*
  util.h

  Miscellaneous helper functions.

  $Id: util.h 608 2003-07-23 09:31:01Z bears $
*/

#ifndef UTL_H
#define UTL_H

#if HAVE_CONFIG_H
#include <config.h>
#endif

#include <signal.h>

#if TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <time.h>
#else
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#include <time.h>
#endif
#endif

#include "common.h"

typedef void (*SignalHandler)( int );

/*
  Find first non-whitespace character after <token> tokens in string <line>.
  Return pointer to end of string, if parsing failed.
*/
const char *
Utl_restOfLn( const char *line, unsigned int token );

void
Utl_toLower( Str line );

/*
  Read a line from string.
  Return NULL if pos == NULL or no more line to read
*/
const char *
Utl_getLn( Str result, const char *p );

/*
  Go back to last line.
*/
const char *
Utl_ungetLn( const char *str, const char *p );

/*
  Read a header line from string. Reads continuation lines if
  necessary. Line is returned as formatted, including '\n's.
  Return NULL if pos == NULL or no more line to read.
*/
const char *
Utl_getHeaderLn( Str result, const char *p );

/*
  Strip white spaces from left and right side.
  Return pointer to new start. This is within line.
*/
char *
Utl_stripWhiteSpace( char *line );

/* Strip comment from a line. Comments start with '#'. */
void
Utl_stripComment( char *line );

/* Write timestamp into <file>. */
void
Utl_stamp( Str file );

/* Get time stamp from <file> */
Bool
Utl_getStamp( time_t *result, Str file );

/* Like mktime, but GMT */
time_t
Utl_mktimeGMT( struct tm *t );

/* Put SonOfRFC1036 compliant date string into res. */
void
Utl_newsDate( time_t t, Str res );

/* Attempt to parse a SonOfRFC1036 compliant date string. Return -1 on fail. */
time_t
Utl_parseNewsDate( const char *s );

void
Utl_cpyStr( Str dst, const char *src );

void
Utl_cpyStrN( Str dst, const char *src, int n );

void
Utl_catStr( Str dst, const char *src );

void
Utl_catStrN( Str dst, const char *src, int n );

/* String allocation and copying. */
void
Utl_allocAndCpy( char **dst, const char *src );

/* Install signal handler. */
SignalHandler
Utl_installSignalHandler( int sig, SignalHandler handler );

/* Obtain this system FQDN. */
Bool
Utl_getFQDN( Str result );

/* Ensure a directory exists and create it if not. */
Bool
Utl_createDir( const char *dir );

/* Write text to file in given dir, creating dir if necessary. */
Bool
Utl_writeFile( const char *dirPrefix, const char *dir,
	       const char *file, const char *text);

#endif