misc.c File Reference

#include "services.h"
#include "language.h"

Go to the source code of this file.

Data Structures

struct  arc4_stream

Defines

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

Functions

void add_entropy_userkeys (void)
void binary_to_hex (unsigned char *bin, char *hex, int length)
char ** buildStringList (char *src, int *number)
void doCleanBuffer (char *str)
int dotime (const char *s)
int doValidHost (const char *host, int type)
char * duration (NickAlias *na, char *buf, int bufsize, time_t seconds)
void EnforceQlinedNick (char *nick, char *killer)
char * expire_left (NickAlias *na, char *buf, int len, time_t expires)
u_int16_t getrandom16 (void)
u_int32_t getrandom32 (void)
unsigned char getrandom8 (void)
char * host_resolve (char *host)
int isvalidchar (const char c)
int isValidHost (const char *host, int type)
int match_wild (const char *pattern, const char *str)
int match_wild_nocase (const char *pattern, const char *str)
char * merge_args (int argc, char **argv)
int myNumToken (const char *str, const char dilim)
char * myStrGetOnlyToken (const char *str, const char dilim, int token_number)
char * myStrGetToken (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)
int nickIsServices (char *tempnick, int bot)
void ntoa (struct in_addr addr, char *ipaddr, int len)
int process_numlist (const char *numstr, int *count_ret, range_callback_t callback, User *u,...)
void protocol_debug (char *source, char *cmd, int argc, char **argv)
void rand_init (void)
char * send_token (char *token1, char *token2)
char * str_signed (unsigned char *str)
char * stripModePrefix (const char *str)
char * stristr (char *s1, char *s2)
size_t strlcat (char *dst, const char *src, size_t siz)
size_t strlcpy (char *dst, const char *src, size_t siz)
char * strnrepl (char *s, int32 size, const char *old, const char *new)
char * strscpy (char *d, const char *s, size_t len)
int tolower (char c)
int toupper (char c)

Variables

arc4_stream rs


Define Documentation

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

Definition at line 20 of file misc.c.

Referenced by doCleanBuffer().


Function Documentation

void add_entropy_userkeys ( void   ) 

Setup the random numbers

Returns:
void

Definition at line 1030 of file misc.c.

References UserKey1, UserKey2, and UserKey3.

Referenced by init_secondary().

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 68 of file misc.c.

Referenced by md5_encrypt(), old_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 1214 of file misc.c.

References sstrdup().

void doCleanBuffer ( char *  str  ) 

Clean up the buffer for extra spaces

Parameters:
str to clean up
Returns:
void

Definition at line 801 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:
s String to convert
Returns:
int

Definition at line 365 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(), 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 530 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:
na Nick Alias
buf buffer to store result into
bufsize Size of the buffer
seconds time in seconds
Returns:
buffer

Definition at line 403 of file misc.c.

References getstring, and snprintf().

void EnforceQlinedNick ( char *  nick,
char *  killer 
)

Kill the user to enforce the sqline

Parameters:
nick to kill
killer whom is doing the killing
Returns:
void

Definition at line 838 of file misc.c.

References alog(), finduser(), user_::host, kill_user(), user_::nick, and user_::username.

Referenced by bahamut_cmd_bot_nick(), bahamut_cmd_nick(), charybdis_cmd_bot_nick(), charybdis_cmd_nick(), do_bot(), dreamforge_cmd_bot_nick(), dreamforge_cmd_nick(), hybrid_cmd_bot_nick(), hybrid_cmd_nick(), plexus_cmd_bot_nick(), plexus_cmd_nick(), ptlink_cmd_bot_nick(), ptlink_cmd_nick(), rageircd_cmd_bot_nick(), rageircd_cmd_nick(), ratbox_cmd_bot_nick(), ratbox_cmd_nick(), shadowircd_cmd_bot_nick(), shadowircd_cmd_nick(), solidircd_cmd_bot_nick(), solidircd_cmd_nick(), ultimate2_cmd_bot_nick(), ultimate2_cmd_nick(), ultimate3_cmd_bot_nick(), ultimate3_cmd_nick(), unreal_cmd_bot_nick(), unreal_cmd_nick(), viagra_cmd_bot_nick(), and viagra_cmd_nick().

