view src/subscriberfuncs.c @ 27:91830455b49c

mygetline is turned into myfgetline since it works on FILE *'s and mygetline(int fd) was added.
author mmj
date Fri, 23 Apr 2004 07:14:22 +1000
parents 035484b0da60
children b7b8efd520ec
line wrap: on
line source

/* Copyright (C) 2003 Mads Martin Joergensen <mmj at mmj.dk>
 *
 * $Id$
 *
 * This file is redistributable under version 2 of the GNU General
 * Public License as described at http://www.gnu.org/licenses/gpl.txt
 */

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

#include "mlmmj.h"
#include "subscriberfuncs.h"
#include "mygetline.h"
#include "log_error.h"

int find_subscriber(int subfilefd, const char *address)
{
	char *buf;
	FILE *subfile;

	if((subfile = fdopen(subfilefd, "r")) == NULL) {
		log_error("could not fdopen subfilefd");
		exit(EXIT_FAILURE);
	}
	
	while ((buf = myfgetline(subfile))) {
		while (buf[0] && isspace(buf[strlen(buf)-1]))
			buf[strlen(buf)-1] = '\0';
		if (strcasecmp(buf, address) == 0) {
			free(buf);
			return 0;
		}
		free(buf);
	}

	free(buf);
	
	return 1;
}