コード例 #1
0
ファイル: libann.c プロジェクト: marvelliu/lilacsrc
static int a_additem_base(MENU *pm,const char *title,const char *fname,char *host,int port,long attachpos){
    ITEM *it;
    if(!(pm->total<MAXITEMS)&&!a_trim_menu(pm))
        return -2;
    if(!(it=I_ALLOC()))
        return -1;
    strnzhcpy(it->title,title,ITITLE_LEN);
    it->host=(!host?NULL:strdup(host));
    it->port=port;
    it->attachpos=attachpos;
    strncpy(it->fname,fname,(STRLEN-1));
    pm->pool[pm->total++]=it;
    return 0;
}
コード例 #2
0
ファイル: receive_article.c プロジェクト: wyat/kbs
static char *post_article(char *homepath, char *userid, char *board, int (*writebody)(), char *pathname, char *firstpath)
{
    struct fileheader header;
    struct fileheader threadfh;

/*    char        *subject = SUBJECT;  */
    char index[MAXPATHLEN];
    static char name[MAXPATHLEN];
    char article[MAXPATHLEN];
    FILE *fidx;
    int fh;
    int ret;
    int linkflag;
    char conv_buf[256];
    char old_path[255];

    getcwd(old_path, 255);
    sprintf(index, "%s/.DIR", homepath);
    if ((fidx = fopen(index, "r")) == NULL) {
        if ((fidx = fopen(index, "w")) == NULL) {
            innbbsdlog(":Err: Unable to post in %s.\n", homepath);
            return NULL;
        }
    }
    fclose(fidx);

    if (GET_POSTFILENAME(name, homepath) < 0)
	{
		innbbslog(" Err: can't get a postfile name\n");
		return NULL;
	}
	sprintf(article, "%s/%s", homepath, name);
	fh = open(article, O_WRONLY, 0644);

#ifdef DEBUG
    printf("post to %s\n", article);
#endif

    linkflag = 1;
    if (firstpath && *firstpath) {
        close(fh);
        unlink(article);
#ifdef DEBUGLINK
        innbbsdlog("try to link %s to %s", firstpath, article);
#endif
        linkflag = link(firstpath, article);
        if (linkflag) {
            fh = open(article, O_CREAT | O_EXCL | O_WRONLY, 0644);
        }
    }
    if (linkflag != 0) {
        if (writebody) {
            if ((*writebody) (fh, board, pathname) < 0)
                return NULL;
        } else {
            if (bbspost_write_post(fh, board, pathname) < 0)
                return NULL;
        }
        close(fh);
    }
    bzero((void *) &header, sizeof(header));
    strcpy(header.filename, name);
    strncpy(header.owner, userid, OWNER_LEN);
    header.owner[OWNER_LEN - 1] = 0;

    str_decode((unsigned char*)conv_buf, (unsigned char*)SUBJECT);
    /* big 标题转码,original patch by dgwang @ 笔山书院 */
    if(strstr(SUBJECT,"=?big5?") || strstr(SUBJECT,"=?Big5?") ||
       strstr(SUBJECT,"=?BIG5?") ){
       int len;
       len = strlen(conv_buf);
       big2gb(conv_buf,&len,0,getSession());
    }

    strnzhcpy(header.title, conv_buf, ARTICLE_TITLE_LEN);
    header.innflag[1] = 'M';
	set_posttime(&header);
    /*
     * if append record record, should return fail message 
     */
    chdir(BBSHOME);
    resolve_boards();
    linkflag = find_thread(&threadfh, board, header.title);
    header.eff_size = get_effsize(article);
    ret = after_post(NULL, &header, board, linkflag ? &threadfh : NULL, 0, getSession());
    if ((ret < 0) && (ret != -2)) {
        innbbslog(":Err:after_post Unable to post.\n");
        chdir(old_path);
        return NULL;
    }
    chdir(old_path);
    return name;
}
コード例 #3
0
ファイル: genhot.c プロジェクト: xingskycn/kbs
int gen_commend_xml(const char *bname, const char *fn, int max)
{
    int dirfd;
    FILE *fp;
    FILE *fp1;
    struct fileheader dirfh;
    char dirpath[STRLEN];
    char dirfile[STRLEN];
    char xml_buf[1024]; //changed from 256 to 1024, for <brief> - atppp
    char buf[256];
    char url_buf[1024]; //changed from 256 to 1024, for <brief> - atppp
    struct stat st;
    int numrecords;
    int i, brieflen, len;
    char *c;
    struct boardheader *bh;

    setbfile(dirpath, bname, DIGEST_DIR);
    if (stat(dirpath, &st) < 0)
        return -1;
    numrecords = st.st_size / sizeof(struct fileheader) ;
    if (numrecords <= 0)
        return -1;

    if ((fp = fopen(fn, "w")) == NULL)
        return -1;

    fprintf(fp, "<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
    fprintf(fp, "<hotsubjects>\n");

    dirfd = open(dirpath, O_RDONLY);
    if (dirfd >= 0) {
        if (numrecords > max)
            lseek(dirfd, sizeof(struct fileheader)*(numrecords - max), SEEK_SET);

        numrecords -= max;

        while (read(dirfd, &dirfh, sizeof(dirfh)) >= sizeof(dirfh)) {

            setbfile(dirfile, bname, dirfh.filename);

            if ((fp1=fopen(dirfile, "r"))==NULL)
                continue;

            numrecords ++;

            fprintf(fp, "<hotsubject>\n");
            fprintf(fp, "<title>%s</title>\n", encode_url(url_buf,encode_xml(xml_buf, dirfh.title, sizeof(xml_buf)),sizeof(url_buf)));
            fprintf(fp, "<author>%s</author>\n", encode_url(url_buf,dirfh.owner,sizeof(url_buf)));
            fprintf(fp, "<time>%ld</time>\n", get_posttime(&dirfh));
            fprintf(fp, "<board>%s</board>\n", encode_url(url_buf,bname,sizeof(url_buf)));
            fprintf(fp, "<id>%d</id>\n", dirfh.id);
            fprintf(fp, "<groupid>%d</groupid>\n", dirfh.groupid);
            bh = (struct boardheader *) getboard(dirfh.o_bid);
            fprintf(fp, "<o_board>%s</o_board>\n", encode_url(url_buf,(bh ? bh->filename : ""),sizeof(url_buf)));
            fprintf(fp, "<o_id>%d</o_id>\n",dirfh.o_id);
            if (fgets(buf, 255, fp1)) {
                if (! strncmp(buf, "发信人: ", 8)) {
                    if ((c=strchr(buf+8, ' ')) != NULL)
                        *c = 0;
                    fprintf(fp, "<owner>%s</owner>\n", buf+8);
                }
            }
            fprintf(fp, "<o_groupid>%d</o_groupid>\n<brief>", dirfh.o_groupid);
            for (i=0;i<3;i++) fgets(buf, 255, fp1);
            brieflen = 240;
            for (i=0;i<4;) {
                if (fgets(buf, 240, fp1)) {
                    if (buf[0] == '\n' || buf[0] == '\r' || buf[0]=='\0')
                        continue;
                    buf[240]=0;
                    /* etnlegend, 2006.09.17, 过滤控制字符... */
                    process_control_chars(buf,"\n");

                    len = strlen(buf);
                    if (!(len<brieflen-1)) {
                        strnzhcpy(buf,buf,brieflen);
                        len=brieflen;
                    }
                    fprintf(fp, "%s", encode_url(url_buf,encode_xml(xml_buf, buf, sizeof(xml_buf)),sizeof(url_buf)));
                    i++;

                    brieflen -= len;

                    if (brieflen<2)
                        break;
                } else
                    break;
            }
            fprintf(fp, " </brief>\n</hotsubject>\n");

            fclose(fp1);
        }
        close(dirfd);
    }

    fprintf(fp, "</hotsubjects>\n");
    fclose(fp);
    return 0;
}