src/mod/transfer.mod/transferfstat.c File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static int fstat_unpack (struct userrec *u, struct user_entry *e)
static int fstat_pack (struct userrec *u, struct user_entry *e)
static int fstat_write_userfile (FILE *f, struct userrec *u, struct user_entry *e)
static int fstat_set (struct userrec *u, struct user_entry *e, void *buf)
static int fstat_tcl_get (Tcl_Interp *irp, struct userrec *u, struct user_entry *e, int argc, char **argv)
static int fstat_kill (struct user_entry *e)
static int fstat_expmem (struct user_entry *e)
static void fstat_display (int idx, struct user_entry *e)
static int fstat_gotshare (struct userrec *u, struct user_entry *e, char *par, int idx)
static int fstat_dupuser (struct userrec *u, struct userrec *o, struct user_entry *e)
static void stats_add_dnload (struct userrec *u, unsigned long bytes)
static void stats_add_upload (struct userrec *u, unsigned long bytes)
static int fstat_tcl_set (Tcl_Interp *irp, struct userrec *u, struct user_entry *e, int argc, char **argv)

Variables

static struct user_entry_type USERENTRY_FSTAT

Function Documentation

static void fstat_display ( int  idx,
struct user_entry e 
) [static]

Definition at line 158 of file transferfstat.c.

References filesys_stats::dnload_ks, filesys_stats::dnloads, dprintf, user_entry::extra, user_entry::u, filesys_stats::upload_ks, and filesys_stats::uploads.

00159 {
00160   struct filesys_stats *fs;
00161 
00162   fs = e->u.extra;
00163   dprintf(idx, "  FILES: %u download%s (%luk), %u upload%s (%luk)\n",
00164           fs->dnloads, (fs->dnloads == 1) ? "" : "s", fs->dnload_ks,
00165           fs->uploads, (fs->uploads == 1) ? "" : "s", fs->upload_ks);
00166 }

static int fstat_dupuser ( struct userrec u,
struct userrec o,
struct user_entry e 
) [static]

Definition at line 229 of file transferfstat.c.

References user_entry::extra, my_memcpy, set_user, user_entry::u, and user_malloc.

00231 {
00232   struct filesys_stats *fs;
00233 
00234   if (e->u.extra) {
00235     fs = user_malloc(sizeof(struct filesys_stats));
00236     my_memcpy(fs, e->u.extra, sizeof(struct filesys_stats));
00237     return set_user(&USERENTRY_FSTAT, u, fs);
00238   }
00239 
00240   return 0;
00241 }

static int fstat_expmem ( struct user_entry e  )  [static]

Definition at line 153 of file transferfstat.c.

00154 {
00155   return sizeof(struct filesys_stats);
00156 }

static int fstat_gotshare ( struct userrec u,
struct user_entry e,
char *  par,
int  idx 
) [static]

Definition at line 185 of file transferfstat.c.

References filesys_stats::dnload_ks, filesys_stats::dnloads, egg_bzero, user_entry::extra, newsplit, noshare, NULL, set_user, user_entry::u, filesys_stats::upload_ks, filesys_stats::uploads, and user_malloc.

00187 {
00188   char *p;
00189   struct filesys_stats *fs;
00190 
00191   noshare = 1;
00192   switch (par[0]) {
00193   case 'u':
00194   case 'd':
00195     break;
00196   case 'r':
00197     set_user(&USERENTRY_FSTAT, u, NULL);
00198     break;
00199   default:
00200     if (!(fs = e->u.extra)) {
00201       fs = user_malloc(sizeof(struct filesys_stats));
00202       egg_bzero(fs, sizeof(struct filesys_stats));
00203     }
00204 
00205     p = newsplit(&par);
00206     if (p[0])
00207       fs->uploads = atoi(p);
00208 
00209     p = newsplit(&par);
00210     if (p[0])
00211       fs->upload_ks = atoi(p);
00212 
00213     p = newsplit(&par);
00214     if (p[0])
00215       fs->dnloads = atoi(p);
00216 
00217     p = newsplit(&par);
00218     if (p[0])
00219       fs->dnload_ks = atoi(p);
00220 
00221     set_user(&USERENTRY_FSTAT, u, fs);
00222     break;
00223   }
00224   noshare = 0;
00225 
00226   return 1;
00227 }

static int fstat_kill ( struct user_entry e  )  [static]

Definition at line 144 of file transferfstat.c.

References user_entry::extra, nfree, and user_entry::u.

00145 {
00146   if (e->u.extra)
00147     nfree(e->u.extra);
00148   nfree(e);
00149 
00150   return 1;
00151 }

static int fstat_pack ( struct userrec u,
struct user_entry e 
) [static]

Definition at line 54 of file transferfstat.c.

