-
- /*
- * Now start scanning this room's netconfig file for the
- * specified token.
- */
- assoc_file_name(filename, sizeof filename, &qrbuf, ctdl_netcfg_dir);
- begin_critical_section(S_NETCONFIGS);
- ncfp = fopen(filename, "r+");
- if (ncfp != NULL) {
- while (line_offset = ftell(ncfp),
- (fgets(buf, sizeof buf, ncfp) != NULL) ) {
- buf[strlen(buf)-1] = 0;
- line_length = strlen(buf);
- extract_token(cmd, buf, 0, '|', sizeof cmd);
- if (!strcasecmp(cmd, "subpending")) {
- extract_token(email, buf, 1, '|', sizeof email);
- extract_token(subtype, buf, 2, '|', sizeof subtype);
- extract_token(line_token, buf, 3, '|', sizeof line_token);
- if (!strcasecmp(token, line_token)) {
- if (!strcasecmp(subtype, "digest")) {
- safestrncpy(buf, "digestrecp|", sizeof buf);
- }
- else {
- safestrncpy(buf, "listrecp|", sizeof buf);
- }
- strcat(buf, email);
- strcat(buf, "|");
- /* SLEAZY HACK: pad the line out so
- * it's the same length as the line
- * we're replacing.
- */
- while (strlen(buf) < line_length) {
- strcat(buf, " ");
- }
- fseek(ncfp, line_offset, SEEK_SET);
- fprintf(ncfp, "%s\n", buf);
- ++success;
- }
- }
- if (!strcasecmp(cmd, "unsubpending")) {
- extract_token(line_token, buf, 2, '|', sizeof line_token);
- if (!strcasecmp(token, line_token)) {
- extract_token(address_to_unsubscribe, buf, 1, '|',
- sizeof address_to_unsubscribe);
- }
- }
- }
- fclose(ncfp);
- }
- end_critical_section(S_NETCONFIGS);
-
- /*
- * If "address_to_unsubscribe" contains something, then we have to
- * make another pass at the file, stripping out lines referring to
- * that address.
- */
- if (strlen(address_to_unsubscribe) > 0) {
- holdbuf = malloc(SIZ);
- begin_critical_section(S_NETCONFIGS);
- ncfp = fopen(filename, "r+");
- if (ncfp != NULL) {
- while (line_offset = ftell(ncfp),
- (fgets(buf, sizeof buf, ncfp) != NULL) ) {
- buf[strlen(buf)-1]=0;
- extract_token(scancmd, buf, 0, '|', sizeof scancmd);
- extract_token(scanemail, buf, 1, '|', sizeof scanemail);
- if ( (!strcasecmp(scancmd, "listrecp"))
- && (!strcasecmp(scanemail,
- address_to_unsubscribe)) ) {
- ++success;
- }
- else if ( (!strcasecmp(scancmd, "digestrecp"))
- && (!strcasecmp(scanemail,
- address_to_unsubscribe)) ) {
- ++success;
- }
- else if ( (!strcasecmp(scancmd, "subpending"))
- && (!strcasecmp(scanemail,
- address_to_unsubscribe)) ) {
- ++success;
- }
- else if ( (!strcasecmp(scancmd, "unsubpending"))
- && (!strcasecmp(scanemail,
- address_to_unsubscribe)) ) {
- ++success;
- }
- else { /* Not relevant, so *keep* it! */
- linelen = strlen(buf);
- holdbuf = realloc(holdbuf,
- (buflen + linelen + 2) );
- strcpy(&holdbuf[buflen], buf);
- buflen += linelen;
- strcpy(&holdbuf[buflen], "\n");
- buflen += 1;
- }
- }
- fclose(ncfp);
- }
- ncfp = fopen(filename, "w");
- if (ncfp != NULL) {
- fwrite(holdbuf, buflen+1, 1, ncfp);
- fclose(ncfp);
- }
- end_critical_section(S_NETCONFIGS);
- free(holdbuf);