diff options
| author | Marcel Holtmann <marcel@holtmann.org> | 2003-03-07 23:10:29 +0000 | 
|---|---|---|
| committer | Marcel Holtmann <marcel@holtmann.org> | 2003-03-07 23:10:29 +0000 | 
| commit | c7c04aac86fec5084e3e1caf3eaaa3abd545f58d (patch) | |
| tree | c720a81d87ca50b47806fd5454ddc87015fdb2a9 | |
| parent | eeb3109cedd192d95abe9b103d78d10685ba4004 (diff) | |
Removes all dependencies on glib
| -rw-r--r-- | configure.in | 16 | ||||
| -rw-r--r-- | hcid/Makefile.am | 4 | ||||
| -rw-r--r-- | hcid/glib-ectomy.c | 168 | ||||
| -rw-r--r-- | hcid/glib-ectomy.h | 101 | ||||
| -rw-r--r-- | hcid/hcid.h | 2 | ||||
| -rw-r--r-- | hcid/main.c | 2 | ||||
| -rw-r--r-- | hcid/security.c | 21 | ||||
| -rw-r--r-- | utils.spec | 3 | 
8 files changed, 287 insertions, 30 deletions
| diff --git a/configure.in b/configure.in index 80a1b092..3ee5b5f0 100644 --- a/configure.in +++ b/configure.in @@ -16,9 +16,6 @@ AM_INIT_AUTOMAKE(bluez-utils, 2.2)  AC_SUBST(DISTRO)  AC_SUBST(PCMCIA) -AC_SUBST(GLIB_CFLAGS) -AC_SUBST(GLIB_LDFLAGS) -  CFLAGS="-Wall -g -O2"  AC_PREFIX_DEFAULT() @@ -57,19 +54,6 @@ AC_SEARCH_LIB(bluetooth, hci_open_dev, $BLUEZ_LIBDIR,,  		Please compile and install bluez-libs package.)  ) -AC_ARG_WITH(glib-config, -        --with-glib-config=prog   glib-config location, -        GLIB_CONFIG="$withval", -        [ -                AC_PATH_PROGS(GLIB_CONFIG, glib-config, no) -                if test "$GLIB_CONFIG" = "no"; then -                        AC_MSG_ERROR(GLib not found) -                fi -        ] -) -GLIB_CFLAGS="`$GLIB_CONFIG --cflags`" -GLIB_LDFLAGS="`$GLIB_CONFIG --libs`" -  dnl Check for distro type.  DISTRO=unknown diff --git a/hcid/Makefile.am b/hcid/Makefile.am index 49386a93..bb666044 100644 --- a/hcid/Makefile.am +++ b/hcid/Makefile.am @@ -4,11 +4,9 @@  sbin_PROGRAMS = hcid -hcid_SOURCES = main.c security.c hcid.h lib.c lib.h parser.h parser.y lexer.l kword.h kword.c +hcid_SOURCES = main.c security.c hcid.h lib.c lib.h parser.h parser.y lexer.l kword.h kword.c glib-ectomy.h glib-ectomy.c  hcid_CONFIG  = hcid.conf -hcid_LDADD   = @GLIB_LDFLAGS@ -INCLUDES = @GLIB_CFLAGS@  YFLAGS   = -d  CLEANFILES = lexer.c parser.c parser.h diff --git a/hcid/glib-ectomy.c b/hcid/glib-ectomy.c new file mode 100644 index 00000000..0f168d80 --- /dev/null +++ b/hcid/glib-ectomy.c @@ -0,0 +1,168 @@ +#include "glib-ectomy.h" + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <errno.h> +#include <fcntl.h> +#include <limits.h> + +// static void remove_watch(int fd); + +GIOError    g_io_channel_read   (GIOChannel    *channel,  +			         gchar         *buf,  +			         gsize          count, +			         gsize         *bytes_read) +{ +	int fd = channel->fd; +	gssize result; +	 +  if (count > SSIZE_MAX) /* At least according to the Debian manpage for read */ +    count = SSIZE_MAX; + + retry: +  result = read (fd, buf, count); +  +  if (result < 0) +    { +      *bytes_read = 0; + +      switch (errno) +        { +#ifdef EINTR +          case EINTR: +            goto retry; +#endif +#ifdef EAGAIN +          case EAGAIN: +            return G_IO_STATUS_AGAIN; +#endif +          default: +            return G_IO_STATUS_ERROR; +        } +    } + +  *bytes_read = result; + +  return (result > 0) ? G_IO_STATUS_NORMAL : G_IO_STATUS_EOF; +} + +void      g_io_channel_close    (GIOChannel    *channel) +{ +	int fd = channel->fd; + +	close(fd); + +	memset(channel, 0, sizeof(channel)); +	free(channel); +} + +GIOChannel* g_io_channel_unix_new    (int         fd) +{ +	GIOChannel *channel = malloc(sizeof(GIOChannel)); +	channel->fd = fd; +	return channel; +} + +gint        g_io_channel_unix_get_fd (GIOChannel *channel) +{ +	return channel->fd; +} + + + +struct watch { +	guint id; +	GIOChannel *channel; +	GIOCondition condition; +	GIOFunc func; +	gpointer user_data; + +	struct watch *next; +}; + +static struct watch watch_head = { .id = 0, .next = 0 }; + +guint     g_io_add_watch        (GIOChannel      *channel, +				 GIOCondition     condition, +				 GIOFunc          func, +				 gpointer         user_data) +{ +	struct watch *watch = malloc(sizeof(struct watch)); + +	watch->id = ++watch_head.id; +	watch->channel = channel; +	watch->condition = condition; +	watch->func = func; +	watch->user_data = user_data; + +	watch->next = watch_head.next; +	watch_head.next = watch; + +	return watch->id; +} + +GMainLoop *g_main_loop_new        (GMainContext *context, +			    	   gboolean      is_running) +{ +	GMainLoop *ml = malloc(sizeof(GMainLoop)); + +	ml->bail = 0; + +	return ml; +} + +void       g_main_loop_run        (GMainLoop    *loop) +{ +	int open_max = sysconf(_SC_OPEN_MAX); +	struct pollfd *ufds = malloc(open_max * sizeof(struct pollfd)); + +	while (!loop->bail) { +		int nfds, rc, i; +		struct watch *p, *w; + +		nfds = 0; +		for (w = watch_head.next; w != NULL; w = w->next) { +			ufds[nfds].fd = w->channel->fd; +			ufds[nfds].events = w->condition; +			ufds[nfds].revents = 0; +			nfds++; +		} +		 +		rc = poll(ufds, nfds, -1); + +		if (rc < 0 && (errno == EINTR)) +			continue; + +		if (rc < 0) { +			perror("poll"); +			continue; +		} +		 +		p = &watch_head; +		w = watch_head.next; +		i = 0; +		while (w) { +			if (ufds[i].revents) { +				gboolean keep = w->func(w->channel, ufds[i].revents, w->user_data); +				if (!keep) { +					 p->next = w->next; +					 memset(w, 0, sizeof(*w)); +					 w = p->next; +					 i++; +					 continue; +				} +			}	 +		 +			p = w; +			w = w->next; +			i++; +		} + +	} +} + +void       g_main_loop_quit       (GMainLoop    *loop) +{ +	loop->bail = 1; +} diff --git a/hcid/glib-ectomy.h b/hcid/glib-ectomy.h new file mode 100644 index 00000000..78cd9d8a --- /dev/null +++ b/hcid/glib-ectomy.h @@ -0,0 +1,101 @@ +#ifndef _GLIB_ECTOMY_H_ +#define _GLIB_ECTOMY_H_ + +#include <stdlib.h> +#include <sys/poll.h> + +typedef char   gchar; +typedef short  gshort; +typedef long   glong; +typedef int    gint; +typedef gint   gboolean; + +typedef unsigned char   guchar; +typedef unsigned short  gushort; +typedef unsigned long   gulong; +typedef unsigned int    guint; + +typedef float   gfloat; +typedef double  gdouble; + +typedef void* gpointer; +typedef const void *gconstpointer; + +typedef size_t gsize; +typedef ssize_t gssize; + +typedef struct _GIOChannel { +	int fd; +} GIOChannel; + +typedef struct _GMainContext { +	int dummy; +} GMainContext; + +typedef struct _GMainLoop { +	int bail; +} GMainLoop; + +typedef enum +{ +  G_IO_ERROR_NONE, +  G_IO_ERROR_AGAIN, +  G_IO_ERROR_INVAL, +  G_IO_ERROR_UNKNOWN +} GIOError; + +typedef enum +{ +  G_IO_STATUS_ERROR = -1, +  G_IO_STATUS_NORMAL = 0, +  G_IO_STATUS_EOF = 1, +  G_IO_STATUS_AGAIN = 2 +} GIOStatus; + +#ifndef	FALSE +#define	FALSE	(0) +#endif + +#ifndef	TRUE +#define	TRUE	(!FALSE) +#endif + + +typedef enum +{ +  G_IO_IN	= POLLIN, +  G_IO_OUT	= POLLOUT, +  G_IO_PRI	= POLLPRI, +  G_IO_ERR	= POLLERR, +  G_IO_HUP	= POLLHUP, +  G_IO_NVAL	= POLLNVAL +} GIOCondition; + +typedef gboolean (*GIOFunc) (GIOChannel   *source, +			     GIOCondition  condition, +			     gpointer      data); + +GIOError    g_io_channel_read   (GIOChannel    *channel,  +			         gchar         *buf,  +			         gsize          count, +			         gsize         *bytes_read); +void      g_io_channel_close    (GIOChannel    *channel); + +GIOChannel* g_io_channel_unix_new    (int         fd); +gint        g_io_channel_unix_get_fd (GIOChannel *channel); +guint     g_io_add_watch        (GIOChannel      *channel, +				 GIOCondition     condition, +				 GIOFunc          func, +				 gpointer         user_data); + + +GMainLoop *g_main_loop_new        (GMainContext *context, +			    	   gboolean      is_running); +void       g_main_loop_run        (GMainLoop    *loop); +void       g_main_loop_quit       (GMainLoop    *loop); + +#define 	g_main_new(is_running)	g_main_loop_new (NULL, is_running); +#define         g_main_run(loop)        g_main_loop_run(loop) +#define         g_main_quit(loop)       g_main_loop_quit(loop) + +#endif diff --git a/hcid/hcid.h b/hcid/hcid.h index 3e7838b4..55ef0ab0 100644 --- a/hcid/hcid.h +++ b/hcid/hcid.h @@ -26,7 +26,7 @@  #include <sys/types.h> -#include <glib.h> +#include "glib-ectomy.h"  #include <bluetooth/bluetooth.h> diff --git a/hcid/main.c b/hcid/main.c index 8a5371e5..85534fdf 100644 --- a/hcid/main.c +++ b/hcid/main.c @@ -44,7 +44,7 @@  #include <bluetooth/hci.h>  #include <bluetooth/hci_lib.h> -#include <glib.h> +#include "glib-ectomy.h"  #include "hcid.h"  #include "lib.h" diff --git a/hcid/security.c b/hcid/security.c index b7839c4c..0380d31f 100644 --- a/hcid/security.c +++ b/hcid/security.c @@ -46,7 +46,7 @@  #include <bluetooth/hci.h>  #include <bluetooth/hci_lib.h> -#include <glib.h> +#include "glib-ectomy.h"  #include "hcid.h"  #include "lib.h" @@ -108,6 +108,9 @@ static void link_key_request(int dev, bdaddr_t *sba, bdaddr_t *dba)  {  	struct link_key *key = get_link_key(sba, dba); +	syslog(LOG_INFO, "link_key_request (sba=%s, dba=%s)\n", +	       batostr(sba), batostr(dba)); +  	if (key) {  		/* Link key found */  		link_key_reply_cp lr; @@ -170,6 +173,8 @@ static void link_key_notify(int dev, bdaddr_t *sba, void *ptr)  	bdaddr_t *dba = &evt->bdaddr;  	struct link_key key; +	syslog(LOG_INFO, "link_key_notify (sba=%s)\n", batostr(sba)); +  	memcpy(key.key, evt->link_key, 16);  	bacpy(&key.sba, sba);  	bacpy(&key.dba, dba); @@ -289,6 +294,9 @@ static void pin_code_request(int dev, bdaddr_t *sba, bdaddr_t *dba)  	struct hci_conn_info_req *cr;  	struct hci_conn_info *ci; +	syslog(LOG_INFO, "pin_code_request (sba=%s, dba=%s)\n", +	       batostr(sba), batostr(dba)); +  	cr = malloc(sizeof(*cr) + sizeof(*ci));  	if (!cr)  		return; @@ -350,12 +358,7 @@ gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer data)  	hci_event_hdr *eh;  	GIOError err; -	if (cond & G_IO_NVAL) { -		free(data); -		return FALSE; -	} - -	if (cond & (G_IO_HUP | G_IO_ERR)) { +	if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {  		g_io_channel_close(chan);  		free(data);  		return FALSE; @@ -365,6 +368,7 @@ gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer data)  		if (err == G_IO_ERROR_AGAIN)  			return TRUE;  		g_io_channel_close(chan); +		free(data);  		return FALSE;  	} @@ -458,6 +462,9 @@ void stop_security_manager(int hdev)  	syslog(LOG_INFO, "Stoping security manager %d", hdev); +	/* this is a bit sneaky. closing the fd will cause the event +	   loop to call us right back with G_IO_NVAL set, at which +	   point we will see it and clean things up */  	close(g_io_channel_unix_get_fd(chan));  	io_chan[hdev] = NULL;  } @@ -18,10 +18,8 @@ BuildRoot: /var/tmp/%{name}-%{PACKAGE_VERSION}-root  URL: http://bluez.sourceforge.net  Docdir: %{prefix}/usr/share/doc  Requires: glibc >= 2.2.4 -Requires: glib >= 1.2  Requires: bluez-libs >= 2.0  BuildRequires: glibc >= 2.2.4 -BuildRequires: glib-devel >= 1.2  BuildRequires: bluez-libs >= 2.0  %description @@ -71,6 +69,7 @@ rm -rf $RPM_BUILD_ROOT  %{_mandir}/man8/hciconfig.8.gz  %{_mandir}/man1/hcitool.1.gz  %{_mandir}/man1/l2ping.1.gz +%{_mandir}/man1/rfcomm.1.gz  %{_sysconfdir}/bluetooth/*  %{_sysconfdir}/pcmcia/bluetooth.conf  %{_sysconfdir}/pcmcia/bluetooth | 
