Esempio n. 1
0
static int filter_pure_content(char *tmpfile,  struct fileheader *fh, size_t *size, int type) {
	FILE *fp_in, *fp_out;
	char newfn[256], buf[1024];
	int i;

	*size = 0;

	if(type == 2) // Blog的文章是utf-8编码, 先转换一下
		utf82gb_file(tmpfile);
	if(filter_attach(tmpfile)) // 过滤附件
		fh->accessed |=  FH_ATTACHED;
	
	fp_in = fopen(tmpfile, "r");
	if(fp_in == NULL)
		return -1;

	sprintf(newfn, "%s.tmp", tmpfile);
	fp_out = fopen(newfn, "w");
	if(fp_out == NULL) {
		fclose(fp_in);
		return -1;
	}
	get_article_info(fp_in, fh, type, tmpfile);
	for(i=0; fgets(buf, sizeof(buf), fp_in); i++) {
		if(*buf == '\n' || *buf == '\r')
			continue;
		if(i < 3) {
			if(!strncmp("发信人: ", buf, 8) ||
			   !strncmp("标  题: ", buf, 8) ||
			   !strncmp("发信站: ", buf, 8))
				continue;
		}			
		if(!strcmp(buf, "--\n")) //过滤签名档, 并认为内容结束
			break;
		if(*buf == ':' || !strncmp(buf, "【 在 ", 6)) //过滤引文
			continue; 
		fputs(buf, fp_out);
	}
	fclose(fp_in);
	fclose(fp_out);
	*size = file_size(newfn);
	if(*size < 64) {
		unlink(newfn);
		return -1;
	}
	return rename(newfn, tmpfile);
}
int main(int argc, char **argv) {
    CGI_varlist *varlist;
    const char *value;

    if ((varlist = CGI_get_all(0)) == 0) {
        fputs("Content-type: text/plain\r\n\r\n", stdout);
        printf("No CGI data received\r\n");
        return 0;
    }

    value = CGI_lookup(varlist, "id");


    cl = clnt_create(PAPER_ADDRESS, PAPERSERVER_PROG, PAPERSERVER_VERS, "tcp");
    if (cl == NULL) {
        fputs("Content-type: text/plain\r\n\r\n", stdout);
        perror("Error creating RPC client!");
        CGI_free_varlist(varlist);  /* free variable list */
        exit(1);
    }

    if (value != NULL) {
        get_article_info(value);
    }
    else {
        printf("Content-Type: text/plain\n\n");
        printf("id value missing\n\n");
    }

    CGI_free_varlist(varlist);  /* free variable list */


    clnt_destroy(cl);


    return 0;
}