ekg2  GIT master
 All Struktury Danych Pliki Funkcje Zmienne Definicje typów Wyliczenia Wartości wyliczeń Definicje Grupay Strony
Struktury danych | Definicje | Funkcje | Zmienne
Dokumentacja pliku stuff.c
#include "ekg2.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <sched.h>
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

Struktury danych

struct  ekg_status_info
 

Definicje

#define __sq(x)   ((x)*(x))
 

Funkcje

void windows_save ()
 
static void list_alias_free (alias_t *data)
 
static void aliases_add (alias_t *new_)
 
static alias_taliases_removei (alias_t *elem)
 
void aliases_destroy (void)
 
int alias_add (const char *string, int quiet, int append)
 
int alias_remove (const char *name, int quiet)
 
static void list_buffer_free (struct buffer *data)
 
static void buffers_add (struct buffer **lista, struct buffer *new_)
 
static struct bufferbuffers_removei (struct buffer **lista, struct buffer *elem)
 
static void buffers_destroy (struct buffer **lista)
 
static int buffers_count (struct buffer *lista)
 
static struct bufferbuffers_get_nth (struct buffer *lista, int id)
 
static void buffer_add_common (struct buffer_info *type, const char *target, const char *line, time_t ts)
 
int buffer_add (struct buffer_info *type, const char *target, const char *line)
 
int buffer_add_str (struct buffer_info *type, const char *target, const char *str)
 
char * buffer_tail (struct buffer_info *type)
 
void buffer_free (struct buffer_info *type)
 
void changed_make_window (const char *var)
 
void changed_mesg (const char *var)
 
static gint auto_save_timer (gint type, gpointer data)
 
void changed_auto_save (const char *var)
 
void changed_display_blinking (const char *var)
 
void changed_theme (const char *var)
 
void changed_config_timestamp (const char *var)
 
const char * compile_time ()
 
static void newconference_free_item (newconference_t *data)
 
static void newconferences_add (newconference_t *new_)
 
static void newconferences_remove (newconference_t *elem)
 
void newconferences_destroy (void)
 
userlist_tnewconference_member_find (newconference_t *conf, const char *uid)
 
userlist_tnewconference_member_add (newconference_t *conf, const char *uid, const char *nick)
 
int newconference_member_remove (newconference_t *conf, userlist_t *u)
 
newconference_tnewconference_find (session_t *s, const char *name)
 
newconference_tnewconference_create (session_t *s, const char *name, int create_wnd)
 
void newconference_destroy (newconference_t *conf, int kill_wnd)
 
static void conference_free_item (struct conference *data)
 
static void conferences_add (struct conference *new_)
 
static struct conferenceconferences_removei (struct conference *elem)
 
void conferences_destroy (void)
 
struct conferenceconference_add (session_t *session, const char *name, const char *nicklist, int quiet)
 
int conference_remove (const char *name, int quiet)
 
struct conferenceconference_create (session_t *session, const char *nicks)
 
struct conferenceconference_find (const char *name)
 
int conference_participant (struct conference *c, const char *uid)
 
struct conferenceconference_find_by_uids (session_t *s, const char *from, const char **recipients, int count, int quiet)
 
int conference_set_ignore (const char *name, int flag, int quiet)
 
int conference_rename (const char *oldname, const char *newname, int quiet)
 
GDataInputStream * help_open (const gchar *name, const gchar *plugin)
 
int ekg_hash (const char *name)
 
int mesg_set (int what)
 
char * strip_spaces (char *line)
 
int play_sound (const char *sound_path)
 
int mkdir_recursive (const char *pathname, int isdir)
 
const char * prepare_pathf (const char *filename,...)
 
const char * prepare_path (const char *filename, int do_mkdir)
 
const char * prepare_path_user (const char *path)
 
static char * random_line (const char *path)
 
char * read_file_utf (FILE *f, int alloc)
 
char * read_file (FILE *f, int alloc)
 
gchar * read_line (GDataInputStream *f)
 
const char * timestamp (const char *format)
 
const char * timestamp_time (const char *format, time_t t)
 
char * xstrmid (const char *str, int start, int length)
 
