lib/eggdrop/ident.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <eggdrop/eggdrop.h>

Go to the source code of this file.

Data Structures

struct  _ident_info

Typedefs

typedef struct _ident_info ident_info_t

Functions

static int ident_on_connect (void *client_data, int idx, const char *peer_ip, int peer_port)
static int ident_on_read (void *client_data, int idx, char *data, int len)
static int ident_on_eof (void *client_data, int idx, int err, const char *errmsg)
static int ident_result (ident_info_t *ident_info, const char *ident)
int egg_ident_lookup (const char *ip, int their_port, int our_port, int timeout, ident_callback_t *callback, void *client_data, event_owner_t *owner)
int egg_ident_cancel (int id, int issue_callback)
int egg_ident_cancel_by_owner (egg_module_t *module, void *script)

Variables

static const char rcsid [] = "$Id: ident.c,v 1.7 2007-09-13 22:20:55 sven Exp $"
static sockbuf_handler_t ident_handler
static ident_info_tident_head = NULL


Typedef Documentation

typedef struct _ident_info ident_info_t


Function Documentation

int egg_ident_cancel ( int  id,
int  issue_callback 
)

Definition at line 86 of file ident.c.

References _ident_info::callback, _ident_info::client_data, _ident_info::id, _ident_info::idx, _ident_info::ip, _ident_info::next, NULL, event_owner_b::on_delete, _ident_info::owner, sockbuf_delete(), and _ident_info::their_port.

Referenced by kill_session().

00087 {
00088   ident_info_t *ptr, *prev;
00089 
00090   prev = NULL;
00091   for (ptr = ident_head; ptr; ptr = ptr->next) {
00092     if (ptr->id == id) break;
00093     prev = ptr;
00094   }
00095   if (!ptr) return(-1);
00096   if (prev) prev->next = ptr->next;
00097   else ident_head = ptr->next;
00098   sockbuf_delete(ptr->idx);
00099   if (issue_callback) {
00100     ptr->callback(ptr->client_data, ptr->ip, ptr->their_port, NULL);
00101   }
00102   if (ptr->owner && ptr->owner->on_delete) ptr->owner->on_delete(ptr->owner, ptr->client_data);
00103   free(ptr->ip);
00104   free(ptr);
00105   return(0);
00106 }

int egg_ident_cancel_by_owner ( egg_module_t module,
void *  script 
)

Definition at line 108 of file ident.c.

References _ident_info::client_data, event_owner_b::client_data, _ident_info::idx, _ident_info::ip, event_owner_b::module, _ident_info::next, NULL, event_owner_b::on_delete, _ident_info::owner, and sockbuf_delete().

Referenced by script_remove_events_by_owner().

00109 {
00110   int removed = 0;
00111   ident_info_t *ptr, *prev = NULL, *next;
00112 
00113   for (ptr = ident_head; ptr; ptr = next) {
00114     next = ptr->next;
00115     if (!ptr->owner || ptr->owner->module != module || (script && ptr->owner->client_data != script)) {
00116       prev = ptr;
00117       continue;
00118     }
00119     if (prev) prev->next = ptr->next;
00120     else ident_head = ptr->next;
00121     ++removed;
00122     sockbuf_delete(ptr->idx);
00123     if (ptr->owner && ptr->owner->on_delete) ptr->owner->on_delete(ptr->owner, ptr->client_data);
00124     free(ptr->ip);
00125     free(ptr);
00126   }
00127   return removed;
00128 }

int egg_ident_lookup ( const char *  ip,
int  their_port,
int  our_port,
int  timeout,
ident_callback_t callback,
void *  client_data,
event_owner_t owner 
)

Definition at line 57 of file ident.c.

References _ident_info::callback, _ident_info::client_data, egg_connect(), _ident_info::id, _ident_info::idx, _ident_info::ip, _ident_info::next, NULL, event_owner_b::on_delete, _ident_info::our_port, _ident_info::owner, sockbuf_set_handler(), _ident_info::their_port, and _ident_info::timeout.

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

