#include "copyright.h"
#include "autoconf.h"
#include "config.h"
#include "externs.h"
#include "command.h"
#include "file_c.h"
Include dependency graph for file_c.cpp:
Go to the source code of this file.
Data Structures | |
struct | filecache_block |
struct | filecache_block::filecache_block_hdr |
struct | filecache_hdr |
Defines | |
#define | FBLOCK_SIZE (MBUF_SIZE - sizeof(FBLKHDR)) |
Typedefs | |
typedef filecache_block_hdr | FBLKHDR |
typedef filecache_block | FBLOCK |
typedef filecache_hdr | FCACHE |
Functions | |
void | do_list_file (dbref executor, dbref caller, dbref enactor, int extra, char *arg) |
static FBLOCK * | fcache_fill (FBLOCK *fp, char ch) |
static int | fcache_read (FBLOCK **cp, char *filename) |
void | fcache_rawdump (SOCKET fd, int num) |
void | fcache_dump (DESC *d, int num) |
void | fcache_send (dbref player, int num) |
void | fcache_load (dbref player) |
void | fcache_init (void) |
Variables | |
static FCACHE | fcache [] |
static NAMETAB | list_files [] |
#define FBLOCK_SIZE (MBUF_SIZE - sizeof(FBLKHDR)) |
Definition at line 36 of file file_c.cpp.
typedef struct filecache_block_hdr FBLKHDR |
Definition at line 14 of file file_c.cpp.
typedef struct filecache_block FBLOCK |
Definition at line 15 of file file_c.cpp.
typedef struct filecache_hdr FCACHE |
Definition at line 34 of file file_c.cpp.
Definition at line 70 of file file_c.cpp.
References display_nametab(), fcache_send(), list_files, search_nametab(), and UNUSED_PARAMETER.
00071 { 00072 UNUSED_PARAMETER(caller); 00073 UNUSED_PARAMETER(enactor); 00074 UNUSED_PARAMETER(extra); 00075 00076 int flagvalue; 00077 if (!search_nametab(executor, list_files, arg, &flagvalue)) 00078 { 00079 display_nametab(executor, list_files, "Unknown file. Use one of:", true); 00080 return; 00081 } 00082 fcache_send(executor, flagvalue); 00083 }
void fcache_dump | ( | DESC * | d, | |
int | num | |||
) |
Definition at line 212 of file file_c.cpp.
References filecache_block::data, FC_LAST, fcache, filecache_hdr::fileblock, filecache_block::hdr, filecache_block::filecache_block_hdr::nchars, filecache_block::filecache_block_hdr::nxt, and queue_write_LEN().
Referenced by check_connect(), failconn(), fcache_send(), shutdownsock(), and welcome_user().
00213 { 00214 if ((num < 0) || (num > FC_LAST)) 00215 { 00216 return; 00217 } 00218 FBLOCK *fp = fcache[num].fileblock; 00219 00220 while (fp != NULL) 00221 { 00222 queue_write_LEN(d, fp->data, fp->hdr.nchars); 00223 fp = fp->hdr.nxt; 00224 } 00225 }
Definition at line 85 of file file_c.cpp.
References alloc_mbuf, filecache_block::data, filecache_block::hdr, filecache_block::filecache_block_hdr::nchars, and filecache_block::filecache_block_hdr::nxt.
Referenced by fcache_read().
00086 { 00087 if (fp->hdr.nchars >= sizeof(fp->data)) 00088 { 00089 // We filled the current buffer. Go get a new one. 00090 // 00091 FBLOCK *tfp = fp; 00092 fp = (FBLOCK *) alloc_mbuf("fcache_fill"); 00093 fp->hdr.nxt = NULL; 00094 fp->hdr.nchars = 0; 00095 tfp->hdr.nxt = fp; 00096 } 00097 fp->data[fp->hdr.nchars++] = ch; 00098 return fp; 00099 }
void fcache_init | ( | void | ) |
Definition at line 274 of file file_c.cpp.
References fcache, fcache_load(), filecache_hdr::fileblock, NOTHING, and filecache_hdr::ppFilename.
Referenced by main().
00275 { 00276 FCACHE *fp = fcache; 00277 for (fp = fcache; fp->ppFilename; fp++) 00278 { 00279 fp->fileblock = NULL; 00280 } 00281 00282 fcache_load(NOTHING); 00283 }
void fcache_load | ( | dbref | player | ) |
Definition at line 237 of file file_c.cpp.
References alloc_lbuf, alloc_sbuf, filecache_hdr::desc, fcache, fcache_read(), filecache_hdr::fileblock, free_lbuf, free_sbuf, mux_ltoa(), NOTHING, notify, filecache_hdr::ppFilename, Quiet, and safe_str.
Referenced by do_readcache(), and fcache_init().
00238 { 00239 FCACHE *fp; 00240 char *buff, *bufc, *sbuf; 00241 00242 buff = bufc = alloc_lbuf("fcache_load.lbuf"); 00243 sbuf = alloc_sbuf("fcache_load.sbuf"); 00244 for (fp = fcache; fp->ppFilename; fp++) 00245 { 00246 int i = fcache_read(&fp->fileblock, *fp->ppFilename); 00247 if ( player != NOTHING 00248 && !Quiet(player)) 00249 { 00250 mux_ltoa(i, sbuf); 00251 if (fp == fcache) 00252 { 00253 safe_str("File sizes: ", buff, &bufc); 00254 } 00255 else 00256 { 00257 safe_str(" ", buff, &bufc); 00258 } 00259 safe_str(fp->desc, buff, &bufc); 00260 safe_str("...", buff, &bufc); 00261 safe_str(sbuf, buff, &bufc); 00262 } 00263 } 00264 *bufc = '\0'; 00265 if ( player != NOTHING 00266 && !Quiet(player)) 00267 { 00268 notify(player, buff); 00269 } 00270 free_lbuf(buff); 00271 free_sbuf(sbuf); 00272 }
void fcache_rawdump | ( | SOCKET | fd, | |
int | num | |||
) |
Definition at line 182 of file file_c.cpp.
References cnt, filecache_block::data, FC_LAST, fcache, filecache_hdr::fileblock, filecache_block::hdr, filecache_block::filecache_block_hdr::nchars, filecache_block::filecache_block_hdr::nxt, and SOCKET_WRITE.
Referenced by new_connection().
00183 { 00184 if ((num < 0) || (num > FC_LAST)) 00185 { 00186 return; 00187 } 00188 00189 FBLOCK *fp = fcache[num].fileblock; 00190 int cnt, remaining; 00191 char *start; 00192 00193 while (fp != NULL) 00194 { 00195 start = fp->data; 00196 remaining = fp->hdr.nchars; 00197 while (remaining > 0) 00198 { 00199 cnt = SOCKET_WRITE(fd, start, remaining, 0); 00200 if (cnt < 0) 00201 { 00202 return; 00203 } 00204 remaining -= cnt; 00205 start += cnt; 00206 } 00207 fp = fp->hdr.nxt; 00208 } 00209 return; 00210 }
static int fcache_read | ( | FBLOCK ** | cp, | |
char * | filename | |||
) | [static] |
Definition at line 101 of file file_c.cpp.
References alloc_lbuf, alloc_mbuf, DebugTotalFiles, ENDLOG, fcache_fill(), free_lbuf, free_mbuf, filecache_block::hdr, LBUF_SIZE, LOG_PROBLEMS, log_text(), filecache_block::filecache_block_hdr::nchars, filecache_block::filecache_block_hdr::nxt, O_BINARY, and STARTLOG.
Referenced by fcache_load().
00102 { 00103 int n, nmax, tchars, fd; 00104 char *buff; 00105 FBLOCK *fp, *tfp; 00106 00107 // Free a prior buffer chain. 00108 // 00109 fp = *cp; 00110 while (fp != NULL) 00111 { 00112 tfp = fp->hdr.nxt; 00113 free_mbuf(fp); 00114 fp = tfp; 00115 } 00116 *cp = NULL; 00117 00118 // Read the text file into a new chain. 00119 // 00120 if ((fd = open(filename, O_RDONLY|O_BINARY)) == -1) 00121 { 00122 // Failure: log the event 00123 // 00124 STARTLOG(LOG_PROBLEMS, "FIL", "OPEN"); 00125 buff = alloc_mbuf("fcache_read.LOG"); 00126 sprintf(buff, "Couldn't open file '%s'.", filename); 00127 log_text(buff); 00128 free_mbuf(buff); 00129 ENDLOG 00130 return -1; 00131 } 00132 DebugTotalFiles++; 00133 buff = alloc_lbuf("fcache_read.temp"); 00134 00135 // Set up the initial cache buffer to make things easier. 00136 // 00137 fp = (FBLOCK *) alloc_mbuf("fcache_read.first"); 00138 fp->hdr.nxt = NULL; 00139 fp->hdr.nchars = 0; 00140 *cp = fp; 00141 tchars = 0; 00142 00143 // Process the file, one lbuf at a time. 00144 // 00145 nmax = read(fd, buff, LBUF_SIZE); 00146 while (nmax > 0) 00147 { 00148 for (n = 0; n < nmax; n++) 00149 { 00150 switch (buff[n]) 00151 { 00152 case '\n': 00153 fp = fcache_fill(fp, '\r'); 00154 fp = fcache_fill(fp, '\n'); 00155 tchars += 2; 00156 case '\0': 00157 case '\r': 00158 break; 00159 default: 00160 fp = fcache_fill(fp, buff[n]); 00161 tchars++; 00162 } 00163 } 00164 nmax = read(fd, buff, LBUF_SIZE); 00165 } 00166 free_lbuf(buff); 00167 if (close(fd) == 0) 00168 { 00169 DebugTotalFiles--; 00170 } 00171 00172 // If we didn't read anything in, toss the initial buffer. 00173 // 00174 if (fp->hdr.nchars == 0) 00175 { 00176 *cp = NULL; 00177 free_mbuf(fp); 00178 } 00179 return tchars; 00180 }
void fcache_send | ( | dbref | player, | |
int | num | |||
) |
Definition at line 227 of file file_c.cpp.
References DESC_ITER_PLAYER, and fcache_dump().
Referenced by do_list_file(), and do_motd().
00228 { 00229 DESC *d; 00230 00231 DESC_ITER_PLAYER(player, d) 00232 { 00233 fcache_dump(d, num); 00234 } 00235 }
Initial value:
{ { &mudconf.conn_file, NULL, "Conn" }, { &mudconf.site_file, NULL, "Conn/Badsite" }, { &mudconf.down_file, NULL, "Conn/Down" }, { &mudconf.full_file, NULL, "Conn/Full" }, { &mudconf.guest_file, NULL, "Conn/Guest" }, { &mudconf.creg_file, NULL, "Conn/Reg" }, { &mudconf.crea_file, NULL, "Crea/Newuser" }, { &mudconf.regf_file, NULL, "Crea/RegFaill" }, { &mudconf.motd_file, NULL, "Motd" }, { &mudconf.wizmotd_file, NULL, "Wizmotd" }, { &mudconf.quit_file, NULL, "Quit" }, { NULL, NULL, NULL } }
Definition at line 38 of file file_c.cpp.
Referenced by fcache_dump(), fcache_init(), fcache_load(), and fcache_rawdump().
NAMETAB list_files[] [static] |
Initial value:
{ {"badsite_connect", 1, CA_WIZARD, FC_CONN_SITE}, {"connect", 2, CA_WIZARD, FC_CONN}, {"create_register", 2, CA_WIZARD, FC_CREA_REG}, {"down", 1, CA_WIZARD, FC_CONN_DOWN}, {"full", 1, CA_WIZARD, FC_CONN_FULL}, {"guest_motd", 1, CA_WIZARD, FC_CONN_GUEST}, {"motd", 1, CA_WIZARD, FC_MOTD}, {"newuser", 1, CA_WIZARD, FC_CREA_NEW}, {"quit", 1, CA_WIZARD, FC_QUIT}, {"register_connect", 1, CA_WIZARD, FC_CONN_REG}, {"wizard_motd", 1, CA_WIZARD, FC_WIZMOTD}, { NULL, 0, 0, 0} }
Definition at line 54 of file file_c.cpp.
Referenced by do_list_file().