Anope IRC Services  Version 1.8
Data Structures | Macros | Functions | Variables
misc.c File Reference
#include "services.h"
#include "language.h"
Include dependency graph for misc.c:

Go to the source code of this file.

Data Structures

struct  arc4_stream
 

Macros

#define issp(c)   ((c) == 32)
 

Functions

int toupper (char c)
 
int tolower (char c)
 
void binary_to_hex (unsigned char *bin, char *hex, int length)
 
char * strscpy (char *d, const char *s, size_t len)
 
char * stristr (char *s1, char *s2)
 
char * strnrepl (char *s, int32 size, const char *old, const char *new)
 
char * merge_args (int argc, char **argv)
 
static int do_match_wild (const char *pattern, const char *str, int docase)
 
int match_wild (const char *pattern, const char *str)
 
int match_wild_nocase (const char *pattern, const char *str)
 
int process_numlist (const char *numstr, int *count_ret, range_callback_t callback, User *u,...)
 
int dotime (const char *s)
 
char * duration (NickAlias *na, char *buf, int bufsize, time_t seconds)
 
char * expire_left (NickAlias *na, char *buf, int len, time_t expires)
 
int doValidHost (const char *host, int type)
 
int isValidHost (const char *host, int type)
 
int isvalidchar (const char c)
 
char * myStrGetToken (const char *str, const char dilim, int token_number)
 
char * myStrGetOnlyToken (const char *str, const char dilim, int token_number)
 
char * myStrGetTokenRemainder (const char *str, const char dilim, int token_number)
 
char * myStrSubString (const char *src, int start, int end)
 
void protocol_debug (char *source, char *cmd, int argc, char **argv)
 
void doCleanBuffer (char *str)
 
void EnforceQlinedNick (char *nick, char *killer)
 
int nickIsServices (char *tempnick, int bot)
 
static void arc4_init (void)
 
static void arc4_addrandom (void *dat, int datlen)
 
void rand_init (void)
 
void add_entropy_userkeys (void)
 
unsigned char getrandom8 (void)
 
u_int16_t getrandom16 (void)
 
u_int32_t getrandom32 (void)
 
char * send_token (char *token1, char *token2)
 
int myNumToken (const char *str, const char dilim)
 
char * host_resolve (char *host)
 
char * str_signed (unsigned char *str)
 
char * stripModePrefix (const char *str)
 
void ntoa (struct in_addr addr, char *ipaddr, int len)
 
char ** buildStringList (char *src, int *number)
 
size_t strlcat (char *dst, const char *src, size_t siz)
 
size_t strlcpy (char *dst, const char *src, size_t siz)
 
uint32 cidr_to_netmask (uint16 cidr)
 
uint16 netmask_to_cidr (uint32 mask)
 
int str_is_wildcard (const char *str)
 
int str_is_pure_wildcard (const char *str)
 
uint32 str_is_ip (char *str)
 
int str_is_cidr (char *str, uint32 *ip, uint32 *mask, char **host)
 

Variables

struct arc4_stream rs
 

Macro Definition Documentation

#define issp (   c)    ((c) == 32)

Definition at line 19 of file misc.c.

Referenced by doCleanBuffer().

Function Documentation

void add_entropy_userkeys ( void  )

Setup the random numbers

Returns
void

Definition at line 1028 of file misc.c.

References arc4_addrandom(), UserKey1, UserKey2, and UserKey3.

Referenced by init_secondary().

static void arc4_addrandom ( void *  dat,
int  datlen 
)
static

arc4 addrandom

Parameters
data
dalenData Length
Returns
void

Definition at line 956 of file misc.c.

References arc4_stream::i, arc4_stream::j, rs, and arc4_stream::s.

Referenced by add_entropy_userkeys(), and rand_init().

static void arc4_init ( void  )
static

arc4 init

Returns
void

Definition at line 939 of file misc.c.

References arc4_stream::i, arc4_stream::j, rs, and arc4_stream::s.

Referenced by rand_init().

void binary_to_hex ( unsigned char *  bin,
char *  hex,
int  length 
)

Simple function to convert binary data to hex. Taken from hybrid-ircd ( http://ircd-hybrid.com/ )

Definition at line 67 of file misc.c.

Referenced by md5_encrypt(), and sha1_encrypt().

char** buildStringList ( char *  src,
int *  number 
)

Build a string list from a given source string. This is usually used for parsing out values from the config file, but could be used for other things. NOTE: this function uses strtok(), be aware it will break any buffer you think you have in there ;)