char color_map (unsigned char r, unsigned char g, unsigned char b)
 
int isalpha_pl (unsigned char c)
 
void ignore_result_helper (int __attribute__((unused)) dummy,...)
 
char * strcasestr (const char *haystack, const char *needle)
 
int msg_all (session_t *s, const char *function, const char *what)
 
static void speech_child_handler (GPid pid, gint status, gpointer data)
 
int say_it (const char *str)
 
void debug_ext (debug_level_t level, const char *format,...)
 
void debug (const char *format,...)
 
char * base64_encode (const char *buf, size_t len)
 
char * base64_decode (const char *buf)
 
char * split_line (char **ptr)
 
const char * ekg_status_label (const int status, const char *descr, const char *prefix)
 
char * ekg_draw_descr (const int status)
 
void ekg_update_status (session_t *session)
 
static const struct
ekg_status_info
status_find (const int status)
 
const char * ekg_status_string (const int status, const int cmd)
 
int ekg_status_int (const char *text)
 
guint32 * ekg_sent_message_format (const char *text)
 
int strncasecmp_pl (const char *cs, const char *ct, size_t count)
 
char * saprintf (const char *format,...)
 
void xstrtr (char *text, char from, char to)
 
void ekg_yield_cpu ()
 
int ekg_write (int fd, const char *buf, int len)
 
int ekg_writef (int fd, const char *format,...)
 
int ekg_close (int fd)
 
char * password_input (const char *prompt, const char *rprompt, const bool norepeat)
 
int is_utf8_string (const char *txt)
 
static char * get_variable_value (variable_t *v)
 
void variable_display (variable_t *v, int quiet)
 
static variable_tget_fake_sess_variable (session_t *s, const char *name)
 
int session_variable_display (session_t *s, const char *name, int quiet)
 
void session_variable_info (session_t *s, const char *name, int quiet)
 

Zmienne

alias_taliases = NULL
 
list_t autofinds = NULL
 
struct conferenceconferences = NULL
 
newconference_tnewconferences = NULL
 
struct buffer_info buffer_debug = { NULL, 0, 50 }
 
struct buffer_info buffer_speech = { NULL, 0, 50 }
 
int old_stderr
 
char * config_subject_prefix
 
char * config_subject_reply_prefix
 
int in_autoexec = 0
 
int config_auto_save = 0
 
int config_auto_user_add = 0
 
int config_display_color = 1
 
int config_beep = 1
 
int config_beep_msg = 1
 
int config_beep_chat = 1
 
int config_beep_notify = 1
 
char * config_dcc_dir
 
int config_display_blinking = 1
 
int config_events_delay = 3
 
int config_expert_mode = 0
 
int config_history_savedups = 1
 
char * config_sound_msg_file = NULL
 
char * config_sound_chat_file = NULL
 
char * config_sound_notify_file = NULL
 
char * config_sound_sysmsg_file = NULL
 
char * config_sound_mail_file = NULL
 
char * config_sound_app = NULL
 
int config_changed = 0
 
int config_display_ack = 12
 
int config_completion_notify = 1
 
char * config_completion_char = NULL
 
time_t ekg_started = 0
 
int config_display_notify = 1
 
char * config_theme = NULL
 
int config_default_status_window = 0
 
char * home_dir = NULL
 
char * config_quit_reason = NULL
 
char * config_away_reason = NULL
 
char * config_back_reason = NULL
 
int config_query_commands = 0
 
int config_slash_messages = 0
 
int quit_message_send = 0
 
int batch_mode = 0
 
char * batch_line = NULL
 
int config_make_window = 6
 
char * config_tab_command = NULL
 
int config_save_password = 1
 
int config_save_quit = 1
 
char * config_timestamp = NULL
 
int config_timestamp_show = 1
 
int config_display_sent = 1
 
int config_send_white_lines = 0
 
int config_sort_windows = 1
 
int config_keep_reason = 1
 
char * config_speech_app = NULL
 
int config_time_deviation = 300
 
int config_mesg = MESG_DEFAULT
 
int config_display_welcome = 1
 
char * config_display_color_map = NULL
 
char * config_session_default = NULL
 
int config_sessions_save = 0
 