References filesys_stats::dnload_ks, filesys_stats::dnloads, egg_snprintf, list_type::extra, user_entry::extra, user_entry::list, list_type::next, nfree, NULL, user_entry::u, filesys_stats::upload_ks, filesys_stats::uploads, and user_malloc.

00055 {
00056   register struct filesys_stats *fs;
00057   struct list_type *l = user_malloc(sizeof(struct list_type));
00058 
00059   fs = e->u.extra;
00060   l->extra = user_malloc(41);
00061   egg_snprintf(l->extra, 41, "%09u %09u %09u %09u", fs->uploads, fs->upload_ks,
00062                fs->dnloads, fs->dnload_ks);
00063   l->next = NULL;
00064   e->u.list = l;
00065   nfree(fs);
00066 
00067   return 1;
00068 }

static int fstat_set ( struct userrec u,
struct user_entry e,
void *  buf 
) [static]

Definition at line 83 of file transferfstat.c.

References filesys_stats::dnload_ks, filesys_stats::dnloads, user_entry::extra, userrec::flags, nfree, noshare, NULL, shareout, user_entry::u, filesys_stats::upload_ks, filesys_stats::uploads, USER_BOT, and USER_UNSHARED.

00084 {
00085   register struct filesys_stats *fs = buf;
00086 
00087   if (e->u.extra != fs) {
00088     if (e->u.extra)
00089       nfree(e->u.extra);
00090     e->u.extra = fs;
00091   } else if (!fs) /* e->u.extra == NULL && fs == NULL */
00092     return 1;
00093 
00094   if (!noshare && !(u->flags & (USER_BOT | USER_UNSHARED))) {
00095     if (fs)
00096       /* Don't check here for something like:
00097        *  ofs->uploads != fs->uploads || ofs->upload_ks != fs->upload_ks ||
00098        *  ofs->dnloads != fs->dnloads || ofs->dnload_ks != fs->dnload_ks
00099        *
00100        * Someone could do:
00101        *  e->u.extra->uploads = 12345;
00102        *  fs = user_malloc(sizeof(struct filesys_stats));
00103        *  my_memcpy(...e->u.extra...fs...);
00104        *  set_user(&USERENTRY_FSTAT, u, fs);
00105        *
00106        * Then we wouldn't detect here that something's changed.
00107        * --rtc
00108        */
00109       shareout(NULL, "ch fstat %09u %09u %09u %09u\n", fs->uploads,
00110                fs->upload_ks, fs->dnloads, fs->dnload_ks);
00111     else
00112       shareout(NULL, "ch fstat r\n");
00113   }
00114 
00115   return 1;
00116 }

static int fstat_tcl_get ( Tcl_Interp irp,
struct userrec u,
struct user_entry e,
int  argc,
char **  argv 
) [static]

Definition at line 118 of file transferfstat.c.

References BADARGS, filesys_stats::dnload_ks, filesys_stats::dnloads, egg_snprintf, user_entry::extra, NULL, user_entry::u, filesys_stats::upload_ks, and filesys_stats::uploads.

00120 {
00121   register struct filesys_stats *fs;
00122   char d[50];
00123 
00124   BADARGS(3, 4, " handle FSTAT ?u/d?");
00125 
00126   fs = e->u.extra;
00127   if (argc == 3)
00128     egg_snprintf(d, sizeof d, "%u %u %u %u", fs->uploads, fs->upload_ks,
00129                  fs->dnloads, fs->dnload_ks);
00130   else
00131     switch (argv[3][0]) {
00132     case 'u':
00133       egg_snprintf(d, sizeof d, "%u %u", fs->uploads, fs->upload_ks);
00134       break;
00135     case 'd':
00136       egg_snprintf(d, sizeof d, "%u %u", fs->dnloads, fs->dnload_ks);
00137       break;
00138     }
00139 
00140   Tcl_AppendResult(irp, d, NULL);
00141   return TCL_OK;
00142 }

static int fstat_tcl_set ( Tcl_Interp irp,
struct userrec u,
struct user_entry e,
int  argc,
char **  argv 
) [static]

Definition at line 277 of file transferfstat.c.

References BADARGS, filesys_stats::dnload_ks, filesys_stats::dnloads, egg_bzero, user_entry::extra, NULL, set_user, user_entry::u, filesys_stats::upload_ks, filesys_stats::uploads, and user_malloc.

