modules/dccparty/dccparty.c File Reference

#include <eggdrop/eggdrop.h>
#include "dccparty.h"

Go to the source code of this file.

Functions

EXPORT_SCOPE int dccparty_LTX_start (egg_module_t *modinfo)
static int dccparty_close (int why)
static int got_chat_request (char *nick, char *uhost, user_t *u, char *type, char *ip, int port)
static int dcc_on_connect (void *client_data, int idx, const char *peer_ip, int peer_port)
static int dcc_on_read (void *client_data, int idx, char *data, int len)
static int dcc_on_eof (void *client_data, int idx, int err, const char *errmsg)
static int dcc_on_delete (event_owner_t *owner, void *client_data)
static int dcc_pm_delete (event_owner_t *owner, void *client_data)
static int ident_result (void *client_data, const char *ip, int port, const char *reply)
static int dns_result (void *client_data, const char *ip, char **hosts)
static int process_results (dcc_session_t *session)
int dcc_init ()
static void kill_session (dcc_session_t *session)

Variables

static const char rcsid [] = "$Id: dccparty.c,v 1.17 2007-11-06 00:05:40 sven Exp $"
dcc_config_t dcc_config = {0}
static config_var_t dcc_config_vars []
partyline_event_t dcc_party_handler
static event_owner_t dcc_generic_owner
static event_owner_t dcc_pm_owner
static event_owner_t dcc_sock_owner
static sockbuf_handler_t dcc_handler


Function Documentation

int dcc_init (  ) 

Definition at line 81 of file dccparty.c.

References bind_add_simple(), got_chat_request(), and NULL.

Referenced by dccparty_LTX_start().

00082 {
00083   bind_add_simple("dcc_chat", NULL, "*", got_chat_request);
00084   return(0);
00085 }

static int dcc_on_connect ( void *  client_data,
int  idx,
const char *  peer_ip,
int  peer_port 
) [static]

Definition at line 121 of file dccparty.c.

References dcc_session_t::count, dcc_session_t::dns_id, dns_result(), egg_dns_reverse(), egg_ident_lookup(), egg_iprintf(), dcc_session_t::ident_id, ident_result(), dcc_session_t::ip, NULL, dcc_session_t::port, sockbuf_get_sock(), socket_get_name(), dcc_session_t::state, and STATE_NICKNAME.

00122 {
00123   dcc_session_t *session = client_data;
00124   int sock, our_port = 0;
00125 
00126   sock = sockbuf_get_sock(idx);
00127   socket_get_name(sock, NULL, &our_port);
00128   session->ip = strdup(peer_ip);
00129   session->port = peer_port;
00130   egg_iprintf(idx, "Hello %s/%d!\r\n\r\n", peer_ip, peer_port);
00131   egg_iprintf(idx, "Please enter your nickname.\r\n");
00132   session->state = STATE_NICKNAME;
00133   session->count = 0;
00134 
00135   /* Start lookups. */
00136   session->ident_id = egg_ident_lookup(peer_ip, peer_port, our_port, -1, ident_result, session, &dcc_generic_owner);
00137   session->dns_id = egg_dns_reverse(peer_ip, -1, dns_result, session, &dcc_generic_owner);
00138 
00139   return(0);
00140 }

static int dcc_on_delete ( event_owner_t owner,
void *  client_data 
) [static]

Definition at line 260 of file dccparty.c.

References dcc_session_t::idx, kill_session(), NULL, dcc_session_t::party, and partymember_delete().

00261 {
00262   dcc_session_t *session = client_data;
00263 
00264   session->idx = -1;
00265   if (session->party) {
00266     partymember_delete(session->party, NULL, "Deleted!");
00267     session->party = NULL;
00268   }
00269   kill_session(session);
00270   return(0);
00271 }

static int dcc_on_eof ( void *  client_data,
int  idx,
int  err,
const char *  errmsg 
) [static]

Definition at line 232 of file dccparty.c.

References NULL, dcc_session_t::party, partymember_delete(), and sockbuf_delete().

00233 {
00234   dcc_session_t *session = client_data;
00235 
00236   if (session->party) {
00237     if (!err) errmsg = "Client disconnected";
00238     else if (!errmsg) errmsg = "Unknown error";
00239     partymember_delete(session->party, NULL, errmsg);
00240     /* This will call our on_quit handler which will delete the sockbuf
00241      * which will call our on_delete handler which will kill the session.
00242      * Summery: All the data is gone, don't touch any of the variables */
00243   } else {
00244     sockbuf_delete(idx);
00245   }
00246   return(0);
00247 }

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

Definition at line 190 of file dccparty.c.

References _, dcc_session_t::count, egg_iprintf(), dcc_session_t::host, dcc_session_t::ident, dcc_session_t::idx, dcc_session_t::ip, dcc_config_t::max_retries, dcc_session_t::nick, NULL, dcc_session_t::party, partychan_join_name(), partyline_on_input(), partymember_new(), sockbuf_delete(), sockbuf_write(), socktimer_off(), dcc_session_t::state, STATE_NICKNAME, STATE_PARTYLINE, STATE_PASSWORD, dcc_session_t::user, and user_lookup_authed().

