modules/server/dcc.h File Reference

Go to the source code of this file.

Defines

#define DCC_SEND_SENT   1
#define DCC_SEND_LEFT   2
#define DCC_SEND_CPS_TOTAL   3
#define DCC_SEND_CPS_SNAPSHOT   4
#define DCC_SEND_ACKS   5
#define DCC_SEND_BYTES_ACKED   6
#define DCC_SEND_RESUMED_AT   7
#define DCC_SEND_REQUEST_TIME   8
#define DCC_SEND_CONNECT_TIME   9

Functions

int dcc_dns_set (const char *host)
int dcc_start_chat (const char *nick, int timeout)
int dcc_start_send (const char *nick, const char *fname, int timeout)
int dcc_send_info (int idx, int field, void *valueptr)
int dcc_accept_send (char *nick, char *localfname, char *fname, int size, int resume, char *ip, int port, int timeout)

Variables

bind_list_t ctcp_dcc_binds []


Define Documentation

#define DCC_SEND_ACKS   5

Definition at line 30 of file dcc.h.

Referenced by dcc_send_info(), and script_dcc_send_info().

#define DCC_SEND_BYTES_ACKED   6

Definition at line 31 of file dcc.h.

Referenced by dcc_send_info(), and script_dcc_send_info().

#define DCC_SEND_CONNECT_TIME   9

Definition at line 34 of file dcc.h.

Referenced by dcc_send_info(), and script_dcc_send_info().

#define DCC_SEND_CPS_SNAPSHOT   4

Definition at line 29 of file dcc.h.

Referenced by dcc_send_info(), and script_dcc_send_info().

#define DCC_SEND_CPS_TOTAL   3

Definition at line 28 of file dcc.h.

Referenced by dcc_send_info(), and script_dcc_send_info().

#define DCC_SEND_LEFT   2

Definition at line 27 of file dcc.h.

Referenced by dcc_send_info(), and script_dcc_send_info().

#define DCC_SEND_REQUEST_TIME   8

Definition at line 33 of file dcc.h.

Referenced by dcc_send_info(), and script_dcc_send_info().

#define DCC_SEND_RESUMED_AT   7

Definition at line 32 of file dcc.h.

Referenced by script_dcc_send_info().

#define DCC_SEND_SENT   1

Definition at line 26 of file dcc.h.

Referenced by dcc_send_info(), and script_dcc_send_info().


Function Documentation

int dcc_accept_send ( char *  nick,
char *  localfname,
char *  fname,
int  size,
int  resume,
char *  ip,
int  port,
int  timeout 
)

Definition at line 506 of file dcc.c.

References dcc_send::bytes_left, dcc_send::bytes_sent, dcc_send::connect_time, dcc_recv_timeout(), egg_connect(), dcc_send::fd, dcc_send::fname, dcc_send::idx, dcc_send::ip, LOG_MISC, dcc_send::next, dcc_send::nick, dcc_send::port, printserv, putlog(), dcc_send::request_time, egg_timeval::sec, server_config, SERVER_NORMAL, server_owner, dcc_send::size, sockbuf_attach_filter(), sockbuf_new(), timer_create_complex(), timer_get_now_sec(), dcc_send::timer_id, and egg_timeval::usec.