00279 {
00280   register struct filesys_stats *fs;
00281   int f = 0, k = 0;
00282 
00283   BADARGS(4, 6, " handle FSTAT u/d ?files ?ks??");
00284 
00285   if (argc > 4)
00286     f = atoi(argv[4]);
00287   if (argc > 5)
00288     k = atoi(argv[5]);
00289 
00290   switch (argv[3][0]) {
00291   case 'u':
00292   case 'd':
00293     if (!(fs = e->u.extra)) {
00294       fs = user_malloc(sizeof(struct filesys_stats));
00295       egg_bzero(fs, sizeof(struct filesys_stats));
00296     }
00297     switch (argv[3][0]) {
00298     case 'u':
00299       fs->uploads = f;
00300       fs->upload_ks = k;
00301       break;
00302     case 'd':
00303       fs->dnloads = f;
00304       fs->dnload_ks = k;
00305       break;
00306     }
00307     set_user(&USERENTRY_FSTAT, u, fs);
00308     break;
00309   case 'r':
00310     set_user(&USERENTRY_FSTAT, u, NULL);
00311     break;
00312   }
00313 
00314   return TCL_OK;
00315 }

static int fstat_unpack ( struct userrec u,
struct user_entry e 
) [static]

Definition at line 23 of file transferfstat.c.

References filesys_stats::dnload_ks, filesys_stats::dnloads, egg_bzero, user_entry::extra, list_type::extra, user_entry::list, list_type_kill, newsplit, user_entry::u, filesys_stats::upload_ks, filesys_stats::uploads, and user_malloc.

00024 {
00025   char *par, *arg;
00026   struct filesys_stats *fs;
00027 
00028   fs = user_malloc(sizeof(struct filesys_stats));
00029   egg_bzero(fs, sizeof(struct filesys_stats));
00030   par = e->u.list->extra;
00031 
00032   arg = newsplit(&par);
00033   if (arg[0])
00034     fs->uploads = atoi(arg);
00035 
00036   arg = newsplit(&par);
00037   if (arg[0])
00038     fs->upload_ks = atoi(arg);
00039 
00040   arg = newsplit(&par);
00041   if (arg[0])
00042     fs->dnloads = atoi(arg);
00043 
00044   arg = newsplit(&par);
00045   if (arg[0])
00046     fs->dnload_ks = atoi(arg);
00047 
00048   list_type_kill(e->u.list);
00049   e->u.extra = fs;
00050 
00051   return 1;
00052 }

static int fstat_write_userfile ( FILE *  f,
struct userrec u,
struct user_entry e 
) [static]

Definition at line 70 of file transferfstat.c.

References filesys_stats::dnload_ks, filesys_stats::dnloads, user_entry::extra, user_entry::u, filesys_stats::upload_ks, and filesys_stats::uploads.

00072 {
00073   register struct filesys_stats *fs;
00074 
00075   fs = e->u.extra;
00076   if (fprintf(f, "--FSTAT %09u %09u %09u %09u\n", fs->uploads, fs->upload_ks,
00077               fs->dnloads, fs->dnload_ks) == EOF)
00078     return 0;
00079 
00080   return 1;
00081 }

static void stats_add_dnload ( struct userrec u,
unsigned long  bytes 
) [static]

Definition at line 243 of file transferfstat.c.

References filesys_stats::dnload_ks, filesys_stats::dnloads, egg_bzero, user_entry::extra, find_user_entry, set_user, user_entry::u, and user_malloc.

00244 {
00245   struct user_entry *ue;
00246   register struct filesys_stats *fs;
00247 
00248   if (u) {
00249     if (!(ue = find_user_entry(&USERENTRY_FSTAT, u)) || !(fs = ue->u.extra)) {
00250       fs = user_malloc(sizeof(struct filesys_stats));
00251       egg_bzero(fs, sizeof(struct filesys_stats));
00252     }
00253     fs->dnloads++;
00254     fs->dnload_ks += ((bytes + 512) / 1024);
00255     set_user(&USERENTRY_FSTAT, u, fs);
00256     /* No shareout here, set_user already sends info... --rtc */
00257   }
00258 }

static void stats_add_upload ( struct userrec u,
unsigned long  bytes 
) [static]

Definition at line 260 of file transferfstat.c.

References egg_bzero, user_entry::extra, find_user_entry, set_user, user_entry::u, filesys_stats::upload_ks, filesys_stats::uploads, and user_malloc.

00261 {
00262   struct user_entry *ue;
00263   register struct filesys_stats *fs;
00264 
00265   if (u) {
00266     if (!(ue = find_user_entry(&USERENTRY_FSTAT, u)) || !(fs = ue->u.extra)) {
00267       fs = user_malloc(sizeof(struct filesys_stats));
00268       egg_bzero(fs, sizeof(struct filesys_stats));
00269     }
00270     fs->uploads++;
00271     fs->upload_ks += ((bytes + 512) / 1024);
00272     set_user(&USERENTRY_FSTAT, u, fs);
00273     /* No shareout here, set_user already sends info... --rtc */
00274   }
00275 }


Variable Documentation


Generated on 7 Sep 2016 for Eggdrop by  doxygen 1.6.1