ekg2
 All Struktury Danych Pliki Funkcje Zmienne Definicje typów Wyliczenia Wartości wyliczeń Definicje Grupay Strony
Definicje | Funkcje | Zmienne
Dokumentacja pliku plugins.c
#include "win32.h"
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <dlfcn.h>
#include "configfile.h"
#include "commands.h"
#include "debug.h"
#include "dynstuff.h"
#include "events.h"
#include "objects.h"
#include "plugins.h"
#include "userlist.h"
#include "stuff.h"
#include "vars.h"
#include "themes.h"
#include "xmalloc.h"
#include "dynstuff_inline.h"
#include "queries.h"

Definicje

#define __DECLARE_QUERIES_STUFF
#define ID_AND_QUERY_EXTERNAL

Funkcje

static int plugin_register_compare (plugin_t *data1, plugin_t *data2)
 DYNSTUFF_LIST_DECLARE_SORTED_NF (plugins, plugin_t, plugin_register_compare, static __DYNSTUFF_LIST_ADD_SORTED, __DYNSTUFF_LIST_UNLINK) list_t watches
int ekg2_dlinit ()
int ekg2_dlclose (void *plugin)
static void * ekg2_dlopen (const char *name)
static void * ekg2_dlsym (void *plugin, char *name)
int plugin_load (const char *name, int prio, int quiet)
plugin_tplugin_find (const char *name)
plugin_tplugin_find_uid (const char *uid)
int plugin_unload (plugin_t *p)
int plugin_register (plugin_t *p, int prio)
int plugin_unregister (plugin_t *p)
int plugin_var_find (plugin_t *pl, const char *name)
int plugin_var_add (plugin_t *pl, const char *name, int type, const char *value, int secret, plugin_notify_func_t *notify)
static LIST_FREE_ITEM (query_external_free_data, list_t)
void query_external_free ()
static int query_id (const char *name)
struct query_defquery_struct (const int id)
const char * query_name (const int id)
static query_tquery_connect_common (plugin_t *plugin, const int id, query_handler_func_t *handler, void *data)
query_tquery_connect_id (plugin_t *plugin, const int id, query_handler_func_t *handler, void *data)
query_tquery_connect (plugin_t *plugin, const char *name, query_handler_func_t *handler, void *data)
int query_free (query_t *q)
static int query_emit_common (query_t *q, va_list ap)
int query_emit_id (plugin_t *plugin, const int id,...)
int query_emit (plugin_t *plugin, const char *name,...)
static int query_compare (query_t *data1, query_t *data2)
void queries_reconnect ()
watch_twatch_find (plugin_t *plugin, int fd, watch_type_t type)
static LIST_FREE_ITEM (watch_free_data, watch_t *)
void watch_free (watch_t *w)
void watch_handle_line (watch_t *w)
int watch_handle_write (watch_t *w)
int watch_write_data (watch_t *w, const char *buf, int len)
int watch_write (watch_t *w, const char *format,...)
void watch_handle (watch_t *w)
watch_twatch_add (plugin_t *plugin, int fd, watch_type_t type, watcher_handler_func_t *handler, void *data)
watch_twatch_add_session (session_t *session, int fd, watch_type_t type, watcher_session_handler_func_t *handler)
int watch_remove (plugin_t *plugin, int fd, watch_type_t type)
int have_plugin_of_class (plugin_class_t pclass)
int plugin_abi_version (int plugin_abi_ver, const char *plugin_name)

Zmienne

plugin_tplugins = NULL
query_tqueries [QUERY_EXTERNAL+1]

Dokumentacja definicji

#define __DECLARE_QUERIES_STUFF
#define ID_AND_QUERY_EXTERNAL
Wartość:
"Here, we have two possibilites.\n" \
"\t1/ You are lazy moron, who doesn't rebuilt core but use plugin with this enum...\n" \
"\t2/ You are ekg2 hacker who use query_id(\"your_own_query_name\") to get new query id and use this id with " \
"query_connect_id()... but unfortunetly it won't work cause of 1st possibility, sorry.\n"

Dokumentacja funkcji

DYNSTUFF_LIST_DECLARE_SORTED_NF ( plugins  ,
plugin_t  ,
plugin_register_compare  ,
static  __DYNSTUFF_LIST_ADD_SORTED,
__DYNSTUFF_LIST_UNLINK   
)
int ekg2_dlclose ( void *  plugin)

ekg2_dlclose()

Close handler to dynamic loaded library.
Support POSIX dlclose() and FreeLibrary() [WINDOWS]

Do zrobienia:
For support of more dynamic interfaces see sources of lt_dlclose() [libltdl]
Parametry
plugin- Handler to loaded library.
Zwraca
0 on success, else fail.
int ekg2_dlinit ( )
static void* ekg2_dlopen ( const char *  name)
static

ekg2_dlopen()

Load dynamic library file from name
Support POSIX dlopen() and LoadLibraryA() [WINDOWS]

Do zrobienia:
For support of more dynamic interfaces see sources of lt_dlopen() [libltdl]
Do zrobienia:
Think more about flags for dlopen() [was: RTLD_LAZY | RTLD_GLOBAL]
Parametry
name- Full path of library to load.
Zwraca
Pointer to the loaded library, or NULL if fail.
static void* ekg2_dlsym ( void *  plugin,
char *  name 
)
static

ekg2_dlsym()

Get symbol with name from loaded dynamic library.
Support POSIX dlsym() and GetProcAddress() [WINDOWS]