char* expire_left ( NickAlias na,
char *  buf,
int  len,
time_t  expires 
)

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

Parameters:
na Nick Alias
buf buffer to store result into
bufsize Size of the buffer
seconds time in seconds
Returns:
buffer

Definition at line 471 of file misc.c.

References getstring, and snprintf().

Referenced by akill_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 1063 of file misc.c.

References getrandom8().

Referenced by collide().

u_int32_t getrandom32 ( void   ) 

Get the random numbers 32 byte deep

Returns:
char

Definition at line 1078 of file misc.c.

References getrandom8().

unsigned char getrandom8 ( void   ) 

Get the random numbers 8 byte deep

Returns:
char

Definition at line 1044 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:
host to convert
Returns:
ip address

Definition at line 1137 of file misc.c.

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

Referenced by common_unban().

int isvalidchar ( const char  c  ) 

Valid character check

Parameters:
c Character to check
Returns:
1 if a host is valid, 0 if it isnt.

Definition at line 635 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 615 of file misc.c.

References doValidHost().

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

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

match_wild: Case Senstive wild card search

Parameters:
pattern To be matched
str String in which the pattern is to be matched
Returns:
1 if the string matches the pattern, 0 if not.

Definition at line 256 of file misc.c.

Referenced by do_noop().

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

match_wild: Case Insenstive wild card search

Parameters:
pattern To be matched
str String in which the pattern is to be matched
Returns:
1 if the string matches the pattern, 0 if not.

Definition at line 269 of file misc.c.

Referenced by add_akill(), add_ban(), add_sgline(), add_sqline(), add_szline(), bot_join(), check_akill(), check_chan_sqline(), check_sgline(), check_sqline(), check_szline(), do_admin(), do_akill(), do_chanlist(), do_exception(), do_list(), do_oper(), do_sgline(), do_sqline(), do_szline(), do_userlist(), find_host_exception(), find_hostip_exception(), is_excepted_mask(), is_on_access(), is_stuck(), listOut(), match_userip(), match_usermask(), sqline(), and stick_mask().

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:
int Number of Args
argv Array
Returns:
string of the merged array

Definition at line 181 of file misc.c.

References snprintf().

Referenced by 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:
str String
dilim Dilimiter
Returns:
number of tokens

Definition at line 1114 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:
str String to search in
dilim Character to search for
token_number the token number
Returns:
token

Definition at line 686 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 
)

Get the token

Parameters:
str String to search in
dilim Character to search for
token_number the token number
Returns:
token

Definition at line 655 of file misc.c.

References myStrSubString().

Referenced by anope_event_bmask(), anope_event_capab(), anope_event_fjoin(), anope_event_server(), anope_event_tburst(), base64dects(), capab_parse(), do_sjoin(), do_tban(), do_topic(), hs_do_activate(), hs_do_reject(), hs_do_request(), hsreq_load_db(), mLoadData(), my_cs_appendtopic(), my_cs_enforce(), my_ns_register(), my_ns_set(), myAddChanInfo(), myAddNickInfo(), myChanInfo(), and myNickInfo().

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

Get the Remaining tokens

Parameters:
str String to search in
dilim Character to search for
token_number the token number
Returns:
token

Definition at line 721 of file misc.c.

References myStrSubString().

Referenced by anope_event_newmask(), anope_event_server(), capab_parse(), do_list(), do_setall(), hs_do_reject(), hs_do_request(), listOut(), 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:
str String to search in
start Point A
end Point B
Returns:
the string in between

Definition at line 754 of file misc.c.

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

int nickIsServices ( char *  tempnick,
int  bot 
)

Is the given nick a network service

Parameters:
nick to check
int Check if botserv bots
Returns:
int

Definition at line 858 of file misc.c.