int config_window_session_allow = 0
 
int config_windows_save = 0
 
char * config_windows_layout = NULL
 
char * config_profile = NULL
 
int config_debug = 1
 
int config_version = 0
 
char * config_exit_exec = NULL
 
int config_session_locks = 0
 
char * config_nickname = NULL
 
char * last_search_first_name = NULL
 
char * last_search_last_name = NULL
 
char * last_search_nickname = NULL
 
char * last_search_uid = 0
 
char * formated_config_timestamp = NULL
 
int ekg2_reason_changed = 0
 
struct color_map color_map_default [26]
 
const struct ekg_status_info ekg_statuses []
 

Dokumentacja definicji

#define __sq (   x)    ((x)*(x))

Dokumentacja funkcji

int alias_add ( const char *  string,
int  quiet,
int  append 
)
int alias_remove ( const char *  name,
int  quiet 
)
static void aliases_add ( alias_t new_)
static
void aliases_destroy ( void  )
static alias_t* aliases_removei ( alias_t elem)
static
static gint auto_save_timer ( gint  type,
gpointer  data 
)
static
char* base64_decode ( const char *  buf)
char* base64_encode ( const char *  buf,
size_t  len 
)
int buffer_add ( struct buffer_info type,
const char *  target,
const char *  line 
)

buffer_add()

Add new line to given buffer_t, if max_lines > 0 than it maintain list that we can have max: max_lines items on it.

Parametry
type- pointer to buffer beginning ptr
target- name of target.. or just name of smth we want to keep in b->target
line- line which we want to save.
Zwraca
0 - when line was successfully added to buffer, else -1 (when type was NULL)
static void buffer_add_common ( struct buffer_info type,
const char *  target,
const char *  line,
time_t  ts 
)
static
int buffer_add_str ( struct buffer_info type,
const char *  target,
const char *  str 
)

buffer_add_str()

Add new line to given buffer_t, if max_lines > 0 than it maintain list that we can have max: max_lines items on it.

Parametry
type- pointer to buffer beginning ptr
target- name of target, or just name of smth we want to keep in b->target
str- string in format: [time_when_it_happen proper line... blah, blah] time_when_it_happen should be in digits.
Zwraca
0 - when line was successfully added to buffer, else -1 (when type was NULL, or line was in wrong format)
void buffer_free ( struct buffer_info type)

buffer_free()

Free memory after given buffer.
After it set *type to NULL

Parametry
type- pointer to buffer beginning ptr
char* buffer_tail ( struct buffer_info type)

buffer_tail()

Return oldest b->line, free b->target and remove whole buffer_t from list

Parametry
type- pointer to buffer beginning ptr
Zwraca
First b->line on the list, or NULL, if no items on list.
static void buffers_add ( struct buffer **  lista,
struct buffer new_ 
)
static
static int buffers_count ( struct buffer lista)
static
static void buffers_destroy ( struct buffer **  lista)
static
static struct buffer* buffers_get_nth ( struct buffer lista,
int  id 
)
static
static struct buffer* buffers_removei ( struct buffer **  lista,
struct buffer elem 
)
static
void changed_auto_save ( const char *  var)
void changed_config_timestamp ( const char *  var)
void changed_display_blinking ( const char *  var)
void changed_make_window ( const char *  var)
void changed_mesg ( const char *  var)
void changed_theme ( const char *  var)
char color_map ( unsigned char  r,
unsigned char  g,
unsigned char  b 
)
const char* compile_time ( )

compile_time()

Return compilation date, and time..
Used by /version command and ekg2 –version

Zwraca
DATE" "__TIME__
For example: "Jun 21 1987" " " "22:06:47"
struct conference* conference_add ( session_t session,
const char *  name,
const char *  nicklist,
int  quiet 
)
struct conference* conference_create ( session_t session,
const char *  nicks 
)
struct conference* conference_find ( const char *  name)
struct conference* conference_find_by_uids ( session_t s,
const char *  from,
const char **  recipients,
int  count,
int  quiet 
)
static void conference_free_item ( struct conference data)
static
int conference_participant ( struct conference c,
const char *  uid 
)
int conference_remove ( const char *  name,
int  quiet 
)
int conference_rename ( const char *  oldname,
const char *  newname,
int  quiet 
)
int conference_set_ignore ( const char *  name,
int  flag,
int  quiet 
)
static void conferences_add ( struct conference new_)
static
void conferences_destroy ( void  )
static struct conference* conferences_removei ( struct conference elem)
static
void debug ( const char *  format,
  ... 
)
void debug_ext ( debug_level_t  level,
const char *  format,
  ... 
)
int ekg_close ( int  fd)

