Пример #1
0
void gen_board_rank_xml()
{
    int i;
    FILE *fp;
    char xmlfile[STRLEN];
    char xml_buf[256];
    char url_buf[256];
    const struct boardheader *bp;
    int sec_id;

    snprintf(xmlfile, sizeof(xmlfile), BBSHOME "/xml/board.xml");
    if ((fp = fopen(xmlfile, "w")) == NULL)
        return;
    fprintf(fp, "<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
    fprintf(fp, "<BoardList Desc=\"%s\">\n",encode_url(url_buf,"讨论区使用状况统计",sizeof(url_buf)));
    for (i = 0; i < n; i++) {
        bp = getbcache(x[i].filename);
        if (bp == NULL || (bp->flag & BOARD_GROUP))
            continue;
        if ((sec_id = get_seccode_index(bp->title[0])) < 0)
            continue;
        fprintf(fp, "<Board>\n");
        fprintf(fp, "<EnglishName>%s</EnglishName>\n",
                encode_url(url_buf,encode_xml(xml_buf, x[i].filename, sizeof(xml_buf)),sizeof(url_buf)));
        fprintf(fp, "<ChineseName>%s</ChineseName>\n",
                encode_url(url_buf,encode_xml(xml_buf, x[i].title, sizeof(xml_buf)),sizeof(url_buf)));
        fprintf(fp, "<Online>%d</Online>\n", x[i].online);
        fprintf(fp, "<Articles>%d</Articles>\n", x[i].nowid-x[i].yesid);
        fprintf(fp, "<SecId>%d</SecId>\n", sec_id);
        fprintf(fp, "</Board>\n");
    }
    fprintf(fp, "</BoardList>\n");
    fclose(fp);
}
Пример #2
0
xmpp_stanza_t *
stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient,
    const char * const type, const char * const message,
    const char * const state)
{
    char *encoded_xml = encode_xml(message);

    xmpp_stanza_t *msg, *body, *text;

    msg = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(msg, STANZA_NAME_MESSAGE);
    xmpp_stanza_set_type(msg, type);
    xmpp_stanza_set_attribute(msg, STANZA_ATTR_TO, recipient);

    body = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(body, STANZA_NAME_BODY);

    text = xmpp_stanza_new(ctx);
    xmpp_stanza_set_text(text, encoded_xml);
    xmpp_stanza_add_child(body, text);
    xmpp_stanza_add_child(msg, body);

    if (state != NULL) {
        xmpp_stanza_t *chat_state = xmpp_stanza_new(ctx);
        xmpp_stanza_set_name(chat_state, state);
        xmpp_stanza_set_ns(chat_state, STANZA_NS_CHATSTATES);
        xmpp_stanza_add_child(msg, chat_state);
    }

    g_free(encoded_xml);

    return msg;
}
Пример #3
0
void gen_blessing_list_xml()
{
	FILE *fp;
	char curfile[256];
	char xml_buf[256];
	char url_buf[256];
	int i;

    sprintf(curfile, "xml/%s.xml", myfile[4]);
    if ((fp = fopen(curfile, "w")) != NULL) 
	{
		fprintf(fp, "<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
		fprintf(fp, "<hotsubjects>\n");

        for (i = 0; i < topnum; i++) 
		{
			fprintf(fp, "<hotsubject>\n");
			fprintf(fp, "<title>%s</title>\n", encode_url(url_buf,encode_xml(xml_buf, top[i].title, 
						sizeof(xml_buf)),sizeof(url_buf)));
			fprintf(fp, "<author>%s</author>\n", encode_url(url_buf,top[i].userid,sizeof(url_buf)));
			fprintf(fp, "<board>%s</board>\n", encode_url(url_buf,top[i].board,sizeof(url_buf)));
			fprintf(fp, "<time>%ld</time>\n", top[i].date);
			fprintf(fp, "<number>%d</number>\n", top[i].number);
			fprintf(fp, "<groupid>%d</groupid>\n", top[i].groupid);
			fprintf(fp, "</hotsubject>\n");
        }
		fprintf(fp, "</hotsubjects>\n");

        fclose(fp);
    }
}
Пример #4
0
void gen_sec_hot_subjects_xml(int mytype, int secid)
{
	FILE *fp;
	char curfile[256];
	char xml_buf[256];
	char url_buf[256];
	int i;

    sprintf(curfile, "xml/%s_sec%d.xml", myfile[mytype], secid);
    if ((fp = fopen(curfile, "w")) != NULL) 
	{
		fprintf(fp, "<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
		fprintf(fp, "<hotsubjects>\n");

        for (i = 0; i < sectopnum[secid]; i++) 
		{

			fprintf(fp, "<hotsubject>\n");
			fprintf(fp, "<title>%s</title>\n", encode_url(url_buf,encode_xml(xml_buf, sectop[secid][i].title, 
						sizeof(xml_buf)),sizeof(url_buf)));
			fprintf(fp, "<author>%s</author>\n", encode_url(url_buf,sectop[secid][i].userid,sizeof(url_buf)));
			fprintf(fp, "<board>%s</board>\n", encode_url(url_buf,sectop[secid][i].board,sizeof(url_buf)));
			fprintf(fp, "<time>%ld</time>\n", sectop[secid][i].date);
			fprintf(fp, "<number>%d</number>\n", sectop[secid][i].number);
			fprintf(fp, "<groupid>%d</groupid>\n", sectop[secid][i].groupid);
			fprintf(fp, "</hotsubject>\n");
        }
		fprintf(fp, "</hotsubjects>\n");

        fclose(fp);
    }
}
Пример #5
0
void gen_hot_subjects_xml(int mytype)
{
    FILE *fp;
    char curfile[256];
    char xml_buf[256];
    char url_buf[256];
    int i;

    if (mytype==4) {
        gen_blessing_list_xml();
        return;
    }

    sprintf(curfile, "xml/%s.xml", myfile[mytype]);
    if ((fp = fopen(curfile, "w")) != NULL) {
        fprintf(fp, "<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
        fprintf(fp, "<hotsubjects>\n");

        for (i = 0; i < topnum; i++) {
            fprintf(fp, "<hotsubject>\n");
            fprintf(fp, "<title>%s</title>\n", encode_url(url_buf,encode_xml(xml_buf, top[i].title,
                    sizeof(xml_buf)),sizeof(url_buf)));
            fprintf(fp, "<author>%s</author>\n", encode_url(url_buf,top[i].userid,sizeof(url_buf)));
            fprintf(fp, "<board>%s</board>\n", encode_url(url_buf,top[i].board,sizeof(url_buf)));
            fprintf(fp, "<time>%ld</time>\n", top[i].date);
            fprintf(fp, "<number>%d</number>\n", top[i].number);
            fprintf(fp, "<groupid>%d</groupid>\n", top[i].groupid);
            fprintf(fp, "</hotsubject>\n");
        }
        fprintf(fp, "</hotsubjects>\n");

        fclose(fp);
    }

#ifdef REDIS
    redisContext *redis = redisConnect("127.0.0.1", 6379);
    const char *pattern = "stat:%s:%s";
    char key[128];
    char value[512];
    const char *argv[3] = { "RPUSH", key, value };

#define RPUSH(ikey,itype,ivalue) {\
    snprintf(key, 128, pattern, myfile[mytype], ikey);\
    snprintf(value, 512, itype, ivalue);\
    redisAppendCommandArgv(redis, 3, argv, NULL);\
}

#define DEL(ikey) {\
    snprintf(key, 128, pattern, myfile[mytype], ikey);\
    snprintf(value, 512, "DEL %s", key);\
    redisAppendCommand(redis, value);\
}

    DEL("title");
    DEL("author");
    DEL("board");
    DEL("replies");
    DEL("time");
    DEL("id");
    for (i = 0; i < topnum; i++) {
        RPUSH("title"   , "%s"  , top[i].title);
        RPUSH("author"  , "%s"  , top[i].userid);
        RPUSH("board"   , "%s"  , top[i].board);
        RPUSH("replies" , "%lu" , (unsigned long)top[i].number);
        RPUSH("time"    , "%lu" , (unsigned long)top[i].date);
        RPUSH("id"      , "%lu" , (unsigned long)top[i].groupid);
    }
    redisReply *reply;
    redisGetReply(redis, (void*)&reply);
    freeReplyObject(reply);
    redisFree(redis);

#undef RPUSH
#undef DEL
#endif
}
Пример #6
0
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;
}