Esempio n. 1
0
static int func_http_repl_send_start(clientHttpRequest *http)
{
	assert(http);
    if (0 == http->request->flags.redirected)
        return -1;

    HttpHeader *hdr = &http->reply->header;
    HttpHeaderEntry e;
    stringInit(&e.name,"Content-Disposition");
    stringInit(&e.value,"attachment; filename=\"");

    char *filename = strrchr(http->uri, '/');
    if (NULL == filename)
        return -1;
    filename++;
    stringAppend(&e.value, filename, strlen(filename));
    stringAppend(&e.value, "\"", 1);

    e.id = HDR_CONTENT_DISPOSITION;
    httpHeaderDelById(hdr, e.id);  
    httpHeaderAddEntry(hdr, httpHeaderEntryClone(&e));
    stringClean(&e.name);
    stringClean(&e.value);
	return 0;
}
Esempio n. 2
0
/*
 *This line is to modify the header
 */
static int mod_modify_s2o_header(HttpStateData* data, HttpHeader* hdr)
{
	assert(data);
	int fd = data->fd;
	int i, len;

	struct mod_conf_param *param = (struct mod_conf_param *)cc_get_mod_param(fd, mod);
	assert(param);

	debug(107, 3)("param->orig_name=%s, param->new_name=%s\n", strBuf(param->orig_name), strBuf(param->new_name));
	HttpHeaderPos pos = HttpHeaderInitPos;
	HttpHeaderEntry *myheader;
	HttpHeaderEntry e;

	while ((myheader = httpHeaderGetEntry(hdr, &pos)))
	{
		debug(107, 3)("myheader=%s, param->new_name=%s\n", strBuf(myheader->name), strBuf(param->new_name));
		if (strCaseCmp(myheader->name, strBuf(param->orig_name)) == 0)
		{
			debug(107, 3)("%s is myheader->value,%s is param->orig_name\n",strBuf(myheader->value), strBuf(param->orig_name));

			if(strLen(myheader->value) >= 4095)
			{
				debug(107, 3)("A too long header value!!\n");
				return -1;
			}

			stringInit(&e.name, strBuf(param->new_name));
			stringInit(&e.value, myheader->value.buf);
			len=strlen(strBuf(e.name));
			i=httpHeaderIdByNameDef(strBuf(e.name), len);
			if(-1 == i)
				e.id = HDR_OTHER;
			else    
				e.id = i;
			httpHeaderDelByName(hdr, strBuf(param->orig_name));
			httpHeaderAddEntry(hdr, httpHeaderEntryClone(&e));
			//httpHeaderDelAt(&request->header, pos);
			//httpHeaderRefreshMask(&request->header);
			//httpHeaderInsertEntry(&request->header, httpHeaderEntryClone(&e), pos);
			stringClean(&e.name);
			stringClean(&e.value);			
			break;
		}
	}
	return 0;

}
Esempio n. 3
0
void
httpReplySetHeaders(HttpReply * reply, http_version_t ver, http_status status, const char *reason,
    const char *ctype, squid_off_t clen, time_t lmt, time_t expires)
{
    HttpHeader *hdr;
    assert(reply);
    httpStatusLineSet(&reply->sline, ver, status, reason);
    hdr = &reply->header;
    httpHeaderPutStr(hdr, HDR_SERVER, full_appname_string);
    httpHeaderPutStr(hdr, HDR_MIME_VERSION, "1.0");
    httpHeaderPutTime(hdr, HDR_DATE, squid_curtime);
    if (ctype) {
	httpHeaderPutStr(hdr, HDR_CONTENT_TYPE, ctype);
	stringInit(&reply->content_type, ctype);
    } else
	reply->content_type = StringNull;
    if (clen >= 0)
	httpHeaderPutSize(hdr, HDR_CONTENT_LENGTH, clen);
    if (expires >= 0)
	httpHeaderPutTime(hdr, HDR_EXPIRES, expires);
    if (lmt > 0)		/* this used to be lmt != 0 @?@ */
	httpHeaderPutTime(hdr, HDR_LAST_MODIFIED, lmt);
    reply->date = squid_curtime;
    reply->content_length = clen;
    reply->expires = expires;
    reply->last_modified = lmt;
}
HttpHeaderFieldInfo *
httpHeaderBuildFieldsInfo(const HttpHeaderFieldAttrs * attrs, int count)
{
    int i;
    HttpHeaderFieldInfo *table = NULL;
    assert(attrs && count);

    /* allocate space */
    table = xcalloc(count, sizeof(HttpHeaderFieldInfo));

    for (i = 0; i < count; ++i) {
	const int id = attrs[i].id;
	HttpHeaderFieldInfo *info = table + id;
	/* sanity checks */
	assert(id >= 0 && id < count);
	assert(attrs[i].name);
	assert(info->id == 0 && info->type == 0);	/* was not set before */
	/* copy and init fields */
	info->id = id;
	info->type = attrs[i].type;
	stringInit(&info->name, attrs[i].name);
	assert(strLen(info->name));
	/* init stats */
	memset(&info->stat, 0, sizeof(info->stat));
    }
    return table;
}
Esempio n. 5
0
static HttpHeaderEntry *
httpHeaderEntryCreate(http_hdr_type id, const char *name, const char *value)
{
    HttpHeaderEntry *e;
    assert_eid(id);
    e = memAllocate(MEM_HTTP_HDR_ENTRY);
    e->id = id;
    if (id != HDR_OTHER)
	e->name = Headers[id].name;
    else
	stringInit(&e->name, name);
    stringInit(&e->value, value);
    Headers[id].stat.aliveCount++;
    debug(55, 9) ("created entry %p: '%s: %s'\n", e, strBuf(e->name), strBuf(e->value));
    return e;
}
Esempio n. 6
0
File: parser.cpp Progetto: wfwt/jszb
static Stmt *parseStmt(Parser *p)
{
	String id;
	
	assert(p->tok == TK_ID);
	if (stringInit(&id, p->toklen))
		return 0;
	stringAdd(&id, p->tokval, p->toklen);
	
	p->tok = lexerGetToken(p->lex, &p->tokval, &p->toklen);
	if (p->tok == TK_COLON_EQ || p->tok == TK_COLON) {
		enum Token op = p->tok;
		p->tok = lexerGetToken(p->lex, &p->tokval, &p->toklen);
		Node *expr = parseExpr(p);
		if (expr) {
			if (p->tok == TK_SEMICOLON) {
#ifdef LOG_PARSE
				info("解析得到stmt\n");
#endif
				return stmtNew(&id, op, expr);
			} else {
				handleParserError(p, 0, "解析stmt,缺少;");
			}
		}
	} else {
		handleParserError(p, 1, "解析stmt,不识别符号,只能是:=或者:");
	}
	
	stringFree(&id);
	return 0;
}
Esempio n. 7
0
File: parser.cpp Progetto: wfwt/jszb
static Node *parseIdOrFuncCall(Parser *p)
{
	Node *expr = 0;
	String id;
	stringInit(&id, p->toklen);
	stringAdd(&id, p->tokval, p->toklen);
	
	p->tok = lexerGetToken(p->lex, &p->tokval, &p->toklen);
	if (p->tok == TK_LP) { // (
		ExprList *arg;
		p->tok = lexerGetToken(p->lex, &p->tokval, &p->toklen);
		arg = parseExprList(p);
		if (p->tok == TK_RP) {
#ifdef LOG_PARSE
			info("解析得到FuncCall\n");
#endif
			expr = (Node *)funcCallNew(&id, arg);
			p->tok = lexerGetToken(p->lex, &p->tokval, &p->toklen);
		} else {
			handleParserError(p, 1, "解析FuncCall,缺少)");
		}
	} else {
#ifdef LOG_PARSE
		info("解析得到IdExpr\n");
#endif
		expr = (Node *)idExprNew(&id);
	}
	return expr;
}
Esempio n. 8
0
int main(int argc, char *argv[])
{
    int ret;

    ret = open_File(argc, argv);
    if (ret != 0)
        return E_INTERN;

    //init symbol table
    symbol_table = table_init(DEFAULT_TABLE_SIZE);
    if (symbol_table == NULL) {
        close_File();
        return E_INTERN;
    }

    //init token (init string in token)
    ret = stringInit(&token.attr.lit_string_or_id);
    if (ret != STR_OPERATION_OK) {
        close_File();
        table_destroy(symbol_table);
        return E_INTERN;
    }

    //init instruction list
    instr_list_init(&instruction_list);

    //call parser
    ret = parse();
    if (ret != E_OK) {
#ifdef DEBUG
        fprintf(stderr, "PARSE ERROR %d\n", ret);
#endif
        instr_list_dispose(&instruction_list);
        stringFree(&token.attr.lit_string_or_id);
        table_destroy(symbol_table);
        close_File();
        return ret;
    }
#ifdef DEBUG
    fprintf(stderr, "PARSE OK\n");
#endif
    
    //call interpreter
    ret = interpret();
    if (ret != E_OK) {
#ifdef DEBUG
        fprintf(stderr, "INTERPRET ERROR %d\n", ret);
#endif
    } else {
#ifdef DEBUG
        fprintf(stderr, "INTERPRET OK\n");
#endif
    }
    
    instr_list_dispose(&instruction_list);
    stringFree(&token.attr.lit_string_or_id);
    table_destroy(symbol_table);
    close_File();
    return ret;
}
Esempio n. 9
0
/* initialize peer digest */
static void
peerDigestInit(PeerDigest * pd, peer * p)
{
    assert(pd && p);

    memset(pd, 0, sizeof(*pd));
    pd->peer = p;
    /* if peer disappears, we will know it's name */
    stringInit(&pd->host, p->host);

    pd->times.initialized = squid_curtime;
}
Esempio n. 10
0
/* return a string or list of entries with the same id separated by ',' and ws */
String
httpHeaderGetStrOrList(const HttpHeader * hdr, http_hdr_type id)
{
    HttpHeaderEntry *e;

    if (CBIT_TEST(ListHeadersMask, id))
	return httpHeaderGetList(hdr, id);
    if ((e = httpHeaderFindEntry(hdr, id))) {
	String s;
	stringInit(&s, strBuf(e->value));
	return s;
    }
    return StringNull;
}
Esempio n. 11
0
// A function to get keyboard input.
// This function will validate the input before returning as string.
// Require dispose to be done after use.
string scanString(int Type)
{
	int appendIndex = 0;
	char currentInputChar;
	string tempString = stringInit(CMD_MAX + 1);

	if (Type == 0)
	{
		// Default scanf.
		scanf("%s", tempString);
		fflush(stdin);
	}
	else if (Type == 1)
	{
		// Scan only one line.
		scanf("%[^\n]", tempString);
		fflush(stdin);
	}
	else if (Type == 2)
	{
		// Password.
		do
		{
			currentInputChar = getch();

			if (isalnum(currentInputChar))
			{
				printf("*");
				tempString[appendIndex] = currentInputChar;
				appendIndex++;
			}
			else if (currentInputChar == '\r' || currentInputChar == '\n')
				break;
		} while (appendIndex < CMD_MAX);

		tempString[appendIndex] = '\0';
	}

	return tempString;
}
Esempio n. 12
0
/*if the origindomain doesn't need cookie,this part is not neccessary 
 *
static int update_cookie_direction_0(clientHttpRequest *http)
{
	assert(http);
	assert(http->request);

	const char head_name_request[20] = "Cookie";
	int len = strlen(head_name_request);
	int flag = 0;
	HttpHeaderPos pos = HttpHeaderInitPos;

	request_t* request = http->request;

	char *uri = http->uri;
	char cookie_value[100]="0";
	
	char cookie_primary_key_name[20];
	char cookie_sub_key_name[20];
	int i = 0;

	debug(139,3)("in update_cookie_direction_0 receive uri %s\n",uri);

	HttpHeaderEntry e;
	HttpHeaderEntry *myheader;

	stringInit(&e.name, head_name_request);
	i = httpHeaderIdByNameDef(head_name_request, len);
	e.id = i;
	if (-1 == i)
		e.id = HDR_OTHER; 
	while ((myheader = httpHeaderGetEntry(&request->header, &pos))) 
	{
		if (strCaseCmp(myheader->name, head_name_request) == 0)
		{
			debug(139, 3)("%s is myheader->value,%s is name\n",myheader->value.buf,myheader->name.buf);
			flag = 1;
		}
	}

	debug(139,3)("flag=%d\n",flag);
	if(!flag)
	{
		if(0 == get_param_from_uri(uri,cookie_primary_key_name,cookie_sub_key_name))
		{
			return 1;
		}
		to_upper(cookie_primary_key_name);
		snprintf(cookie_value,100,"%s:(FM%s=0)",cookie_primary_key_name,cookie_sub_key_name);
		debug(139,3)("cookie value is %s\n",cookie_value);
		debug(139,3)("cookie_primary_key_name is %s\n",cookie_primary_key_name);
		debug(139,3)("cookie_sub_key_name is %s\n",cookie_sub_key_name);
		stringInit(&e.value, cookie_value);
		httpHeaderAddEntry(&request->header, httpHeaderEntryClone(&e));
	}
	return 1;
}
*/
static int update_cookie_direction_3(clientHttpRequest *http)
{
	assert(http);
	assert(http->request);

//	const char head_name_request[20] = "Cookie";
	const char head_name_reply[20] = "Set-Cookie";
//	int len = strlen(head_name_reply);
//	int flag = 0;
//	HttpHeaderPos pos = HttpHeaderInitPos;

//	request_t* request = http->request;
	HttpReply* reply = http->reply; 

	char *uri = http->uri;
//	char cookie_value[MAX_NAME_SIZE] = "0";
//	char cookie_value_from_url[MAX_NAME_SIZE] = "0 ";
	char cookie_primary_key_name[MAX_NAME_SIZE] = "0";
	char cookie_sub_key_name[MAX_NAME_SIZE] = "0";
	char cookie_file_name[MAX_NAME_SIZE] = "0";

	debug(139,3)("in update_cookie_direction_3 receive uri %s\n",uri);

	HttpHeaderEntry e;
//	HttpHeaderEntry *myheader;

	stringInit(&e.name, head_name_reply);
//	i = httpHeaderIdByNameDef(head_name_reply, len);
//	e.id = i;
	e.id = HDR_SET_COOKIE;
//	if (-1 == i)
//		e.id = HDR_OTHER; 
	/*
	while ((myheader = httpHeaderGetEntry(&request->header, &pos))) 
	{
		if (strCaseCmp(myheader->name, head_name_request) == 0)
		{
			debug(139, 3)("%s is myheader->value,%s is name\n",myheader->value.buf,myheader->name.buf);
			flag = 1;
			strcpy(cookie_value,myheader->value.buf);
			debug(139,5)("cookie_value =%s\n",cookie_value);
			if(0 == deal_with_cookie(cookie_value))
			{
				debug(139,3)("Cookie format is wrong\n");
				return 0;
			}
			if(0 == get_param_from_uri(uri,cookie_primary_key_name,cookie_sub_key_name))
			{
				debug(139,3)("get_param_from_uri error\n");
				return 0;
			}
			to_upper(cookie_primary_key_name);
			snprintf(cookie_value_from_url,100,"%s:(FM%s=",cookie_primary_key_name,cookie_sub_key_name);
			debug(139,5)("cookie_value_from_url is %s\n",cookie_value_from_url);
			if(strncmp(cookie_value,cookie_value_from_url,strlen(cookie_value_from_url)))
			{
				debug(139,3)("get_param_from_uri cookie_value_from_url doesn't match cookie_value\n");
				return 0;
			}

		}
	}
	*/

	if(reply->sline.status >= HTTP_OK && reply->sline.status < HTTP_BAD_REQUEST )
	{
		if(0 == get_param_from_uri(uri,cookie_primary_key_name,cookie_sub_key_name,cookie_file_name))
		{
			debug(139,3)("get_param_from_uri error\n");
			stringClean(&e.name);
			return 0;
		}
		struct tm *ptr;  
		ptr = gmtime(&reply->expires);  

		debug(139,3)("expires = %s\n", asctime(ptr));

		char tmpbuf[128];
		char cookie_value[MAX_HEADER_SIZE];

		strftime( tmpbuf, 128, "%a, %d %b %G %T GMT \n", ptr); 
		debug(139,3)("expires = %s\n", tmpbuf);
		snprintf(cookie_value,MAX_HEADER_SIZE,"DTAG=CAM=%s&LOC=%s&CRT=%s; expires=%s; path=/",cookie_primary_key_name,cookie_sub_key_name,cookie_file_name,tmpbuf);
		
		debug(139,5)("cookie value is %s\n",cookie_value);
		stringInit(&e.value, cookie_value);
		httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e));
		stringClean(&e.value);
	}
	else
	{
		;//do nothing
	}
	stringClean(&e.name);


	return 1;
}
/****************************************************************************
* Menu option #4: Stemming Report
* Creates an external file with statistics of all words in the index that
* have common suffixes.
****************************************************************************/
void stemmingReport(IndexType* index)
{
  FILE *fp;
  WordTypePtr node;
  char filename[FILENAME_MAX];
  String stem;
  char c;
  char buffer[BUFFSIZE];
  char* longestword;

  unsigned int nodelength;



  printf("\nStemming Report\n");
  printf("---------------\n");


  getString(filename,FILENAME_MAX,0,"Enter name of a suffixes file:");
  /*if they enter no file name cancel to the main menu*/
  if(strlen(filename)==0)
  {
    printf("\nStemm report cancelled. Returning to main menu.\n");
    return;
  }

  /*open the file*/
  fp=fopen(filename,"r");
  if(fp==NULL)
  {
    printf("\n Failed to read %s file!\n",filename);
    return;
  }

   stringInit(&stem);

  /*reserve space for longest word*/
  longestword=malloc(strlen(index->longestWord->word)*sizeof(char));


  /*speed up*/
  setvbuf(fp,buffer,_IOFBF,BUFFSIZE);

  printf("\nResults:\n\n");

  /*loop through all nodes*/
  node=index->headWord;
  while(node!=NULL)
  {
    /*printf("node is %s\n",node->word);*/
    nodelength=strlen(node->word);

    /*loop through all stem words*/
    fseek(fp,0,0);
    while((c=fgetc(fp))!=EOF)
    {
      /*next stem words is ready*/
      if(c=='\n')
      {
        /*if the stem word is larger than the node word skip the node*/
        if(stem.offset>nodelength)
        {
          stringClear(&stem);
          continue;
        }
        /*check if the node word containts the stem word*/
        if(strcmp(stem.contents,node->word+nodelength-stem.offset)==0)
        {
          /*get the base word and null terminate*/
          strncpy(longestword,node->word,nodelength-stem.offset);
          *(longestword+nodelength-stem.offset)='\0';
          /*display the node and the stem prefix*/
          printf("%s %s\n",node->word,longestword);
        }
        stringClear(&stem);
      }
      /*keep building the stem word*/
      else
        stringAddChar(&stem,c);
    }
    node=node->nextWord;
  }
  fclose(fp);
  free(longestword);
  stringFree(&stem);
}
Esempio n. 14
0
// confige line example:
// mod_header [direction add|del|modify header_name [header_value]]{1,..n} allow|deny acl
// ??????ͷ??ʼ?????? allow|deny ??ֹ
// ????????????
static int func_sys_parse_param(char *cfg_line)
{
	assert(cfg_line);

	struct mod_conf_param* data = NULL;
	char* token = NULL;
	int ret = 0;
	int i;
	
	// add by xueye.zhao
	// 2013/6/19
	
# if 0
	//?ҵ?allow????deny?? Ȼ????֮???Ľ?ȥ
	//zhoudshu add for bug mantis 0002002

	char* tmptoken = NULL;
	char* tmp_line = xstrdup(cfg_line);
	if ((tmptoken = strtok(tmp_line, w_space)) == NULL)
	{	
		debug(98, 3)("(mod_header) ->  parse line error\n");
		safe_free(tmp_line);
		return -1;
	
	}

	int haskey = 0;
	while(NULL != (tmptoken = strtok(NULL, w_space)))
	{
		if(strcmp("allow",tmptoken) == 0 || strcmp("deny",tmptoken) == 0){
			haskey = 1;
		}
	}

	safe_free(tmp_line);
	
	if(haskey != 1){
		debug(98, 3)("(mod_header) ->  has not key of allow or deny in config line \n");
		return -1;
	}	

#endif
	

	if (NULL == strstr(cfg_line, " allow "))
	{
		debug(98, 3)("(mod_header) ->  has not key of allow or deny in config line \n");
		return -1;
	}
	
	//end add

	//开始截取	
	if ((token = strtok(cfg_line, w_space)) != NULL)
	{
		if(strcmp(token, "mod_header"))
			goto errA;	
	}
	else
	{
		debug(98, 3)("(mod_header) ->  parse line error\n");
		goto errA;	
	}

	data = mod_config_pool_alloc();
	data->count = 0;
	//?????↑ʼѭ??ȡ??????..???Dz???+header+value?ķ?ʽ, ????,ѭ????????
	while(NULL != (token = strtok(NULL, w_space)))
	{
		if(strcmp("allow",token) == 0 || strcmp("deny",token) == 0 || strcmp("reply_check",token) == 0) {
			break;
		}	

		struct action_part* part;
		struct header_info* info;
		part = action_part_pool_alloc();
		info = header_info_pool_alloc();
		data->acp[data->count] = part;
		data->acp[data->count]->hdr = info;
		data->count++;
		
		part->direct = atoi(token); //fetch the direction

		if(part->direct > 3 || part->direct < 0)
		{
			debug(98, 3)("(mod_header) ->  parse direction error, cant be %d\n", part->direct);
			goto err;
		}

		//???↑ʼ?ǽ???????????
		if (NULL == (token = strtok(NULL, w_space)))
		{
			debug(98, 3)("(mod_header) ->  parse line data does not existed\n");
			goto err;
		}
		ret = parse_operation(part, token);//??????????, ???????????ṹ
		if(-1 == ret)
		{
			debug(98, 3)("(mod_header) ->  parse line operation error, cant be %s\n", token);
			goto err;
		}

		//?????и?header, ?????϶??е?
		if (NULL == (token = strtok(NULL, w_space)))
		{
			debug(98, 3)("(mod_header) ->  parse line data does not existed\n");
			goto err;
		}
		stringInit(&info->header, token);	

		//?и???header, value?Ͳ?һ??????. ????Ҫ??????��?ж???. ??????Ҫ?и?value, ?͸???
		if (1 != part->action)
		{
			if (NULL == (token = strtok(NULL, w_space))) {
				debug(98, 3)("(mod_header) ->  parse line data does not existed\n");
				goto err;
			}

			//??Ȼ??value, ?ͱ???????. ?? header һ???????ŵ?????.
			stringInit(&info->value, token);	

			/* case http://sis.ssr.chinacache.com/rms/view.php?id=4124 */
			if (*token == '\"') {
				stringClean(&info->value);
				stringInit(&info->value, token+1);	
				int len = 0;
				while (NULL !=(token = strtok(NULL,w_space))){
					len = strlen(token);
					if (token[len-1] == '\"'){
						stringAppend(&info->value, " ", 1);
						stringAppend(&info->value, token, len-1);
						break;
					}
					else if (strcmp("allow",token) == 0 || strcmp("deny",token) == 0) 
						goto err;
					else {
						stringAppend(&info->value, " ", 1);
						stringAppend(&info->value, token, len);
					}
				}
			}
		}
	}
	//һ??û???κ????ݣ? ֱ?ӱ???
	if(data->count == 0)
		goto err;
	else
		cc_register_mod_param(mod, data, free_callback);
	return 0;

err:
	debug(98,1)("mod_header: parse error\n");
	for(i=0; i<data->count; i++)
	{
		if(data->acp[i]->hdr)
		{
			if(strLen(data->acp[i]->hdr->header))
				stringClean(&data->acp[i]->hdr->header);
			if(strLen(data->acp[i]->hdr->value))
				stringClean(&data->acp[i]->hdr->value);
			memPoolFree(header_info_pool, data->acp[i]->hdr);
			data->acp[i]->hdr = NULL;
		}
		if(data->acp[i])
		{
			memPoolFree(action_part_pool, data->acp[i]);
			data->acp[i] = NULL;
		}
	}
errA:
	if (data)
	{
		memPoolFree(mod_config_pool, data);
		data = NULL;
	}
	return -1;
}
static void func_sys_after_parse_param()
{
	int i;
	for(i = 0 ; i < mod->mod_params.count; i++)
	{
		cc_mod_param *mod_param = mod->mod_params.items[i];
		mod_config *cfg = mod_param->param;

        // add by xueye.zhao
        // 2013-4-18

        if (is_http_move_status(cfg->ResponseStatus))
        {
            continue;
        }

        // end add

        if(is_url(cfg->location))
		{

			struct stat sb;
			if (stat("/data/proclog/log/squid/customized_error_page", &sb) != 0){
				mkdir("/data/proclog/log/squid/customized_error_page", S_IRWXU);
			}
			FILE *fp = popen("/usr/local/squid/bin/get_file_from_url.pl", "r");
			assert(fp);
			while(1)
			{
				char perloutput[512];
				if(!fgets(perloutput, 512, fp))
				{
					break;
				}

				debug(115, 1)("mod_customized_server_side_error_page get_file_from_url.pl said: %s\n", perloutput);
			}
			pclose(fp);


			/*
			   if (stat("/data/proclog/log/squid/customized_error_page", &sb) != 0){
			   mkdir("/data/proclog/log/squid/customized_error_page", S_IRWXU);
			   }
			   */
			if(stringConvert((cfg->location)))
			{
				debug(115,0) ( "mod_customized_server_side_error_page: cfg->location url error\n");
				continue;
			}

			debug(115,4) ( "mod_customized_server_side_error_page: cfg->location is: %s\n", cfg->location);

			//char* tmp = NULL;
			String tmp = StringNull;
			stringInit(&tmp, "/data/proclog/log/squid/customized_error_page/");
			stringAppend(&tmp, cfg->location+7, strlen(cfg->location)-7);
			memset(cfg->location,0,sizeof(cfg->location));
			strncpy(cfg->location,strBuf(tmp),strLen(tmp));
			errorTryLoadText(&cfg->customized_error_text, cfg->location);
			stringClean(&tmp);
		}
		else
		{
			//cfg->is_url = 0;
			errorTryLoadText(&cfg->customized_error_text, cfg->location);
		}
	}
}
Esempio n. 16
0
int main(void)
{
    t_table *table = table_init(128);
    if (table == NULL) {
        fprintf(stderr, "Table could not be initialized!\n");
        return EXIT_FAILURE;
    }
    
    print_table_info(table);
    print_table(table);

    int data_pole[NUM] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    t_string key_pole[NUM];

    int i;
    for (i = 0; i < NUM; i++) {
        stringInit(&key_pole[i]);
    }

    for (i = 0; i < NUM; i++) {
        stringAddChar(&key_pole[i], 'a' + i);
    }

    int ret = 0;
    t_tab_data * data_ptr;

    for (i = 0; i < NUM; i++) {
        ret = table_insert(table, &key_pole[i], &data_ptr);
        switch (ret) {
        case TAB_INSERT_OK:
            data_ptr->a = data_pole[i];
            break;
        case TAB_INSERT_FOUND:
            fprintf(stderr, "Item already inserted\n");
            break;
        case TAB_INSERT_ALL_ERR:
            fprintf(stderr, "Allocation error\n");
            break;
        }
    }

    print_table_info(table);
    print_table(table);
    
    /*
    //1. raz
    printf("INSERT\n\n");
    for (i = 0; i < NUM; i++) {
        ret = table_insert(table, key_pole[i], 7, (t_tab_data **) &data);
        switch (ret) {
        case TAB_INSERT_FAIL:
            fprintf(stderr, "Item already inserted.\n");
            break;
        case TAB_INSERT_FULL:
            while (ret == TAB_INSERT_FULL) {
                if (table_resize(table) == TAB_RESIZE_FAIL) {
                    fprintf(stderr, "RESIZE FAIL\n");
                    table_destroy(table);
                    return EXIT_FAILURE;
                }
                ret = table_insert(table, key_pole[i], 7, (t_tab_data **)&data);
            }
            if (ret == TAB_INSERT_FAIL) {
                fprintf(stderr, "Item already inserted.\n");
                break;
            }
            if (ret == TAB_INSERT_ALL_ERR) {
                fprintf(stderr, "ALLOC ERR\n");
                table_destroy(table);
                return EXIT_FAILURE;
            }
            *(int *)data = data_pole[i];
            break;
        case TAB_INSERT_OK:
            *(int *)data = data_pole[i];
            break;
        case TAB_INSERT_ALL_ERR:
            fprintf(stderr, "ALLOC ERROR\n");
            table_destroy(table);
            return EXIT_FAILURE;
        }
    }

    print_table(table);
    */
    
    printf("-----------------------------------------------------------------------------------------\n\n");

    printf("GET DATA\n\n");
    for (i = 0; i < NUM; i++) {
        ret = table_search(table, &key_pole[i], (t_tab_data **) &data_ptr);
        if (ret == TAB_SEARCH_OK) {
            printf("Key:    %s\n", key_pole[i].string);
            printf("Data:  %d\n\n", data_ptr == NULL ? -1 : ((t_tab_data *)data_ptr)->a);
        }
    }

    /*
    print_table(table);
    */

    for (i = 0; i < NUM; i++) {
        stringFree(&key_pole[i]);
    }
    table_destroy(table);
    return EXIT_SUCCESS;
}
/****************************************************************************
* Menu option #6: Delete Stop Words
* Removes common words from the index supplied from an external file.
****************************************************************************/
void deleteStopWords(IndexType* index)
{
  FILE *fp;
  unsigned int injunk,in,notin;
  char word[MAXLENGTH],c;
  char buffer[BUFFSIZE];
  WordTypePtr node,prev,temp;
  String line;

  printf("\nDelete Stop Words\n");
  printf("-----------------\n");


  getString(word,MAXLENGTH,0,"Enter name of stop word file:");

  if(strlen(word)==0)
  {
    printf("Delete Stop Words cancelled. Returning to main menu.\n");
    return;
  }

  if((fp=fopen(word,"rb"))==NULL)
  {
    printf("Failed to read %s !\n",word);
    return;
  }

  setvbuf(fp,buffer,_IOFBF,BUFFSIZE);

  stringInit(&line);
  injunk=FALSE;
  in=FALSE;
  notin=FALSE;

  while((c=fgetc(fp))!=EOF)
  {
    if((c>=a && c<=z) || (c>=A && c<=Z))
    {
      injunk=FALSE;
      stringAddChar(&line,c);
    }
    if(!injunk)
    {
      if(c==SPACE || c=='\n')
      {
        /*found the word so search index and remove the node if its found*/
        node=index->headWord;
        prev=node;
        while(node!=NULL)
        {
          /*found the word to delete so delete it*/
          if(strcmp(node->word,line.contents)==0)
          {
            temp=deletebetween(prev,node);

            /*temp=node;*/


            if(node==index->headWord)
                index->headWord=temp;
            else
                node=temp;


            stringClear(&line);
            injunk=TRUE;
            in++;
            break;
          }
          prev=node;
          node=node->nextWord;

        }
        /*the word wasnt found in the list*/
        if(node==NULL)
            notin++;

      }
    }
  }
  printf("\n\n%d words removed from the index. %d words not found."
         ,in,notin);

  stringFree(&line);
  fclose(fp);


}
Esempio n. 18
0
// confige line example:
// mod_modify_s2o_header_name orig_header_name new_header_name allow/deny acl
// dont support func : on
static int func_sys_parse_param(char *cfg_line)
{
	struct mod_conf_param *data = mod_config_pool_alloc();
	char* token = NULL;
//mod_modify_s2o_header_name
	if ((token = strtok(cfg_line, w_space)) != NULL)
	{
		if(strcmp(token, "mod_modify_s2o_header_name"))
			goto err;	
	}
	else
	{
		debug(107, 1)("(mod_modify_s2o_header_name) ->  parse line error\n");
		goto err;	
	}
//orig_name
	if ((token = strtok(NULL, w_space)) != NULL)
	{
		stringInit(&data->orig_name, token);
	}
	else
	{
		debug(107, 1)("(mod_modify_s2o_header_name) ->  parse line error\n");
		goto err;	
	}
//new_name
	if ((token = strtok(NULL, w_space)) != NULL)
	{
		stringInit(&data->new_name, token);
	}
	else
	{
		debug(107, 1)("(mod_modify_s2o_header_name) ->  parse line error\n");
		goto err;	
	}
//allow or deny
	if ((token = strtok(NULL, w_space)) != NULL)
	{
		if(!(!strcmp(token, "allow")||!strcmp(token, "deny")||!strcmp(token, "on")||!strcmp(token, "off")))
			goto err;
	}
	else
	{
		debug(107, 1)("(mod_modify_s2o_header_name) ->  parse line error\n");
		goto err;	
	}


	cc_register_mod_param(mod, data, free_callback);

	return 0;		
err:
	if(data)
	{
		if(strLen(data->orig_name))
			stringClean(&data->orig_name);
		if(strLen(data->new_name))
			stringClean(&data->new_name);
		memPoolFree(mod_config_pool, data);
		data = NULL;
	}
	return -1;
}
Esempio n. 19
0
static void
authenticateDigestDecodeAuth(auth_user_request_t * auth_user_request, const char *proxy_auth)
{
    String temp;
    const char *item;
    const char *p;
    const char *pos = NULL;
    char *username = NULL;
    digest_nonce_h *nonce;
    int ilen;
    digest_request_h *digest_request;
    digest_user_h *digest_user;
    auth_user_t *auth_user;
    dlink_node *node;

    debug(29, 9) ("authenticateDigestDecodeAuth: beginning\n");
    assert(auth_user_request != NULL);

    digest_request = authDigestRequestNew();

    /* trim DIGEST from string */
    while (xisgraph(*proxy_auth))
	proxy_auth++;

    /* Trim leading whitespace before decoding */
    while (xisspace(*proxy_auth))
	proxy_auth++;

    stringInit(&temp, proxy_auth);
    while (strListGetItem(&temp, ',', &item, &ilen, &pos)) {
	if ((p = strchr(item, '=')) && (p - item < ilen))
	    ilen = p++ - item;
	if (!strncmp(item, "username", ilen)) {
	    /* white space */
	    while (xisspace(*p))
		p++;
	    /* quote mark */
	    p++;
	    username = xstrndup(p, strchr(p, '"') + 1 - p);
	    debug(29, 9) ("authDigestDecodeAuth: Found Username '%s'\n", username);
	} else if (!strncmp(item, "realm", ilen)) {
	    /* white space */
	    while (xisspace(*p))
		p++;
	    /* quote mark */
	    p++;
	    digest_request->realm = xstrndup(p, strchr(p, '"') + 1 - p);
	    debug(29, 9) ("authDigestDecodeAuth: Found realm '%s'\n", digest_request->realm);
	} else if (!strncmp(item, "qop", ilen)) {
	    /* white space */
	    while (xisspace(*p))
		p++;
	    if (*p == '\"')
		/* quote mark */
		p++;
	    digest_request->qop = xstrndup(p, strcspn(p, "\" \t\r\n()<>@,;:\\/[]?={}") + 1);
	    debug(29, 9) ("authDigestDecodeAuth: Found qop '%s'\n", digest_request->qop);
	} else if (!strncmp(item, "algorithm", ilen)) {
	    /* white space */
	    while (xisspace(*p))
		p++;
	    if (*p == '\"')
		/* quote mark */
		p++;
	    digest_request->algorithm = xstrndup(p, strcspn(p, "\" \t\r\n()<>@,;:\\/[]?={}") + 1);
	    debug(29, 9) ("authDigestDecodeAuth: Found algorithm '%s'\n", digest_request->algorithm);
	} else if (!strncmp(item, "uri", ilen)) {
	    /* white space */
	    while (xisspace(*p))
		p++;
	    /* quote mark */
	    p++;
	    digest_request->uri = xstrndup(p, strchr(p, '"') + 1 - p);
	    debug(29, 9) ("authDigestDecodeAuth: Found uri '%s'\n", digest_request->uri);
	} else if (!strncmp(item, "nonce", ilen)) {
	    /* white space */
	    while (xisspace(*p))
		p++;
	    /* quote mark */
	    p++;
	    digest_request->nonceb64 = xstrndup(p, strchr(p, '"') + 1 - p);
	    debug(29, 9) ("authDigestDecodeAuth: Found nonce '%s'\n", digest_request->nonceb64);
	} else if (!strncmp(item, "nc", ilen)) {
	    /* white space */
	    while (xisspace(*p))
		p++;
	    xstrncpy(digest_request->nc, p, 9);
	    debug(29, 9) ("authDigestDecodeAuth: Found noncecount '%s'\n", digest_request->nc);
	} else if (!strncmp(item, "cnonce", ilen)) {
	    /* white space */
	    while (xisspace(*p))
		p++;
	    /* quote mark */
	    p++;
	    digest_request->cnonce = xstrndup(p, strchr(p, '"') + 1 - p);
	    debug(29, 9) ("authDigestDecodeAuth: Found cnonce '%s'\n", digest_request->cnonce);
	} else if (!strncmp(item, "response", ilen)) {
	    /* white space */
	    while (xisspace(*p))
		p++;
	    /* quote mark */
	    p++;
	    digest_request->response = xstrndup(p, strchr(p, '"') + 1 - p);
	    debug(29, 9) ("authDigestDecodeAuth: Found response '%s'\n", digest_request->response);
	}
    }
    stringClean(&temp);


    /* now we validate the data given to us */

    /*
     * TODO: on invalid parameters we should return 400, not 407.
     * Find some clean way of doing this. perhaps return a valid
     * struct, and set the direction to clientwards combined with
     * a change to the clientwards handling code (ie let the
     * clientwards call set the error type (but limited to known
     * correct values - 400/401/407
     */

    /* first the NONCE count */
    if (digest_request->cnonce && strlen(digest_request->nc) != 8) {
	debug(29, 4) ("authenticateDigestDecode: nonce count length invalid\n");
	authDigestLogUsername(auth_user_request, username);

	/* we don't need the scheme specific data anymore */
	authDigestRequestDelete(digest_request);
	auth_user_request->scheme_data = NULL;
	return;
    }
    /* now the nonce */
    nonce = authenticateDigestNonceFindNonce(digest_request->nonceb64);
    if (!nonce) {
	/* we couldn't find a matching nonce! */
	debug(29, 4) ("authenticateDigestDecode: Unexpected or invalid nonce recieved\n");
	authDigestLogUsername(auth_user_request, username);

	/* we don't need the scheme specific data anymore */
	authDigestRequestDelete(digest_request);
	auth_user_request->scheme_data = NULL;
	return;
    }
    digest_request->nonce = nonce;
    authDigestNonceLink(nonce);

    /* check the qop is what we expected. Note that for compatability with 
     * RFC 2069 we should support a missing qop. Tough. */
    if (!digest_request->qop || strcmp(digest_request->qop, QOP_AUTH)) {
	/* we recieved a qop option we didn't send */
	debug(29, 4) ("authenticateDigestDecode: Invalid qop option recieved\n");
	authDigestLogUsername(auth_user_request, username);

	/* we don't need the scheme specific data anymore */
	authDigestRequestDelete(digest_request);
	auth_user_request->scheme_data = NULL;
	return;
    }
    /* we can't check the URI just yet. We'll check it in the
     * authenticate phase */

    /* is the response the correct length? */

    if (!digest_request->response || strlen(digest_request->response) != 32) {
	debug(29, 4) ("authenticateDigestDecode: Response length invalid\n");
	authDigestLogUsername(auth_user_request, username);

	/* we don't need the scheme specific data anymore */
	authDigestRequestDelete(digest_request);
	auth_user_request->scheme_data = NULL;
	return;
    }
    /* do we have a username ? */
    if (!username || username[0] == '\0') {
	debug(29, 4) ("authenticateDigestDecode: Empty or not present username\n");
	authDigestLogUsername(auth_user_request, username);

	/* we don't need the scheme specific data anymore */
	authDigestRequestDelete(digest_request);
	auth_user_request->scheme_data = NULL;
	return;
    }
    /* check that we're not being hacked / the username hasn't changed */
    if (nonce->auth_user && strcmp(username, authenticateUserUsername(nonce->auth_user))) {
	debug(29, 4) ("authenticateDigestDecode: Username for the nonce does not equal the username for the request\n");
	authDigestLogUsername(auth_user_request, username);

	/* we don't need the scheme specific data anymore */
	authDigestRequestDelete(digest_request);
	auth_user_request->scheme_data = NULL;
	return;
    }
    /* if we got a qop, did we get a cnonce or did we get a cnonce wihtout a qop? */
    if ((digest_request->qop && !digest_request->cnonce)
	|| (!digest_request->qop && digest_request->cnonce)) {
	debug(29, 4) ("authenticateDigestDecode: qop without cnonce, or vice versa!\n");
	authDigestLogUsername(auth_user_request, username);

	/* we don't need the scheme specific data anymore */
	authDigestRequestDelete(digest_request);
	auth_user_request->scheme_data = NULL;
	return;
    }
    /* check the algorithm is present and supported */
    if (!digest_request->algorithm)
	digest_request->algorithm = xstrndup("MD5", 4);
    else if (strcmp(digest_request->algorithm, "MD5")
	&& strcmp(digest_request->algorithm, "MD5-sess")) {
	debug(29, 4) ("authenticateDigestDecode: invalid algorithm specified!\n");
	authDigestLogUsername(auth_user_request, username);

	/* we don't need the scheme specific data anymore */
	authDigestRequestDelete(digest_request);
	auth_user_request->scheme_data = NULL;
	return;
    }
    /* the method we'll check at the authenticate step as well */


    /* we don't send or parse opaques. Ok so we're flexable ... */

    /* find the user */

    if ((auth_user = authDigestUserFindUsername(username)) == NULL) {
	/* the user doesn't exist in the username cache yet */
	debug(29, 9) ("authDigestDecodeAuth: Creating new digest user '%s'\n", username);
	/* new auth_user */
	auth_user = authenticateAuthUserNew("digest");
	/* new scheme user data */
	digest_user = authDigestUserNew();
	/* save the username */
	digest_user->username = username;
	/* link the primary struct in */
	auth_user->scheme_data = digest_user;
	/* set the user type */
	auth_user->auth_type = AUTH_DIGEST;
	/* this auth_user struct is the one to get added to the
	 * username cache */
	/* store user in hash's */
	authenticateUserNameCacheAdd(auth_user);
	/* 
	 * Add the digest to the user so we can tell if a hacking
	 * or spoofing attack is taking place. We do this by assuming
	 * the user agent won't change user name without warning.
	 */
	authDigestUserLinkNonce(auth_user, nonce);
    } else {
	debug(29, 9) ("authDigestDecodeAuth: Found user '%s' in the user cache as '%p'\n", username, auth_user);
	digest_user = auth_user->scheme_data;
	xfree(username);
    }
    /*link the request and the user */
    auth_user_request->auth_user = auth_user;
    auth_user_request->scheme_data = digest_request;
    /* lock for the request link */
    authenticateAuthUserLock(auth_user);
    node = dlinkNodeNew();
    dlinkAdd(auth_user_request, node, &auth_user->requests);

    debug(29, 9) ("username = '******'\nrealm = '%s'\nqop = '%s'\nalgorithm = '%s'\nuri = '%s'\nnonce = '%s'\nnc = '%s'\ncnonce = '%s'\nresponse = '%s'\ndigestnonce = '%p'\n",
	digest_user->username, digest_request->realm,
	digest_request->qop, digest_request->algorithm,
	digest_request->uri, digest_request->nonceb64,
	digest_request->nc, digest_request->cnonce, digest_request->response, nonce);

    return;
}