00058 {
00059   static int ident_id = 0;
00060   int idx;
00061   ident_info_t *ident_info;
00062   
00063   idx = egg_connect(ip, 113, -1);
00064   if (idx < 0) {
00065     callback(client_data, ip, their_port, NULL);
00066     if (owner && owner->on_delete) owner->on_delete(owner, client_data);
00067     return(-1);
00068   }
00069   ident_info = calloc(1, sizeof(*ident_info));
00070   ident_info->ip = strdup(ip);
00071   ident_info->their_port = their_port;
00072   ident_info->our_port = our_port;
00073   ident_info->timeout = timeout;
00074   ident_info->callback = callback;
00075   ident_info->client_data = client_data;
00076   ident_info->owner = owner;
00077   ident_info->idx = idx;
00078   ident_info->id = ident_id++;
00079   ident_info->next = ident_head;
00080   ident_head = ident_info;
00081   sockbuf_set_handler(idx, &ident_handler, ident_info, NULL);
00082   return(ident_info->id);
00083 }

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

Definition at line 130 of file ident.c.

References egg_iprintf(), _ident_info::our_port, and _ident_info::their_port.

00131 {
00132   ident_info_t *ident_info = client_data;
00133 
00134   egg_iprintf(idx, "%d,%d\r\n", ident_info->their_port, ident_info->our_port);
00135   return(0);
00136 }

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

Definition at line 181 of file ident.c.

References ident_result(), and NULL.

00182 {
00183   ident_result(client_data, NULL);
00184   return(0);
00185 }

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

Definition at line 138 of file ident.c.

References ident_result(), and NULL.

00139 {
00140   char *colon, *ident;
00141   int i;
00142 
00143   colon = strchr(data, ':');
00144   if (!colon) goto ident_error;
00145 
00146   /* See if it's a successful lookup. */
00147   colon++;
00148   while (isspace(*colon)) colon++;
00149   if (strncasecmp(colon, "USERID", 6)) goto ident_error;
00150 
00151   /* Go to the OS identifier. */
00152   colon = strchr(colon, ':');
00153   if (!colon) goto ident_error;
00154   colon++;
00155 
00156   /* Go to the user id. */
00157   ident = strchr(colon, ':');
00158   if (!ident) goto ident_error;
00159   ident++;
00160   while (*ident && isspace(*ident)) ident++;
00161 
00162   /* Replace bad chars. */
00163   len = strlen(ident);
00164   for (i = 0; i < len; i++) {
00165     if (ident[i] == '\r' || ident[i] == '\n') {
00166       ident[i] = 0;
00167       break;
00168     }
00169     if (!isalnum(ident[i]) && ident[i] != '_') ident[i] = 'x';
00170   }
00171   if (!*ident) goto ident_error;
00172   if (len > 20) ident[20] = 0;
00173   ident_result(client_data, ident);
00174   return(0);
00175 
00176 ident_error:
00177   ident_result(client_data, NULL);
00178   return(0);
00179 }

static int ident_result ( ident_info_t ident_info,
const char *  ident 
) [static]

Definition at line 187 of file ident.c.

References _ident_info::callback, _ident_info::client_data, _ident_info::idx, _ident_info::ip, _ident_info::next, NULL, event_owner_b::on_delete, _ident_info::owner, sockbuf_delete(), and _ident_info::their_port.

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

00188 {
00189   ident_info_t *ptr, *prev = NULL;
00190   
00191   for (ptr = ident_head; ptr; ptr = ptr->next) {
00192     if (ptr == ident_info) break;
00193     prev = ptr;
00194   }
00195 
00196   if (prev) prev->next = ptr->next;
00197   else ident_head = ptr->next;
00198 
00199   sockbuf_delete(ident_info->idx);
00200   ident_info->callback(ident_info->client_data, ident_info->ip, ident_info->their_port, ident);
00201   if (ident_info->owner && ident_info->owner->on_delete) ident_info->owner->on_delete(ident_info->owner, ident_info->client_data);
00202   free(ident_info->ip);
00203   free(ident_info);
00204   return(0);
00205 }


Variable Documentation

Initial value:

Definition at line 47 of file ident.c.

ident_info_t* ident_head = NULL [static]

Definition at line 53 of file ident.c.

const char rcsid[] = "$Id: ident.c,v 1.7 2007-09-13 22:20:55 sven Exp $" [static]

Definition at line 21 of file ident.c.


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