/* * URL: ^F*D&S^s~09d * ENC: %5EF%2AD%26S%5Es%7E09d * DH.org: %5EF%2AD%26S%5Es%7E09d * * For details, see http://hn.org/hnRFC10.txt */ int main(void) { char url[] = "^F*D&S^s~09d"; char buf[3 * sizeof(url)]; printf("URL : %s\n", url); printf("ENC : %s\n", urlencode(url, strlen(url))); printf("ENC2 : %s\n", urlencode2(url, buf, sizeof(buf))); printf("DH.org: %%5EF%%2AD%%26S%%5Es%%7E09d\n"); return 0; }
int main() { wml_init(); wml_head(); int i, tmp, max, min; int z; char board[80]; char buf[256], buf2[256], title[256]; FILE * fp; struct rmd r; if (loginok) { wmlmode(u_info, SELECT); } z = atoi(getparm("zone")); if (!*(getparm("zone")) || z < -1 || z >= SECNUM) { z = -3;//list mode } strncpy(board, getparm("board"), 79); if (*board)//zone模式 { z = -2; } if (z == -3) { printf ("<card title=\"选择讨论区 -- %s\" >", BBSNAME); printf ("<p>"); min = 0; if (loginok) { min -= 2; } for (i = min; i < SECNUM; i++) { if (i == -2) { printf ("  <anchor><go href=\"bbsboa.wml?zone=-1\" />我的收藏</anchor>"); } else if ( i == -1) { printf ("  <anchor><go href=\"bbsdoc.wml?board=%s\" />查看邮箱</anchor>", WML_VB_MAIL); } else { printf ("  <anchor><go href=\"bbsboa.wml?zone=%d\" />%s</anchor>", i, secname[i][0]); } if ((i & 1) && (i < SECNUM - 1)) { printf ("<br />"); } } printf ("</p>"); fp = fopen(PATHRMD, "rb"); if (fp) { printf ("<p><em>精彩推荐</em><br />"); while (fread (&r, sizeof(struct rmd), 1, fp)) { w_hsprintf(buf, "%s", r.cn); printf ("<anchor><go href=\"bbscon.wml?board=%s&file=%s\" />%s</anchor> <anchor><go href=\"bbsqry.wml?userid=%s\" />%s</anchor>@<anchor><go href=\"bbsdoc.wml?board=%s\" />%s</anchor><br />", r.board, r.en, buf, r.owner, r.owner, r.board, r.board); } printf ("</p>"); fclose (fp); } fp = fopen("etc/posts/day", "rt"); if (fp) { printf ("<p><em>十大热门话题</em><br />"); fgets(buf, 255, fp); fgets(buf, 255, fp);//跳过两行开头 for(i = 1; i <= 10; i++) { if (!fgets(buf, 255, fp)) { break; } sscanf (buf + 45, "%s", board); if (!fgets(buf, 255, fp))//话说,显示ID没有用啊,反正也老出错 { break; } strsncpy (title, buf + 27, 60); rtrims(title); printf ("<anchor><go href=\"bbstopic.wml?board=%s&topic=%s\" />", board, urlencode2(title)); w_hsprintf(buf2, "%s", title); printf ("%s</anchor> <anchor><go href=\"bbsdoc.wml?board=%s\" />%s板</anchor> <br />", buf2, board, board); } fclose (fp); printf ("</p>"); } printf ("<p><input name=\"inp_goto\" /><anchor><go href=\"bbssel.wml\" method=\"post\"><postfield name=\"goto\" value=\"$(inp_goto)\" /></go>带我去</anchor></p>"); wml_bar(0); printf ("</card>"); } else//板面 { struct shortfile data[MAXBOARD], *x; int total, br; printf ("<card title=\"%s -- %s\">", (z >= 0 ? secname[z][0] : (z == -1 ? "我的收藏" : board)), BBSNAME); if (z == -1) { char mybrd[GOOD_BRC_NUM][80]; int mybrdnum = 0; mybrdnum = LoadMyBrdsFromGoodBrd(currentuser.userid, mybrd); for(i=0; i<mybrdnum; i++) { if(!(x=getbcache(mybrd[i]))) { continue; } if(x->filename[0] <= 32 || x->filename[0] > 'z') { continue; } if(!has_read_perm(¤tuser, x->filename)) { continue; } if(x->flag & ZONE_FLAG) { continue; } data[total++] = *x; } } else { for(i = 0; i < MAXBOARD; i++) { x = &(shm_bcache->bcache[i]); if(x->filename[0] <= 32 || x->filename[0] > 'z') { continue; } if(!has_read_perm(¤tuser, x->filename)) { continue; } if(z >= 0 && !strchr(seccode[z], x->title[0])) { continue; } if (z == -2) //这是某个子分区 { if(!(x->flag & CHILDBOARD_FLAG) && strcasecmp(x->owner, board)) { continue; } } else //这是某个分区 { if(x->flag & CHILDBOARD_FLAG) { continue; } } if((x->flag & ZONE_FLAG) && !count_zone(BOARDS, x->filename)) { continue; } //节约资源? memcpy(&data[total], x, sizeof(struct shortfile)); total++; } qsort(data, total, sizeof(struct shortfile), cmpboard); //printf ("<p><anchor><go href=\"userindex.wml?zone=%d\" />本区导读</anchor></p>", z); } for (i = 0; i < total; i++) { printf ("<p>"); br = board_read(data[i].filename); printf ("<anchor><go href=\"%s.wml?board=%s\" />", (data[i].flag & ZONE_FLAG) ? "bbsboa" : "bbsdoc", data[i].filename); if (!br) { printf ("<em>*"); } w_hprintf ("%s/%s", data[i].title + 10, data[i].filename); if (!br) { printf ("</em>"); } printf ("</anchor></p>"); } wml_bar(0); printf ("</card>"); } wml_tail(); return 0; }
int bbstopic_act(char * info) { char board[80], topic[256], curr[256]; int boardmode, start; int total, cnt, i, tmp, ismail, slen; struct fileheader fh[WMLP_TPOST_PER_PAGE], fhs[WMLP_TPOST_PER_PAGE], fh1[WMLP_TPOST_PER_PAGE]; struct shortfile * b; char buf[256], buf2[256]; char * ptr; FILE * fp; if (loginok) { wmlmode (u_info, READING); } strncpy (board, getparm("board"), 79); strncpy (topic, getparm("topic"), 255); strncpy (curr, getparm("curr"), 255); boardmode = atoi(getparm ("mode")); start = atoi(getparm("start")); ismail = !strcmp(board, WML_VB_MAIL); boardModeDir(board, boardmode, buf, buf2); b = getbcache(board); if (!*topic) { strcpy (info, "缺少主题。"); return -1; } if (!loginok || (!ismail && (!has_read_perm(¤tuser, board) ))) { strcpy (info, "权限不够。"); return -2; } fp = fopen (buf, "rb"); if (!fp) { sprintf (info, "无法打开索引。"); return -1; } printf ("<card title=\"主题树 -- %s\">", BBSNAME); if (ismail) { printf ("<p><anchor><go href=\"bbsdoc.wml?board=%s\" />信箱</anchor></p>", WML_VB_MAIL); } else { printf ("<p>板面:<anchor><go href=\"bbsdoc.wml?board=%s&mode=%d\" />%s/%s</anchor></p>", b->filename, boardmode, b->title + 11, b->filename); } w_hsprintf (buf, "%s", topic); printf ("<p>主题:%s</p>", buf); cnt = 0; slen = 0; start --; memset (fhs, 0, sizeof(fhs)); while (tmp = fread(fh, sizeof(struct fileheader), WMLP_TPOST_PER_PAGE, fp)) { for (i = 0; i < tmp; i++) { ptr = (fh + i)->title; if (!strncasecmp(ptr, "Re: ", 3)) { ptr += 4; } if (!strncmp(topic, ptr, 56)) { cnt++; if (start < 0 || start / WMLP_TPOST_PER_PAGE <= cnt / WMLP_TPOST_PER_PAGE) { *(fhs + slen) = *(fh + i); slen = slen % WMLP_TPOST_PER_PAGE + 1; //循环使用好吧。 } if (curr && !strcmp((fh + i)->filename, curr)) { start = (cnt - 1) / WMLP_TPOST_PER_PAGE * WMLP_TPOST_PER_PAGE; } if (cnt == WMLP_TPOST_PER_PAGE) { memcpy (fh1, fhs, sizeof(fh1)); } } } } if (start < 0) { if (cnt > WMLP_TPOST_PER_PAGE) { memcpy (fhs, fh1, sizeof(fh1)); slen = WMLP_TPOST_PER_PAGE; } start = 0; } printf ("<p>同主题%d篇,以下显示%d至%d。</p>", cnt, start + 1, start + slen); for (i = 0; i < slen; i++) { ptr = ismail ? (((fhs + i)->accessed[0] & FILE_READ) ? "" : "N") : flag_str2 ((fhs + i)->accessed[0], brc_has_read((fhs + i)->filename)); printf ("<p>%s %s ", strncasecmp((fhs + i)->title, "Re: ", 3) ? "T" : "R", ptr); strncpy (buf, (fhs + i)->owner, IDLEN + 1); for (ptr = buf; *ptr; ptr++) { if (!(isalnum(*ptr))) { *ptr = 0; break; } } printf ("<anchor><go href=\"bbsqry.wml?userid=%s\" />%s</anchor> ", buf, buf); printf ("<anchor><go href=\"bbscon.wml?board=%s&mode=%d&file=%s\" />", board, boardmode, (fhs + i)->filename); datetime (buf, atoi((fhs + i)->filename + 2)); w_hprintf ("%s", buf); printf ("</anchor></p>"); } if (cnt > WMLP_TPOST_PER_PAGE) { printf ("<p>"); strcpy (buf, urlencode2(topic)); for (i = 0; i <= cnt / WMLP_TPOST_PER_PAGE; i++) { if (i == 0 || i == cnt / WMLP_TPOST_PER_PAGE || abs(i - (start / WMLP_TPOST_PER_PAGE)) < 3) { if (i == start / WMLP_TPOST_PER_PAGE) { printf ("%d ", i + 1); } else { printf ("<anchor><go href=\"bbstopic.wml?board=%s&mode=%d&topic=%s&start=%d\" />%d</anchor> ", board, boardmode, buf, (i * WMLP_TPOST_PER_PAGE) + 1, i + 1); } } } printf ("</p>"); } return 0; }