References botlists, botinfo_::next, botinfo_::nick, s_BotServ, s_BotServAlias, s_ChanServ, s_ChanServAlias, s_DevNull, s_DevNullAlias, s_GlobalNoticer, s_GlobalNoticerAlias, s_HelpServ, s_HelpServAlias, s_HostServ, s_HostServAlias, s_MemoServ, s_MemoServAlias, s_NickServ, s_NickServAlias, s_OperServ, s_OperServAlias, ServerName, sstrdup(), and stricmp().

Referenced by do_bot(), m_kill(), and process().

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

Definition at line 1201 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 
callback Call back function
u User Struct
... various args
Returns:
int

Definition at line 293 of file misc.c.

References VA_COPY.

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

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

Definition at line 774 of file misc.c.

References alog(), and protocoldebug.

Referenced by process().

void rand_init ( void   ) 

random init

Returns:
void

Definition at line 978 of file misc.c.

References mysql_rand().

Referenced by init_secondary().

char* send_token ( char *  token1,
char *  token2 
)

Determine if we need to send the TOKEN

Parameters:
token1 
token2 
Returns:
token to send

Definition at line 1097 of file misc.c.

References ircd, ircdcap, ircdcapab_::token, ircdvars_::token, and UseTokens.

Referenced by unreal_cmd_akill(), unreal_cmd_bot_nick(), unreal_cmd_chg_nick(), unreal_cmd_chghost(), unreal_cmd_chgident(), unreal_cmd_ctcp(), unreal_cmd_eob(), unreal_cmd_global(), unreal_cmd_global_legacy(), unreal_cmd_guest_nick(), unreal_cmd_invite(), unreal_cmd_join(), unreal_cmd_kick(), unreal_cmd_mode(), unreal_cmd_netinfo(), unreal_cmd_nick(), unreal_cmd_notice(), unreal_cmd_notice2(), unreal_cmd_notice_ops(), unreal_cmd_part(), unreal_cmd_pong(), unreal_cmd_privmsg(), unreal_cmd_privmsg2(), unreal_cmd_quit(), unreal_cmd_release_svshold(), unreal_cmd_remove_akill(), unreal_cmd_serv_notice(), unreal_cmd_serv_privmsg(), unreal_cmd_sgline(), unreal_cmd_sqline(), unreal_cmd_squit(), unreal_cmd_svid_umode(), unreal_cmd_svshold(), unreal_cmd_svsjoin(), unreal_cmd_svskill(), unreal_cmd_svsmode(), unreal_cmd_svsmode_chan(), unreal_cmd_svsnick(), unreal_cmd_svsnoop(), unreal_cmd_svso(), unreal_cmd_svspart(), unreal_cmd_svswatch(), unreal_cmd_swhois(), unreal_cmd_szline(), unreal_cmd_topic(), unreal_cmd_unsgline(), unreal_cmd_unsqline(), unreal_cmd_unszline(), and unreal_cmd_vhost_off().

char* str_signed ( unsigned char *  str  ) 

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

Parameters:
input string
Returns:
output string, same as input string.

Definition at line 1172 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 1191 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:
s1 String 1
s2 String 2
Returns:
first occurrence of s2

Definition at line 114 of file misc.c.

References tolower.

Referenced by botchanmsgs().

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

Definition at line 1266 of file misc.c.

Referenced by plexus_cmd_svid_umode3().

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

Definition at line 1296 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:
s String
size size of s
old character to replace
new character to replace with
Returns:
updated s

Definition at line 145 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:
d Buffer to copy into
s Data to copy int
len Length of data
Returns:
updated buffer

Definition at line 92 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:
c Char
Returns:
int

Definition at line 53 of file misc.c.

int toupper ( char  c  ) 

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

Parameters:
c Char
Returns:
int

Definition at line 36 of file misc.c.


Variable Documentation

struct arc4_stream rs

Referenced by getrandom8().


Generated on Sun Dec 30 09:26:56 2007 for Anope by  doxygen 1.5.1-20070107