Definition at line 1211 of file misc.c.

References srealloc(), and sstrdup().

Referenced by read_config().

uint32 cidr_to_netmask ( uint16  cidr)

Turn a cidr value into a netmask

Parameters
cidrCIDR value
Returns
Netmask value

Definition at line 1501 of file misc.c.

Referenced by str_is_cidr().

static int do_match_wild ( const char *  pattern,
const char *  str,
int  docase 
)
static

do_match_wild: Attempt to match a string to a pattern which might contain '*' or '?' wildcards. Return 1 if the string matches the pattern, 0 if not.

Parameters
patternTo be matched
strString in which the pattern is to be matched
docaseCase In/Senstive
Returns
1 if the string matches the pattern, 0 if not.

Definition at line 204 of file misc.c.

References c, and tolower().

Referenced by match_wild(), and match_wild_nocase().

void doCleanBuffer ( char *  str)

Clean up the buffer for extra spaces

Parameters
strto clean up
Returns
void

Definition at line 800 of file misc.c.

References issp.

Referenced by event_message_process(), and process().

int dotime ( const char *  s)

dotime: Return the number of seconds corresponding to the given time string. If the given string does not represent a valid time, return -1.

A time string is either a plain integer (representing a number of seconds), or an integer followed by one of these characters: "s" (seconds), "m" (minutes), "h" (hours), or "d" (days).

Parameters
sString to convert
Returns
int

Definition at line 364 of file misc.c.

Referenced by AnopeInit(), do_akill(), do_chankill(), do_exception(), do_ignoreuser(), do_nick(), do_sgline(), do_sqline(), do_szline(), do_tban(), main(), parse_directive(), and resetDefCon().

int doValidHost ( const char *  host,
int  type 
)

Validate the host shortname = ( letter / digit ) *( letter / digit / "-" ) *( letter / digit ) hostname = shortname *( "." shortname ) ip4addr = 1*3digit "." 1*3digit "." 1*3digit "." 1*3digit

Parameters
host= string to check
type= format, 1 = ip4addr, 2 = hostname
Returns
1 if a host is valid, 0 if it isnt.

Ultimate3 dosnt like a non-dotted hosts at all, nor does unreal, so just dont allow them.

Definition at line 529 of file misc.c.

References HOSTMAX.

Referenced by isValidHost().

char* duration ( NickAlias na,
char *  buf,
int  bufsize,
time_t  seconds 
)

Expresses in a string the period of time represented by a given amount of seconds (with days/hours/minutes).

Parameters
naNick Alias
bufbuffer to store result into
bufsizeSize of the buffer
secondstime in seconds
Returns
buffer

Definition at line 402 of file misc.c.

References getstring, and snprintf().

Referenced by do_fantasy(), do_recover(), and myHelpResonse().

void EnforceQlinedNick ( char *  nick,
char *  killer 
)
char* expire_left ( NickAlias na,
char *  buf,
int  len,
time_t  expires 
)

Generates a human readable string of type "expires in ..."

Parameters
naNick Alias
bufbuffer to store result into
bufsizeSize of the buffer
secondstime in seconds
Returns
buffer

Definition at line 470 of file misc.c.

References getstring, and snprintf().

Referenced by akill_view(), exception_view(), sgline_view(), sqline_view(), and szline_view().

u_int16_t getrandom16 ( void  )

Get the random numbers 16 byte deep

Returns
char

Definition at line 1061 of file misc.c.

References getrandom8().

Referenced by collide(), and do_register().

u_int32_t getrandom32 ( void  )

Get the random numbers 32 byte deep

Returns
char

Definition at line 1076 of file misc.c.

References getrandom8().

unsigned char getrandom8 ( void  )

Get the random numbers 8 byte deep

Returns
char

Definition at line 1042 of file misc.c.

References arc4_stream::i, arc4_stream::j, rs, and arc4_stream::s.

Referenced by getrandom16(), and getrandom32().

char* host_resolve ( char *  host)

Resolve a host to an IP

Parameters
hostto convert
Returns
ip address

Definition at line 1134 of file misc.c.

References alog(), debug, ntoa(), and sstrdup().

Referenced by _common_unban(), and _elist_match_user().

int isvalidchar ( const char  c)

Valid character check

