From 4d0d4eb9117c6557b701725643935dea97d05682 Mon Sep 17 00:00:00 2001
From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>
Date: Sun, 7 Jun 2009 08:05:31 +0000
Subject:  - code revise

git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4506 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 mbbsd/register.c | 108 +++++++++++++++++++++++++++++++------------------------
 1 file changed, 62 insertions(+), 46 deletions(-)

(limited to 'mbbsd')

diff --git a/mbbsd/register.c b/mbbsd/register.c
index f580058e..4ef775a9 100644
--- a/mbbsd/register.c
+++ b/mbbsd/register.c
@@ -348,7 +348,7 @@ delregcodefile(void)
 ////////////////////////////////////////////////////////////////////////////
 #ifdef USE_FIGLET_CAPTCHA
 
-int
+static int
 gen_captcha(char *buf, int szbuf, char *fpath)
 {
     // do not use: GQV
@@ -427,7 +427,7 @@ _vgetcb_data_post(int key, VGET_RUNTIME *prt, void *instance)
 }
 
 
-int verify_captcha()
+static int verify_captcha()
 {
     char captcha[7] = "", code[STRLEN];
     char fpath[PATHLEN];
@@ -485,7 +485,7 @@ int verify_captcha()
 }
 #else // !USE_FIGLET_CAPTCHA
 
-int 
+static int 
 verify_captcha()
 {
     return 1;
@@ -1110,7 +1110,7 @@ check_register(void)
 #endif
 }
 
-int
+static int
 create_regform_request()
 {
     FILE *fn;
@@ -1597,7 +1597,7 @@ load_regform_entry(RegformEntry *pre, FILE *fp)
 }
 */
 
-int
+static int
 print_regform_entry(const RegformEntry *pre, FILE *fp, int close)
 {
     fprintf(fp, "uid: %s\n",	pre->u.userid);
@@ -1610,17 +1610,26 @@ print_regform_entry(const RegformEntry *pre, FILE *fp, int close)
     return 1;
 }
 
-int
-print_regform_entry_localized(const RegformEntry *pre, FILE *fp, int close)
+static int
+concat_regform_entry_localized(const RegformEntry *pre, char *result, int maxlen)
 {
-    fprintf(fp, "�ϥΪ�ID: %s\n", pre->u.userid);
-    fprintf(fp, "�u��m�W: %s\n", pre->u.realname);
-    fprintf(fp, "¾�~�Ǯ�: %s\n", pre->u.career);
-    fprintf(fp, "�ثe���}: %s\n", pre->u.address);
-    fprintf(fp, "�q�ܸ��X: %s\n", pre->u.phone);
-    fprintf(fp, "�W����m: %s\n", pre->u.lasthost);
-    if (close)
-	fprintf(fp, "----\n");
+    int len = strlen(result);
+    len += snprintf(result, maxlen - len, "�ϥΪ�ID: %s\n", pre->u.userid);
+    len += snprintf(result, maxlen - len, "�u��m�W: %s\n", pre->u.realname);
+    len += snprintf(result, maxlen - len, "¾�~�Ǯ�: %s\n", pre->u.career);
+    len += snprintf(result, maxlen - len, "�ثe���}: %s\n", pre->u.address);
+    len += snprintf(result, maxlen - len, "�q�ܸ��X: %s\n", pre->u.phone);
+    len += snprintf(result, maxlen - len, "�W����m: %s\n", pre->u.lasthost);
+    len += snprintf(result, maxlen - len, "----\n");
+    return 1;
+}
+
+static int
+print_regform_entry_localized(const RegformEntry *pre, FILE *fp)
+{
+    char buf[STRLEN * 6];
+    concat_regform_entry_localized(pre, buf, sizeof(buf));
+    fputs(buf, fp);
     return 1;
 }
 
@@ -1649,18 +1658,17 @@ append_regform(const RegformEntry *pre, const char *logfn, const char *ext)
 static void regform_print_reasons(const char *reason, FILE *fp);
 
 void