Do zrobienia:
For support of more dynamic interfaces see lt_dlsym() [libltdl]
Parametry
plugin- Pointer to the loaded library.
name- Name of symbol to lookup.
Zwraca
Address of symbol or NULL if error occur.
int have_plugin_of_class ( plugin_class_t  pclass)

have_plugin_of_class()

Check if we have loaded plugin from pclass

Parametry
pclass
Zwraca
1 - If such plugin was founded
else 0
static LIST_FREE_ITEM ( query_external_free_data  ,
list_t   
)
static
static LIST_FREE_ITEM ( watch_free_data  ,
watch_t  
)
static
int plugin_abi_version ( int  plugin_abi_ver,
const char *  plugin_name 
)
plugin_t* plugin_find ( const char *  name)

plugin_find()

Find plugin by name

Parametry
name- name of plugin_t
Zwraca
plugin_t with given name, or NULL if not found.
plugin_t* plugin_find_uid ( const char *  uid)

plugin_find_uid()

Find PLUGIN_PROTOCOL plugin which can handle uid

Do zrobienia:
used only by session_add() in session.c move it there?
Zobacz również
valid_plugin_uid() - For function to check if given plugin can handle given uid
Zwraca
If such plugin was founded return it, or NULL if not found.
int plugin_load ( const char *  name,
int  prio,
int  quiet 
)
int plugin_register ( plugin_t p,
int  prio 
)
static int plugin_register_compare ( plugin_t data1,
plugin_t data2 
)
static
int plugin_unload ( plugin_t p)
int plugin_unregister ( plugin_t p)
int plugin_var_add ( plugin_t pl,
const char *  name,
int  type,
const char *  value,
int  secret,
plugin_notify_func_t notify 
)
int plugin_var_find ( plugin_t pl,
const char *  name 
)

plugin_var_find()

it looks for given variable name in given plugin

Parametry
pl- plugin
name- variable name

returns sequence number+1 of variable if found, else 0

void queries_reconnect ( )

queries_reconnect()

Reconnect (resort) all queries, e.g. after plugin prio change.

static int query_compare ( query_t data1,
query_t data2 
)
static
query_t* query_connect ( plugin_t plugin,
const char *  name,
query_handler_func_t handler,
void *  data 
)
static query_t* query_connect_common ( plugin_t plugin,
const int  id,
query_handler_func_t handler,
void *  data 
)
static
query_t* query_connect_id ( plugin_t plugin,
const int  id,
query_handler_func_t handler,
void *  data 
)
int query_emit ( plugin_t plugin,
const char *  name,
  ... 
)
static int query_emit_common ( query_t q,
va_list  ap 
)
static
int query_emit_id ( plugin_t plugin,
const int  id,
  ... 
)
void query_external_free ( )

query_external_free()

Free memory allocated by query_id() for not-known-in-core-query-names

Do zrobienia:
We don't destroy here queries which uses these ids >= QUERY_EXTERNAL.
It's quite correct in current api. But if you change it, you must clean after yourself.
int query_free ( query_t q)
static int query_id ( const char *  name)
static

query_id()

Get unique query id, for passed name

Parametry
name
Zwraca
  • If it's query known for core than return id of it.
  • If it's ,,seen'' by query_id() from previous call, than return assigned id also [from queries_external list_t]
  • else it allocate struct query in queries_external, and return next available id.
const char* query_name ( const int  id)

query_name()

Get name of query, by passed id

Zwraca
  • If id is known for core (id < QUERY_EXTERNAL) than return it's name
  • If it was ,,seen'' by query_id() than return name registered.
  • else return NULL, and display info that smth really nasty happen.
struct query_def* query_struct ( const int  id)
read

query_struct()

Get struct of query, by passed id

watch_t* watch_add ( plugin_t plugin,
int  fd,
watch_type_t  type,
watcher_handler_func_t handler,
void *  data 
)

watch_add()

Create new watch_t and add it on the beginning of watches list.

Parametry
plugin- plugin
fd- fd to watch data for.
type- type of watch.
handler- handler of watch.
data- data which be passed to handler.
Zwraca
Created watch_t. if type is either WATCH_READ_LINE or WATCH_WRITE_LINE than also allocate memory for buffer
watch_t* watch_add_session ( session_t session,
int  fd,
watch_type_t  type,
watcher_session_handler_func_t handler 
)

watch_add_session()

Create new session watch_t and add it on the beginning of watches list.

Parametry
session- session
fd- fd to watch data for
type- type of watch.
handler- handler of watch.
Zwraca
If session is NULL, or session->plugin is NULL, it return NULL.
else created watch_t
watch_t* watch_find ( plugin_t plugin,
int  fd,
watch_type_t  type 
)
void watch_free ( watch_t w)
void watch_handle ( watch_t w)

watch_handle()

Handler for watches with type: WATCH_READ or WATCH_WRITE
Mark watch with w->removed = -1, to indicate that watch is in use. And it shouldn't be executed again. [If watch can or even must be executed twice from ekg_loop() than you must change w->removed by yourself.]

If handler of watch return -1 or watch was removed inside function [by watch_remove() or watch_free()]. Than it'll be removed.
ELSE Update w->started field to current time.

Parametry
w- watch_t to handler
Do zrobienia:
We only check for w->removed == -1, maybe instead change it to: w->removed != 0
void watch_handle_line ( watch_t w)
int watch_handle_write ( watch_t w)
int watch_remove ( plugin_t plugin,
int  fd,
watch_type_t  type 
)
int watch_write ( watch_t w,
const char *  format,
  ... 
)
int watch_write_data ( watch_t w,
const char *  buf,
int  len 
)

Dokumentacja zmiennych

plugin_t* plugins = NULL
query_t* queries[QUERY_EXTERNAL+1]