diff options
author | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-09-20 20:57:23 +0800 |
---|---|---|
committer | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-09-20 20:57:23 +0800 |
commit | 81c98e60178549e9933961219d370252e91198cb (patch) | |
tree | 1b8d399ee196b1d1cdbd152ab261c0e598d20fc0 /mbbsd/friend.c | |
parent | c909e6f54001e88ab3017d9e5ac49d60da6b00cd (diff) | |
download | pttbbs-81c98e60178549e9933961219d370252e91198cb.tar pttbbs-81c98e60178549e9933961219d370252e91198cb.tar.gz pttbbs-81c98e60178549e9933961219d370252e91198cb.tar.bz2 pttbbs-81c98e60178549e9933961219d370252e91198cb.tar.lz pttbbs-81c98e60178549e9933961219d370252e91198cb.tar.xz pttbbs-81c98e60178549e9933961219d370252e91198cb.tar.zst pttbbs-81c98e60178549e9933961219d370252e91198cb.zip |
fix bug: when deleting an user, the aloha record won't be deleted.
add file: file.c, move some useful subroutine out of friend.c
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2205 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/friend.c')
-rw-r--r-- | mbbsd/friend.c | 75 |
1 files changed, 40 insertions, 35 deletions
diff --git a/mbbsd/friend.c b/mbbsd/friend.c index d70a33da..64761c2a 100644 --- a/mbbsd/friend.c +++ b/mbbsd/friend.c @@ -56,19 +56,10 @@ setfriendfile(char *fpath, int type) setbfile(fpath, currboard, friend_file[type]); } -static int +inline static int friend_count(char *fname) { - FILE *fp; - int count = 0; - char buf[200]; - - if ((fp = fopen(fname, "r"))) { - while (fgets(buf, sizeof(buf), fp)) - count++; - fclose(fp); - } - return count; + return file_count_line(fname); } void @@ -81,8 +72,7 @@ friend_add(char *uident, int type, char* des) return; if ((uident[0] > ' ') && !belong(fpath, uident)) { - FILE *fp; - char buf[40] = ""; + char buf[40] = "", buf2[256]; char t_uident[IDLEN + 1]; /* Thor: avoid uident run away when get data */ @@ -95,12 +85,8 @@ friend_add(char *uident, int type, char* des) getdata_str(2, 0, friend_desc[type], buf, sizeof(buf), DOECHO, des); } - if ((fp = fopen(fpath, "a"))) { - flock(fileno(fp), LOCK_EX); - fprintf(fp, "%-13s%s\n", t_uident, buf); - flock(fileno(fp), LOCK_UN); - fclose(fp); - } + sprintf(buf2, "%-13s%s\n", t_uident, buf); + file_append_line(fpath, buf2); } } @@ -184,7 +170,7 @@ friend_append(int type, int count) char the_id[15]; sscanf(buf, "%s", the_id); // XXX check buffer size - if (!belong(fpath, the_id)) { + if (!file_exist_record(fpath, the_id)) { if ((fp1 = fopen(fpath, "a"))) { flock(fileno(fp1), LOCK_EX); fputs(buf, fp1); @@ -200,25 +186,44 @@ friend_append(int type, int count) void friend_delete(char *uident, int type) { - FILE *fp, *nfp = NULL; - char fn[80], fnnew[80]; - char genbuf[200]; - + char fn[80]; setfriendfile(fn, type); + file_delete_line(fn, uident); +} - sprintf(fnnew, "%s-", fn); - if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) { - int length = strlen(uident); +static void +delete_user_friend(char *uident, char *friend, int type) +{ + char fn[80]; +#if 0 + if (type == FRIEND_ALOHA) { +#endif + sethomefile(fn, uident, "aloha"); + file_delete_line(fn, friend); +#if 0 + } + else { + } +#endif +} - while (fgets(genbuf, STRLEN, fp)) - if ((genbuf[0] > ' ') && strncmp(genbuf, uident, length)) - fputs(genbuf, nfp); - Rename(fnnew, fn); +void +friend_delete_all(char *uident, int type) +{ + char buf[80], line[80]; + FILE *fp; + + sethomefile(buf, uident, friend_file[type]); + + if ((fp = fopen(buf, "r")) == NULL) + return; + + while (fgets(line, sizeof(line), fp)) { + sscanf(line, "%s", buf); + delete_user_friend(buf, uident, type); } - if(fp) - fclose(fp); - if(nfp) - fclose(nfp); + + fclose(fp); } static void |