Parameters
cCharacter to check
Returns
1 if a host is valid, 0 if it isnt.

Definition at line 634 of file misc.c.

Referenced by do_setall(), and myDoSet().

int isValidHost ( const char *  host,
int  type 
)

Front end to doValidHost

Parameters
host= string to check
type= format, 1 = ip4addr, 2 = hostname
Returns
1 if a host is valid, 0 if it isnt.

Definition at line 614 of file misc.c.

References doValidHost().

Referenced by do_bot(), do_jupe(), do_setall(), hs_do_request(), and myDoSet().

int match_wild ( const char *  pattern,
const char *  str 
)

match_wild: Case Senstive wild card search

Parameters
patternTo be matched
strString in which the pattern is to be matched
Returns
1 if the string matches the pattern, 0 if not.

Definition at line 255 of file misc.c.

References do_match_wild().

Referenced by do_access(), and do_noop().

int match_wild_nocase ( const char *  pattern,
const char *  str 
)
char* merge_args ( int  argc,
char **  argv 
)

merge_args: Take an argument count and argument vector and merge them into a single string in which each argument is separated by a space.

Parameters
intNumber of Args
argvArray
Returns
string of the merged array

Definition at line 180 of file misc.c.

References snprintf().

Referenced by anope_event_fjoin(), anope_event_tburst(), anope_event_topic(), chan_set_modes(), do_cmode(), do_join(), do_kick(), do_part(), do_quit(), do_topic(), do_umode(), do_umode2(), and inspircd_cmd_svsmode().

int myNumToken ( const char *  str,
const char  dilim 
)

Number of tokens in a string

Parameters
strString
dilimDilimiter
Returns
number of tokens

Definition at line 1112 of file misc.c.

Referenced by anope_event_bmask().

char* myStrGetOnlyToken ( const char *  str,
const char  dilim,
int  token_number 
)

Get the token only

Parameters
strString to search in
dilimCharacter to search for
token_numberthe token number
Returns
token

Definition at line 685 of file misc.c.

References myStrSubString().

Referenced by anope_event_newmask(), do_list(), do_setall(), hs_do_request(), listOut(), moduleGetConfigDirective(), and myDoSet().

char* myStrGetToken ( const char *  str,
const char  dilim,
int  token_number 
)
char* myStrGetTokenRemainder ( const char *  str,
const char  dilim,
int  token_number 
)

Get the Remaining tokens

Parameters
strString to search in
dilimCharacter to search for
token_numberthe token number
Returns
token

Definition at line 720 of file misc.c.

References myStrSubString().

Referenced by anope_event_newmask(), anope_event_server(), capab_parse(), do_fantasy(), do_list(), do_setall(), hs_do_reject(), hs_do_request(), listOut(), mLoadData(), moduleGetConfigDirective(), my_cs_appendtopic(), myAddChanInfo(), myAddNickInfo(), and myDoSet().

char* myStrSubString ( const char *  src,
int  start,
int  end 
)

Get the string between point A and point B

Parameters
strString to search in
startPoint A
endPoint B
Returns
the string in between

Definition at line 753 of file misc.c.

Referenced by myStrGetOnlyToken(), myStrGetToken(), and myStrGetTokenRemainder().

uint16 netmask_to_cidr ( uint32  mask)

Turn a netmask into a cidr value

Parameters
maskNetmask
Returns
CIDR value

Definition at line 1514 of file misc.c.

int nickIsServices ( char *  tempnick,
int  bot 
)
void ntoa ( struct in_addr  addr,
char *  ipaddr,
int  len 
)

Definition at line 1198 of file misc.c.

References snprintf().

Referenced by do_nick(), and host_resolve().

int process_numlist ( const char *  numstr,
int *  count_ret,
range_callback_t  callback,
User u,
  ... 
)

