int keymanage_efuse_init(const char *buf, int len) { char ver; int ret = 0; const char* dtbLoadAddr = getenv("dtb_mem_addr"); if (!dtbLoadAddr) { setenv("dtb_mem_addr", simple_itoa(CONFIG_SYS_SDRAM_BASE + (16U<<20))); } dtbLoadAddr = (char*)simple_strtoul(dtbLoadAddr, NULL, 0); ret = efuse_usr_api_init_dtb(dtbLoadAddr); if (ret) { KM_ERR("efuse init failed\n"); return __LINE__; } ver = unifykey_get_efuse_version(); if (ver == 0) { KM_DBG("efuse version not cfg\n"); return 0; } //TODO: program the efuse version return ret; }
int setup_waveform_file(ulong waveform_buf) { char *fs_argv[5]; char addr[17]; ulong file_len, mmc_dev; if (!check_mmc_autodetect()) mmc_dev = getenv_ulong("mmcdev", 10, 0); else mmc_dev = mmc_get_env_devno(); sprintf(addr, "%lx", waveform_buf); fs_argv[0] = "fatload"; fs_argv[1] = "mmc"; fs_argv[2] = simple_itoa(mmc_dev); fs_argv[3] = addr; fs_argv[4] = getenv("epdc_waveform"); if (!fs_argv[4]) fs_argv[4] = "epdc_splash.bin"; if (do_fat_fsload(NULL, 0, 5, fs_argv)) { printf("MMC Device %lu not found\n", mmc_dev); return -1; } file_len = getenv_hex("filesize", 0); if (!file_len) return -1; flush_cache((ulong)addr, file_len); return 0; }
/* R_SERVICE_UNAVAILABLE: 503 */ void send_r_service_unavailable(request * req) /* 503 */ { static char body[] = "<HTML><HEAD><TITLE>503 Service Unavailable</TITLE></HEAD>\n" "<BODY><H1>503 Service Unavailable</H1>\n" "There are too many connections in use right now.\r\n" "Please try again later.\r\n</BODY></HTML>\n"; static int _body_len; static char *body_len; if (!_body_len) _body_len = strlen(body); if (!body_len) body_len = strdup(simple_itoa(_body_len)); SQUASH_KA(req); req->response_status = R_SERVICE_UNAV; if (!req->simple) { req_write(req, "HTTP/1.0 503 Service Unavailable\r\n"); print_http_headers(req); req_write(req, "Content-Length: "); req_write(req, body_len); req_write(req, "\r\nContent-Type: " HTML "\r\n\r\n"); /* terminate header */ } if (req->method != M_HEAD) { req_write(req, body); } req_flush(req); }
/** * Set an environment variable to an integer value * * @param varname Environment variable to set * @param value Value to set it to * @return 0 if ok, 1 on error */ int setenv_ulong(const char *varname, ulong value) { /* TODO: this should be unsigned */ char *str = simple_itoa(value); return setenv(varname, str); }
int main(int argc, char* argv[]) { int i; uint32_t t1, t2; const int max = 10000000; puts("FBSTP..."); t1 = get_time(); for (i=1; i < max; i++) { invoke_fbstp(i); } t2 = get_time(); printf("... %0.3f s\n", (t2 - t1)/1000000.0); puts("simple itoa..."); t1 = get_time(); for (i=1; i < max; i++) { simple_itoa(i); } t2 = get_time(); printf("... %0.3f s\n", (t2 - t1)/1000000.0); return 0; }
int do_tuna_get_bootmode(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { gpio_direction_input(30); int volup = !gpio_get_value(30); gpio_direction_input(8); int voldown = !gpio_get_value(8); tuna_bootmode = (voldown << 1) | volup; if (tuna_bootmode == BOOTMODE_NORMAL) { tuna_check_bootflag(); } #if defined(CONFIG_TWL6030_POWER) if (tuna_bootmode == BOOTMODE_POWEROFF) { twl6030_system_shutdown(); } #endif //reset bootmode flag to avoid getting stuck in the boot loop if (tuna_bootmode == BOOTMODE_RECOVERY || tuna_bootmode == BOOTMODE_USBDEBUG) { writel(REBOOT_FLAG_NORMAL, SAMSUNG_BOOTFLAG_ADDR); } setenv("tuna_bootmode_val", simple_itoa(tuna_bootmode)); return 0; }
void print_http_headers(request * req) { req_write(req, "Date: "); req_write_rfc822_time(req, 0); req_write(req, "\r\nServer: " SERVER_VERSION "\r\n"); if (req->keepalive == KA_ACTIVE) { req_write(req, "Connection: Keep-Alive\r\n" \ "Keep-Alive: timeout="); req_write(req, simple_itoa(ka_timeout)); req_write(req, ", max="); req_write(req, simple_itoa(ka_max)); req_write(req, "\r\n"); } else req_write(req, "Connection: close\r\n"); }
void create_common_env() { int index = 0, i; /* NOTE NOTE NOTE: If you (the reader) someday modify this chunk of code to handle more "common" CGI environment variables, then bump the value COMMON_CGI_COUNT in defines.h UP Also, in the case of document_root and server_admin, two variables that may or may not be defined depending on the way the server is configured, we check for null values and use an empty string to denote a NULL value to the environment, as per the specification. The quote for which follows: "In all cases, a missing environment variable is equivalent to a zero-length (NULL) value, and vice versa." */ common_cgi_env[index++] = env_gen_extra("PATH", ((cgi_path != NULL) ? cgi_path : DEFAULT_PATH), 0); common_cgi_env[index++] = env_gen_extra("SERVER_SOFTWARE", SERVER_VERSION, 0); common_cgi_env[index++] = env_gen_extra("SERVER_NAME", server_name, 0); common_cgi_env[index++] = env_gen_extra("GATEWAY_INTERFACE", CGI_VERSION, 0); common_cgi_env[index++] = env_gen_extra("SERVER_PORT", simple_itoa(server_port), 0); /* NCSA and APACHE added -- not in CGI spec */ /* common_cgi_env[index++] = env_gen_extra("DOCUMENT_ROOT", document_root); */ /* NCSA added */ /* common_cgi_env[index++] = env_gen_extra("SERVER_ROOT", server_root); */ /* APACHE added */ common_cgi_env[index++] = env_gen_extra("SERVER_ADMIN", server_admin, 0); common_cgi_env[index] = NULL; /* Sanity checking -- make *sure* the memory got allocated */ if (index > COMMON_CGI_COUNT) { log_error_time(); fprintf(stderr, "COMMON_CGI_COUNT not high enough.\n"); exit(1); } for(i = 0;i < index;++i) { if (common_cgi_env[i] == NULL) { log_error_time(); fprintf(stderr, "Unable to allocate a component of common_cgi_env - out of memory.\n"); exit(1); } } }
/** * Add all bootstage timings to a device tree. * * @param blob Device tree blob * @return 0 on success, != 0 on failure. */ static int add_bootstages_devicetree(struct fdt_header *blob) { struct bootstage_data *data = gd->bootstage; int bootstage; char buf[20]; int recnum; int i; if (!blob) return 0; /* * Create the node for bootstage. * The address of flat device tree is set up by the command bootm. */ bootstage = fdt_add_subnode(blob, 0, "bootstage"); if (bootstage < 0) return -EINVAL; /* * Insert the timings to the device tree in the reverse order so * that they can be printed in the Linux kernel in the right order. */ for (recnum = data->rec_count - 1, i = 0; recnum >= 0; recnum--, i++) { struct bootstage_record *rec = &data->record[recnum]; int node; if (rec->id != BOOTSTAGE_ID_AWAKE && rec->time_us == 0) continue; node = fdt_add_subnode(blob, bootstage, simple_itoa(i)); if (node < 0) break; /* add properties to the node. */ if (fdt_setprop_string(blob, node, "name", get_record_name(buf, sizeof(buf), rec))) return -EINVAL; /* Check if this is a 'mark' or 'accum' record */ if (fdt_setprop_cell(blob, node, rec->start_us ? "accum" : "mark", rec->time_us)) return -EINVAL; } return 0; }
int boa_atoi(char *s) { int retval; char *reconv; if (!isdigit(*s)) return -1; retval = atoi(s); if (retval < 0) return -1; reconv = simple_itoa(retval); if (memcmp(s,reconv,strlen(s)) != 0) { return -1; } return retval; }
void create_common_env() { int index = 0; common_cgi_env = (char **) malloc(sizeof(char *) * COMMON_CGI_VARS); common_cgi_env[index++] = env_gen("PATH", DEFAULT_PATH); common_cgi_env[index++] = env_gen("SERVER_SOFTWARE", SERVER_VERSION); common_cgi_env[index++] = env_gen("SERVER_NAME", server_name); common_cgi_env[index++] = env_gen("GATEWAY_INTERFACE", CGI_VERSION); common_cgi_env[index++] = env_gen("SERVER_PORT", simple_itoa(server_port)); /* NCSA and APACHE added -- not in CGI spec */ common_cgi_env[index++] = env_gen("DOCUMENT_ROOT", document_root); /* NCSA added */ common_cgi_env[index++] = env_gen("SERVER_ROOT", server_root); /* APACHE added */ common_cgi_env[index++] = env_gen("SERVER_ADMIN", server_admin); }
static int complete_env(request * req) #endif { #ifndef EXCLUDE_CGI int i; for (i = 0; common_cgi_env[i]; i++) req->cgi_env[i] = common_cgi_env[i]; { const char *w; switch (req->method) { case M_POST: w = "POST"; break; case M_HEAD: w = "HEAD"; break; case M_GET: w = "GET"; break; default: w = "UNKNOWN"; break; } my_add_cgi_env(req, "REQUEST_METHOD", w); } if (req->header_host) my_add_cgi_env(req, "HTTP_HOST", req->header_host); my_add_cgi_env(req, "SERVER_ADDR", req->local_ip_addr); my_add_cgi_env(req, "SERVER_PROTOCOL", http_ver_string(req->http_version)); my_add_cgi_env(req, "REQUEST_URI", req->request_uri); if (req->path_info) my_add_cgi_env(req, "PATH_INFO", req->path_info); if (req->path_translated) /* while path_translated depends on path_info, * there are cases when path_translated might * not exist when path_info does */ my_add_cgi_env(req, "PATH_TRANSLATED", req->path_translated); my_add_cgi_env(req, "SCRIPT_NAME", req->script_name); if (req->query_string) my_add_cgi_env(req, "QUERY_STRING", req->query_string); my_add_cgi_env(req, "REMOTE_ADDR", req->remote_ip_addr); my_add_cgi_env(req, "REMOTE_PORT", simple_itoa(req->remote_port)); if (req->method == M_POST) { if (req->content_type) { my_add_cgi_env(req, "CONTENT_TYPE", req->content_type); } else { my_add_cgi_env(req, "CONTENT_TYPE", default_type); } if (req->content_length) { my_add_cgi_env(req, "CONTENT_LENGTH", req->content_length); } } #ifdef ACCEPT_ON if (req->accept[0]) my_add_cgi_env(req, "HTTP_ACCEPT", req->accept); #endif if (req->cgi_env_index < CGI_ENV_MAX + 1) { req->cgi_env[req->cgi_env_index] = NULL; /* terminate */ return 1; } log_error_doc(req); fprintf(stderr, "Not enough space in CGI environment for remainder" " of variables.\n"); #endif //!EXCLUDE_CGI return 0; }
int init_get(request * req) { int data_fd, saved_errno; struct stat statbuf; volatile off_t bytes_free; data_fd = open(req->pathname, O_RDONLY|O_LARGEFILE); saved_errno = errno; /* might not get used */ while (use_lang_rewrite && data_fd == -1 && errno == ENOENT) { /* We cannot open that file - Check whether we can rewrite it * to a different language suffix. We only support filenames * of the format: "foo.ll.html" as an alias for "foo.html". */ unsigned int len; len = strlen(req->pathname); if (len < 6 || strcmp (req->pathname + len - 5, ".html")) break; /* does not end in ".html" */ if (len > 8 && req->pathname[len-8] == '.' && req->pathname[len-7] >= 'a' && req->pathname[len-7] <= 'z' && req->pathname[len-6] >= 'a' && req->pathname[len-6] <= 'z') { /* The request was for a language dependent file. Strip * it and try the generic form. */ char save_name[8]; strcpy (save_name, req->pathname + len - 7); strcpy (req->pathname + len - 7, "html"); data_fd = open(req->pathname, O_RDONLY); if (data_fd == -1) strcpy (req->pathname + len - 7, save_name); break; } else if ( 0 ) { /* Fixme: Other items to try from the list of accepted_languages */ data_fd = open(req->pathname, O_RDONLY); } else break; } #ifdef GUNZIP if (data_fd == -1 && errno == ENOENT) { /* cannot open */ /* it's either a gunzipped file or a directory */ char gzip_pathname[MAX_PATH_LENGTH]; unsigned int len; len = strlen(req->pathname); if (len + 4 > sizeof(gzip_pathname)) { log_error_doc(req); fprintf(stderr, "Pathname + .gz too long! (%s)\n", req->pathname); send_r_bad_request(req); return 0; } memcpy(gzip_pathname, req->pathname, len); memcpy(gzip_pathname + len, ".gz", 3); gzip_pathname[len + 3] = '\0'; data_fd = open(gzip_pathname, O_RDONLY|O_LARGEFILE); if (data_fd != -1) { close(data_fd); req->response_status = R_REQUEST_OK; if (req->pathname) free(req->pathname); req->pathname = strdup(gzip_pathname); if (!req->pathname) { boa_perror(req, "strdup req->pathname for gzipped filename " __FILE__ ":" STR(__LINE__)); return 0; } if (req->http_version != HTTP09) { req_write(req, http_ver_string(req->http_version)); req_write(req, " 200 OK-GUNZIP" CRLF); print_http_headers(req); print_content_type(req); print_last_modified(req); req_write(req, CRLF); req_flush(req); } if (req->method == M_HEAD) return 0; return init_cgi(req); } } #endif if (data_fd == -1) { log_error_doc(req); errno = saved_errno; perror("document open"); if (saved_errno == ENOENT) send_r_not_found(req); else if (saved_errno == EACCES) send_r_forbidden(req); else send_r_bad_request(req); return 0; } #ifdef ACCESS_CONTROL if (!access_allow(req->pathname)) { send_r_forbidden(req); return 0; } #endif fstat(data_fd, &statbuf); if (S_ISDIR(statbuf.st_mode)) { /* directory */ close(data_fd); /* close dir */ if (req->pathname[strlen(req->pathname) - 1] != '/') { char buffer[3 * MAX_PATH_LENGTH + 128]; unsigned int len; #ifdef ALLOW_LOCAL_REDIRECT len = strlen(req->request_uri); if (len + 2 > sizeof(buffer)) { send_r_error(req); return 0; } memcpy(buffer, req->request_uri, len); buffer[len] = '/'; buffer[len+1] = '\0'; #else char *host = server_name; unsigned int l2; char *port = NULL; const char *prefix = hsts_header? "https://" : "http://"; static unsigned int l3 = 0; static unsigned int l4 = 0; if (l4 == 0) { l4 = strlen(prefix); } len = strlen(req->request_uri); if (!port && server_port != 80 && !no_redirect_port) { port = strdup(simple_itoa(server_port)); if (port == NULL) { errno = ENOMEM; boa_perror(req, "Unable to perform simple_itoa conversion on server port!"); return 0; } l3 = strlen(port); } /* l3 and l4 are done */ if (req->host) { /* only shows up in vhost mode */ /* what about the port? (in vhost_mode?) */ /* we don't currently report ports that differ * from out "bound" (listening) port, so we don't care */ host = req->host; } l2 = strlen(host); if (server_port != 80 && !no_redirect_port) { if (l4 + l2 + 1 + l3 + len + 1 > sizeof(buffer)) { errno = ENOMEM; boa_perror(req, "buffer not large enough for directory redirect"); return 0; } memcpy(buffer, prefix, l4); memcpy(buffer + l4, host, l2); buffer[l4 + l2] = ':'; memcpy(buffer + l4 + l2 + 1, port, l3); memcpy(buffer + l4 + l2 + 1 + l3, req->request_uri, len); buffer[l4 + l2 + 1 + l3 + len] = '/'; buffer[l4 + l2 + 1 + l3 + len + 1] = '\0'; } else { if (l4 + l2 + len + 1 > sizeof(buffer)) { errno = ENOMEM; boa_perror(req, "buffer not large enough for directory redirect"); return 0; } memcpy(buffer, prefix, l4); memcpy(buffer + l4, host, l2); memcpy(buffer + l4 + l2, req->request_uri, len); buffer[l4 + l2 + len] = '/'; buffer[l4 + l2 + len + 1] = '\0'; } #endif /* ALLOW LOCAL REDIRECT */ send_r_moved_perm(req, buffer); return 0; } data_fd = get_dir(req, &statbuf); /* updates statbuf */ if (data_fd < 0) /* couldn't do it */ return 0; /* errors reported by get_dir */ else if (data_fd == 0 || data_fd == 1) return data_fd; /* else, data_fd contains the fd of the file... */ } if (!S_ISREG(statbuf.st_mode)) { /* regular file */ log_error_doc(req); fprintf(stderr, "Resulting file is not a regular file.\n"); send_r_bad_request(req); close(data_fd); return 0; } /* If-UnModified-Since asks * is the file newer than date located in time_cval * yes -> return 412 * no -> return 200 * * If-Modified-Since asks * is the file date less than or same as the date located in time_cval * yes -> return 304 * no -> return 200 * * If-Unmodified-Since overrides If-Modified-Since */ /* if (req->headers[H_IF_UNMODIFIED_SINCE] && modified_since(&(statbuf.st_mtime), req->headers[H_IF_UNMODIFIED_SINCE])) { send_r_precondition_failed(req); return 0; } else */ if (req->if_modified_since && !modified_since(&(statbuf.st_mtime), req->if_modified_since)) { send_r_not_modified(req); close(data_fd); return 0; } req->filesize = statbuf.st_size; req->last_modified = statbuf.st_mtime; /* ignore if-range without range */ if (req->header_ifrange && !req->ranges) req->header_ifrange = NULL; /* we don't support it yet */ req->header_ifrange = NULL; /* parse ranges now */ /* we have to wait until req->filesize exists to fix them up */ /* fixup handles handles communicating with the client */ /* ranges_fixup logs as appropriate, and sends * send_r_invalid_range on error. */ if (req->filesize == 0) { if (req->http_version < HTTP11) { send_r_request_ok(req); close(data_fd); return 0; } send_r_no_content(req); close(data_fd); return 0; } if (req->ranges && !ranges_fixup(req)) { close(data_fd); return 0; } /* if no range has been set, use default range */ #if 0 DEBUG(DEBUG_RANGE) { log_error_time(); fprintf(stderr, "if-range: %s\time_cval: %d\tmtime: %d\n", req->header_ifrange, req->time_cval, statbuf->st_mtime); } #endif /* If the entity tag given in the If-Range header matches the current entity tag for the entity, then the server should provide the specified sub-range of the entity using a 206 (Partial content) response. If the entity tag does not match, then the server should return the entire entity using a 200 (OK) response. */ /* IF we have range data *and* no if-range or if-range matches... */ #ifdef MAX_FILE_MMAP if (req->filesize > MAX_FILE_MMAP) { req->data_fd = data_fd; req->status = IOSHUFFLE; } else #endif { /* NOTE: I (Jon Nelson) tried performing a read(2) * into the output buffer provided the file data would * fit, before mmapping, and if successful, writing that * and stopping there -- all to avoid the cost * of a mmap. Oddly, it was *slower* in benchmarks. */ req->mmap_entry_var = find_mmap(data_fd, &statbuf); if (req->mmap_entry_var == NULL) { req->data_fd = data_fd; req->status = IOSHUFFLE; } else { req->data_mem = req->mmap_entry_var->mmap; close(data_fd); /* close data file */ } } if (!req->ranges) { req->ranges = range_pool_pop(); req->ranges->start = 0; req->ranges->stop = -1; if (!ranges_fixup(req)) { return 0; } send_r_request_ok(req); } else { /* FIXME: support if-range header here, by the following logic: * if !req->header_ifrange || st_mtime > header_ifrange, * send_r_partial_content * else * reset-ranges, etc... */ if (!req->header_ifrange) { send_r_partial_content(req); } else { /* either no if-range or the if-range does not match */ ranges_reset(req); req->ranges = range_pool_pop(); req->ranges->start = 0; req->ranges->stop = -1; if (!ranges_fixup(req)) { return 0; } send_r_request_ok(req); } } if (req->method == M_HEAD) { return complete_response(req); } bytes_free = 0; if (req->data_mem) { /* things can really go tilt if req->buffer_end > BUFFER_SIZE, * but basically that can't happen */ /* We lose statbuf here, so make sure response has been sent */ bytes_free = BUFFER_SIZE - req->buffer_end; /* 256 bytes for the **trailing** headers */ /* bytes is now how much the buffer can hold * after the headers */ } if (req->data_mem && bytes_free > 256) { unsigned int want; Range *r; r = req->ranges; want = (r->stop - r->start) + 1; if (bytes_free > want) bytes_free = want; else { /* bytes_free <= want */ ; } if (setjmp(env) == 0) { handle_sigbus = 1; memcpy(req->buffer + req->buffer_end, req->data_mem + r->start, bytes_free); handle_sigbus = 0; /* OK, SIGBUS **after** this point is very bad! */ } else { /* sigbus! */ log_error_doc(req); reset_output_buffer(req); send_r_error(req); log_error("Got SIGBUS in memcpy\n"); return 0; } req->buffer_end += bytes_free; req->bytes_written += bytes_free; r->start += bytes_free; if (bytes_free == want) { /* this will fit due to the 256 extra bytes_free */ return complete_response(req); } } /* We lose statbuf here, so make sure response has been sent */ return 1; }
int init_get2(request * req) { int data_fd; //Brad add begin for update content length char *content_length_orig1; char *content_length_orig2; int orig_char_length=0; int exact_char_length=0; int byte_shift=0; int exact_size=0; int total_length_shift=0; char *exact_content=NULL; int head_offset=0; int first_offset=0; int antecedent_segment=0; int subsequent_segment=0; //Brad add end for update content length #ifdef GUNZIP char buf[MAX_PATH_LENGTH]; #endif struct stat statbuf; SQUASH_KA(req); complete_env(req); middle_segment=0; req->cgi_env[req->cgi_env_index] = NULL; /* terminate cgi env */ if ((strstr(req->request_uri,".htm")==NULL) && (strstr(req->request_uri,".asp")==NULL)) { return 1; } data_fd = open(req->pathname, O_RDONLY); if (data_fd == -1) { /* cannot open */ #ifdef GUNZIP sprintf(buf, "%s.gz", req->pathname); data_fd = open(buf, O_RDONLY); if (data_fd == -1) { #endif int errno_save = errno; log_error_doc(req); errno = errno_save; #if 0 perror("document open"); #endif // syslog(LOG_ERR, "Error opening %s for %s: %s\n", req->pathname, // req->remote_ip_addr, strerror(errno_save)); errno = errno_save; if (errno == ENOENT) send_r_not_found(req); else if (errno == EACCES) send_r_forbidden(req); else send_r_bad_request(req); return 0; #ifdef GUNZIP } close(data_fd); req->response_status = R_REQUEST_OK; if (!req->simple) { req_write(req, "HTTP/1.0 200 OK-GUNZIP\r\n"); print_http_headers(req); print_content_type(req); print_last_modified(req); req_write(req, "\r\n"); req_flush(req); } if (req->method == M_HEAD) return 0; if (req->pathname) free(req->pathname); req->pathname = strdup(buf); return init_cgi(req); /* 1 - OK, 2 - die */ #endif } fstat(data_fd, &statbuf); if (S_ISDIR(statbuf.st_mode)) { close(data_fd); /* close dir */ if (req->pathname[strlen(req->pathname) - 1] != '/') { char buffer[3 * MAX_PATH_LENGTH + 128]; if (server_port != 80) sprintf(buffer, "http://%s:%d%s/", req->host?req->host:server_name, server_port, req->request_uri); else sprintf(buffer, "http://%s%s/", req->host?req->host:server_name, req->request_uri); send_redirect_perm(req, buffer); return 0; } data_fd = get_dir(req, &statbuf); /* updates statbuf */ if (data_fd == -1) { /* couldn't do it */ return 0; /* errors reported by get_dir */ } else if (data_fd == 0) { return 1; } } //start modify here : tony #if 0 if (req->if_modified_since && !modified_since(&(statbuf.st_mtime), req->if_modified_since)) { send_r_not_modified(req); close(data_fd); return 0; } #endif req->filesize = statbuf.st_size; // req->last_modified = statbuf.st_mtime; if (req->method == M_HEAD) { send_r_request_ok(req); close(data_fd); return 0; } /* MAP_OPTIONS: see compat.h */ req->data_mem = mmap(0, req->filesize, #ifdef USE_NLS PROT_READ|PROT_WRITE #else PROT_READ #endif , MAP_OPTIONS,data_fd, 0); close(data_fd); /* close data file */ if ((long) req->data_mem == -1) { boa_perror(req, "mmap"); return 0; } send_r_request_ok(req); /* All's well */ { //parse and send asp page char *left,*right,*last_right=req->data_mem; int bob; first_offset=req->buffer_end; //Brad add for update content length while (1) { left=strstr(last_right,"<%"); if (left!=NULL) right=strstr(left,"%>"); if ((left!=NULL) && (right!=NULL)) { bob=(unsigned int)left-(unsigned int)last_right; #ifdef SUPPORT_ASP while((bob+req->buffer_end+10)>(req->max_buffer_size)) { //Brad modify int ret; ret=allocNewBuffer(req); if (ret==-1) { bob=req->max_buffer_size- req->buffer_end; printf("will break\n"); break; } } #endif antecedent_segment =antecedent_segment+bob; //Brad add for update content length if (bob>=0) { memcpy(req->buffer + req->buffer_end, req->data_mem + req->filepos, bob); last_right=right+2; req->buffer_end += bob; req->filepos += (bob+(unsigned int)last_right-(unsigned int)left); handleScript(req,left,right); } } else { bob=(unsigned int)req->data_mem+req->filesize-(unsigned int)last_right; #ifdef SUPPORT_ASP while((bob+req->buffer_end+10)>req->max_buffer_size) { //Brad modify int ret; ret=allocNewBuffer(req); if (ret==-1) { bob=req->max_buffer_size- req->buffer_end; break; } } #endif subsequent_segment = subsequent_segment+bob; //Brad add for update content length if (bob > 0) { memcpy(req->buffer + req->buffer_end, req->data_mem + req->filepos, bob); req->buffer_end += bob; req->filepos += bob; } break; } } } //Brad add begin for update content length exact_content = req->buffer+first_offset; exact_size = antecedent_segment+middle_segment+subsequent_segment; //fprintf(stderr, "the exact total length of asp file=%d\n", exact_size); content_length_orig1 = strstr(req->buffer, "Content-Length:"); content_length_orig2 = strstr(content_length_orig1, "\r\n"); content_length_orig1 = content_length_orig1 + strlen("Content-Length: "); orig_char_length = content_length_orig2 - content_length_orig1; //fprintf(stderr, "the orig_char_length=%d\n", orig_char_length); exact_char_length = strlen(simple_itoa(exact_size)); //fprintf(stderr, "the exact_char_length=%d\n", exact_char_length); if(orig_char_length == exact_char_length) { //fprintf(stderr, "Update the content length with the same char length!\n"); memcpy(content_length_orig1, simple_itoa(exact_size),exact_char_length); }else if(orig_char_length < exact_char_length) { //fprintf(stderr, " Update the content length with shift to later bytes!\n"); byte_shift = exact_char_length - orig_char_length; head_offset = first_offset- (content_length_orig2 - req->buffer); total_length_shift = head_offset+exact_size; memmove((content_length_orig2+byte_shift), content_length_orig2, total_length_shift); memcpy(content_length_orig1, simple_itoa(exact_size),exact_char_length); req->buffer_end = req->buffer_end+byte_shift; }else { //fprintf(stderr, "Update the content length with shift to preceding bytes!\n"); byte_shift = orig_char_length - exact_char_length; head_offset = first_offset- (content_length_orig2 - req->buffer); total_length_shift = head_offset+exact_size; memmove((content_length_orig2-byte_shift), content_length_orig2, total_length_shift); memcpy(content_length_orig1, simple_itoa(exact_size),exact_char_length); req->buffer_end = req->buffer_end-byte_shift; } //Brad add end for update content length if (req->filepos == req->filesize) { // req->status = CLOSE; return 0; /* done! */ } /* We lose statbuf here, so make sure response has been sent */ return 1; }
void print_content_length(request * req) { req_write(req, "Content-Length: "); req_write(req, simple_itoa(req->filesize)); req_write(req, "\r\n"); }
void complete_env(request * req) { if (req->method == M_POST) { if (req->content_type) req->cgi_env[req->cgi_env_index++] = env_gen("CONTENT_TYPE", req->content_type); else req->cgi_env[req->cgi_env_index++] = env_gen("CONTENT_TYPE", default_type); if (req->content_length) { req->cgi_env[req->cgi_env_index++] = env_gen("CONTENT_LENGTH", req->content_length); } } /* if (req->accept[0]) { req->cgi_env[req->cgi_env_index++] = env_gen("HTTP_ACCEPT", req->accept); } */ req->cgi_env[req->cgi_env_index++] = env_gen("SERVER_PROTOCOL", req->http_version); if (req->path_info) { req->cgi_env[req->cgi_env_index++] = env_gen("PATH_INFO", req->path_info); /* path_translated depends upon path_info */ req->cgi_env[req->cgi_env_index++] = env_gen("PATH_TRANSLATED", req->path_translated); } if (req->script_name) { req->cgi_env[req->cgi_env_index++] = env_gen("SCRIPT_NAME", req->script_name); } if (req->query_string) { req->cgi_env[req->cgi_env_index++] = env_gen("QUERY_STRING", req->query_string); } #ifndef NO_COOKIES if (req->cookie) { req->cgi_env[req->cgi_env_index++] = env_gen("HTTP_COOKIE", req->cookie); req->cookie = NULL; } #endif req->cgi_env[req->cgi_env_index++] = env_gen("REMOTE_ADDR", req->remote_ip_addr); req->cgi_env[req->cgi_env_index++] = env_gen("REMOTE_PORT", simple_itoa(req->remote_port)); #ifndef NO_AGENT_LOG if (req->user_agent) req->cgi_env[req->cgi_env_index++] = env_gen("HTTP_USER_AGENT", req->user_agent); #endif #ifndef NO_REFERER_LOG if (req->referer) req->cgi_env[req->cgi_env_index++] = env_gen("HTTP_REFERER", req->referer); #endif #ifdef USE_NLS if (req->cp_name) req->cgi_env[req->cgi_env_index++] = env_gen("CLIENT_CODEPAGE", req->cp_name); #endif #ifdef USE_AUTH { if (*req->user != '\0') req->cgi_env[req->cgi_env_index++] = env_gen("REMOTE_USER", req->user); } #endif req->cgi_env[req->cgi_env_index] = NULL; /* terminate */ }
static int do_update_sdcard(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { //struct update_sdcard_device *fd = f_devices; //struct update_sdcard_part *fp; //struct list_head *entry, *n; char *p; unsigned long addr; unsigned long time; int i = 0; int res = 0; int len_read = 0; int err = 0; if (argc != 5) { printf("## [%s():%d] ret_error \n", __func__,__LINE__); goto ret_error; } memset(f_sdcard_part, 0x0, sizeof(f_sdcard_part)*UPDATE_SDCARD_DEV_PART_MAX); len_read = update_sd_do_load(cmdtp, flag, argc, argv, FS_TYPE_FAT, 16); if(len_read > 0) { fboot_lcd_start(); // partition map parse addr = simple_strtoul(argv[3], NULL, 16); p = (char*)addr; p[len_read+1] = '\0'; update_sdcard_sort_string((char*)p, len_read); setenv("fastboot", (char *)p); saveenv(); err = update_sdcard_part_lists_make(p, strlen(p)); if (err >= 0) { struct update_sdcard_part *fp = f_sdcard_part; update_sdcard_part_lists_print(); printf("\n"); for(i=0; i<UPDATE_SDCARD_DEV_PART_MAX; i++, fp++) { if(!strcmp(fp->device, "")) break; if (!strcmp(fp->file_name, "dummy")) continue; if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, FS_TYPE_FAT)) { printf("## [%s():%d] ret_error \n", __func__,__LINE__); goto ret_error; } printf("=============================================================\n"); fboot_lcd_flash((char*)fp->file_name, "reading "); time = get_timer(0); len_read = fs_read(fp->file_name, addr, 0, 0); time = get_timer(time); printf("%d bytes read in %lu ms", len_read, time); if (time > 0) { puts(" ("); print_size(len_read / time * 1000, "/s"); puts(")"); } puts("\n"); debug(" %s.%d : %s : %s : 0x%llx, 0x%llx : %s\n", fp->device, fp->dev_no, fp->partition_name, UPDATE_SDCARD_FS_MASK&fp->fs_type?"fs":"img", fp->start, fp->length, fp->file_name); if( 0 >= len_read) continue; fboot_lcd_flash((char*)fp->file_name, "flashing "); { block_dev_desc_t *desc; char cmd[128]; int i = 0, l = 0, p = 0; char *device = fp->device; char *partition_name = fp->partition_name; char *file_name = fp->file_name; uint64_t start = fp->start; uint64_t length = fp->length; int dev = fp->dev_no; unsigned int fs_type = fp->fs_type; int part_num = fp->part_num; //lbaint_t blk, cnt; //int blk_size = 512; length=len_read; memset(cmd, 0x0, sizeof(cmd)); if (!strcmp(device, "eeprom")) { p = sprintf(cmd, "update_eeprom "); if (fs_type & UPDATE_SDCARD_FS_BOOT) l = sprintf(&cmd[p], "%s", "uboot"); else if (fs_type & UPDATE_SDCARD_FS_2NDBOOT) l = sprintf(&cmd[p], "%s", "2ndboot"); else l = sprintf(&cmd[p], "%s", "raw"); p += l; l = sprintf(&cmd[p], " 0x%x 0x%llx 0x%llx", (unsigned int)addr, start, length); p += l; cmd[p] = 0; debug("%s\n", cmd); if(0 > run_command(cmd, 0)) printf("Flash : %s - %s\n", file_name, "FAIL"); else printf("Flash : %s - %s\n", file_name, "DONE"); } else if (!strcmp(device, "mmc")) { sprintf(cmd, "mmc dev %d", dev); //printf("** mmc.%d partition %s (%s)**\n", // dev, partition_name, fs_type&UPDATE_SDCARD_FS_EXT4?"FS":"Image"); /* set mmc devicee */ if (0 > get_device("mmc", simple_itoa(dev), &desc)) { if (0 > run_command(cmd, 0)) { printf("## [%s():%d] ret_error \n", __func__,__LINE__); goto ret_error; } if (0 > run_command("mmc rescan", 0)) { printf("## [%s():%d] ret_error \n", __func__,__LINE__); goto ret_error; } } if (0 > run_command(cmd, 0)) /* mmc device */ { printf("## [%s():%d] ret_error \n", __func__,__LINE__); goto ret_error; } if (0 > get_device("mmc", simple_itoa(dev), &desc)) { printf("## [%s():%d] ret_error \n", __func__,__LINE__); goto ret_error; } memset(cmd, 0x0, sizeof(cmd)); if (fs_type == UPDATE_SDCARD_FS_2NDBOOT || fs_type == UPDATE_SDCARD_FS_BOOT) { if (fs_type == UPDATE_SDCARD_FS_2NDBOOT) p = sprintf(cmd, "update_mmc %d 2ndboot", dev); else p = sprintf(cmd, "update_mmc %d boot", dev); l = sprintf(&cmd[p], " 0x%x 0x%llx 0x%llx", (unsigned int)addr, start, length); p += l; cmd[p] = 0; } else if (fs_type & UPDATE_SDCARD_FS_MASK) { if (update_sdcard_mmc_check_part_table(desc, fp) > 0) { struct update_sdcard_part *fp_1 = fp; int j, cnt=0; uint64_t part_start[UPDATE_SDCARD_DEV_PART_MAX]; uint64_t part_length[UPDATE_SDCARD_DEV_PART_MAX]; char args[128]; printf("Warn : [%s] make new partitions ....\n", partition_name); for (j=i; j<UPDATE_SDCARD_DEV_PART_MAX; j++, fp_1++) { if(!strcmp(fp_1->device, "")) break; part_start[cnt] = fp_1->start; part_length[cnt] = fp_1->length; cnt++; } l = sprintf(args, "fdisk %d %d:", dev, cnt); p = l; for (j= 0; j < cnt; j++) { l = sprintf(&args[p], " 0x%llx:0x%llx", part_start[j], part_length[j]); p += l; } args[p] = 0; printf("%s\n", args); if(0 > run_command(args, 0)) printf("fdisk : %s\n", "FAIL"); else printf("fdisk : %s\n", "DONE"); } //blk = fp->start/blk_size ; //cnt = (length/blk_size) + ((length & (blk_size-1)) ? 1 : 0); //p = sprintf(cmd, "mmc write %x %x %x", addr, blk, cnt); p = sprintf(cmd, "update_mmc %d part %x %d %x", dev, (unsigned int)addr, part_num, (unsigned int)length); } printf("%s\n", cmd); if(0 > run_command(cmd, 0)) printf("Flash : %s - %s\n", file_name, "FAIL"); else printf("Flash : %s - %s\n", file_name, "DONE"); } } } printf("=============================================================\n"); } else { printf("## [%s():%d] ret_error \n", __func__,__LINE__); goto ret_error; } } else { printf("## [%s():%d] ret_error \n", __func__,__LINE__); goto ret_error; } fboot_lcd_status("exit"); while (1) { if (ctrlc()) { printf("update_sdcard end\n\n"); break; } } //fboot_lcd_stop(); //do_reset (NULL, 0, 0, NULL); return res; ret_error: fboot_lcd_stop(); return -1; }