13 static stralloc addr
= {0};
14 static stralloc line
= {0};
15 static stralloc fn
= {0};
18 static char ssbuf
[256];
20 static int doit(userhost
)
28 if (!stralloc_copys(&addr
,"T")) return -2;
29 if (!stralloc_cats(&addr
,userhost
)) return -2;
31 j
= byte_rchr(addr
.s
,addr
.len
,'@');
32 if (j
== addr
.len
) return 0;
33 case_lowerb(addr
.s
+ j
+ 1,addr
.len
- j
- 1);
36 for (j
= 0;j
< addr
.len
;++j
)
37 h
= (h
+ (h
<< 5)) ^ (uint32
) (unsigned char) addr
.s
[j
];
40 if (!stralloc_0(&addr
)) return -2;
42 if (!stralloc_copys(&fn
,"subscribers/")) return -2;
43 if (!stralloc_catb(&fn
,&ch
,1)) return -2;
44 if (!stralloc_0(&fn
)) return -2;
48 if (errno
!= error_noent
) return -3;
51 substdio_fdbuf(&ss
,read
,fd
,ssbuf
,sizeof(ssbuf
));
54 if (getln(&ss
,&line
,&match
,'\0') == -1) { close(fd
); return -3; }
56 if (line
.len
== addr
.len
)
57 if (!byte_diff(line
.s
,line
.len
,addr
.s
)) { close(fd
); return 1; }
64 struct strerr issub_err
;
72 fdlock
= open_append("lock");
74 STRERR_SYS(-1,issub_err
,"unable to open lock: ")
75 if (lock_ex(fdlock
) == -1) {
77 STRERR_SYS(-1,issub_err
,"unable to obtain lock: ")
83 if (r
== -2) STRERR(-1,issub_err
,"out of memory")
84 if (r
== -3) STRERR_SYS3(-1,issub_err
,"unable to read ",fn
.s
,": ")