00191 {
00192   dcc_session_t *session = client_data;
00193 
00194   switch (session->state) {
00195     case STATE_PARTYLINE:
00196       partyline_on_input(NULL, session->party, data, len);
00197       break;
00198     case STATE_NICKNAME:
00199       session->nick = strdup(data);
00200       session->state = STATE_PASSWORD;
00201       sockbuf_write(session->idx, "Please enter your password.\r\n", -1);
00202       break;
00203     case STATE_PASSWORD:
00204       session->user = user_lookup_authed(session->nick, data);
00205       if (!session->user) {
00206         sockbuf_write(session->idx, "Invalid username/password.\r\n\r\n", -1);
00207         session->count++;
00208         if (session->count > dcc_config.max_retries) {
00209           sockbuf_delete(session->idx);
00210           break;
00211         }
00212         free(session->nick);
00213         session->nick = NULL;
00214         sockbuf_write(session->idx, "Please enter your nickname.\r\n", -1);
00215         session->state = STATE_NICKNAME;
00216       }
00217       else {
00218         session->party = partymember_new(-1, session->user, NULL, session->nick, session->ident ? session->ident : "~dcc", session->host ? session->host : session->ip, &dcc_party_handler, session, &dcc_pm_owner);
00219         session->state = STATE_PARTYLINE;
00220         egg_iprintf(idx, _("\r\nWelcome to the dcc partyline interface!\r\n"));
00221         if (session->ident) egg_iprintf(idx, _("Your ident is: %s\r\n"), session->ident);
00222         if (session->host) egg_iprintf(idx, _("Your hostname is: %s\r\n"), session->host);
00223         socktimer_off(idx);
00224         /* Put them on the main channel. */
00225         partychan_join_name("*", session->party, 0);
00226       }
00227       break;
00228   }
00229   return(0);
00230 }

static int dcc_pm_delete ( event_owner_t owner,
void *  client_data 
) [static]

Definition at line 249 of file dccparty.c.

References dcc_session_t::idx, NULL, dcc_session_t::party, and sockbuf_delete().

00250 {
00251   dcc_session_t *session = client_data;
00252 
00253   session->party = NULL;
00254 
00255   sockbuf_delete(session->idx);
00256 
00257   return 0;
00258 }

static int dccparty_close ( int  why  )  [static]

Definition at line 273 of file dccparty.c.

References config_get_root(), config_root, config_unlink_table(), and NULL.

Referenced by dccparty_LTX_start().

00274 {
00275   void *config_root;
00276 
00277   config_root = config_get_root("eggdrop");
00278   config_unlink_table(dcc_config_vars, config_root, "dccparty", 0, NULL);
00279 
00280   return(0);
00281 }

int dccparty_LTX_start ( egg_module_t modinfo  ) 

Definition at line 283 of file dccparty.c.

References egg_module::author, egg_module::close_func, config_get_root(), config_link_table(), config_root, config_update_table(), dcc_init(), dccparty_close(), egg_module::description, dcc_config_t::max_retries, event_owner_b::module, egg_module::name, NULL, and egg_module::version.

00284 {
00285   void *config_root;
00286 
00287   dcc_generic_owner.module = dcc_sock_owner.module = dcc_pm_owner.module = modinfo;
00288 
00289   modinfo->name = "dccparty";
00290   modinfo->author = "eggdev";
00291   modinfo->version = "1.0.0";
00292   modinfo->description = "dcc chat support for the partyline";
00293   modinfo->close_func = dccparty_close;
00294 
00295   /* Set defaults. */
00296   memset(&dcc_config, 0, sizeof(dcc_config));
00297   dcc_config.max_retries = 3;
00298 
00299   /* Link our vars in. */
00300   config_root = config_get_root("eggdrop");
00301   config_link_table(dcc_config_vars, config_root, "dccparty", 0, NULL);
00302   config_update_table(dcc_config_vars, config_root, "dccparty", 0, NULL);
00303 
00304   dcc_init();
00305   return(0);
00306 }

static int dns_result ( void *  client_data,
const char *  ip,
char **  hosts 
) [static]

Definition at line 153 of file dccparty.c.

References dcc_session_t::dns_id, dcc_session_t::host, and process_results().

Referenced by dcc_on_connect(), irc_on_newclient(), and telnet_on_newclient().

00154 {
00155   dcc_session_t *session = client_data;
00156   const char *host;
00157 
00158   session->dns_id = -1;
00159   if (!hosts || !hosts[0]) host = ip;
00160   else host = hosts[0];
00161 
00162   session->host = strdup(host);
00163   process_results(session);
00164   return(0);
00165 }