Process a string containing a number/range list in the form "n1[-n2][,n3[-n4]]...", calling a caller-specified routine for each number in the list. If the callback returns -1, stop immediately. Returns the sum of all nonnegative return values from the callback. If `count' is non-NULL, it will be set to the total number of times the callback was called.

The callback should be of type range_callback_t, which is defined as: int (*range_callback_t)(User *u, int num, va_list args)

Parameters
numstr
count_ret
callbackCall back function
uUser Struct
...various args
Returns
int

Definition at line 292 of file misc.c.

References VA_COPY.

Referenced by do_access(), do_akick(), do_badwords(), do_del(), do_exception(), do_list(), do_read(), and do_xop().

void protocol_debug ( char *  source,
char *  cmd,
int  argc,
char **  argv 
)

Definition at line 773 of file misc.c.

References alog(), and protocoldebug.

Referenced by process().

void rand_init ( void  )

random init

Returns
void

Definition at line 977 of file misc.c.

References arc4_addrandom(), arc4_init(), and mysql_rand().

Referenced by init_secondary().

char* send_token ( char *  token1,
char *  token2 
)
int str_is_cidr ( char *  str,
uint32 ip,
uint32 mask,
char **  host 
)

Check if the given string is an IP or CIDR mask, and fill the given ip/cidr params if so.

Parameters
strString to check
ipThe ipmask to fill when a CIDR is found
maskThe CIDR mask to fill when a CIDR is found
hostDisplayed host
Returns
1 for IP/CIDR, 0 for anything else

Definition at line 1602 of file misc.c.

References cidr_to_netmask(), snprintf(), and sstrdup().

Referenced by entry_create().

uint32 str_is_ip ( char *  str)

Check if the given string is an IP, and return the IP.

Parameters
strString to check
Returns
The IP, if one found. 0 if none.

Definition at line 1565 of file misc.c.

Referenced by _common_unban(), and _elist_match_user().

int str_is_pure_wildcard ( const char *  str)

Check if the given string is a pure wildcard

Parameters
strString to check
Returns
1 for pure wildcard, 0 for anything else

Definition at line 1547 of file misc.c.

Referenced by entry_create().

int str_is_wildcard ( const char *  str)

Check if the given string is some sort of wildcard

Parameters
strString to check
Returns
1 for wildcard, 0 for anything else

Definition at line 1531 of file misc.c.

Referenced by entry_create().

char* str_signed ( unsigned char *  str)

Change an unsigned string to a signed string, overwriting the original string.

Parameters
inputstring
Returns
output string, same as input string.

Definition at line 1169 of file misc.c.

Referenced by encode_ip().

char* stripModePrefix ( const char *  str)

Strip the mode prefix from the given string. Useful for using the modes stored in things like ircd->ownerset etc..

Definition at line 1188 of file misc.c.

References sstrdup().

Referenced by chan_set_correct_modes(), check_should_owner(), check_should_protect(), and check_valid_op().

char* stristr ( char *  s1,
char *  s2 
)

stristr: Search case-insensitively for string s2 within string s1, returning the first occurrence of s2 or NULL if s2 was not found.

Parameters
s1String 1
s2String 2
Returns
first occurrence of s2

Definition at line 113 of file misc.c.

References tolower().

Referenced by botchanmsgs(), do_group(), and do_register().

size_t strlcat ( char *  dst,
const char *  src,
size_t  siz 
)

Definition at line 1263 of file misc.c.

Referenced by anope_event_fjoin(), and plexus_cmd_svid_umode3().

size_t strlcpy ( char *  dst,
const char *  src,
size_t  siz 
)

Definition at line 1293 of file misc.c.

Referenced by plexus_cmd_svid_umode3().

char* strnrepl ( char *  s,
int32  size,
const char *  old,
const char *  new 
)

strnrepl: Replace occurrences of `old' with `new' in string `s'. Stop replacing if a replacement would cause the string to exceed `size' bytes (including the null terminator). Return the string.

Parameters
sString
sizesize of s
oldcharacter to replace
newcharacter to replace with
Returns
updated s

Definition at line 144 of file misc.c.

Referenced by do_act(), lang_sanitize(), notice_help(), strftime_lang(), and unreal_cmd_sgline().

char* strscpy ( char *  d,
const char *  s,
size_t  len 
)

strscpy: Copy at most len-1 characters from a string to a buffer, and add a null terminator after the last character copied.

Parameters
dBuffer to copy into
sData to copy int
lenLength of data
Returns
updated buffer

Definition at line 91 of file misc.c.

int tolower ( char  c)

tolower: Like the ANSI functions, but make sure we return an int instead of a (signed) char.

Parameters
cChar
Returns
int

Definition at line 52 of file misc.c.

References c.

Referenced by do_match_wild(), and stristr().

int toupper ( char  c)

toupper: Like the ANSI functions, but make sure we return an int instead of a (signed) char.

Parameters
cChar
Returns
int

Definition at line 35 of file misc.c.

References c.

Variable Documentation

struct arc4_stream rs