00507 {
00508   dcc_send_t *send;
00509   char *quote;
00510   egg_timeval_t howlong;
00511 
00512   send = calloc(1, sizeof(*send));
00513   send->next = dcc_recv_head;
00514   dcc_recv_head = send;
00515 
00516   /* See if they want the default timeout. */
00517   if (!timeout) timeout = server_config.dcc_timeout;
00518   if (timeout > 0) {
00519     char buf[128];
00520 
00521     snprintf(buf, sizeof(buf), "dcc recv %s/%d", ip, port);
00522     howlong.sec = timeout;
00523     howlong.usec = 0;
00524     send->timer_id = timer_create_complex(&howlong, buf, dcc_recv_timeout, send, 0, &server_owner);
00525   }
00526   else send->connect_time = -1;
00527 
00528   send->port = port;
00529   send->fname = strdup(localfname);
00530   send->nick = strdup(nick);
00531   send->ip = strdup(ip);
00532   send->size = size;
00533   send->bytes_sent = 0;
00534   send->bytes_left = size;
00535   timer_get_now_sec(&send->request_time);
00536 
00537   if (resume < 0) {
00538     send->fd = open(localfname, O_RDWR | O_CREAT, 0640);
00539     resume = lseek(send->fd, 0, SEEK_END);
00540     close(send->fd);
00541     if (resume < 0) resume = 0;
00542   }
00543 
00544   if (resume >= size) resume = 0;
00545 
00546   if (resume) {
00547     putlog(LOG_MISC, "*", "sending resume request");
00548     send->idx = sockbuf_new();
00549     send->fd = open(localfname, O_RDWR | O_CREAT, 0640);
00550     if (resume < 0) resume = lseek(send->fd, 0, SEEK_END);
00551     else resume = lseek(send->fd, resume, SEEK_SET);
00552     if (strchr(fname, ' ')) quote = "\"";
00553     else quote = "";
00554     printserv(SERVER_NORMAL, "PRIVMSG %s :%cDCC RESUME %s%s%s %d %d%c", nick, 1, quote, fname, quote, port, resume, 1);
00555   }
00556   else {
00557     send->idx = egg_connect(ip, port, -1);
00558     send->fd = open(localfname, O_RDWR | O_CREAT | O_TRUNC, 0640);
00559   }
00560 
00561   sockbuf_attach_filter(send->idx, &dcc_recv_filter, send);
00562 
00563   return(send->idx);
00564 }

int dcc_dns_set ( const char *  host  ) 

Definition at line 124 of file dcc.c.

References dcc_dns_callback(), egg_dns_lookup(), NULL, and server_owner.

00125 {
00126   egg_dns_lookup(host, 0, dcc_dns_callback, NULL, &server_owner);
00127   return(0);
00128 }

int dcc_send_info ( int  idx,
int  field,
void *  valueptr 
)

Definition at line 440 of file dcc.c.

References dcc_send::acks, dcc_send::bytes_acked, dcc_send::bytes_left, dcc_send::bytes_sent, dcc_send::connect_time, DCC_SEND_ACKS, DCC_SEND_BYTES_ACKED, DCC_SEND_CONNECT_TIME, DCC_SEND_CPS_SNAPSHOT, DCC_SEND_CPS_TOTAL, DCC_SEND_LEFT, DCC_SEND_REQUEST_TIME, DCC_SEND_SENT, now, dcc_send::request_time, dcc_send::snapshot_bytes, dcc_send::snapshot_counter, sockbuf_get_filter_data(), timer_get_now_sec(), and update_snapshot().

00441 {
00442   dcc_send_t *send;
00443   int i, n;
00444   long now;
00445 
00446   if (!valueptr)
00447     return(-1);
00448 
00449   if (sockbuf_get_filter_data(idx, &dcc_send_filter, &send) < 0)
00450     if (sockbuf_get_filter_data(idx, &dcc_recv_filter, &send) < 0)
00451       return(-1);
00452 
00453   timer_get_now_sec(&now);
00454   switch (field) {
00455     case DCC_SEND_SENT:
00456       *(int *)valueptr = send->bytes_sent;
00457       break;
00458     case DCC_SEND_LEFT:
00459       *(int *)valueptr = send->bytes_left;
00460       break;
00461     case DCC_SEND_CPS_TOTAL:
00462       if (!send->connect_time)
00463         n = 0;
00464       else if (send->connect_time >= now)
00465         n = send->bytes_sent;
00466       else
00467         n = (int) ((float) send->bytes_sent / ((float) now - (float) send->connect_time));
00468       *(int *)valueptr = n;
00469       break;
00470     case DCC_SEND_CPS_SNAPSHOT:
00471       update_snapshot(send, 0);
00472       /* When we calculate the total, we do not include
00473        * the current second (snapshot_counter) because more
00474        * data might be sent this second and our report won't
00475        * be accurate. */
00476       n = 0;
00477       for (i = 0; i < 5; i++) {
00478         if (i != send->snapshot_counter)
00479           n += send->snapshot_bytes[i];
00480       }
00481       if (now - send->connect_time >= 5)
00482         n = (int) ((float) n / 4.0);
00483       else if (now - send->connect_time > 1)
00484         n = (int) ((float) n / (float) (now - send->connect_time - 1));
00485       else n = 0;
00486       *(int *)valueptr = n;
00487       break;
00488     case DCC_SEND_ACKS:
00489       *(int *)valueptr = send->acks;
00490       break;
00491     case DCC_SEND_BYTES_ACKED:
00492       *(int *)valueptr = send->bytes_acked;
00493       break;
00494     case DCC_SEND_REQUEST_TIME:
00495       *(int *)valueptr = send->request_time;
00496       break;
00497     case DCC_SEND_CONNECT_TIME:
00498       *(int *)valueptr = send->connect_time;
00499       break;
00500     default:
00501       return(-1);
00502   }
00503   return(0);
00504 }

