static void errorTryLoadText(MemBuf * text, char *path) { int fd; struct stat sb; // char *text = NULL; //snprintf(path, sizeof(path), "%s/%s", dir, page_name); #ifdef _SQUID_MSWIN_ fd = open(path, O_RDONLY | O_BINARY); #else fd = open(path, O_RDONLY | O_TEXT); #endif if (fd < 0 || fstat(fd, &sb) < 0) { debug(115, 0) ("mod_customized_server_side_error_page errorTryLoadText: '%s': %s\n", path, xstrerror()); if (fd >= 0) file_close(fd); //return NULL; memBufInit(text, 1*sizeof(char), 1*sizeof(char)); memBufPrintf(text, "%s", ""); } else { memBufInit(text, (size_t)sb.st_size+2+1, (size_t)sb.st_size+2+1); if (read(fd, text->buf, (int) sb.st_size) != sb.st_size) { debug(115,0) ("mod_customized_server_side_error_page errorTryLoadText: failed to fully read: '%s': %s\n", path, xstrerror()); memBufClean(text); } text->size += sb.st_size; text->buf[text->size] = '\0'; debug(115,4)("mod_customized_server_side_error_page errorTryLoadText: the path is: %s point before end and text is: %s.....\n", path,text->buf); close(fd); } #ifndef CC_FRAMEWORK if (NULL != text->buf && strstr(text->buf, "%s") == NULL) memBufAppend(text,"%S", strlen("%S")); /* add signature */ #endif }
static void idnsSendTcpQuery(int fd, int status, void *data) { MemBuf buf; idns_query *q = data; short nsz; if (status != COMM_OK) { int ns = (q->nsends - 1) % nns; debug(78, 1) ("idnsSendTcpQuery: Failed to connect to DNS server %d using TCP\n", ns + 1); idnsTcpCleanup(q); return; } memBufInit(&buf, q->sz + 2, q->sz + 2); nsz = htons(q->sz); memBufAppend(&buf, &nsz, 2); memBufAppend(&buf, q->buf, q->sz); comm_write_mbuf(q->tcp_socket, buf, idnsSendTcpQueryDone, q); }
static int clientHandleErrorPage(clientHttpRequest *http) { debug(115, 4)("mod_customized_server_side_error_page clientHandleErrorPage\n"); request_t *request = http->request; int fd = http->conn->fd; if(fd_table[fd].cc_run_state[mod->slot] > 0) { error_page_private_data* pd=NULL; pd = error_page_private_data_pool_alloc(); mod_config* cfg = (mod_config*)cc_get_mod_param(fd,mod); pd->OfflineTimeToLive= cfg->OfflineTimeToLive; pd->TimeToTrigger = squid_curtime + cfg->TriggerTimeSec; pd->ResponseStatus = cfg->ResponseStatus; pd->recusive_time = 0; pd->old_status = 0; strncpy(pd->OptionalHttpStatusPattern,cfg->OptionalHttpStatusPattern, strlen(cfg->OptionalHttpStatusPattern)); cc_register_mod_private_data(REQUEST_PRIVATE_DATA,http, pd, free_error_page_private_data ,mod); //int *timeout = timeout_pool_alloc(); //*timeout = cfg->TriggerTimeSec; //debug(115,4)("clientHandleErrorPage: the timeout before register mod private data is: %d \n ",*timeout); //cc_register_mod_private_data(FDE_PRIVATE_DATA,&fd, timeout,free_timeout,mod); // add by xueye.zhao // 2013-4-18 if (!is_http_move_status(cfg->ResponseStatus)) { MemBuf * text = text_mb_pool_alloc(); memBufInit(text, cfg->customized_error_text.size+1, cfg->customized_error_text.size+1); memBufAppend(text, cfg->customized_error_text.buf, cfg->customized_error_text.size); debug(115,4)("mod_customized_server_side_error_page clientHanleErrorPage :before cc_register_mod_private_data and the request is: %p\n",request); cc_register_mod_private_data(REQUEST_T_PRIVATE_DATA,request,text,free_data,mod); } //end add } return 0; }
/* init with defaults */ void memBufDefInit(MemBuf * mb) { memBufInit(mb, MEM_BUF_INIT_SIZE, MEM_BUF_MAX_SIZE); }