static int got_chat_request ( char *  nick,
char *  uhost,
user_t u,
char *  type,
char *  ip,
int  port 
) [static]

Definition at line 98 of file dccparty.c.

References _, egg_connect(), dcc_session_t::idx, linemode_on(), LOG_MISC, dcc_session_t::nick, NULL, putlog(), sockbuf_set_handler(), and socktimer_on().

Referenced by dcc_init().

00099 {
00100   int idx;
00101   dcc_session_t *session;
00102 
00103   /* Ignore chats from unknown users. */
00104   if (!u) {
00105     putlog(LOG_MISC, "*", _("Ignoring chat request from %s (user unknown)."), nick);
00106     return(0);
00107   }
00108 
00109   idx = egg_connect(ip, port, 0);
00110 
00111   session = calloc(1, sizeof(*session));
00112   session->nick = strdup(nick);
00113   session->idx = idx;
00114 
00115   sockbuf_set_handler(idx, &dcc_handler, session, &dcc_sock_owner);
00116   linemode_on(idx);
00117   socktimer_on(idx, 60, 0, NULL, NULL, &dcc_generic_owner);
00118   return(0);
00119 }

static int ident_result ( void *  client_data,
const char *  ip,
int  port,
const char *  reply 
) [static]

Definition at line 142 of file dccparty.c.

References dcc_session_t::ident, dcc_session_t::ident_id, and process_results().

00143 {
00144   dcc_session_t *session = client_data;
00145 
00146   session->ident_id = -1;
00147   if (reply) session->ident = strdup(reply);
00148   else session->ident = strdup("~dcc");
00149   process_results(session);
00150   return(0);
00151 }

static void kill_session ( dcc_session_t session  )  [static]

Definition at line 87 of file dccparty.c.

References dcc_session_t::dns_id, egg_dns_cancel(), egg_ident_cancel(), dcc_session_t::host, dcc_session_t::ident, dcc_session_t::ident_id, dcc_session_t::ip, and dcc_session_t::nick.

Referenced by dcc_on_delete(), irc_on_delete(), and telnet_on_delete().

00088 {
00089   if (session->ident_id != -1) egg_ident_cancel(session->ident_id, 0);
00090   if (session->dns_id != -1) egg_dns_cancel(session->dns_id, 0);
00091   if (session->ip) free(session->ip);
00092   if (session->host) free(session->host);
00093   if (session->ident) free(session->ident);
00094   if (session->nick) free(session->nick);
00095   free(session);
00096 }

static int process_results ( dcc_session_t session  )  [static]

Definition at line 167 of file dccparty.c.

References egg_iprintf(), dcc_session_t::flags, dcc_session_t::host, dcc_session_t::ident, dcc_session_t::idx, dcc_session_t::party, partyline_update_info(), sockbuf_delete(), dcc_session_t::state, STATE_NICKNAME, STATE_PARTYLINE, STEALTH_LOGIN, and user_lookup_by_irchost().

Referenced by dns_result(), and ident_result().

00168 {
00169   char fakehost[512];
00170 
00171   if (!session->ident || !session->host) return(0);
00172 
00173   if (session->state == STATE_PARTYLINE) {
00174     partyline_update_info(session->party, session->ident, session->host);
00175     return(0);
00176   }
00177   if (session->flags & STEALTH_LOGIN) {
00178     snprintf(fakehost, sizeof(fakehost), "-dcc!%s@%s", session->ident, session->host);
00179     fakehost[sizeof(fakehost)-1] = 0;
00180     if (!user_lookup_by_irchost(fakehost)) {
00181       sockbuf_delete(session->idx);
00182       return(0);
00183     }
00184     egg_iprintf(session->idx, "\r\nPlease enter your nickname.\r\n");
00185     session->state = STATE_NICKNAME;
00186   }
00187   return(0);
00188 }


Variable Documentation

Definition at line 28 of file dccparty.c.

Initial value:

 {
  {"vhost", &dcc_config.vhost, CONFIG_STRING},
  {"port", &dcc_config.port, CONFIG_INT},
  {"stealth", &dcc_config.stealth, CONFIG_INT},
  {"max_retries", &dcc_config.max_retries, CONFIG_INT},

  {0}
}

Definition at line 30 of file dccparty.c.

Initial value:

 {
  "dccparty", 0,
  0, 0,
  0
}

Definition at line 57 of file dccparty.c.

Initial value:

Definition at line 75 of file dccparty.c.

Definition at line 37 of file events.c.

Initial value:

 {
  "dccparty", 0,
  0, 0,
  dcc_pm_delete
}

Definition at line 63 of file dccparty.c.

Initial value:

 {
  "dccparty", 0,
  0, 0,
  dcc_on_delete
}

Definition at line 69 of file dccparty.c.

const char rcsid[] = "$Id: dccparty.c,v 1.17 2007-11-06 00:05:40 sven Exp $" [static]

Definition at line 21 of file dccparty.c.


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