int dcc_start_chat ( const char *  nick,
int  timeout 
)

Definition at line 165 of file dcc.c.

References dcc_listen::client, current_server, dcc_listen(), dcc_send::idx, dcc_listen::port, printserv, dcc_listen::serv, SERVER_NORMAL, sockbuf_attach_filter(), and sockbuf_new().

00166 {
00167   dcc_listen_t *listen;
00168   int idx;
00169 
00170   /* Create a listening idx to accept the chat connection. */
00171   listen = dcc_listen(timeout);
00172   if (!listen) return(-1);
00173 
00174   /* Create an empty sockbuf that will eventually be used for the
00175    * dcc chat (when they connect to us). */
00176   idx = sockbuf_new();
00177   sockbuf_attach_filter(idx, &dcc_chat_filter, (void *)listen->serv);
00178   listen->client = idx;
00179 
00180   printserv(SERVER_NORMAL, "PRIVMSG %s :%cDCC CHAT chat %u %d%c", nick, 1, current_server.mylongip, listen->port, 1);
00181   return(idx);
00182 }

int dcc_start_send ( const char *  nick,
const char *  fname,
int  timeout 
)

Definition at line 256 of file dcc.c.

References dcc_send::bytes_left, dcc_send::bytes_sent, dcc_listen::client, current_server, dcc_listen(), dcc_send::fd, dcc_send::fname, dcc_send::idx, dcc_send::next, dcc_send::nick, dcc_listen::port, dcc_send::port, printserv, dcc_send::request_time, dcc_listen::serv, dcc_send::serv, SERVER_NORMAL, dcc_send::size, sockbuf_attach_filter(), sockbuf_new(), and timer_get_now_sec().

00257 {
00258   dcc_listen_t *listen;
00259   dcc_send_t *send;
00260   int idx, size, fd;
00261   char *quote, *slash;
00262 
00263   fd = open(fname, O_RDONLY);
00264   if (!fd)
00265     return(-2); /* File could not be opened. */
00266 
00267   size = lseek(fd, 0, SEEK_END);
00268   lseek(fd, 0, SEEK_SET);
00269 
00270   listen = dcc_listen(timeout);
00271   if (!listen) {
00272     close(fd);
00273     return(-1);
00274   }
00275 
00276   /* Create an empty sockbuf that will eventually be used for the
00277    * dcc chat (when they connect to us). */
00278   idx = sockbuf_new();
00279   send = calloc(1, sizeof(*send));
00280   sockbuf_attach_filter(idx, &dcc_send_filter, send);
00281 
00282   listen->client = idx;
00283   send->next = dcc_send_head;
00284   dcc_send_head = send;
00285   send->serv = listen->serv;
00286   send->port = listen->port;
00287   send->fd = fd;
00288   send->idx = idx;
00289   send->size = size;
00290   send->bytes_sent = 0;
00291   send->bytes_left = size;
00292   timer_get_now_sec(&send->request_time);
00293   send->fname = strdup(fname);
00294   send->nick = strdup(nick);
00295 
00296   slash = strrchr(fname, '/');
00297   if (slash)
00298     fname = slash+1;
00299 
00300   if (strchr(fname, ' '))
00301     quote = "\"";
00302   else
00303     quote = "";
00304 
00305   printserv(SERVER_NORMAL, "PRIVMSG %s :%cDCC SEND %s%s%s %u %d %d%c", nick, 1, quote, fname, quote,
00306       current_server.mylongip, listen->port, size, 1);
00307 
00308   return(idx);
00309 }


Variable Documentation

Definition at line 782 of file dcc.c.


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