-regform_log2board(const RegformEntry *pre, char accept, 
+regform_log2board(const RegformEntry *pre, char accepted, 
 	const char *reason, int priority)
 {
 #ifdef BN_ID_RECORD
-    char fn[PATHLEN];
     char title[STRLEN];
-    FILE *fp = NULL;
     char *title2 = NULL;
+    char msg[STRLEN * REJECT_REASONS];
 
     snprintf(title, sizeof(title), 
 	    "[�f��] %s: %s (%s: %s)", 
-	    accept ? "���q�L":"���h�^", pre->u.userid, 
+	    accepted ? "���q�L":"���h�^", pre->u.userid, 
 	    priority ? "���w�f��" : "�f�֪�",
 	    cuser.userid);
 
@@ -1668,18 +1676,18 @@ regform_log2board(const RegformEntry *pre, char accept,
     title2 = strchr(title, ' ');
     if (title2) title2++;
 
-    if (post_msg_fpath(BN_ID_RECORD, title, title2 ? title2 : title, "[���U�t��]", fn) < 0 ||
-	((fp = fopen(fn, "at")) == NULL))
-	return;
 
-    fprintf(fp, "\n");
+    // construct msg
+    strlcpy(msg, title2 ? title2 : title, sizeof(msg));
+    strlcat(msg, "\n", sizeof(msg));
+    if (!accepted) {
+	regform_concat_reasons(reasons, msg, sizeof(msg));
+    }
+    strlcat(msg, "\n", sizeof(msg));
+    concat_regform_entry_localized(pre, msg, sizeof(msg));
 
-    if (!accept) // print out reject reasons
-	regform_print_reasons(reason, fp);
+    post_msg(BN_ID_RECORD, title, msg, "[���U�t��]");
 
-    fprintf(fp, "\n");
-    print_regform_entry_localized(pre, fp, 1);
-    fclose(fp);
 #endif  // BN_ID_RECORD
 }
 
@@ -1695,12 +1703,12 @@ int regform_estimate_queuesize()
 #define REJECT_REASONS	(6)
 #define REASON_LEN	(60)
 static const char *reasonstr[REJECT_REASONS] = {
-    "��J�u��m�W",
-    "�Զ�(���~)�Ǯաy�t�z�y�šz�ΪA�ȳ��(�t���ݿ�����¾��)",
-    "��g������} (�t����/�m������, �x�_���аO�o�[��F�ϰ�)",
-    "�Զ�s���q�� (�t�ϽX, �������[ '-', '(', ')' ���Ÿ�)",
-    "��T�ç����g���U�ӽЪ�",
-    "�Τ����g�ӽг�",
+    "�п�J�u��m�W",
+    "�иԶ�(���~)�Ǯաy�t�z�y�šz�ΪA�ȳ��(�t���ݿ�����¾��)",
+    "�ж�g������} (�t����/�m������, �x�_���аO�o�[��F�ϰ�)",
+    "�иԶ�s���q�� (�t�ϽX, �������[ '-', '(', ')' ���Ÿ�)",
+    "�к�T�ç����g���U�ӽЪ�",
+    "�ХΤ����g�ӽг�",
 };
 
 #define REASON_FIRSTABBREV '0'
@@ -1787,7 +1795,7 @@ regform_reject(const char *userid, const char *reason, const RegformEntry *pre)
     // log reference for mail-reply.
     fprintf(fp, "#%010d\n\n", usernum);
 
-    if(pre) print_regform_entry_localized(pre, fp, 1);
+    if(pre) print_regform_entry_localized(pre, fp);
     fprintf(fp, "%s ���U���ѡC\n", Cdate(&now));
 
 
@@ -1825,19 +1833,30 @@ prompt_regform_ui()
 }
 
 static void
-regform_print_reasons(const char *reason, FILE *fp)
+regform_concat_reasons(const char *reason, char *result, int maxlen)
 {
+    int len = strlen(result);
     // multiple abbrev loop
     if (REASON_IN_ABBREV(reason[0]))
     {
 	int i = 0;
-	for (i = 0; i < REASON_LEN && REASON_IN_ABBREV(reason[i]); i++)
-	    fprintf(fp, "[�h�^��]] ��%s\n", REASON_EXPANDABBREV(reason[i]));
+	for (i = 0; reason[i] && REASON_IN_ABBREV(reason[i]); i++) {
+	    len += snprintf(result, maxlen - len, "[�h�^��]] %s\n", REASON_EXPANDABBREV(reason[i]));
+	}
     } else {
-	fprintf(fp, "[�h�^��]] %s\n", reason);
+	len += snprintf(result, maxlen - len, "[�h�^��]] %s\n", reason);
     }
 }
 
+static void
+regform_print_reasons(const char *reason, FILE *fp)
+{
+    char msg[STRLEN * REJECT_REASONS];
+    msg[0] = '\0';
+    regform_concat_reasons(reason, msg, sizeof(msg));
+    fputs(msg, fp);
+}
+
 static void
 resolve_reason(char *s, int y, int force)
 {
@@ -1851,18 +1870,15 @@ resolve_reason(char *s, int y, int force)
     outs(reason_prompt); outs("\n");
 
     do {
-	getdata(y+1, 0, 
-		"�h�^��]: ", s, REASON_LEN, DOECHO);
+	getdata(y+1, 0, "�h�^��]: ", s, REASON_LEN, DOECHO);
 
 	// convert abbrev reasons (format: single digit, or multiple digites)
 	if (REASON_IN_ABBREV(s[0]))
 	{
 	    if (s[1] == 0) // simple replace ment
 	    {
-		strlcpy(s+2, REASON_EXPANDABBREV(s[0]),
-			REASON_LEN-2);
-		s[0] = 0xbd; // '��'[0];
-		s[1] = 0xd0; // '��'[1];
+		strlcpy(s, REASON_EXPANDABBREV(s[0]),
+			REASON_LEN);
 	    } else {
 		// strip until all digites
 		char *p = s;
@@ -2181,7 +2197,7 @@ ui_display_regform_single(
 	    outs("\n" ANSI_COLOR(1;31) 
 		    "�д��X�h�^�ӽЪ���]�A�� <Enter> ����:\n" ANSI_RESET);
 	    for (n = 0; n < REJECT_REASONS; n++)
-		prints("%d) ��%s\n", n, reasonstr[n]);
+		prints("%d) %s\n", n, reasonstr[n]);
 	    outs("\n\n\n"); // preserved for prompt
 
 	    getdata(3+2+REJECT_REASONS+1, 0,"�h�^��]: ",
-- 
cgit v1.2.3