src/terminal.c File Reference

#include <eggdrop/eggdrop.h>
#include <unistd.h>
#include "terminal.h"

Go to the source code of this file.

Defines

#define RUNMODE_RESTART   3

Functions

static int on_privmsg (void *client_data, partymember_t *dest, botnet_entity_t *src, const char *text, int len)
static int on_nick (void *client_data, partymember_t *src, const char *oldnick, const char *newnick)
static int on_quit (void *client_data, partymember_t *src, const botnet_bot_t *lostbot, const char *text, int len)
static int on_chanmsg (void *client_data, partychan_t *chan, botnet_entity_t *src, const char *text, int len)
static int on_join (void *client_data, partychan_t *chan, partymember_t *src, int linking)
static int on_part (void *client_data, partychan_t *chan, partymember_t *src, const char *text, int len)
static int on_read (void *client_data, int idx, char *data, int len)
int terminal_init (void)
int terminal_shutdown (int runmode)

Variables

static const char rcsid [] = "$Id: terminal.c,v 1.11 2007-09-13 22:20:58 sven Exp $"
int terminal_enabled
static sockbuf_handler_t terminal_sockbuf_handler
static partyline_event_t terminal_party_handler
struct {
   int   in_idx
   int   out_idx
   partymember_t *   party
terminal_session
static user_tterminal_user = NULL


Define Documentation

#define RUNMODE_RESTART   3

Definition at line 95 of file terminal.c.


Function Documentation

static int on_chanmsg ( void *  client_data,
partychan_t chan,
botnet_entity_t src,
const char *  text,
int  len 
) [static]

Definition at line 163 of file terminal.c.

References partyline_idx_chanmsg(), and terminal_session.

00164 {
00165   return partyline_idx_chanmsg(terminal_session.out_idx, chan, src, text, len);
00166 }

static int on_join ( void *  client_data,
partychan_t chan,
partymember_t src,
int  linking 
) [static]

Definition at line 168 of file terminal.c.

References partyline_idx_join(), and terminal_session.

00169 {
00170   if (linking) return 0;
00171   return partyline_idx_join(terminal_session.out_idx, chan, src);
00172 }

static int on_nick ( void *  client_data,
partymember_t src,
const char *  oldnick,
const char *  newnick 
) [static]

Definition at line 146 of file terminal.c.

References partyline_idx_nick(), and terminal_session.

00147 {
00148   return partyline_idx_nick (terminal_session.out_idx, src, oldnick, newnick);
00149 }

static int on_part ( void *  client_data,
partychan_t chan,
partymember_t src,
const char *  text,
int  len 
) [static]

Definition at line 174 of file terminal.c.

References partyline_idx_part(), and terminal_session.

00175 {
00176   return partyline_idx_part(terminal_session.out_idx, chan, src, text, len);
00177 }

static int on_privmsg ( void *  client_data,
partymember_t dest,
botnet_entity_t src,
const char *  text,
int  len 
) [static]

Definition at line 141 of file terminal.c.

References partyline_idx_privmsg(), and terminal_session.

00142 {
00143   return partyline_idx_privmsg(terminal_session.out_idx, dest, src, text, len);
00144 }

static int on_quit ( void *  client_data,
partymember_t src,
const botnet_bot_t lostbot,
const char *  text,
int  len 
) [static]

Definition at line 151 of file terminal.c.

References partyline_idx_quit(), sockbuf_delete(), and terminal_session.

00152 {
00153   if (lostbot) return 0;
00154   partyline_idx_quit(terminal_session.out_idx, src, text, len);
00155 
00156   /* if this quit are we delete our sockbuf. */
00157   if (src == terminal_session.party)
00158     sockbuf_delete(terminal_session.out_idx);
00159 
00160   return(0);
00161 }

static int on_read ( void *  client_data,
int  idx,
char *  data,
int  len 
) [static]

Definition at line 135 of file terminal.c.

References NULL, partyline_on_input(), and terminal_session.

00136 {
00137   partyline_on_input(NULL, terminal_session.party, data, len);
00138   return 0;
00139 }

int terminal_init ( void   ) 

Definition at line 63 of file terminal.c.

References _, linemode_on(), LOG_MISC, NULL, partychan_join_name(), partymember_new(), putlog(), SOCKBUF_CLIENT, sockbuf_new(), SOCKBUF_NOREAD, sockbuf_set_handler(), sockbuf_set_sock(), TERMINAL_HANDLE, TERMINAL_HOST, TERMINAL_NICK, terminal_session, TERMINAL_USER, user_lookup_by_handle(), user_new(), and user_set_flags_str().

Referenced by core_init().

00064 {
00065   if (terminal_user == NULL) {
00066     terminal_user = user_lookup_by_handle(TERMINAL_HANDLE);
00067     if (terminal_user == NULL) {
00068       terminal_user = user_new(TERMINAL_HANDLE);
00069       user_set_flags_str(terminal_user, NULL, "n");
00070     }
00071   }
00072 
00073   /* Connect an idx to stdin. */
00074   terminal_session.in_idx = sockbuf_new();
00075   sockbuf_set_sock(terminal_session.in_idx, dup(fileno(stdin)), SOCKBUF_CLIENT);
00076   sockbuf_set_handler(terminal_session.in_idx, &terminal_sockbuf_handler, NULL, NULL);
00077   linemode_on(terminal_session.in_idx);
00078 
00079   /* And one for stdout. */
00080   terminal_session.out_idx = sockbuf_new();
00081   sockbuf_set_sock(terminal_session.out_idx, dup(fileno(stdout)), SOCKBUF_NOREAD);
00082 
00083   putlog(LOG_MISC, "*", _("Entering terminal mode."));
00084 
00085   terminal_session.party = partymember_new(-1,
00086     terminal_user, NULL, TERMINAL_NICK, TERMINAL_USER,
00087       TERMINAL_HOST, &terminal_party_handler, NULL, NULL);
00088 
00089   /* Put them on the main channel. */
00090   partychan_join_name("*", terminal_session.party, 0);
00091 
00092   return (0);
00093 }

int terminal_shutdown ( int  runmode  ) 

Definition at line 97 of file terminal.c.

References _, LOG_MISC, NULL, partymember_delete(), putlog(), RUNMODE_RESTART, sockbuf_delete(), sockbuf_set_sock(), terminal_enabled, terminal_session, and user_delete().

Referenced by core_shutdown_or_restart().

00098 {
00099   if (runmode == RUNMODE_RESTART) {
00100     terminal_user = NULL;
00101     return(0);
00102   }
00103 
00104   if (terminal_session.party) {
00105     partymember_delete(terminal_session.party, NULL, _("Shutdown"));
00106     terminal_session.party = NULL;
00107   }
00108 
00109   if (terminal_session.in_idx != -1) {
00110     sockbuf_set_sock(terminal_session.in_idx, -1, 0);
00111     sockbuf_delete(terminal_session.in_idx);
00112     terminal_session.in_idx = -1;
00113   }
00114 
00115   if (terminal_session.out_idx != -1) {
00116     sockbuf_set_sock(terminal_session.out_idx, -1, 0);
00117     sockbuf_delete(terminal_session.out_idx);
00118     terminal_session.out_idx = -1;
00119   }
00120 
00121   if (terminal_user) {
00122     user_delete(terminal_user);
00123     terminal_user = NULL;
00124   }
00125 
00126   /* let logfile.c know that there's no longer the faked
00127    * stdout sockbuf of our HQ partymember */
00128   terminal_enabled = 0;
00129 
00130   putlog(LOG_MISC, "*", _("Leaving terminal mode."));
00131 
00132   return (0);
00133 }


Variable Documentation

int in_idx

Definition at line 57 of file terminal.c.

int out_idx

Definition at line 57 of file terminal.c.

Definition at line 58 of file terminal.c.

const char rcsid[] = "$Id: terminal.c,v 1.11 2007-09-13 22:20:58 sven Exp $" [static]

Definition at line 21 of file terminal.c.

Definition at line 36 of file logfile.c.

Referenced by on_putlog(), and terminal_shutdown().

Initial value:

Definition at line 47 of file terminal.c.

struct { ... } terminal_session

Initial value:

 {
  "terminal",
  NULL,
  NULL,
  NULL,
  on_read,
  NULL
}

Definition at line 38 of file terminal.c.

user_t* terminal_user = NULL [static]

Definition at line 61 of file terminal.c.


Generated on Sun Nov 30 18:43:37 2008 for eggdrop1.9 by  doxygen 1.5.6