Beispiel #1
0
static char * get_file_title(char *boardname, int threadid, char *title, char *userid)
{

	char dirfile[256];
	int fd;
	struct fileheader fh;

            sprintf(dirfile, "boards/%s/.DIR", boardname);
			if ((fd = open(dirfile, O_RDWR, 0644)) < 0)
				return NULL;

    		if( get_records_from_id(fd, threadid, &fh, 1, NULL) == 0 ){
				close(fd);
				return NULL;
			}
			close(fd);

			strncpy(title, fh.title, 80);
			title[80]=0;

			strncpy(userid, fh.owner, IDLEN);
			userid[IDLEN]='\0';

			return title;
}
Beispiel #2
0
static char * get_file_title(char *boardname, int threadid, char *title, char *userid)
{

    char dirfile[256];
    int fd;
    struct fileheader fh;

    sprintf(dirfile, "boards/%s/.DIR", boardname);
    if ((fd = open(dirfile, O_RDWR, 0644)) < 0)
        return NULL;

    if (get_records_from_id(fd, threadid, &fh, 1, NULL) == 0) {
        close(fd);
        return NULL;
    }
    close(fd);

#ifdef NEWSMTH
    // pig2532 Feb 2008: ignore topic with FEN flag in top10
    if (fh.accessed[1] & FILE_FEN) {
        printf("skip:%s/%d/%s/%s\n", boardname, fh.id, fh.owner, fh.title);
        return NULL;
    }
#endif /* NEWSMTH */

    strncpy(title, fh.title, 80);
    title[80]=0;

    strncpy(userid, fh.owner, IDLEN);
    userid[IDLEN]='\0';

    return title;
}
Beispiel #3
0
static char * get_file_name(char *boardname, int threadid, char *fname)
{

	char dirfile[256];
	int fd;
	struct fileheader fh;

	fname[0]='\0';
            sprintf(dirfile, "boards/%s/.DIR", boardname);
			if ((fd = open(dirfile, O_RDWR, 0644)) < 0)
				return fname;

    		if( get_records_from_id(fd, threadid, &fh, 1, NULL) == 0 ){
				close(fd);
				return fname;
			}
			close(fd);

			strcpy(fname, fh.filename);
			return fname;
}
Beispiel #4
0
static char * get_file_info(char *boardname, int threadid, char *title, char *userid, char *filename, int pic)
{

    char dirfile[256];
    int fd;
    struct fileheader fh;

    setbdir(DIR_MODE_NORMAL, dirfile, boardname);
    if ((fd = open(dirfile, O_RDWR, 0644)) < 0)
        return NULL;

    if (get_records_from_id(fd, threadid, &fh, 1, NULL) == 0) {
        close(fd);
        return NULL;
    }
    close(fd);

#ifdef NEWSMTH
    // pig2532 Feb 2008: ignore topic with FEN flag in top10
    if (fh.accessed[1] & FILE_FEN) {
        printf("skip:%s/%d/%s/%s\n", boardname, fh.id, fh.owner, fh.title);
        return NULL;
    }
#endif /* NEWSMTH */

    if (pic) {
        if (!fh.attachment) {
            return NULL;
        } else {
            // 读取楼主的第一个附件,判断是否为图片,是则输出该图以备缩略之用,否则返回NULL
            char fn[PATHLEN];
            int fd_pic;
            char *src, *dst, *dot;
            off_t size_src, size_dst;
            char *aname, *start;
            long asize;

            setbfile(fn, boardname, fh.filename);
            if ((fd = open(fn, O_RDONLY)) == -1)
                return NULL;
            if (readw_lock(fd, 0, SEEK_SET, 0) == -1) {
                close(fd);
                return NULL;
            }
            if (safe_mmapfile_handle(fd, PROT_READ, MAP_PRIVATE, &src, &size_src) == 0) {
                un_lock(fd, 0, SEEK_SET, 0);
                close(fd);
                return NULL;
            }
            if (!(aname = checkattach(src + fh.attachment, size_src - fh.attachment, &asize, &start)))
                return NULL;

            dot = strrchr(aname, '.');
            // 是否图片?
            if (get_attachment_type_from_ext(dot) != ATTACH_IMG) {
                end_mmapfile(src, size_src, -1);
                un_lock(fd, 0, SEEK_SET, 0);
                close(fd);
                return NULL;
            }
            sprintf(fn, "hotpic/%s_%d", boardname, threadid);
            if ((fd_pic = open(fn, O_RDWR | O_CREAT, 0600)) == -1) {
                end_mmapfile(src, size_src, -1);
                un_lock(fd, 0, SEEK_SET, 0);
                close(fd);
                return NULL;
            }
            ftruncate(fd_pic, asize);
            if (safe_mmapfile_handle(fd_pic, PROT_WRITE, MAP_SHARED, &dst, &size_dst) == 0) {
                close(fd_pic);
                un_lock(fd, 0, SEEK_SET, 0);
                close(fd);
                return NULL;
            }
            printf("HOTPIC: %s_%d\n", boardname, threadid);
            memcpy(dst, start, asize);
            end_mmapfile(dst, size_dst, -1);
            end_mmapfile(src, size_src, -1);
            close(fd_pic);
            un_lock(fd, 0, SEEK_SET, 0);
            close(fd);
        }
    }

    strncpy(title, fh.title, 80);
    title[80]=0;

    strncpy(userid, fh.owner, IDLEN);
    userid[IDLEN]='\0';

    strncpy(filename, fh.filename, FILENAME_LEN);
    filename[FILENAME_LEN]='\0';

    return title;
}