Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

stuff.c File Reference

#include "services.h"
#include "hash.h"
#include "nickserv.h"
#include "log.h"

Go to the source code of this file.

Defines

#define HOSTMAX   (HOSTLEN + 1)
#define IrcStr(point)   ((!*(point)) ? "*" : (point))

Functions

void breakString (int numargs, char *string, char **args, char delimiter)
 Splits a string into a vector across a delimeter.

int match (const char *mask, const char *string)
 Matches a string against the specified pattern for wildcards \ as allowed done by IRC clients/servers.

void strtolower (char *str)
 Lowercases a NUL-terminated string in place.

char * sfgets (char *str, int len, FILE *fp)
char * xorit (char *tocrypt)
 Encrypt a password string.

void parse_str (char **args, int argc, int startarg, char *workingstring, size_t sz)
 Merge a vector of strings into one string across delimeters.

void mask (char *user, char *host, int type, char *where)
 This function is used by the NickServ ADDMASK command.

void * oalloc (size_t size)
 Clean and allocate a memory area.

char * flagstring (int flags, const char *bits[])
 Report the names of bits set.

int flagbit (char *name, const char *bits[])
void tzapply (char *to)
char * tokenEncode (char *str)
 Applies the mask (string) hashing algorithm to a token.

char * genHostMask (char *host)
 Returns the masked version of a host.

char * str_dup (const char *input)
 Allocates and returns a copy of the supplied string.

char * strn_dup (const char *input, int max)
 Allocates and returns a copy of part of the supplied string.

MaskDatamake_mask ()
 Allocates a mask structure.

void free_mask (MaskData *mask)
 Frees a mask structure.

int split_userhost (const char *input_host, MaskData *data)
 Splits a string into a supplied mask structure.

void AppendBuffer (char **buf, const char *add)
void SetDynBuffer (char **buf, const char *newStr)
char * urlEncode (const char *in)
void rshift_argv (char **args, int x, int numargs)


Detailed Description

Implementation of utility functions
Author:
Chip Norkus

Max Byrd

Greg Poma

James Hess

Definition in file stuff.c.


Function Documentation

void AppendBuffer char **  buf,
const char *  add
 

Precondition:
From points to a valid NUL-terminated character array, and add is a reference to a character array to be changed.
Postcondition:
*Buf area is reallocated to contain its present state plus the string specified as 'add'

Definition at line 744 of file stuff.c.

References oalloc().

Referenced by dbReadString().

void breakString int  numargs,
char *  string,
char **  args,
char  delimiter
 

Splits a string into a vector across a delimeter.

Parameters:
numargs Maximum number of args to split the string into (N of args[])
string The string to split
args An array to store the string after it is split
delimeter Where to separate the string
Todo:
Remove this function if possible (or redo it)
===DOC=== This function returns data much like an argc/argv setup. send it an integer, the string of data you want broken up, an array for storage, and a delimiter character to seperate sets of data by. Ex: I call fixUpData like this: int blah; char *holdme[]; ... breakString(blah, "WD is a programmer", holdme[], ' '); now: blah == 5 holdme[0] == "WD", holdme[2] == "a", holdme[3] == "programmer", etc. (All strings end in ) the idea for this was given to me by JoelKatz (David Schwartz) of DALnet

Definition at line 74 of file stuff.c.

int flagbit char *  name,
const char *  bits[]
 

Parameters:
Get the bit flag number from the name and array of flag names
name Name of the flag to get the bit number of
bits Array of bit names (in bit order)

Definition at line 467 of file stuff.c.

char* flagstring int  flags,
const char *  bits[]
 

Report the names of bits set.

Parameters:
flags Mask of bits from which the names of those set is to be reported
bits Array of strings that represent the names of bits (in order)
The bitmask is converted into a string indicating which flags are present in the string.

Definition at line 441 of file stuff.c.

void free_mask MaskData mask  ) 
 

Frees a mask structure.

Parameters:
mask Mask structure to free

Definition at line 646 of file stuff.c.

References mask().

char* genHostMask char *  host  ) 
 

Returns the masked version of a host.

Parameters:
host Name of the host to mask

Definition at line 521 of file stuff.c.

References FALSE, tokenEncode(), and TRUE.

Referenced by addUserToChan(), getMiscChanOp(), IpcType::queryRegNickMessage(), and regnick_ugethost().

void mask char *  user,
char *  host,
int  type,
char *  where
 

This function is used by the NickServ ADDMASK command.

Parameters:
user Username field
host Hostname field
type Prefix username in result with a *? (1 or 0)
The mask function is used to generate a pattern that matches the supplied usermask information at the user@*.domain.com level.

Definition at line 355 of file stuff.c.

Referenced by addAccessMask(), addakill(), autoremoveakill(), banKick(), delAccessMask(), free_mask(), GetCrule(), listAkills(), loadakills(), make_mask(), match(), ns_addmask(), queueakill(), removeAkill(), and removeAkillType().

