void rktio_close_noerr(rktio_t *rktio, rktio_fd_t *rfd) { (void)do_close(rktio, rfd, 0); }
void *extra_self_tests(int arg1, void *arg2) { /* creating /test1/test2/ directories */ dbg(DBG_ERROR | DBG_VFS,"TEST: Creating directories\n"); do_mkdir("dir"); do_mkdir("dir/dir1"); do_mkdir("dir/dir2"); do_mkdir("dir/dir3"); do_mkdir("dir/dir4"); dbg(DBG_ERROR | DBG_VFS,"TEST: Directories are created\n"); int fd; char *file2buf="File 2 write only test case"; char *file1buf="Testing file_1 for write operation"; char readbuf[150]; dbg(DBG_ERROR | DBG_VFS,"TEST: Change directory to dir/dir1\n"); do_chdir("dir/dir1"); /* file1.txt creation with O_CREAT|O_WRONLY flag*/ dbg(DBG_ERROR | DBG_VFS,"TEST: Create file1.txt with O_CREAT|O_WRONLY flag in directory dir/dir1\n"); fd = do_open("file1.txt", O_CREAT|O_WRONLY); do_write(fd, file1buf, strlen(file1buf)); do_close(fd); /* file2.txt creation with O_CREAT|O_RDONLY flag*/ dbg(DBG_ERROR | DBG_VFS,"TEST: Change directory to dir/dir2\n"); do_chdir("/dir/dir2"); dbg(DBG_ERROR | DBG_VFS,"TEST: Create file2.txt with O_CREAT | O_RDONLY flag in directory dir/dir2\n"); fd = do_open("file2.txt", O_CREAT | O_RDONLY); do_close(fd); /* Write into file2.txt using O_WRONLY flag*/ dbg(DBG_ERROR | DBG_VFS,"TEST: Write into file2.txt with O_WRONLY flag in directory dir/dir2\n"); fd = do_open("file2.txt", O_WRONLY); do_write(fd, file2buf, strlen(file2buf)); do_close(fd); dbg(DBG_ERROR | DBG_VFS,"TEST: written chars: \"%s\" in file2.txt\n",file2buf); char *appendbuf=" Appending for O_WRONLY|O_APPEND mode"; /* Append into file2.txt using O_WRONLY|O_APPEND flag*/ dbg(DBG_ERROR | DBG_VFS,"TEST: Append into file2.txt with O_WRONLY|O_APPEND flag in directory dir/dir2\n"); fd = do_open("file2.txt", O_WRONLY|O_APPEND); do_write(fd, appendbuf, strlen(appendbuf)); do_close(fd); dbg(DBG_ERROR | DBG_VFS,"TEST: Appending chars: \"%s\" in file2.txt\n",appendbuf); fd = do_open("file2.txt", O_RDONLY); memset(readbuf,0,sizeof(char)*150); do_read(fd,readbuf,strlen(file2buf)+strlen(appendbuf)); dbg(DBG_ERROR | DBG_VFS,"TEST: After Appending text in file2.txt is: \"%s\" \n",readbuf); char *append2buf=" Appending for O_RDWR|O_APPEND mode in file2"; /* Append into file2.txt using O_RDWR|O_APPEND flag*/ dbg(DBG_ERROR | DBG_VFS,"TEST: Append into file2.txt with O_RDWR|O_APPEND flag in directory dir/dir2\n"); fd = do_open("file2.txt", O_RDWR|O_APPEND); do_write(fd, append2buf, strlen(append2buf)); do_close(fd); dbg(DBG_ERROR | DBG_VFS,"TEST: Appending chars: \"%s\" in file2.txt\n",append2buf); fd = do_open("file2.txt", O_RDONLY); memset(readbuf,0,sizeof(char)*150); do_read(fd,readbuf,strlen(file2buf)+strlen(append2buf)+strlen(appendbuf)); dbg(DBG_ERROR | DBG_VFS,"TEST: After Appending text in file2.txt is: \"%s\" \n",readbuf); dbg(DBG_ERROR | DBG_VFS,"TEST:Linking Source directory => /dir/dir2, Destination directory => /dir/linkofdir2 \n"); do_chdir("/"); do_link("dir/dir2","dir/linkofdir2"); dbg(DBG_ERROR | DBG_VFS,"TEST:Linking Source file => /dir/dir1/file1.txt, to the Destination => /dir/linkoffile1 \n"); do_link("dir/dir1/file1.txt","dir/linkoffile1"); dbg(DBG_ERROR | DBG_VFS,"TEST: Renaming directory from dir/dir3 to dir/renamed \n"); do_rename("dir/dir3","dir/renameddir3"); dbg(DBG_ERROR | DBG_VFS,"TEST: Renaming file from dir/dir1/file1.txt to dir/dir1/renamedfile1.txt \n"); do_rename("dir/dir1/file1.txt","dir/dir1/renamedfile1.txt"); dbg(DBG_ERROR | DBG_VFS,"TEST: Removing directory dir/dir4 \n"); do_rmdir("dir/dir4"); dbg(DBG_ERROR | DBG_VFS,"TEST: reading 18 chars from file: /dir/linkoffile2 which is hard link of /dir/dir2/file2.txt \n"); fd = do_open("dir/linkoffile2", O_RDONLY); memset(readbuf,0,sizeof(char)*150); do_close(fd); dbg(DBG_ERROR | DBG_VFS,"TEST: read 18 chars: \"%s\" from file: /dir/linkoffile1\n",readbuf); dbg(DBG_ERROR | DBG_VFS,"TEST: reading file using lseek function on /dir/linkoffile2 which is hard link of /dir/dir2/file2.txt \n"); memset(readbuf,0,sizeof(char)*150); fd = do_open("dir/linkoffile2", O_RDONLY); do_lseek(fd,-19,2); do_read(fd,readbuf,19); do_close(fd); dbg(DBG_ERROR | DBG_VFS,"TEST: read chars: \"%s\" using lseek from file: /dir/linkoffile1\n",readbuf); dbg(DBG_ERROR | DBG_VFS,"TEST: creating a duplicate file descriptor of file: /dir/dir2/file2.txt using do_dup()\n"); fd = do_open("/dir/dir2/file2.txt", O_RDONLY); int fd2= do_dup(fd); dbg(DBG_ERROR | DBG_VFS,"TEST: duplicate file descriptor is :\"%d\" of file: /dir/dir2/file2.txt \n",fd2); do_close(fd); do_close(fd2); dbg(DBG_ERROR | DBG_VFS,"TEST: creating a duplicate file descriptor of file: /dir/dir2/file2.txt using do_dup2()\n"); fd = do_open("/dir/dir2/file2.txt", O_RDONLY); fd2= do_dup2(fd,20); dbg(DBG_ERROR | DBG_VFS,"TEST: custom file descriptor is :\"%d\" of file: /dir/dir2/file2.txt \n",fd2); do_close(fd); do_close(fd2); /* Testing stat struct *statbuf; dbg(DBG_ERROR | DBG_VFS,"TEST: Testing the stat system call for directory dir\n"); do_stat("dir",statbuf); dbg(DBG_ERROR | DBG_VFS,"TEST: Output of stat for directory dir is :\"%s\" \n",statbuf);*/ shellTest(); return NULL; }
static void do_send_file(struct st_h2o_sendfile_generator_t *self, h2o_req_t *req, int status, const char *reason, h2o_iovec_t mime_type, h2o_mime_attributes_t *mime_attr, int is_get) { /* link the request */ self->req = req; /* setup response */ req->res.status = status; req->res.reason = reason; req->res.content_length = self->bytesleft; req->res.mime_attr = mime_attr; if (self->ranged.range_count > 1) { mime_type.base = h2o_mem_alloc_pool(&req->pool, 52); mime_type.len = sprintf(mime_type.base, "multipart/byteranges; boundary=%s", self->ranged.boundary.base); } h2o_add_header(&req->pool, &req->res.headers, H2O_TOKEN_CONTENT_TYPE, mime_type.base, mime_type.len); h2o_filecache_get_last_modified(self->file.ref, self->header_bufs.last_modified); h2o_add_header(&req->pool, &req->res.headers, H2O_TOKEN_LAST_MODIFIED, self->header_bufs.last_modified, H2O_TIMESTR_RFC1123_LEN); add_headers_unconditional(self, req); if (self->content_encoding.base != NULL) h2o_add_header(&req->pool, &req->res.headers, H2O_TOKEN_CONTENT_ENCODING, self->content_encoding.base, self->content_encoding.len); if (self->ranged.range_count == 0) h2o_add_header(&req->pool, &req->res.headers, H2O_TOKEN_ACCEPT_RANGES, H2O_STRLIT("bytes")); else if (self->ranged.range_count == 1) { h2o_iovec_t content_range; content_range.base = h2o_mem_alloc_pool(&req->pool, 128); content_range.len = sprintf(content_range.base, "bytes %zd-%zd/%zd", self->ranged.range_infos[0], self->ranged.range_infos[0] + self->ranged.range_infos[1] - 1, self->ranged.filesize); h2o_add_header(&req->pool, &req->res.headers, H2O_TOKEN_CONTENT_RANGE, content_range.base, content_range.len); } /* special path for cases where we do not need to send any data */ if (!is_get || self->bytesleft == 0) { static h2o_generator_t generator = {NULL, NULL}; h2o_start_response(req, &generator); h2o_send(req, NULL, 0, 1); do_close(&self->super, req); return; } /* send data */ h2o_start_response(req, &self->super); if (self->ranged.range_count == 1) self->file.off = self->ranged.range_infos[0]; if (req->_ostr_top->start_pull != NULL && self->ranged.range_count < 2) { req->_ostr_top->start_pull(req->_ostr_top, do_pull); } else { size_t bufsz = MAX_BUF_SIZE; if (self->bytesleft < bufsz) bufsz = self->bytesleft; self->buf = h2o_mem_alloc_pool(&req->pool, bufsz); if (self->ranged.range_count < 2) do_proceed(&self->super, req); else { self->bytesleft = 0; self->super.proceed = do_multirange_proceed; do_multirange_proceed(&self->super, req); } } }
/* low-level idle function: read/write buffers as needed, etc */ void imc_idle_select(fd_set *read, fd_set *write, fd_set *exc, time_t now) { const char *command; imc_packet *p; imc_connect *c, *c_next ; if (imc_active<IA_CONFIG1) return; if (imc_lock) { imc_logerror("imc_idle_select: recursive call"); return; } imc_lock=1; if (imc_sequencenumber < (unsigned long)imc_now) imc_sequencenumber=(unsigned long)imc_now; imc_run_events(now); if (imc_active<IA_UP) { imc_lock=0; return; } /* handle results of the select */ if (imc_active >= IA_LISTENING && FD_ISSET(control, read)) do_accept(); for (c=imc_connect_list; c; c=c_next) { c_next=c->next; if (c->state!=IMC_CLOSED && FD_ISSET(c->desc, exc)) do_close(c); if (c->state!=IMC_CLOSED && FD_ISSET(c->desc, read)) do_read(c); while (c->state!=IMC_CLOSED && // (c->spamtime1>=0 || c->spamcounter1<=IMC_SPAM1MAX) && // (c->spamtime2>=0 || c->spamcounter2<=IMC_SPAM2MAX) && (command = get_one_line(c->inbuf)) != NULL) { if (strlen(command) > imc_stats.max_pkt) imc_stats.max_pkt=strlen(command); // imc_debug(c, 0, command); /* log incoming packets */ switch (c->state) { case IMC_CLOSED: break; case IMC_WAIT1: clientpassword(c, command); break; case IMC_WAIT2: serverpassword(c, command); break; case IMC_CONNECTED: p = do_interpret_packet(c, command); if (p) { #ifdef IMC_PARANOIA /* paranoia: check the last entry in the path is the same as the * sending mud. Also check the first entry to see that it matches * the sender. */ imc_stats.rx_pkts++; if (strcasecmp(c->info->name, imc_lastinpath(p->i.path))) imc_logerror("PARANOIA: packet from %s allegedly from %s", c->info->name, imc_lastinpath(p->i.path)); else if (strcasecmp(imc_mudof(p->i.from), imc_firstinpath(p->i.path))) imc_logerror("PARANOIA: packet from %s has firstinpath %s", p->i.from, imc_firstinpath(p->i.path)); else forward(p); /* only forward if its a valid packet! */ #else imc_stats.rx_pkts++; forward(p); #endif #ifdef SPAMPROT if (!strcasecmp(p->type, "chat") || !strcasecmp(p->type, "tell") || !strcasecmp(p->type, "emote") || 1) { if (!c->spamcounter1 && !c->spamtime1) imc_add_event(IMC_SPAM1INTERVAL, ev_spam1, c, 0); c->spamcounter1++; if (!c->spamcounter2 && !c->spamtime2) imc_add_event(IMC_SPAM2INTERVAL, ev_spam2, c, 0); c->spamcounter2++; } #endif imc_freedata(&p->data); } break; } } } for (c=imc_connect_list; c; c=c_next) { c_next=c->next; if (c->state!=IMC_CLOSED && (FD_ISSET(c->desc, write) || c->newoutput)) { // c->newoutput=0; do_write(c); c->newoutput=c->outbuf[0]; } } for (c=imc_connect_list; c; c=c_next) { c_next=c->next; if (c->state==IMC_CLOSED) imc_extract_connect(c); } imc_lock=0; }
/* handle a password from a client */ static void clientpassword(imc_connect *c, const char *argument) { char arg1[3], name[IMC_MNAME_LENGTH], pw[IMC_PW_LENGTH], version[20]; imc_info *i; char response[IMC_PACKET_LENGTH]; argument=imc_getarg(argument, arg1, 4); /* packet type (has to be PW) */ argument=imc_getarg(argument, name, IMC_MNAME_LENGTH); /* remote mud name */ argument=imc_getarg(argument, pw, IMC_PW_LENGTH); /* password */ argument=imc_getarg(argument, version, 20); /* optional version=n string */ if (strcasecmp(arg1, "PW")) { imc_logstring("%s: non-PW password packet", imc_getconnectname(c)); do_close(c); return; } /* do we know them, and do they have the right password? */ i=imc_getinfo(name); if (!i || strcmp(i->clientpw, pw)) { if (!i || !(i->flags & IMC_QUIET)) imc_logstring("%s: password failure for %s", imc_getconnectname(c), name); do_close(c); return; } /* deny access if deny flag is set (good for eg. muds that start crashing * on rwho) */ if (i->flags & IMC_DENY) { if (!(i->flags & IMC_QUIET)) imc_logstring("%s: denying connection", name); do_close(c); return; } if (i->connection) /* kill old connections */ do_close(i->connection); /* register them */ i->connection = c; c->state = IMC_CONNECTED; c->info = i; c->spamcounter1 = 0; c->spamcounter2 = 0; /* check for a version string (assume version 0 if not present) */ if (sscanf(version, "version=%hu", &c->version)!=1) c->version=0; /* check for generator/interpreter */ if (!imc_vinfo[c->version].generate || !imc_vinfo[c->version].interpret) { if (!(i->flags & IMC_QUIET)) imc_logstring("%s: unsupported version %d", imc_getconnectname(c), c->version); do_close(c); return; } /* send our response */ sprintf(response, "PW %s %s version=%d", imc_name, i->serverpw, IMC_VERSION); do_send(c, response); if (!(i->flags & IMC_QUIET)) imc_logstring("%s: connected (version %d)", imc_getconnectname(c), c->version); c->info->timer_duration=IMC_MIN_RECONNECT_TIME; c->info->last_connected=imc_now; imc_cancel_event(ev_login_timeout, c); imc_cancel_event(ev_reconnect, c->info); }
/********************************************************************/ /** * Prepares and calls do_create command. ********************************************************************** */ int do_create_cmd(int args, char* argv[]) { ARG_CHECK(args, 2); char* filename = argv[1]; args -= 2; argv += 2; uint32_t max_files = FILE_DEFAULT; uint16_t x_thumb_res = THUMB_DEFAULT; uint16_t y_thumb_res = THUMB_DEFAULT; uint16_t x_small_res = SMALL_DEFAULT; uint16_t y_small_res = SMALL_DEFAULT; // Use of int instead of size_t for the comparison with args // For each command line argument, checks if there are enough arguments // remaining, converts the arguments to integers and assigns them to the // variable, and then checks if the variable is valid. for (int i = 0; i < args; ++i) { switch (parse_create_options(argv[i])) { case MAX_FILES: OPTION_ARG_CHECK(args, i, 1); max_files = atouint32(argv[i + 1]); if (max_files == 0 || max_files > MAX_MAX_FILES) { return ERR_MAX_FILES; } i += 1; break; case THUMB_RES: OPTION_ARG_CHECK(args, i, 2); x_thumb_res = atouint16(argv[i + 1]); y_thumb_res = atouint16(argv[i + 2]); RES_CHECK(x_thumb_res, y_thumb_res, THUMB_MAX); i += 2; break; case SMALL_RES: OPTION_ARG_CHECK(args, i, 2); x_small_res = atouint16(argv[i + 1]); y_small_res = atouint16(argv[i + 2]); RES_CHECK(x_small_res, y_small_res, SMALL_MAX); i += 2; break; case INVALID_OPTION: return ERR_INVALID_ARGUMENT; } } puts("Create"); struct pictdb_header db_header = { .max_files = max_files, .res_resized = { x_thumb_res, y_thumb_res, x_small_res, y_small_res } }; struct pictdb_file db_file = {.header = db_header }; int ret = do_create(filename, &db_file); if (ret == 0) { print_header(&db_file.header); } do_close(&db_file); return ret; }
int main(int argc, char **argv) { int opt; int len, rc; struct sigaction sigact; char *rest; int oflags = 0; int no_tag; memset(&sigact, 0, sizeof(sigact)); sigact.sa_handler = sighandler; if (sigaction(SIGALRM, &sigact, NULL) == -1) return 1; if (sigaction(SIGPIPE, &sigact, NULL) == -1) return 1; input = stdin; output = stdout; /* now parsing options with getopt */ while ((opt = getopt(argc, argv, options)) != EOF) { switch (opt) { case 'c': rc = chdir(optarg); if (rc == -1) { fprintf(stderr, "Can not change dir to %s errno = %d \"%s\"\n", optarg, errno, strerror(errno)); exit(1); } break; case 'q': quiet = true; break; case 'd': duperrors = true; break; case 's': if (oflags > 7) show_usage(1, "Can not combine -x and -s\n"); oflags |= 1; script = true; strncpy(server, optarg, MAXSTR); break; case 'x': if ((oflags & 7) != 0) show_usage(1, "Can not combine -x and -s/-p/-n\n"); oflags |= 8; script = true; input = fopen(optarg, "r"); if (input == NULL) fatal("Could not open %s\n", optarg); break; case 'n': if (oflags > 7) show_usage(1, "Can not combine -x and -n\n"); oflags |= 2; strncpy(name, optarg, MAXSTR); break; case 'p': if (oflags > 7) show_usage(1, "Can not combine -x and -p\n"); oflags |= 4; strncpy(portstr, optarg, MAXSTR); port = atoi(optarg); break; case '?': case 'h': default: /* display the help */ show_usage(0, "Help\n"); } } if (oflags > 0 && oflags < 7) show_usage(1, "Must specify -s, -p, and -n together\n"); if (oflags == 7) openserver(); while (1) { len = readln(input, line, MAXSTR * 2); if (len < 0) { if (script) fatal("End of file on input\n"); else break; } else { struct response resp; lno++; memset(&resp, 0, sizeof(resp)); rest = SkipWhite(line, REQUIRES_MORE, "Invalid line"); /* Skip totally blank line */ if (rest == NULL) continue; if (script && !quiet) fprintf(stdout, "%s\n", rest); /* If line doesn't start with a tag, that's ok */ no_tag = (!isdigit(*rest) && (*rest != '$')); /* Parse request into response structure */ rest = parse_request(rest, &resp, no_tag); if (rest == NULL) { resp.r_status = STATUS_ERRNO; resp.r_errno = errno; } else { /* Make sure default status is ok */ resp.r_status = STATUS_OK; if (*rest != '\0' && *rest != '#') fprintf_stderr( "Command line not consumed, rest=\"%s\"\n", rest); switch (resp.r_cmd) { case CMD_OPEN: do_open(&resp); break; case CMD_CLOSE: do_close(&resp); break; case CMD_LOCKW: do_lock(&resp); break; case CMD_LOCK: do_lock(&resp); break; case CMD_UNLOCK: do_unlock(&resp); break; case CMD_TEST: do_test(&resp); break; case CMD_LIST: do_list(&resp); break; case CMD_HOP: do_hop(&resp); break; case CMD_UNHOP: do_unhop(&resp); break; case CMD_SEEK: do_seek(&resp); break; case CMD_READ: do_read(&resp); break; case CMD_WRITE: do_write(&resp); break; case CMD_ALARM: do_alarm(&resp); break; case CMD_HELLO: case CMD_COMMENT: case CMD_QUIT: resp.r_status = STATUS_OK; break; case NUM_COMMANDS: fprintf_stderr("Invalid command %s\n", line); continue; } } respond(&resp); if (resp.r_cmd == CMD_QUIT) exit(0); } } return 0; }
int rtime (struct sockaddr_in *addrp, struct rpc_timeval *timep, struct rpc_timeval *timeout) { int s; struct pollfd fd; int milliseconds; int res; /* RFC 868 says the time is transmitted as a 32-bit value. */ uint32_t thetime; struct sockaddr_in from; int fromlen; int type; if (timeout == NULL) type = SOCK_STREAM; else type = SOCK_DGRAM; s = __socket (AF_INET, type, 0); if (s < 0) return (-1); addrp->sin_family = AF_INET; addrp->sin_port = htons (IPPORT_TIMESERVER); if (type == SOCK_DGRAM) { res = __sendto (s, (char *) &thetime, sizeof (thetime), 0, (struct sockaddr *) addrp, sizeof (*addrp)); if (res < 0) { do_close (s); return -1; } milliseconds = (timeout->tv_sec * 1000) + (timeout->tv_usec / 1000); fd.fd = s; fd.events = POLLIN; do res = __poll (&fd, 1, milliseconds); while (res < 0 && errno == EINTR); if (res <= 0) { if (res == 0) __set_errno (ETIMEDOUT); do_close (s); return (-1); } fromlen = sizeof (from); res = __recvfrom (s, (char *) &thetime, sizeof (thetime), 0, (struct sockaddr *) &from, &fromlen); do_close (s); if (res < 0) return -1; } else { if (__connect (s, (struct sockaddr *) addrp, sizeof (*addrp)) < 0) { do_close (s); return -1; } res = __read (s, (char *) &thetime, sizeof (thetime)); do_close (s); if (res < 0) return (-1); } if (res != sizeof (thetime)) { __set_errno (EIO); return -1; } thetime = ntohl (thetime); timep->tv_sec = thetime - TOFFSET; timep->tv_usec = 0; return 0; }
static void close_socket(MVMThreadContext *tc, MVMOSHandle *h) { MVMIOSyncSocketData *data = (MVMIOSyncSocketData *)h->body.data; do_close(tc, data); }
int connect_vcc(struct sockaddr *remote,const struct atm_qos *qos,int sndbuf, int timeout) { int fd,error,flags; if (remote->sa_family == AF_ATMSVC && incoming < 0) return -EUNATCH; if ((fd = socket(remote->sa_family,SOCK_DGRAM,0)) < 0) { error = -errno; diag(COMPONENT,DIAG_ERROR,"socket: %s",strerror(errno)); return error; } if (setsockopt(fd,SOL_ATM,SO_ATMQOS,qos,sizeof(*qos)) < 0) { error = -errno; diag(COMPONENT,DIAG_ERROR,"setsockopt SO_ATMQOS: %s",strerror(errno)); return error; } if (sndbuf) if (setsockopt(fd,SOL_SOCKET,SO_SNDBUF,&sndbuf,sizeof(sndbuf)) < 0) { error = -errno; diag(COMPONENT,DIAG_ERROR,"setsockopt SO_SNDBUF: %s", strerror(errno)); return error; } if ((flags = fcntl(fd,F_GETFL)) < 0) { error = -errno; diag(COMPONENT,DIAG_ERROR,"fcntl F_GETFL: %s",strerror(errno)); return error; } flags |= O_NONBLOCK; if (fcntl(fd,F_SETFL,flags) < 0) { error = -errno; diag(COMPONENT,DIAG_ERROR,"fcntl F_GETFL: %s",strerror(errno)); return error; } if (remote->sa_family == AF_ATMSVC) { /* @@@ that's cheating */ struct atm_sap sap; memset(&sap,0,sizeof(sap)); sap.blli[0].l2_proto = ATM_L2_ISO8802; sap.blli[0].l3_proto = ATM_L3_NONE; if (setsockopt(fd,SOL_ATM,SO_ATMSAP,&sap,sizeof(sap)) < 0) { error = -errno; diag(COMPONENT,DIAG_ERROR,"setsockopt SO_ATMSAP: %s", strerror(errno)); return error; } } /* PVC connect never blocks */ if (connect(fd,remote,remote->sa_family == AF_ATMPVC ? sizeof(struct sockaddr_atmpvc) : sizeof(struct sockaddr_atmsvc)) < 0) { if (errno != EINPROGRESS) { error = -errno; diag(COMPONENT,DIAG_ERROR,"[1]connect: %s",strerror(errno)); return error; } return fd; } if (ioctl(fd,ATMARP_MKIP,timeout) < 0) { error = -errno; diag(COMPONENT,DIAG_ERROR,"ioctl ATMARP_MKIP: %s",strerror(errno)); (void) do_close(fd); return error; } return fd; }
// 0x7944 - request account id lookup by name (response: 0x7945) // 0x7946 - request account name lookup by id (response: 0x7947) // 0x7952 - request account information lookup by name (response: 0x7953) // 0x7954 - request account information lookup by id (response: 0x7953) //--------------------------------------- int parse_admin(int fd) { unsigned int i, j; char* account_name; struct mmo_account acc; uint32 ipl = session[fd]->client_addr; char ip[16]; ip2str(ipl, ip); if( session[fd]->flag.eof ) { do_close(fd); ShowInfo("Remote administration has disconnected (session #%d).\n", fd); return 0; } while( RFIFOREST(fd) >= 2 ) { uint16 command = RFIFOW(fd,0); switch( command ) { case 0x7530: // Request of the server version ShowStatus("'ladmin': Sending of the server version (ip: %s)\n", ip); WFIFOHEAD(fd,10); WFIFOW(fd,0) = 0x7531; WFIFOB(fd,2) = ATHENA_MAJOR_VERSION; WFIFOB(fd,3) = ATHENA_MINOR_VERSION; WFIFOB(fd,4) = ATHENA_REVISION; WFIFOB(fd,5) = ATHENA_RELEASE_FLAG; WFIFOB(fd,6) = ATHENA_OFFICIAL_FLAG; WFIFOB(fd,7) = ATHENA_SERVER_LOGIN; WFIFOW(fd,8) = ATHENA_MOD_VERSION; WFIFOSET(fd,10); RFIFOSKIP(fd,2); break; /* case 0x7920: // Request of an accounts list if (RFIFOREST(fd) < 10) return 0; { int st, ed; uint16 len; CREATE_BUFFER(id, int, auth_num); st = RFIFOL(fd,2); ed = RFIFOL(fd,6); RFIFOSKIP(fd,10); WFIFOW(fd,0) = 0x7921; if (st < 0) st = 0; if (ed > END_ACCOUNT_NUM || ed < st || ed <= 0) ed = END_ACCOUNT_NUM; ShowStatus("'ladmin': Sending an accounts list (ask: from %d to %d, ip: %s)\n", st, ed, ip); // Sort before send for(i = 0; i < auth_num; i++) { unsigned int k; id[i] = i; for(j = 0; j < i; j++) { if (auth_dat[id[i]].account_id < auth_dat[id[j]].account_id) { for(k = i; k > j; k--) { id[k] = id[k-1]; } id[j] = i; // id[i] break; } } } // Sending accounts information len = 4; for(i = 0; i < auth_num && len < 30000; i++) { int account_id = auth_dat[id[i]].account_id; // use sorted index if (account_id >= st && account_id <= ed) { j = id[i]; WFIFOL(fd,len) = account_id; WFIFOB(fd,len+4) = (unsigned char)isGM(account_id); memcpy(WFIFOP(fd,len+5), auth_dat[j].userid, 24); WFIFOB(fd,len+29) = auth_dat[j].sex; WFIFOL(fd,len+30) = auth_dat[j].logincount; if (auth_dat[j].state == 0 && auth_dat[j].unban_time != 0) // if no state and banished WFIFOL(fd,len+34) = 7; // 6 = Your are Prohibited to log in until %s else WFIFOL(fd,len+34) = auth_dat[j].state; len += 38; } } WFIFOW(fd,2) = len; WFIFOSET(fd,len); //if (id) free(id); DELETE_BUFFER(id); } break; */ case 0x7930: // Request for an account creation if (RFIFOREST(fd) < 91) return 0; { struct mmo_account ma; safestrncpy(ma.userid, (char*)RFIFOP(fd, 2), sizeof(ma.userid)); safestrncpy(ma.pass, (char*)RFIFOP(fd,26), sizeof(ma.pass)); ma.sex = RFIFOB(fd,50); safestrncpy(ma.email, (char*)RFIFOP(fd,51), sizeof(ma.email)); safestrncpy(ma.lastlogin, "-", sizeof(ma.lastlogin)); ShowNotice("'ladmin': Account creation request (account: %s pass: %s, sex: %c, email: %s, ip: %s)\n", ma.userid, ma.pass, ma.sex, ma.email, ip); WFIFOW(fd,0) = 0x7931; WFIFOL(fd,2) = mmo_auth_new(ma.userid, ma.pass, ma.sex, ip); safestrncpy((char*)WFIFOP(fd,6), ma.userid, 24); WFIFOSET(fd,30); } RFIFOSKIP(fd,91); break; /* case 0x7932: // Request for an account deletion if (RFIFOREST(fd) < 26) return 0; { struct mmo_account acc; char* account_name = (char*)RFIFOP(fd,2); account_name[23] = '\0'; WFIFOW(fd,0) = 0x7933; if( accounts->load_str(accounts, &acc, account_name) ) { // Char-server is notified of deletion (for characters deletion). unsigned char buf[65535]; WBUFW(buf,0) = 0x2730; WBUFL(buf,2) = acc.account_id; charif_sendallwos(-1, buf, 6); // send answer memcpy(WFIFOP(fd,6), acc.userid, 24); WFIFOL(fd,2) = acc.account_id; // delete account memset(acc.userid, '\0', sizeof(acc.userid)); auth_dat[i].account_id = -1; mmo_auth_sync(); } else { WFIFOL(fd,2) = -1; memcpy(WFIFOP(fd,6), account_name, 24); ShowNotice("'ladmin': Attempt to delete an unknown account (account: %s, ip: %s)\n", account_name, ip); } WFIFOSET(fd,30); } RFIFOSKIP(fd,26); break; */ case 0x7934: // Request to change a password if (RFIFOREST(fd) < 50) return 0; { struct mmo_account acc; char* account_name = (char*)RFIFOP(fd,2); account_name[23] = '\0'; WFIFOW(fd,0) = 0x7935; if( accounts->load_str(accounts, &acc, account_name) ) { WFIFOL(fd,2) = acc.account_id; safestrncpy((char*)WFIFOP(fd,6), acc.userid, 24); safestrncpy(acc.pass, (char*)RFIFOP(fd,26), 24); ShowNotice("'ladmin': Modification of a password (account: %s, new password: %s, ip: %s)\n", acc.userid, acc.pass, ip); accounts->save(accounts, &acc); } else { WFIFOL(fd,2) = -1; safestrncpy((char*)WFIFOP(fd,6), account_name, 24); ShowNotice("'ladmin': Attempt to modify the password of an unknown account (account: %s, ip: %s)\n", account_name, ip); } WFIFOSET(fd,30); } RFIFOSKIP(fd,50); break; case 0x7936: // Request to modify a state if (RFIFOREST(fd) < 50) return 0; { struct mmo_account acc; char* account_name = (char*)RFIFOP(fd,2); uint32 state = RFIFOL(fd,26); account_name[23] = '\0'; WFIFOW(fd,0) = 0x7937; if( accounts->load_str(accounts, &acc, account_name) ) { memcpy(WFIFOP(fd,6), acc.userid, 24); WFIFOL(fd,2) = acc.account_id; if (acc.state == state) ShowNotice("'ladmin': Modification of a state, but the state of the account already has this value (account: %s, received state: %d, ip: %s)\n", account_name, state, ip); else { ShowNotice("'ladmin': Modification of a state (account: %s, new state: %d, ip: %s)\n", acc.userid, state, ip); if (acc.state == 0) { unsigned char buf[16]; WBUFW(buf,0) = 0x2731; WBUFL(buf,2) = acc.account_id; WBUFB(buf,6) = 0; // 0: change of statut, 1: ban WBUFL(buf,7) = state; // status or final date of a banishment charif_sendallwos(-1, buf, 11); } acc.state = state; accounts->save(accounts, &acc); } } else { ShowNotice("'ladmin': Attempt to modify the state of an unknown account (account: %s, received state: %d, ip: %s)\n", account_name, state, ip); WFIFOL(fd,2) = -1; memcpy(WFIFOP(fd,6), account_name, 24); } WFIFOL(fd,30) = state; WFIFOSET(fd,34); } RFIFOSKIP(fd,50); break; /* case 0x7938: // Request for servers list and # of online players { uint8 server_num = 0; ShowStatus("'ladmin': Sending of servers list (ip: %s)\n", ip); for(i = 0; i < MAX_SERVERS; i++) { if (server[i].fd >= 0) { WFIFOL(fd,4+server_num*32) = htonl(server[i].ip); WFIFOW(fd,4+server_num*32+4) = htons(server[i].port); memcpy(WFIFOP(fd,4+server_num*32+6), server[i].name, 20); WFIFOW(fd,4+server_num*32+26) = server[i].users; WFIFOW(fd,4+server_num*32+28) = server[i].maintenance; WFIFOW(fd,4+server_num*32+30) = server[i].new_; server_num++; } } WFIFOW(fd,0) = 0x7939; WFIFOW(fd,2) = 4 + 32 * server_num; WFIFOSET(fd,4+32*server_num); RFIFOSKIP(fd,2); break; } case 0x793a: // Request to password check if (RFIFOREST(fd) < 50) return 0; WFIFOW(fd,0) = 0x793b; WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? account_name = (char*)RFIFOP(fd,2); account_name[23] = '\0'; remove_control_chars(account_name); if( accounts->load_str(accounts, &acc, account_name) ) { char pass[25]; memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); memcpy(pass, RFIFOP(fd,26), 24); pass[24] = '\0'; remove_control_chars(pass); if (strcmp(acc.pass, pass) == 0) { WFIFOL(fd,2) = acc.account_id; ShowNotice("'ladmin': Check of password OK (account: %s, password: %s, ip: %s)\n", acc.userid, acc.pass, ip); } else { ShowNotice("'ladmin': Failure of password check (account: %s, proposed pass: %s, ip: %s)\n", acc.userid, pass, ip); } } else { memcpy(WFIFOP(fd,6), account_name, 24); ShowNotice("'ladmin': Attempt to check the password of an unknown account (account: %s, ip: %s)\n", account_name, ip); } WFIFOSET(fd,30); RFIFOSKIP(fd,50); break; case 0x793c: // Request to modify sex if (RFIFOREST(fd) < 27) return 0; WFIFOW(fd,0) = 0x793d; WFIFOL(fd,2) = 0xFFFFFFFF; // -1 account_name = (char*)RFIFOP(fd,2); account_name[23] = '\0'; remove_control_chars(account_name); memcpy(WFIFOP(fd,6), account_name, 24); { char sex; sex = RFIFOB(fd,26); if (sex != 'F' && sex != 'M') { if (sex > 31) ShowNotice("'ladmin': Attempt to give an invalid sex (account: %s, received sex: %c, ip: %s)\n", account_name, sex, ip); else ShowNotice("'ladmin': Attempt to give an invalid sex (account: %s, received sex: 'control char', ip: %s)\n", account_name, ip); } else { if( accounts->load_str(accounts, &acc, account_name) ) { memcpy(WFIFOP(fd,6), acc.userid, 24); if (acc.sex != sex) { unsigned char buf[16]; ShowNotice("'ladmin': Modification of a sex (account: %s, new sex: %c, ip: %s)\n", acc.userid, sex, ip); WFIFOL(fd,2) = acc.account_id; acc.sex = sex; accounts->save(accounts, &acc); // send to all char-server the change WBUFW(buf,0) = 0x2723; WBUFL(buf,2) = acc.account_id; WBUFB(buf,6) = acc.sex; charif_sendallwos(-1, buf, 7); } else { ShowNotice("'ladmin': Modification of a sex, but the sex is already the good sex (account: %s, sex: %c, ip: %s)\n", acc.userid, sex, ip); } } else { ShowNotice("'ladmin': Attempt to modify the sex of an unknown account (account: %s, received sex: %c, ip: %s)\n", account_name, sex, ip); } } } WFIFOSET(fd,30); RFIFOSKIP(fd,27); break; case 0x793e: // Request to modify GM level if (RFIFOREST(fd) < 27) return 0; WFIFOW(fd,0) = 0x793f; WFIFOL(fd,2) = 0xFFFFFFFF; // -1 account_name = (char*)RFIFOP(fd,2); account_name[23] = '\0'; remove_control_chars(account_name); memcpy(WFIFOP(fd,6), account_name, 24); { char new_gm_level; new_gm_level = RFIFOB(fd,26); if( new_gm_level < 0 || new_gm_level > 99 ) ShowNotice("'ladmin': Attempt to give an invalid GM level (account: %s, received GM level: %d, ip: %s)\n", account_name, (int)new_gm_level, ip); else if( !accounts->load_str(accounts, &acc, account_name) ) ShowNotice("'ladmin': Attempt to modify the GM level of an unknown account (account: %s, received GM level: %d, ip: %s)\n", account_name, (int)new_gm_level, ip); else { memcpy(WFIFOP(fd,6), acc.userid, 24); if (isGM(acc.account_id) == new_gm_level) ShowNotice("'ladmin': Attempt to modify of a GM level, but the GM level is already the good GM level (account: %s (%d), GM level: %d, ip: %s)\n", acc.userid, acc.account_id, (int)new_gm_level, ip); else { //TODO: change level } } } WFIFOSET(fd,30); RFIFOSKIP(fd,27); break; case 0x7940: // Request to modify e-mail if (RFIFOREST(fd) < 66) return 0; WFIFOW(fd,0) = 0x7941; WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? account_name = (char*)RFIFOP(fd,2); account_name[23] = '\0'; remove_control_chars(account_name); memcpy(WFIFOP(fd,6), account_name, 24); { char email[40]; memcpy(email, RFIFOP(fd,26), 40); if (e_mail_check(email) == 0) { ShowNotice("'ladmin': Attempt to give an invalid e-mail (account: %s, ip: %s)\n", account_name, ip); } else { remove_control_chars(email); i = search_account_index(account_name); if (i != -1) { memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); memcpy(auth_dat[i].email, email, 40); WFIFOL(fd,2) = auth_dat[i].account_id; ShowNotice("'ladmin': Modification of an email (account: %s, new e-mail: %s, ip: %s)\n", auth_dat[i].userid, email, ip); mmo_auth_sync(); } else { ShowNotice("'ladmin': Attempt to modify the e-mail of an unknown account (account: %s, received e-mail: %s, ip: %s)\n", account_name, email, ip); } } } WFIFOSET(fd,30); RFIFOSKIP(fd,66); break; case 0x7942: // Request to modify memo field if ((int)RFIFOREST(fd) < 28 || (int)RFIFOREST(fd) < (28 + RFIFOW(fd,26))) return 0; WFIFOW(fd,0) = 0x7943; WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? account_name = (char*)RFIFOP(fd,2); account_name[23] = '\0'; remove_control_chars(account_name); i = search_account_index(account_name); if (i != -1) { int size_of_memo = sizeof(auth_dat[i].memo); memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); memset(auth_dat[i].memo, '\0', size_of_memo); if (RFIFOW(fd,26) == 0) { strncpy(auth_dat[i].memo, "-", size_of_memo); } else if (RFIFOW(fd,26) > size_of_memo - 1) { memcpy(auth_dat[i].memo, RFIFOP(fd,28), size_of_memo - 1); } else { memcpy(auth_dat[i].memo, RFIFOP(fd,28), RFIFOW(fd,26)); } auth_dat[i].memo[size_of_memo - 1] = '\0'; remove_control_chars(auth_dat[i].memo); WFIFOL(fd,2) = auth_dat[i].account_id; ShowNotice("'ladmin': Modification of a memo field (account: %s, new memo: %s, ip: %s)\n", auth_dat[i].userid, auth_dat[i].memo, ip); mmo_auth_sync(); } else { memcpy(WFIFOP(fd,6), account_name, 24); ShowNotice("'ladmin': Attempt to modify the memo field of an unknown account (account: %s, ip: %s)\n", account_name, ip); } WFIFOSET(fd,30); RFIFOSKIP(fd,28 + RFIFOW(fd,26)); break; case 0x7944: // Request to found an account id if (RFIFOREST(fd) < 26) return 0; WFIFOW(fd,0) = 0x7945; WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? account_name = (char*)RFIFOP(fd,2); account_name[23] = '\0'; remove_control_chars(account_name); i = search_account_index(account_name); if (i != -1) { memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); WFIFOL(fd,2) = auth_dat[i].account_id; ShowNotice("'ladmin': Request (by the name) of an account id (account: %s, id: %d, ip: %s)\n", auth_dat[i].userid, auth_dat[i].account_id, ip); } else { memcpy(WFIFOP(fd,6), account_name, 24); ShowNotice("'ladmin': ID request (by the name) of an unknown account (account: %s, ip: %s)\n", account_name, ip); } WFIFOSET(fd,30); RFIFOSKIP(fd,26); break; case 0x7946: // Request to found an account name if (RFIFOREST(fd) < 6) return 0; WFIFOW(fd,0) = 0x7947; WFIFOL(fd,2) = RFIFOL(fd,2); memset(WFIFOP(fd,6), '\0', 24); for(i = 0; i < auth_num; i++) { if (auth_dat[i].account_id == (int)RFIFOL(fd,2)) { strncpy((char*)WFIFOP(fd,6), auth_dat[i].userid, 24); ShowNotice("'ladmin': Request (by id) of an account name (account: %s, id: %d, ip: %s)\n", auth_dat[i].userid, RFIFOL(fd,2), ip); break; } } if (i == auth_num) { ShowNotice("'ladmin': Name request (by id) of an unknown account (id: %d, ip: %s)\n", RFIFOL(fd,2), ip); strncpy((char*)WFIFOP(fd,6), "", 24); } WFIFOSET(fd,30); RFIFOSKIP(fd,6); break; case 0x7948: // Request to change the validity limit (timestamp) (absolute value) if (RFIFOREST(fd) < 30) return 0; { time_t timestamp; char tmpstr[2048]; WFIFOW(fd,0) = 0x7949; WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? account_name = (char*)RFIFOP(fd,2); account_name[23] = '\0'; remove_control_chars(account_name); timestamp = (time_t)RFIFOL(fd,26); strftime(tmpstr, 24, login_config.date_format, localtime(×tamp)); i = search_account_index(account_name); if (i != -1) { memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); ShowNotice("'ladmin': Change of a validity limit (account: %s, new validity: %d (%s), ip: %s)\n", auth_dat[i].userid, timestamp, (timestamp == 0 ? "unlimited" : tmpstr), ip); auth_dat[i].expiration_time = timestamp; WFIFOL(fd,2) = auth_dat[i].account_id; mmo_auth_sync(); } else { memcpy(WFIFOP(fd,6), account_name, 24); ShowNotice("'ladmin': Attempt to change the validity limit of an unknown account (account: %s, received validity: %d (%s), ip: %s)\n", account_name, timestamp, (timestamp == 0 ? "unlimited" : tmpstr), ip); } WFIFOL(fd,30) = (unsigned int)timestamp; } WFIFOSET(fd,34); RFIFOSKIP(fd,30); break; case 0x794a: // Request to change the final date of a banishment (timestamp) (absolute value) if (RFIFOREST(fd) < 30) return 0; { time_t timestamp; char tmpstr[2048]; WFIFOW(fd,0) = 0x794b; WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? account_name = (char*)RFIFOP(fd,2); account_name[23] = '\0'; remove_control_chars(account_name); timestamp = (time_t)RFIFOL(fd,26); if (timestamp <= time(NULL)) timestamp = 0; strftime(tmpstr, 24, login_config.date_format, localtime(×tamp)); i = search_account_index(account_name); if (i != -1) { memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); WFIFOL(fd,2) = auth_dat[i].account_id; ShowNotice("'ladmin': Change of the final date of a banishment (account: %s, new final date of banishment: %d (%s), ip: %s)\n", auth_dat[i].userid, timestamp, (timestamp == 0 ? "no banishment" : tmpstr), ip); if (auth_dat[i].unban_time != timestamp) { if (timestamp != 0) { unsigned char buf[16]; WBUFW(buf,0) = 0x2731; WBUFL(buf,2) = auth_dat[i].account_id; WBUFB(buf,6) = 1; // 0: change of statut, 1: ban WBUFL(buf,7) = (unsigned int)timestamp; // status or final date of a banishment charif_sendallwos(-1, buf, 11); } auth_dat[i].unban_time = timestamp; mmo_auth_sync(); } } else { memcpy(WFIFOP(fd,6), account_name, 24); ShowNotice("'ladmin': Attempt to change the final date of a banishment of an unknown account (account: %s, received final date of banishment: %d (%s), ip: %s)\n", account_name, timestamp, (timestamp == 0 ? "no banishment" : tmpstr), ip); } WFIFOL(fd,30) = (unsigned int)timestamp; } WFIFOSET(fd,34); RFIFOSKIP(fd,30); break; case 0x794c: // Request to change the final date of a banishment (timestamp) (relative change) if (RFIFOREST(fd) < 38) return 0; { time_t timestamp; struct tm *tmtime; char tmpstr[2048]; WFIFOW(fd,0) = 0x794d; WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? account_name = (char*)RFIFOP(fd,2); account_name[23] = '\0'; remove_control_chars(account_name); i = search_account_index(account_name); if (i != -1) { WFIFOL(fd,2) = auth_dat[i].account_id; memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); if (auth_dat[i].unban_time == 0 || auth_dat[i].unban_time < time(NULL)) timestamp = time(NULL); else timestamp = auth_dat[i].unban_time; tmtime = localtime(×tamp); tmtime->tm_year = tmtime->tm_year + (short)RFIFOW(fd,26); tmtime->tm_mon = tmtime->tm_mon + (short)RFIFOW(fd,28); tmtime->tm_mday = tmtime->tm_mday + (short)RFIFOW(fd,30); tmtime->tm_hour = tmtime->tm_hour + (short)RFIFOW(fd,32); tmtime->tm_min = tmtime->tm_min + (short)RFIFOW(fd,34); tmtime->tm_sec = tmtime->tm_sec + (short)RFIFOW(fd,36); timestamp = mktime(tmtime); if (timestamp != -1) { if (timestamp <= time(NULL)) timestamp = 0; strftime(tmpstr, 24, login_config.date_format, localtime(×tamp)); ShowNotice("'ladmin': Adjustment of a final date of a banishment (account: %s, (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %d (%s), ip: %s)\n", auth_dat[i].userid, (short)RFIFOW(fd,26), (short)RFIFOW(fd,28), (short)RFIFOW(fd,30), (short)RFIFOW(fd,32), (short)RFIFOW(fd,34), (short)RFIFOW(fd,36), timestamp, (timestamp == 0 ? "no banishment" : tmpstr), ip); if (auth_dat[i].unban_time != timestamp) { if (timestamp != 0) { unsigned char buf[16]; WBUFW(buf,0) = 0x2731; WBUFL(buf,2) = auth_dat[i].account_id; WBUFB(buf,6) = 1; // 0: change of statut, 1: ban WBUFL(buf,7) = (unsigned int)timestamp; // status or final date of a banishment charif_sendallwos(-1, buf, 11); } auth_dat[i].unban_time = timestamp; mmo_auth_sync(); } } else { strftime(tmpstr, 24, login_config.date_format, localtime(&auth_dat[i].unban_time)); ShowNotice("'ladmin': Impossible to adjust the final date of a banishment (account: %s, %d (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n", auth_dat[i].userid, auth_dat[i].unban_time, (auth_dat[i].unban_time == 0 ? "no banishment" : tmpstr), (short)RFIFOW(fd,26), (short)RFIFOW(fd,28), (short)RFIFOW(fd,30), (short)RFIFOW(fd,32), (short)RFIFOW(fd,34), (short)RFIFOW(fd,36), ip); } WFIFOL(fd,30) = (unsigned long)auth_dat[i].unban_time; } else { memcpy(WFIFOP(fd,6), account_name, 24); ShowNotice("'ladmin': Attempt to adjust the final date of a banishment of an unknown account (account: %s, ip: %s)\n", account_name, ip); WFIFOL(fd,30) = 0; } } WFIFOSET(fd,34); RFIFOSKIP(fd,38); break; case 0x794e: // Request to send a broadcast message if (RFIFOREST(fd) < 8 || RFIFOREST(fd) < (8 + RFIFOL(fd,4))) return 0; WFIFOW(fd,0) = 0x794f; WFIFOW(fd,2) = 0xFFFF; // WTF??? if (RFIFOL(fd,4) < 1) { ShowNotice("'ladmin': Receiving a message for broadcast, but message is void (ip: %s)\n", ip); } else { // at least 1 char-server for(i = 0; i < MAX_SERVERS; i++) if (server[i].fd >= 0) break; if (i == MAX_SERVERS) { ShowNotice("'ladmin': Receiving a message for broadcast, but no char-server is online (ip: %s)\n", ip); } else { unsigned char buf[32000]; char message[32000]; WFIFOW(fd,2) = 0; memset(message, '\0', sizeof(message)); memcpy(message, RFIFOP(fd,8), RFIFOL(fd,4)); message[sizeof(message)-1] = '\0'; remove_control_chars(message); if (RFIFOW(fd,2) == 0) ShowNotice("'ladmin': Receiving a message for broadcast (message (in yellow): %s, ip: %s)\n", message, ip); else ShowNotice("'ladmin': Receiving a message for broadcast (message (in blue): %s, ip: %s)\n", message, ip); // send same message to all char-servers (no answer) memcpy(WBUFP(buf,0), RFIFOP(fd,0), 8 + RFIFOL(fd,4)); WBUFW(buf,0) = 0x2726; charif_sendallwos(-1, buf, 8 + RFIFOL(fd,4)); } } WFIFOSET(fd,4); RFIFOSKIP(fd,8 + RFIFOL(fd,4)); break; case 0x7950: // Request to change the validity limite (timestamp) (relative change) if (RFIFOREST(fd) < 38) return 0; { time_t timestamp; struct tm *tmtime; char tmpstr[2048]; char tmpstr2[2048]; WFIFOW(fd,0) = 0x7951; WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? account_name = (char*)RFIFOP(fd,2); account_name[23] = '\0'; remove_control_chars(account_name); i = search_account_index(account_name); if (i != -1) { WFIFOL(fd,2) = auth_dat[i].account_id; memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); timestamp = auth_dat[i].expiration_time; if (timestamp == 0 || timestamp < time(NULL)) timestamp = time(NULL); tmtime = localtime(×tamp); tmtime->tm_year = tmtime->tm_year + (short)RFIFOW(fd,26); tmtime->tm_mon = tmtime->tm_mon + (short)RFIFOW(fd,28); tmtime->tm_mday = tmtime->tm_mday + (short)RFIFOW(fd,30); tmtime->tm_hour = tmtime->tm_hour + (short)RFIFOW(fd,32); tmtime->tm_min = tmtime->tm_min + (short)RFIFOW(fd,34); tmtime->tm_sec = tmtime->tm_sec + (short)RFIFOW(fd,36); timestamp = mktime(tmtime); if (timestamp != -1) { strftime(tmpstr, 24, login_config.date_format, localtime(&auth_dat[i].expiration_time)); strftime(tmpstr2, 24, login_config.date_format, localtime(×tamp)); ShowNotice("'ladmin': Adjustment of a validity limit (account: %s, %d (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %d (%s), ip: %s)\n", auth_dat[i].userid, auth_dat[i].expiration_time, (auth_dat[i].expiration_time == 0 ? "unlimited" : tmpstr), (short)RFIFOW(fd,26), (short)RFIFOW(fd,28), (short)RFIFOW(fd,30), (short)RFIFOW(fd,32), (short)RFIFOW(fd,34), (short)RFIFOW(fd,36), timestamp, (timestamp == 0 ? "unlimited" : tmpstr2), ip); auth_dat[i].expiration_time = timestamp; mmo_auth_sync(); WFIFOL(fd,30) = (unsigned long)auth_dat[i].expiration_time; } else { strftime(tmpstr, 24, login_config.date_format, localtime(&auth_dat[i].expiration_time)); ShowNotice("'ladmin': Impossible to adjust a validity limit (account: %s, %d (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n", auth_dat[i].userid, auth_dat[i].expiration_time, (auth_dat[i].expiration_time == 0 ? "unlimited" : tmpstr), (short)RFIFOW(fd,26), (short)RFIFOW(fd,28), (short)RFIFOW(fd,30), (short)RFIFOW(fd,32), (short)RFIFOW(fd,34), (short)RFIFOW(fd,36), ip); WFIFOL(fd,30) = 0; } } else { memcpy(WFIFOP(fd,6), account_name, 24); ShowNotice("'ladmin': Attempt to adjust the validity limit of an unknown account (account: %s, ip: %s)\n", account_name, ip); WFIFOL(fd,30) = 0; } WFIFOSET(fd,34); } RFIFOSKIP(fd,38); break; */ case 0x7952: // Request about informations of an account (by account name) if (RFIFOREST(fd) < 26) return 0; { struct mmo_account acc; WFIFOW(fd,0) = 0x7953; account_name = (char*)RFIFOP(fd,2); account_name[23] = '\0'; if( accounts->load_str(accounts, &acc, account_name) ) { ShowNotice("'ladmin': Sending information of an account (request by the name; account: %s, id: %d, ip: %s)\n", acc.userid, acc.account_id, ip); WFIFOL(fd,2) = acc.account_id; WFIFOB(fd,6) = acc.level; safestrncpy((char*)WFIFOP(fd,7), acc.userid, 24); WFIFOB(fd,31) = acc.sex; WFIFOL(fd,32) = acc.logincount; WFIFOL(fd,36) = acc.state; safestrncpy((char*)WFIFOP(fd,40), "-", 20); // error message (removed) safestrncpy((char*)WFIFOP(fd,60), acc.lastlogin, 24); safestrncpy((char*)WFIFOP(fd,84), acc.last_ip, 16); safestrncpy((char*)WFIFOP(fd,100), acc.email, 40); WFIFOL(fd,140) = (unsigned long)acc.expiration_time; WFIFOL(fd,144) = (unsigned long)acc.unban_time; WFIFOW(fd,148) = 0; // previously, this was strlen(memo), and memo went afterwards } else { ShowNotice("'ladmin': Attempt to obtain information (by the name) of an unknown account (account: %s, ip: %s)\n", account_name, ip); WFIFOL(fd,2) = -1; safestrncpy((char*)WFIFOP(fd,7), account_name, 24); // not found } WFIFOSET(fd,150); } RFIFOSKIP(fd,26); break; case 0x7954: // Request about information of an account (by account id) if (RFIFOREST(fd) < 6) return 0; { struct mmo_account acc; int account_id = RFIFOL(fd,2); WFIFOHEAD(fd,150); WFIFOW(fd,0) = 0x7953; WFIFOL(fd,2) = account_id; if( accounts->load_num(accounts, &acc, account_id) ) { ShowNotice("'ladmin': Sending information of an account (request by the id; account: %s, id: %d, ip: %s)\n", acc.userid, account_id, ip); WFIFOB(fd,6) = acc.level; safestrncpy((char*)WFIFOP(fd,7), acc.userid, 24); WFIFOB(fd,31) = acc.sex; WFIFOL(fd,32) = acc.logincount; WFIFOL(fd,36) = acc.state; safestrncpy((char*)WFIFOP(fd,40), "-", 20); // error message (removed) safestrncpy((char*)WFIFOP(fd,60), acc.lastlogin, 24); safestrncpy((char*)WFIFOP(fd,84), acc.last_ip, 16); safestrncpy((char*)WFIFOP(fd,100), acc.email, 40); WFIFOL(fd,140) = (unsigned long)acc.expiration_time; WFIFOL(fd,144) = (unsigned long)acc.unban_time; WFIFOW(fd,148) = 0; // previously, this was strlen(memo), and memo went afterwards } else { ShowNotice("'ladmin': Attempt to obtain information (by the id) of an unknown account (id: %d, ip: %s)\n", account_id, ip); safestrncpy((char*)WFIFOP(fd,7), "", 24); // not found } WFIFOSET(fd,150); } RFIFOSKIP(fd,6); break; default: ShowStatus("'ladmin': End of connection, unknown packet (ip: %s)\n", ip); set_eof(fd); return 0; } } RFIFOSKIP(fd,RFIFOREST(fd)); return 0; }
static void accept_new(void) { char buffer[MAX_ATM_ADDR_LEN+1]; struct sockaddr_atmsvc addr; struct atm_qos qos; ENTRY *entry; VCC *vcc; int fd,error; socklen_t len,size; len = sizeof(addr); if ((fd = accept(incoming,(struct sockaddr *) &addr,&len)) < 0) { error = errno; diag(COMPONENT,DIAG_ERROR,"accept: %s",strerror(errno)); if (error == EUNATCH) { diag(COMPONENT,DIAG_WARN,"disabling SVCs"); (void) close(incoming); incoming = -1; } return; } /* the following code probably belongs to arp.c ... */ if (atm2text(buffer,MAX_ATM_ADDR_LEN+1,(struct sockaddr *) &addr,pretty) < 0) strcpy(buffer,"<atm2text error>"); diag(COMPONENT,DIAG_DEBUG,"Incoming call from %s",buffer); size = sizeof(qos); if (getsockopt(fd,SOL_ATM,SO_ATMQOS,&qos,&size) < 0) diag(COMPONENT,DIAG_FATAL,"getsockopt SO_ATMQOS: %s",strerror(errno)); if (size != sizeof(qos)) diag(COMPONENT,DIAG_FATAL,"SO_ATMQOS: size %d != %d",size,sizeof(qos)); if (ioctl(fd,ATMARP_MKIP,qos.txtp.traffic_class == ATM_NONE ? 0 : CLIP_DEFAULT_IDLETIMER) < 0) { diag(COMPONENT,DIAG_ERROR,"ioctl ATMARP_MKIP: %s",strerror(errno)); (void) do_close(fd); return; } vcc = alloc_t(VCC); vcc->active = 0; vcc->connecting = 0; vcc->fd = fd; if (qos.txtp.traffic_class == ATM_NONE) { vcc->entry = NULL; incoming_unidirectional(vcc); Q_INSERT_HEAD(unidirectional_vccs,vcc); return; } if (merge) { ITF *itf; for (itf = itfs; itf; itf = itf->next) { entry = lookup_addr(itf,&addr); if (entry) { vcc->entry = entry; Q_INSERT_HEAD(entry->vccs,vcc); if (entry->state == as_valid) { if (set_ip(vcc->fd,entry->ip) < 0) { diag(COMPONENT,DIAG_ERROR,"set_ip: %s", strerror(errno)); disconnect_vcc(vcc); } else set_sndbuf(vcc); } return; } } } entry = alloc_entry(1); entry->state = as_invalid; entry->addr = alloc_t(struct sockaddr_atmsvc); *entry->addr = addr; entry->flags = ATF_PUBL; Q_INSERT_HEAD(unknown_incoming,entry); vcc->entry = entry; Q_INSERT_HEAD(entry->vccs,vcc); incoming_call(vcc); }
/** * <Ring 1> The main loop of TASK FS. * *****************************************************************************/ PUBLIC void task_fs() { printl("{FS} Task FS begins.\n"); init_fs(); while (1) { send_recv(RECEIVE, ANY, &fs_msg); int msgtype = fs_msg.type; int src = fs_msg.source; pcaller = &proc_table[src]; switch (msgtype) { case OPEN: fs_msg.FD = do_open(); break; case CLOSE: fs_msg.RETVAL = do_close(); break; case READ: case WRITE: fs_msg.CNT = do_rdwt(); break; case UNLINK: fs_msg.RETVAL = do_unlink(); break; case RESUME_PROC: src = fs_msg.PROC_NR; break; case FORK: fs_msg.RETVAL = fs_fork(); break; case EXIT: fs_msg.RETVAL = fs_exit(); break; case LSEEK: fs_msg.OFFSET = do_lseek(); break; case STAT: fs_msg.RETVAL = do_stat(); break; default: dump_msg("FS::unknown message:", &fs_msg); assert(0); break; } #ifdef ENABLE_DISK_LOG char * msg_name[128]; msg_name[OPEN] = "OPEN"; msg_name[CLOSE] = "CLOSE"; msg_name[READ] = "READ"; msg_name[WRITE] = "WRITE"; msg_name[LSEEK] = "LSEEK"; msg_name[UNLINK] = "UNLINK"; msg_name[FORK] = "FORK"; msg_name[EXIT] = "EXIT"; msg_name[STAT] = "STAT"; switch (msgtype) { case UNLINK: dump_fd_graph("%s just finished. (pid:%d)", msg_name[msgtype], src); //panic(""); case OPEN: case CLOSE: case READ: case WRITE: case FORK: case EXIT: case LSEEK: case STAT: break; case RESUME_PROC: break; default: assert(0); } #endif /* reply */ if (fs_msg.type != SUSPEND_PROC) { fs_msg.type = SYSCALL_RET; send_recv(SEND, src, &fs_msg); } } }
static int connect_client(int listen_fd) { int fd; struct sockaddr_in client_address; #ifdef __WIN32 int len; #else socklen_t len; #endif //ShowMessage("connect_client : %d\n",listen_fd); len=sizeof(client_address); fd = accept(listen_fd,(struct sockaddr*)&client_address,&len); #ifdef __WIN32 if (fd == SOCKET_ERROR || fd == INVALID_SOCKET || fd < 0) { ShowError("accept failed (code %d)!\n", fd, WSAGetLastError()); return -1; } #else if(fd==-1) { perror("accept"); return -1; } #endif if(fd_max<=fd) fd_max=fd+1; setsocketopts(fd); #ifdef __WIN32 { unsigned long val = 1; if (ioctlsocket(fd, FIONBIO, &val) != 0) ShowError("Nao e necessario ajustar o soquete � modalidade non-blocking (code %d)!\n", WSAGetLastError()); } #else if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) perror("connect_client (set nonblock)"); #endif if (ip_rules && !connect_check(*(unsigned int*)(&client_address.sin_addr))) { do_close(fd); return -1; } else FD_SET(fd,&readfds); CREATE(session[fd], struct socket_data, 1); CREATE_A(session[fd]->rdata, unsigned char, rfifo_size); CREATE_A(session[fd]->wdata, unsigned char, wfifo_size); session[fd]->max_rdata = (int)rfifo_size; session[fd]->max_wdata = (int)wfifo_size; session[fd]->func_recv = recv_to_fifo; session[fd]->func_send = send_from_fifo; session[fd]->func_parse = default_func_parse; session[fd]->client_addr = client_address; session[fd]->rdata_tick = last_tick; session[fd]->type = SESSION_UNKNOWN; // undefined type //ShowMessage("new_session : %d %d\n",fd,session[fd]->eof); return fd; }
static int do_read(struct client* c, struct client_info* info) { assert(info->connect_type == SOCKET_CONNECTED); int to_id = info->to_id; if (to_id < 0) { to_id = connect_to(c, info->id); if (to_id == -1) { do_close(c, info); return -1; } info->to_id = to_id; c->free_connection -= 1; c->time = 0; } int len; struct client_info* to_info = &c->all_fds[to_id % TOTAL_CONNECTION]; if (to_info->id != to_id) { do_close(c, info); return -1; } char* buffer = get_ring_buffer_write_ptr(to_info->buffer, &len); if (!buffer) { return 0; //buff fulled } int n = (int)read(info->fd, buffer, len); if (n == -1) { switch (errno) { case EAGAIN: fprintf(stderr, "%s read fd error:EAGAIN.\n", get_time()); break; case EINTR: break; default: fprintf(stderr, "%s client: read (id=%d) error :%s. \n", get_time(), info->id, strerror(errno)); do_close(c, info); return -1; } return 1; } if (n == 0) { do_close(c, info); //normal close return -1; } move_ring_buffer_write_pos(to_info->buffer, n); FD_SET(to_info->fd, &c->fd_wset); if (n == len && !is_ring_buffer_empty(to_info->buffer)) { fprintf(stderr, "%s client: read again.\n", get_time()); return do_read(c, info); } return 1; }
static void gc_free(MVMThreadContext *tc, MVMObject *h, void *d) { MVMIOSyncSocketData *data = (MVMIOSyncSocketData *)d; do_close(tc, data); }
static void* client_thread(void* param) { struct client_param* cp = (struct client_param*)param; struct client c; memset(&c, 0, sizeof(c)); sprintf(c.remote_ip, "%s", cp->remote_ip); c.remote_port = cp->p1; c.ssh_port = cp->p2; c.wait_closed = alloc_ring_buffer(sizeof(int) * TOTAL_CONNECTION); FD_ZERO(&c.fd_rset); FD_ZERO(&c.fd_wset); FD_SET(cp->pid, &c.fd_rset); c.max_fd = cp->pid + 1; sp_nonblocking(cp->pid); while (1) { pre_check_close(&c); if (connect_to(&c, -1) == -1 && c.cnt == 0) { c.max_fd = cp->pid + 1; int buff = 0; int n = (int)read(cp->pid, &buff, sizeof(int)); if (n > 0) { break; } sleep(1); continue; } fd_set r_set = c.fd_rset; fd_set w_set = c.fd_wset; int cnt = select(c.max_fd, &r_set, &w_set, NULL, NULL); if (cnt == -1) { fprintf(stderr, "%s select error: %s.\n", get_time(), strerror(errno)); continue; } int i; for (i = c.cnt - 1; i >= 0 && cnt > 0; --i) { int id = c.all_ids[i] % TOTAL_CONNECTION; struct client_info* info = &c.all_fds[id]; assert(c.all_ids[i] == info->id); int fd = info->fd; assert(fd > 0); if (FD_ISSET(fd, &r_set)) { // read --cnt; if (do_read(&c, info) == -1) continue; } if (FD_ISSET(fd, &w_set)) { //write --cnt; if (do_write(&c, info, 0) == -1) continue; } } if (FD_ISSET(cp->pid, &r_set)) { //exit break; } } fprintf(stderr, "%s ====================CLIENT: SEND LAST DATA BEGIN===================.\n", get_time()); int i; for (i = c.cnt - 1; i >= 0; --i) { int id = c.all_ids[i] % TOTAL_CONNECTION; struct client_info* info = &c.all_fds[id]; assert(c.all_ids[i] == info->id); if (do_write(&c, info, 1) != -1) { do_close(&c, info); } } fprintf(stderr, "%s ====================CLIENT: SEND LAST DATA END=====================.\n", get_time()); free_ring_buffer(c.wait_closed); assert(c.cnt == 0); return NULL; }
static int on_req(h2o_handler_t *_self, h2o_req_t *req) { h2o_file_handler_t *self = (void*)_self; h2o_buf_t vpath, mime_type; char *rpath; size_t rpath_len; struct st_h2o_sendfile_generator_t *generator = NULL; size_t if_modified_since_header_index, if_none_match_header_index; int is_dir; /* only accept GET (TODO accept HEAD as well) */ if (! h2o_memis(req->method.base, req->method.len, H2O_STRLIT("GET"))) return -1; /* prefix match */ if (req->path.len < self->virtual_path.len || memcmp(req->path.base, self->virtual_path.base, self->virtual_path.len) != 0) return -1; /* normalize path */ vpath = h2o_normalize_path(&req->pool, req->path.base + self->virtual_path.len - 1, req->path.len - self->virtual_path.len + 1); if (vpath.len > PATH_MAX) return -1; /* build path (still unterminated at the end of the block) */ rpath = alloca( self->real_path.len + (vpath.len - 1) /* exclude "/" at the head */ + self->max_index_file_len + 1); rpath_len = 0; memcpy(rpath + rpath_len, self->real_path.base, self->real_path.len); rpath_len += self->real_path.len; memcpy(rpath + rpath_len, vpath.base + 1, vpath.len - 1); rpath_len += vpath.len - 1; /* build generator (as well as terminating the rpath and its length upon success) */ if (rpath[rpath_len - 1] == '/') { h2o_buf_t *index_file; for (index_file = self->index_files; index_file->base != NULL; ++index_file) { memcpy(rpath + rpath_len, index_file->base, index_file->len); rpath[rpath_len + index_file->len] = '\0'; if ((generator = create_generator(&req->pool, rpath, &is_dir)) != NULL) { rpath_len += index_file->len; break; } if (is_dir) { /* note: apache redirects "path/" to "path/index.txt/" if index.txt is a dir */ char *path = alloca(req->path.len + index_file->len + 1); size_t path_len = sprintf(path, "%.*s%.*s", (int)req->path.len, req->path.base, (int)index_file->len, index_file->base); return redirect_to_dir(req, path, path_len); } if (errno != ENOENT) break; } } else { rpath[rpath_len] = '\0'; generator = create_generator(&req->pool, rpath, &is_dir); if (generator == NULL && is_dir) return redirect_to_dir(req, req->path.base, req->path.len); } /* return error if failed */ if (generator == NULL) { if (errno == ENOENT) { h2o_send_error(req, 404, "File Not Found", "file not found"); } else { h2o_send_error(req, 403, "Access Forbidden", "access forbidden"); } return 0; } if ((if_none_match_header_index = h2o_find_header(&req->headers, H2O_TOKEN_IF_NONE_MATCH, SIZE_MAX)) != -1) { h2o_buf_t *if_none_match = &req->headers.entries[if_none_match_header_index].value; if (h2o_memis(if_none_match->base, if_none_match->len, generator->etag_buf, generator->etag_len)) goto NotModified; } else if ((if_modified_since_header_index = h2o_find_header(&req->headers, H2O_TOKEN_IF_MODIFIED_SINCE, SIZE_MAX)) != -1) { h2o_buf_t *if_modified_since = &req->headers.entries[if_modified_since_header_index].value; if (h2o_memis(if_modified_since->base, if_modified_since->len, generator->last_modified_buf, H2O_TIMESTR_RFC1123_LEN)) goto NotModified; } /* obtain mime type */ mime_type = h2o_mimemap_get_type(self->mimemap, h2o_get_filext(rpath, rpath_len)); /* return file */ do_send_file(generator, req, 200, "OK", mime_type); return 0; NotModified: req->res.status = 304; req->res.reason = "Not Modified"; h2o_send_inline(req, NULL, 0); do_close(&generator->super, req); return 0; }
/** * Destroys a server structure. * @param id: id of char-serv (should be >0, FIXME) */ void logchrif_server_destroy(int id){ if( ch_server[id].fd != -1 ) { do_close(ch_server[id].fd); ch_server[id].fd = -1; } }
static int do_lsreaddir(struct sftp_conn *conn, char *path, int printflag, SFTP_DIRENT ***dir) { Buffer msg; u_int count, type, id, handle_len, i, expected_id, ents = 0; char *handle; id = conn->msg_id++; buffer_init(&msg); buffer_put_char(&msg, SSH2_FXP_OPENDIR); buffer_put_int(&msg, id); buffer_put_cstring(&msg, path); send_msg(conn->fd_out, &msg); buffer_clear(&msg); handle = get_handle(conn->fd_in, id, &handle_len); if (handle == NULL) return(-1); if (dir) { ents = 0; *dir = xmalloc(sizeof(**dir)); (*dir)[0] = NULL; } for (; !interrupted;) { id = expected_id = conn->msg_id++; debug3("Sending SSH2_FXP_READDIR I:%u", id); buffer_clear(&msg); buffer_put_char(&msg, SSH2_FXP_READDIR); buffer_put_int(&msg, id); buffer_put_string(&msg, handle, handle_len); send_msg(conn->fd_out, &msg); buffer_clear(&msg); get_msg(conn->fd_in, &msg); type = buffer_get_char(&msg); id = buffer_get_int(&msg); debug3("Received reply T:%u I:%u", type, id); if (id != expected_id) fatal("ID mismatch (%u != %u)", id, expected_id); if (type == SSH2_FXP_STATUS) { int status = buffer_get_int(&msg); debug3("Received SSH2_FXP_STATUS %d", status); if (status == SSH2_FX_EOF) { break; } else { error("Couldn't read directory: %s", fx2txt(status)); do_close(conn, handle, handle_len); xfree(handle); return(status); } } else if (type != SSH2_FXP_NAME) fatal("Expected SSH2_FXP_NAME(%u) packet, got %u", SSH2_FXP_NAME, type); count = buffer_get_int(&msg); if (count == 0) break; debug3("Received %d SSH2_FXP_NAME responses", count); for (i = 0; i < count; i++) { char *filename, *longname; Attrib *a; filename = buffer_get_string(&msg, NULL); longname = buffer_get_string(&msg, NULL); a = decode_attrib(&msg); if (printflag) printf("%s\n", longname); if (dir) { *dir = xrealloc(*dir, (ents + 2) * sizeof(**dir)); (*dir)[ents] = xmalloc(sizeof(***dir)); (*dir)[ents]->filename = xstrdup(filename); (*dir)[ents]->longname = xstrdup(longname); memcpy(&(*dir)[ents]->a, a, sizeof(*a)); (*dir)[++ents] = NULL; } xfree(filename); xfree(longname); } } buffer_free(&msg); do_close(conn, handle, handle_len); xfree(handle); /* Don't return partial matches on interrupt */ if (interrupted && dir != NULL && *dir != NULL) { free_sftp_dirents(*dir); *dir = xmalloc(sizeof(**dir)); **dir = NULL; } return(0); }
void imc_shutdown_network(void) { imc_event *ev, *ev_next; imc_connect *c, *c_next; imc_reminfo *p, *pnext; if (imc_active < IA_UP) { imc_logerror("imc_shutdown_network: called with imc_active==%d", imc_active); return; } if (imc_lock) { imc_logerror("imc_shutdown_network: called from within imc_idle_select"); return; } imc_logstring("shutting down network"); if (imc_active == IA_LISTENING) imc_shutdown_port(); imc_logstring("rx %ld packets, %ld bytes (%ld/second)", imc_stats.rx_pkts, imc_stats.rx_bytes, (imc_now == imc_stats.start) ? 0 : imc_stats.rx_bytes / (imc_now - imc_stats.start)); imc_logstring("tx %ld packets, %ld bytes (%ld/second)", imc_stats.tx_pkts, imc_stats.tx_bytes, (imc_now == imc_stats.start) ? 0 : imc_stats.tx_bytes / (imc_now - imc_stats.start)); imc_logstring("largest packet %d bytes", imc_stats.max_pkt); imc_logstring("dropped %d packets by sequence number", imc_stats.sequence_drops); imc_mail_shutdown(); for (c=imc_connect_list; c; c=c_next) { c_next=c->next; do_close(c); imc_extract_connect(c); } imc_connect_list=NULL; if(!imc_is_router) icec_shutdown(); for (p=imc_reminfo_list; p; p=pnext) { pnext=p->next; imc_strfree(p->version); imc_strfree(p->name); if(p->path) imc_strfree(p->path); imc_free(p, sizeof(imc_reminfo)); } imc_reminfo_list=NULL; for (ev=imc_event_list; ev; ev=ev_next) { ev_next=ev->next; imc_free(ev, sizeof(imc_event)); } for (ev=imc_event_free; ev; ev=ev_next) { ev_next=ev->next; imc_free(ev, sizeof(imc_event)); } imc_event_list=imc_event_free=NULL; unlock_prefix(); imc_active=IA_CONFIG2; }
int rtime(struct sockaddr_in *addrp, struct timeval *timep, struct timeval *timeout) { int s; fd_set readfds; int res; unsigned long thetime; struct sockaddr_in from; socklen_t fromlen; int type; struct servent *serv; if (timeout == NULL) { type = SOCK_STREAM; } else { type = SOCK_DGRAM; } s = _socket(AF_INET, type, 0); if (s < 0) { return(-1); } addrp->sin_family = AF_INET; /* TCP and UDP port are the same in this case */ if ((serv = getservbyname("time", "tcp")) == NULL) { return(-1); } addrp->sin_port = serv->s_port; if (type == SOCK_DGRAM) { res = _sendto(s, (char *)&thetime, sizeof(thetime), 0, (struct sockaddr *)addrp, sizeof(*addrp)); if (res < 0) { do_close(s); return(-1); } do { FD_ZERO(&readfds); FD_SET(s, &readfds); res = _select(_rpc_dtablesize(), &readfds, (fd_set *)NULL, (fd_set *)NULL, timeout); } while (res < 0 && errno == EINTR); if (res <= 0) { if (res == 0) { errno = ETIMEDOUT; } do_close(s); return(-1); } fromlen = sizeof(from); res = _recvfrom(s, (char *)&thetime, sizeof(thetime), 0, (struct sockaddr *)&from, &fromlen); do_close(s); if (res < 0) { return(-1); } } else { if (_connect(s, (struct sockaddr *)addrp, sizeof(*addrp)) < 0) { do_close(s); return(-1); } res = _read(s, (char *)&thetime, sizeof(thetime)); do_close(s); if (res < 0) { return(-1); } } if (res != sizeof(thetime)) { errno = EIO; return(-1); } thetime = ntohl(thetime); timep->tv_sec = thetime - TOFFSET; timep->tv_usec = 0; return(0); }
/* read waiting data from descriptor. * read to a temp buffer to avoid repeated allocations */ static void do_read(imc_connect *c) { int size; int r; char temp[IMC_MAXBUF]; char *newbuf; int newsize; r=read(c->desc, temp, IMC_MAXBUF-1); if (!r || (r<0 && errno != EAGAIN && errno != EWOULDBLOCK)) { if (!c->info || !(c->info->flags & IMC_QUIET)) { if (r<0) /* read error */ { imc_lerror("%s: read", imc_getconnectname(c)); } else /* socket was closed */ { imc_logerror("%s: read: EOF", imc_getconnectname(c)); } } do_close(c); return; } if (r<0) /* EAGAIN error */ return; temp[r]=0; size=strlen(c->inbuf)+r+1; if (size>=c->insize) { #ifdef SHOW_OVERFLOW /* not an error anymore, expected and handled - shogar */ if (size>IMC_MAXBUF) { imc_logerror("%s: input buffer overflow", imc_getconnectname(c)); imc_logerror("%d: was allocated", c->insize); // do_close(c); // imc_free(c->inbuf,c->insize); // c->insize=IMC_MINBUF; // c->inbuf= imc_malloc(c->insize); // size = r + 1; // return; } #endif newsize=c->insize; while(newsize<size) newsize*=2; newbuf=imc_malloc(newsize); strcpy(newbuf, c->inbuf); imc_free(c->inbuf, c->insize); c->inbuf=newbuf; c->insize=newsize; } if (size>c->insize/2) { imc_cancel_event(ev_shrink_input, c); imc_add_event(IMC_SHRINKTIME, ev_shrink_input, c, 0); } if (size<c->insize/2 && size >= IMC_MINBUF) { newsize=c->insize; newsize/=2; newbuf=imc_malloc(newsize); strcpy(newbuf, c->inbuf); imc_free(c->inbuf, c->insize); c->inbuf=newbuf; c->insize=newsize; } strcat(c->inbuf, temp); imc_stats.rx_bytes += r; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { int argc; LPWSTR *wargv = CommandLineToArgvW(GetCommandLineW(), &argc); char **argv; char argv0[256]; MSG msg; int code; fz_context *ctx; int bps = 0; int displayRes = get_system_dpi(); int c; char *layout_css = NULL; ctx = fz_new_context(NULL, NULL, FZ_STORE_DEFAULT); if (!ctx) { fprintf(stderr, "cannot initialise context\n"); exit(1); } pdfapp_init(ctx, &gapp); argv = fz_argv_from_wargv(argc, wargv); while ((c = fz_getopt(argc, argv, "p:r:A:C:W:H:S:U:b:")) != -1) { switch (c) { case 'C': c = strtol(fz_optarg, NULL, 16); gapp.tint = 1; gapp.tint_r = (c >> 16) & 255; gapp.tint_g = (c >> 8) & 255; gapp.tint_b = (c) & 255; break; case 'p': password = fz_optarg; break; case 'r': displayRes = fz_atoi(fz_optarg); break; case 'A': fz_set_aa_level(ctx, fz_atoi(fz_optarg)); break; case 'W': gapp.layout_w = fz_atoi(fz_optarg); break; case 'H': gapp.layout_h = fz_atoi(fz_optarg); break; case 'S': gapp.layout_em = fz_atoi(fz_optarg); break; case 'b': bps = (fz_optarg && *fz_optarg) ? fz_atoi(fz_optarg) : 4096; break; case 'U': layout_css = fz_optarg; break; default: usage(); } } pdfapp_setresolution(&gapp, displayRes); GetModuleFileNameA(NULL, argv0, sizeof argv0); install_app(argv0); winopen(); if (fz_optind < argc) { strcpy(filename, argv[fz_optind]); } else { if (!winfilename(wbuf, nelem(wbuf))) exit(0); code = WideCharToMultiByte(CP_UTF8, 0, wbuf, -1, filename, sizeof filename, NULL, NULL); if (code == 0) winerror(&gapp, "cannot convert filename to utf-8"); } if (layout_css) { fz_buffer *buf = fz_read_file(ctx, layout_css); fz_set_user_css(ctx, fz_string_from_buffer(ctx, buf)); fz_drop_buffer(ctx, buf); } if (bps) pdfapp_open_progressive(&gapp, filename, 0, bps); else pdfapp_open(&gapp, filename, 0); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } fz_free_argv(argc, argv); do_close(&gapp); return 0; }
/** process_run : cmd:string -> args:string array -> 'process <doc> Start a process using a command and the specified arguments. When args is not null, cmd and args will be auto-quoted/escaped. If no auto-quoting/escaping is desired, you should append necessary arguments to cmd as if it is inputted to the shell directly, and pass null as args. </doc> **/ static value process_run( value cmd, value vargs ) { int i, isRaw; vprocess *p; val_check(cmd,string); isRaw = val_is_null(vargs); if (!isRaw) { val_check(vargs,array); } # ifdef NEKO_WINDOWS { SECURITY_ATTRIBUTES sattr; STARTUPINFO sinf; HANDLE proc = GetCurrentProcess(); HANDLE oread,eread,iwrite; // creates commandline buffer b = alloc_buffer(NULL); value sargs; if (isRaw) { char* cmdexe = getenv("COMSPEC"); if (!cmdexe) cmdexe = "cmd.exe"; buffer_append(b,"\""); buffer_append(b,cmdexe); buffer_append(b,"\" /C \""); buffer_append(b,val_string(cmd)); buffer_append_char(b,'"'); } else { buffer_append_char(b,'"'); val_buffer(b,cmd); buffer_append_char(b,'"'); for(i=0;i<val_array_size(vargs);i++) { value v = val_array_ptr(vargs)[i]; int j,len; unsigned int bs_count = 0; unsigned int k; val_check(v,string); len = val_strlen(v); buffer_append(b," \""); for(j=0;j<len;j++) { char c = val_string(v)[j]; switch( c ) { case '"': // Double backslashes. for (k=0;k<bs_count*2;k++) { buffer_append_char(b,'\\'); } bs_count = 0; buffer_append(b, "\\\""); break; case '\\': // Don't know if we need to double yet. bs_count++; break; default: // Normal char for (k=0;k<bs_count;k++) { buffer_append_char(b,'\\'); } bs_count = 0; buffer_append_char(b,c); break; } } // Add remaining backslashes, if any. for (k=0;k<bs_count*2;k++) { buffer_append_char(b,'\\'); } buffer_append_char(b,'"'); } } sargs = buffer_to_string(b); p = (vprocess*)alloc_private(sizeof(vprocess)); // startup process sattr.nLength = sizeof(sattr); sattr.bInheritHandle = TRUE; sattr.lpSecurityDescriptor = NULL; memset(&sinf,0,sizeof(sinf)); sinf.cb = sizeof(sinf); sinf.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; sinf.wShowWindow = SW_HIDE; CreatePipe(&oread,&sinf.hStdOutput,&sattr,0); CreatePipe(&eread,&sinf.hStdError,&sattr,0); CreatePipe(&sinf.hStdInput,&iwrite,&sattr,0); DuplicateHandle(proc,oread,proc,&p->oread,0,FALSE,DUPLICATE_SAME_ACCESS); DuplicateHandle(proc,eread,proc,&p->eread,0,FALSE,DUPLICATE_SAME_ACCESS); DuplicateHandle(proc,iwrite,proc,&p->iwrite,0,FALSE,DUPLICATE_SAME_ACCESS); CloseHandle(oread); CloseHandle(eread); CloseHandle(iwrite); if( !CreateProcess(NULL,val_string(sargs),NULL,NULL,TRUE,0,NULL,NULL,&sinf,&p->pinf) ) neko_error(); // close unused pipes CloseHandle(sinf.hStdOutput); CloseHandle(sinf.hStdError); CloseHandle(sinf.hStdInput); } # else char **argv; if (isRaw) { argv = (char**)alloc_private(sizeof(char*)*4); argv[0] = "/bin/sh"; argv[1] = "-c"; argv[2] = val_string(cmd); argv[3] = NULL; } else { argv = (char**)alloc_private(sizeof(char*)*(val_array_size(vargs)+2)); argv[0] = val_string(cmd); for(i=0;i<val_array_size(vargs);i++) { value v = val_array_ptr(vargs)[i]; val_check(v,string); argv[i+1] = val_string(v); } argv[i+1] = NULL; } int input[2], output[2], error[2]; if( pipe(input) || pipe(output) || pipe(error) ) neko_error(); p = (vprocess*)alloc_private(sizeof(vprocess)); p->pid = fork(); if( p->pid == -1 ) { do_close(input[0]); do_close(input[1]); do_close(output[0]); do_close(output[1]); do_close(error[0]); do_close(error[1]); neko_error(); } // child if( p->pid == 0 ) { close(input[1]); close(output[0]); close(error[0]); dup2(input[0],0); dup2(output[1],1); dup2(error[1],2); execvp(argv[0],argv); fprintf(stderr,"Command not found : %s\n",val_string(cmd)); exit(1); } // parent do_close(input[0]); do_close(output[1]); do_close(error[1]); p->iwrite = input[1]; p->oread = output[0]; p->eread = error[0]; # endif { value vp = alloc_abstract(k_process,p); val_gc(vp,free_process); return vp; } }
int main(int argc, char *argv[]) { long fd; int i, j, k; int bwloops; char *fname; char data[8192]; int runtime; struct stat buf; struct timeval start, stop; stoptime = time(0) + 3600; int filesize = 16 * 1024 * 1024; if(argc != 6) { printf("use: %s <host> <file> <loops> <cycles> <bwloops>\n", argv[0]); return -1; } auth_register_all(); host = argv[1]; fname = argv[2]; loops = atoi(argv[3]); cycles = atoi(argv[4]); bwloops = atoi(argv[5]); if(!strcmp(host, "unix")) { do_chirp = 0; } else { do_chirp = 1; } #ifdef SYS_getpid RUN_LOOP("getpid", syscall(SYS_getpid)); #else RUN_LOOP("getpid", getpid()); #endif fd = do_open(fname, O_WRONLY | O_CREAT | O_TRUNC | do_sync, 0777); if(fd < 0 || fd == 0) { perror(fname); return -1; } RUN_LOOP("write1", do_pwrite(fd, data, 1, 0)); RUN_LOOP("write8", do_pwrite(fd, data, 8192, 0)); do_close(fd); fd = do_open(fname, O_RDONLY | do_sync, 0777); if(fd < 0) { perror(fname); return -1; } RUN_LOOP("read1", do_pread(fd, data, 1, 0)); RUN_LOOP("read8", do_pread(fd, data, 8192, 0)); do_close(fd); RUN_LOOP("stat", do_stat(fname, &buf)); RUN_LOOP("open", fd = do_open(fname, O_RDONLY | do_sync, 0777); do_close(fd); );
void lin_webcam_impl::close() { unmap_memory(); do_close(); }
/*========================================== * *------------------------------------------*/ int chrif_parse(int fd) { int packet_len, cmd; // only process data from the char-server if ( fd != char_fd ) { ShowDebug("chrif_parse: Disconnecting invalid session #%d (is not the char-server)\n", fd); do_close(fd); return 0; } if ( session[fd]->flag.eof ) { do_close(fd); char_fd = -1; chrif_on_disconnect(); return 0; } else if ( session[fd]->flag.ping ) {/* we've reached stall time */ if( DIFF_TICK(last_tick, session[fd]->rdata_tick) > (stall_time * 2) ) {/* we can't wait any longer */ set_eof(fd); return 0; } else if( session[fd]->flag.ping != 2 ) { /* we haven't sent ping out yet */ chrif_keepalive(fd); session[fd]->flag.ping = 2; } } while ( RFIFOREST(fd) >= 2 ) { cmd = RFIFOW(fd,0); if (cmd < 0x2af8 || cmd >= 0x2af8 + ARRAYLENGTH(packet_len_table) || packet_len_table[cmd-0x2af8] == 0) { int r = intif_parse(fd); // Passed on to the intif if (r == 1) continue; // Treated in intif if (r == 2) return 0; // Didn't have enough data (len==-1) ShowWarning("chrif_parse: session #%d, intif_parse failed (unrecognized command 0x%.4x).\n", fd, cmd); set_eof(fd); return 0; } if ( ( packet_len = packet_len_table[cmd-0x2af8] ) == -1) { // dynamic-length packet, second WORD holds the length if (RFIFOREST(fd) < 4) return 0; packet_len = RFIFOW(fd,2); } if ((int)RFIFOREST(fd) < packet_len) return 0; //ShowDebug("Received packet 0x%4x (%d bytes) from char-server (connection %d)\n", RFIFOW(fd,0), packet_len, fd); switch(cmd) { case 0x2af9: chrif_connectack(fd); break; case 0x2afb: chrif_sendmapack(fd); break; case 0x2afd: chrif_authok(fd); break; case 0x2b00: map_setusers(RFIFOL(fd,2)); chrif_keepalive(fd); break; case 0x2b03: clif->charselectok(RFIFOL(fd,2), RFIFOB(fd,6)); break; case 0x2b04: chrif_recvmap(fd); break; case 0x2b06: chrif_changemapserverack(RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOL(fd,14), RFIFOW(fd,18), RFIFOW(fd,20), RFIFOW(fd,22), RFIFOL(fd,24), RFIFOW(fd,28)); break; case 0x2b09: map_addnickdb(RFIFOL(fd,2), (char*)RFIFOP(fd,6)); break; case 0x2b0a: socket_datasync(fd, false); break; case 0x2b0d: chrif_changedsex(fd); break; case 0x2b0f: chrif_char_ask_name_answer(RFIFOL(fd,2), (char*)RFIFOP(fd,6), RFIFOW(fd,30), RFIFOW(fd,32)); break; case 0x2b12: chrif_divorceack(RFIFOL(fd,2), RFIFOL(fd,6)); break; case 0x2b14: chrif_accountban(fd); break; case 0x2b1b: chrif_recvfamelist(fd); break; case 0x2b1d: chrif_load_scdata(fd); break; case 0x2b1e: chrif_update_ip(fd); break; case 0x2b1f: chrif_disconnectplayer(fd); break; case 0x2b20: chrif_removemap(fd); break; case 0x2b21: chrif_save_ack(fd); break; case 0x2b22: chrif_updatefamelist_ack(fd); break; case 0x2b24: chrif_keepalive_ack(fd); break; case 0x2b25: chrif_deadopt(RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)); break; case 0x2b27: chrif_authfail(fd); break; default: ShowError("chrif_parse : unknown packet (session #%d): 0x%x. Disconnecting.\n", fd, cmd); set_eof(fd); return 0; } if ( fd == char_fd ) //There's the slight chance we lost the connection during parse, in which case this would segfault if not checked [Skotlex] RFIFOSKIP(fd, packet_len); } return 0; }
static int serve_with_generator(struct st_h2o_sendfile_generator_t *generator, h2o_req_t *req, const char *rpath, size_t rpath_len, h2o_mimemap_type_t *mime_type) { enum { METHOD_IS_GET, METHOD_IS_HEAD, METHOD_IS_OTHER } method_type; size_t if_modified_since_header_index, if_none_match_header_index; size_t range_header_index; /* determine the method */ if (h2o_memis(req->method.base, req->method.len, H2O_STRLIT("GET"))) { method_type = METHOD_IS_GET; } else if (h2o_memis(req->method.base, req->method.len, H2O_STRLIT("HEAD"))) { method_type = METHOD_IS_HEAD; } else { method_type = METHOD_IS_OTHER; } /* if-non-match and if-modified-since */ if ((if_none_match_header_index = h2o_find_header(&req->headers, H2O_TOKEN_IF_NONE_MATCH, SIZE_MAX)) != -1) { h2o_iovec_t *if_none_match = &req->headers.entries[if_none_match_header_index].value; char etag[H2O_FILECACHE_ETAG_MAXLEN + 1]; size_t etag_len = h2o_filecache_get_etag(generator->file.ref, etag); if (h2o_memis(if_none_match->base, if_none_match->len, etag, etag_len)) goto NotModified; } else if ((if_modified_since_header_index = h2o_find_header(&req->headers, H2O_TOKEN_IF_MODIFIED_SINCE, SIZE_MAX)) != -1) { h2o_iovec_t *ims_vec = &req->headers.entries[if_modified_since_header_index].value; struct tm ims_tm, *last_modified_tm; if (h2o_time_parse_rfc1123(ims_vec->base, ims_vec->len, &ims_tm) == 0) { last_modified_tm = h2o_filecache_get_last_modified(generator->file.ref, NULL); if (!tm_is_lessthan(&ims_tm, last_modified_tm)) goto NotModified; } } /* obtain mime type */ if (mime_type->type == H2O_MIMEMAP_TYPE_DYNAMIC) { do_close(&generator->super, req); return delegate_dynamic_request(req, req->path_normalized.len, rpath, rpath_len, mime_type); } assert(mime_type->type == H2O_MIMEMAP_TYPE_MIMETYPE); /* only allow GET or POST for static files */ if (method_type == METHOD_IS_OTHER) { do_close(&generator->super, req); send_method_not_allowed(req); return 0; } /* if-range */ if ((range_header_index = h2o_find_header(&req->headers, H2O_TOKEN_RANGE, SIZE_MAX)) != -1) { h2o_iovec_t *range = &req->headers.entries[range_header_index].value; size_t *range_infos, range_count; range_infos = process_range(&req->pool, range, generator->bytesleft, &range_count); if (range_infos == NULL) { h2o_iovec_t content_range; content_range.base = h2o_mem_alloc_pool(&req->pool, 32); content_range.len = sprintf(content_range.base, "bytes */%zu", generator->bytesleft); h2o_add_header(&req->pool, &req->res.headers, H2O_TOKEN_CONTENT_RANGE, content_range.base, content_range.len); h2o_send_error(req, 416, "Request Range Not Satisfiable", "requested range not satisfiable", H2O_SEND_ERROR_KEEP_HEADERS); goto Close; } generator->ranged.range_count = range_count; generator->ranged.range_infos = range_infos; generator->ranged.current_range = 0; generator->ranged.filesize = generator->bytesleft; /* set content-length according to range */ if (range_count == 1) generator->bytesleft = range_infos[1]; else { generator->ranged.mimetype = h2o_strdup(&req->pool, mime_type->data.mimetype.base, mime_type->data.mimetype.len); size_t final_content_len = 0, size_tmp = 0, size_fixed_each_part, i; generator->ranged.boundary.base = h2o_mem_alloc_pool(&req->pool, BOUNDARY_SIZE + 1); generator->ranged.boundary.len = BOUNDARY_SIZE; gen_rand_string(&generator->ranged.boundary); i = generator->bytesleft; while (i) { i /= 10; size_tmp++; } size_fixed_each_part = FIXED_PART_SIZE + mime_type->data.mimetype.len + size_tmp; for (i = 0; i < range_count; i++) { size_tmp = *range_infos++; if (size_tmp == 0) final_content_len++; while (size_tmp) { size_tmp /= 10; final_content_len++; } size_tmp = *(range_infos - 1); final_content_len += *range_infos; size_tmp += *range_infos++ - 1; if (size_tmp == 0) final_content_len++; while (size_tmp) { size_tmp /= 10; final_content_len++; } } final_content_len += sizeof("\r\n--") - 1 + BOUNDARY_SIZE + sizeof("--\r\n") - 1 + size_fixed_each_part * range_count - (sizeof("\r\n") - 1); generator->bytesleft = final_content_len; } do_send_file(generator, req, 206, "Partial Content", mime_type->data.mimetype, &h2o_mime_attributes_as_is, method_type == METHOD_IS_GET); return 0; } /* return file */ do_send_file(generator, req, 200, "OK", mime_type->data.mimetype, &mime_type->data.attr, method_type == METHOD_IS_GET); return 0; NotModified: req->res.status = 304; req->res.reason = "Not Modified"; add_headers_unconditional(generator, req); h2o_send_inline(req, NULL, 0); Close: do_close(&generator->super, req); return 0; }
rktio_ok_t rktio_close(rktio_t *rktio, rktio_fd_t *rfd) { return do_close(rktio, rfd, 1); }