ekg_close()

close fd and all watches associated with that fd

Nota
This should be used as replacement for close() (especially in protocol plugins)
char* ekg_draw_descr ( const int  status)
int ekg_hash ( const char *  name)
guint32* ekg_sent_message_format ( const char *  text)
int ekg_status_int ( const char *  text)
const char* ekg_status_label ( const int  status,
const char *  descr,
const char *  prefix 
)
const char* ekg_status_string ( const int  status,
const int  cmd 
)
void ekg_update_status ( session_t session)
int ekg_write ( int  fd,
const char *  buf,
int  len 
)

ekg_write()

write data to given fd, if it cannot be done [because system buffer is too small. it'll create watch, and write as soon as possible] XXX, for now it'll always create watch. (You can be notified about state of buffer when you call ekg_write(fd, NULL, -1))

Nota
This should be used as replacement for write()
int ekg_writef ( int  fd,
const char *  format,
  ... 
)
void ekg_yield_cpu ( )
inline

ekg_yield_cpu()

releases cpu meant to be called while busy-looping

static variable_t* get_fake_sess_variable ( session_t s,
const char *  name 
)
static
static char* get_variable_value ( variable_t v)
static
GDataInputStream* help_open ( const gchar *  name,
const gchar *  plugin 
)

help_open()

Open the help file in best language available.

Parametry
name- help file basename.
plugin- plugin name or NULL if core help is requested.
Zwraca
Open GDataInputStream with utf8 encoding or NULL if no file was found. It should be unreferenced with g_object_unref().
void ignore_result_helper ( int __attribute__((unused))  dummy,
  ... 
)
int is_utf8_string ( const char *  txt)
int isalpha_pl ( unsigned char  c)
static void list_alias_free ( alias_t data)
static
static void list_buffer_free ( struct buffer data)
static
int mesg_set ( int  what)
int mkdir_recursive ( const char *  pathname,
int  isdir 
)

mkdir_recursive()

Create directory pathname and all needed parent directories.

Do zrobienia:
Maybe at begining of function let's check with stat() if that dir/file already exists?
Parametry
pathname- path to directory or file (see isdir comment)
isdir- if isdir is set, than we should also create dir specified by full pathname path, else we shouldn't do it, because it's filename and we want to create directory only to last '/' char
Zwraca
Like mkdir() do we return -1 on fail with errno set.
int msg_all ( session_t s,
const char *  function,
const char *  what 
)
newconference_t* newconference_create ( session_t s,
const char *  name,
int  create_wnd 
)
void newconference_destroy ( newconference_t conf,
int  kill_wnd 
)
newconference_t* newconference_find ( session_t s,
const char *  name 
)
static void newconference_free_item ( newconference_t data)
static
userlist_t* newconference_member_add ( newconference_t conf,
const char *  uid,
const char *  nick 
)
userlist_t* newconference_member_find ( newconference_t conf,
const char *  uid 
)
int newconference_member_remove ( newconference_t conf,
userlist_t u 
)
static void newconferences_add ( newconference_t new_)
static
void newconferences_destroy ( void  )
static void newconferences_remove ( newconference_t elem)
static
char* password_input ( const char *  prompt,
const char *  rprompt,
const bool  norepeat 
)

password_input()

Try to get password through UI_PASSWORD_INPUT, printing error messages if needed.

Zwraca
Pointer to new password (which needs to be freed) or NULL, if not succeeded (wrong input / no support).
int play_sound ( const char *  sound_path)
const char* prepare_path ( const char *  filename,
int  do_mkdir 
)
const char* prepare_path_user ( const char *  path)

prepare_path_user()

Converts path given by user to absolute path.

Błąd:
Behaves correctly only with POSIX slashes, need to be modified for NO_POSIX_SYSTEM.
Parametry
path- input path.
Zwraca
Pointer to output path or NULL, if longer than PATH_MAX.
const char* prepare_pathf ( const char *  filename,
  ... 
)

prepare_pathf()

Return path to configdir/profiledir (~/.ekg2 or ~/.ekg2/$PROFILE) and append filename (formated using vsnprintf()) If length of this string is larger than PATH_MAX (4096 on Linux) than unlike prepare_path() it'll return NULL

static char* random_line ( const char *  path)
static

random_line()

Open file specified by path and select by random one line from file specified by path

Parametry
path- path to file.
Zobacz również
read_file() - if you want read next line from file.
Zwraca
NULL - if file was not found or file has no line inside.
else random line founded at file,
char* read_file ( FILE *  f,
int  alloc 
)

read_file()

Read next line from file f, if needed alloc memory for it.
Remove \r and \n chars from end of line if needed.

Parametry
f- opened FILE *
alloc
  • If 0 than it return internal read_file() either xrealloc()'ed or static char with sizeof()==1024, which you MUST NOT xfree()
  • If 1 than it return strdup()'ed string this MUST xfree()
  • If -1 than it free internal pointer which were used by xrealloc()
Zwraca
Line without \r and \n which must or mustn't be xfree()'d. It depends on alloc param
char* read_file_utf ( FILE *  f,
int  alloc 
)
gchar* read_line ( GDataInputStream *  f)

read_line()

Read a single line from GDataInputStream.

Parametry
f- GDataInputStream to read from.
Zwraca
Pointer to a static line which will be overwritten by next call to read_line() or NULL on EOF or error.
char* saprintf ( const char *  format,
  ... 
)
int say_it ( const char *  str)
int session_variable_display ( session_t s,
const char *  name,
int  quiet 
)
void session_variable_info ( session_t s,
const char *  name,
int  quiet 
)
static void speech_child_handler ( GPid  pid,
gint  status,
gpointer  data 
)
static
char* split_line ( char **  ptr)
static const struct ekg_status_info* status_find ( const int  status)
static
char* strcasestr ( const char *  haystack,
const char *  needle 
)
char* strip_spaces ( char *  line)

strip_spaces()

strips spaces from the begining and the end of string line

Parametry
line- given string
Nota
If you pass here smth which was strdup'ed() malloc'ed() or smth which was allocated.
You must xfree() string passed, not result of this function.
Zwraca
buffer without spaces.
int strncasecmp_pl ( const char *  cs,
const char *  ct,
size_t  count 
)
const char* timestamp ( const char *  format)

timestamp()

It returns static buffer with formated current time.

Parametry
format- format to pass to strftime() [man 3 strftime]
Zwraca
if format is NULL or format == '\0' than it return ""
else it returns strftime()'d value, or "TOOLONG" if buf (sizeof(buf) == 100) was too small..
const char* timestamp_time ( const char *  format,
time_t  t 
)
void variable_display ( variable_t v,
int  quiet 
)
void windows_save ( )
char* xstrmid ( const char *  str,
int  start,
int  length 
)
void xstrtr ( char *  text,
char  from,
char  to 
)

Dokumentacja zmiennych

alias_t* aliases = NULL
list_t autofinds = NULL
char* batch_line = NULL
int batch_mode = 0
struct buffer_info buffer_debug = { NULL, 0, 50 }

debug buffer

struct buffer_info buffer_speech = { NULL, 0, 50 }

speech buffer

struct color_map color_map_default[26]
Wartość początkowa:
= {
{ 'k', 0, 0, 0 },
{ 'r', 168, 0, 0, },
{ 'g', 0, 168, 0, },
{ 'y', 168, 168, 0, },
{ 'b', 0, 0, 168, },
{ 'm', 168, 0, 168, },
{ 'c', 0, 168, 168, },
{ 'w', 168, 168, 168, },
{ 'K', 96, 96, 96 },
{ 'R', 255, 0, 0, },
{ 'G', 0, 255, 0, },
{ 'Y', 255, 255, 0, },
{ 'B', 0, 0, 255, },
{ 'M', 255, 0, 255, },
{ 'C', 0, 255, 255, },
{ 'W', 255, 255, 255, },
{ 'C', 128, 255, 255, },
{ 'G', 128, 255, 128, },
{ 'M', 255, 128, 255, },
{ 'B', 128, 128, 255, },
{ 'R', 255, 128, 128, },
{ 'Y', 255, 255, 128, },
{ 'm', 168, 128, 168, },
{ 'c', 128, 168, 168, },
{ 'g', 64, 168, 64, },
{ 'm', 128, 64, 128, }
}
struct conference* conferences = NULL
int config_auto_save = 0
int config_auto_user_add = 0
char* config_away_reason = NULL
char* config_back_reason = NULL
int config_beep = 1
int config_beep_chat = 1
int config_beep_msg = 1
int config_beep_notify = 1
int config_changed = 0
char* config_completion_char = NULL
int config_completion_notify = 1
char* config_dcc_dir
int config_debug = 1
int config_default_status_window = 0
int config_display_ack = 12
int config_display_blinking = 1
int config_display_color = 1
char* config_display_color_map = NULL
int config_display_notify = 1
int config_display_sent = 1
int config_display_welcome = 1
int config_events_delay = 3
char* config_exit_exec = NULL
int config_expert_mode = 0
int config_history_savedups = 1
int config_keep_reason = 1
int config_make_window = 6
int config_mesg = MESG_DEFAULT
char* config_nickname = NULL
char* config_profile = NULL
int config_query_commands = 0
char* config_quit_reason = NULL
int config_save_password = 1
int config_save_quit = 1
int config_send_white_lines = 0
char* config_session_default = NULL
int config_session_locks = 0
int config_sessions_save = 0
int config_slash_messages = 0
int config_sort_windows = 1
char* config_sound_app = NULL
char* config_sound_chat_file = NULL
char* config_sound_mail_file = NULL
char* config_sound_msg_file = NULL
char* config_sound_notify_file = NULL
char* config_sound_sysmsg_file = NULL
char* config_speech_app = NULL
char* config_subject_prefix
char* config_subject_reply_prefix
char* config_tab_command = NULL
char* config_theme = NULL
int config_time_deviation = 300
char* config_timestamp = NULL
int config_timestamp_show = 1
int config_version = 0
int config_window_session_allow = 0
char* config_windows_layout = NULL
int config_windows_save = 0
int ekg2_reason_changed = 0
time_t ekg_started = 0
const struct ekg_status_info ekg_statuses[]
Wartość początkowa:
= {
{ EKG_STATUS_ERROR, "error" },
{ EKG_STATUS_BLOCKED, "blocking" },
{ EKG_STATUS_UNKNOWN, "unknown" },
{ EKG_STATUS_NA, "notavail" },
{ EKG_STATUS_INVISIBLE,"invisible" },
{ EKG_STATUS_DND, "dnd" },
{ EKG_STATUS_GONE, "gone" },
{ EKG_STATUS_XA, "xa" },
{ EKG_STATUS_AWAY, "away" },
{ EKG_STATUS_AVAIL, "avail", "back", },
{ EKG_STATUS_FFC, "chat", "ffc" },
{ EKG_STATUS_AUTOAWAY, "autoaway" },
{ EKG_STATUS_AUTOXA, "autoxa" },
{ EKG_STATUS_AUTOBACK, "autoback" },
}
Definition: sessions.h:52
Definition: sessions.h:43
Definition: sessions.h:53
Definition: sessions.h:40
Definition: sessions.h:47
Definition: sessions.h:65
Definition: sessions.h:55
Definition: sessions.h:64
Definition: sessions.h:54
Definition: sessions.h:51
Definition: sessions.h:66
Definition: sessions.h:59
Definition: sessions.h:58
Definition: sessions.h:44
Definition: sessions.h:48
char* formated_config_timestamp = NULL
char* home_dir = NULL
int in_autoexec = 0
char* last_search_first_name = NULL
char* last_search_last_name = NULL
char* last_search_nickname = NULL
char* last_search_uid = 0
newconference_t* newconferences = NULL
int old_stderr
int quit_message_send = 0