int match const char *  mask,
const char *  string
 

Matches a string against the specified pattern for wildcards \ as allowed done by IRC clients/servers.

Parameters:
mask Pattern to match against
string String to match

Compare if a given string (name) matches the given mask.

A wildcard match can be made, '*' matches any number of characters and '?' matches any single character.

Additionally, wildcards can be escaped with a preceding \.

return 0, if match 1, if no match

Bug:
match() comes from ircd, it is GPL'ed and services can't be \ distributed while it remains.

Definition at line 129 of file stuff.c.

References mask().

Referenced by addUserToChan(), checkAccess(), checkAkillAllUsers(), do_chanop_list(), GetCruleMatch(), getMiscChanOp(), isAHurt(), isAKilled(), isIgnored(), isQlined(), and UpdateCrule().

void* oalloc size_t  size  ) 
 

Clean and allocate a memory area.

Parameters:
size How many bytes of memory are to be allocated
Allocate n bytes of memory, check that is was properly allocated and clean it. This function is like calloc(), but will shut down services cleanly if it fails to allocate

Definition at line 404 of file stuff.c.

References sshutdown().

Referenced by addakill(), addClone(), addGhost(), addNewUser(), addOpData(), addRegNick(), addUserClone(), addUserToChan(), AppendBuffer(), banKick(), changeNick(), changeNickOnAllChans(), detect_mass(), dlogInit(), fromBase64(), help(), is_postnews(), loadakills(), make_mask(), make_palert(), MakeChannelTrigger(), IpcType::makeMessage(), NewCrule(), IpcType::pollAndHandle(), readChanData(), readInfoData(), readMemoData(), readNickData(), setChanMode(), SetDynBuffer(), setIdentify(), str_dup(), strn_dup(), timer(), and toBase64().

void parse_str char **  args,
int  argc,
int  startarg,
char *  workingstring,
size_t  sz
 

Merge a vector of strings into one string across delimeters.

Parameters:
args Source vector
argc Number of arguments in vector
startarg First item from vector to parse
sz Size of the working buffer Buffer of size IRCBUF to fill parsed buffer into
Takes an array of strings and fills a third single string with their contents, each string separated by a space.

this function is the reverse of the original breakString

Definition at line 318 of file stuff.c.

Referenced by adCheck(), addNewUser(), help(), is_postnews(), and setChanTopic().

void SetDynBuffer char **  buf,
const char *  newStr
 

Precondition:
From points to a valid NUL-terminated character array, and add is a reference to a character array to be changed.
Postcondition:
*Buf area is reallocated to contain the string specified as 'new'

Definition at line 774 of file stuff.c.

References oalloc().

Referenced by IpcType::authObjMessage(), IpcType::authSysMessage(), freeRegNickListRec(), freeUserListRec(), IpcType::makeMessage(), NickSeeUser(), ns_addmask(), readNickData(), and SetUserNickHostReal().

int split_userhost const char *  input_host,
MaskData data
 

Splits a string into a supplied mask structure.

Parameters:
input_host String to split
data Mask structure to fill and allocate members of

Definition at line 664 of file stuff.c.

References corelog, mask_structure::host, logDump(), mask_structure::nick, str_dup(), strn_dup(), and mask_structure::user.

char* str_dup const char *  input  ) 
 

Allocates and returns a copy of the supplied string.

Parameters:
input String to duplicate

Definition at line 597 of file stuff.c.

References oalloc().

Referenced by IpcType::authObjMessage(), IpcType::authSysMessage(), dbWriteString(), is_sendinfo(), MakeChannelTrigger(), and split_userhost().

char * strn_dup const char *  input,
int  max
 

Allocates and returns a copy of part of the supplied string.

Parameters:
input String to duplicate
max Maximum length of new string

Definition at line 614 of file stuff.c.

References oalloc().

Referenced by split_userhost().

char * tokenEncode char *  str  ) 
 

Applies the mask (string) hashing algorithm to a token.

Parameters:
str String (token) that is to be hashed

Definition at line 503 of file stuff.c.

Referenced by genHostMask().

char* xorit char *  tocrypt  ) 
 

Encrypt a password string.

Parameters:
tocrypt String to encrypt in place
Code passwords before writing them to services' database - this measure allows roots to examine the structure of the services database and search for corruption without having passwords that they don't need or want to see shown to them.

Definition at line 286 of file stuff.c.

References strncpyzt.

Referenced by readChanData(), readNickData(), saveChanData(), and saveNickData().


Generated at Sat Oct 25 20:56:12 2003 for Services using Doxygen.
Services Copyr. 1996-2001 Chip Norkus, Max Byrd, Greg Poma, Michael Graff, James Hess, Dafydd James. All rights reserved See LICENSE for licensing information.