On Tue, Nov 07, 2000 at 08:12:09PM +0100, Pontus Fuchs wrote:
> Hi!
> 
> > > I really reccomend that you get the latest version from CVS. If you
> > > cannot
> > > get CVS-access I can mail you a snapshot which will contain the "ircp"
> > > code too.
> > 
> >         Would you mind doing a tar.gz ? Or if you have some
> > instructions on how to set up CVS through a Socks proxy...
> 
> Here it comes. I had a math-exam last week, so thats why it took me so
> long :)

        Yep, and you probably can guess what kept me busy last week ;-)

> I have some problems when sending files from Win2k. I used to get oopses
> very often, but when I tried with 2.4.0-test10 I didn't get oopses, but
> the connection is very easily interrupted. Do do have any idea?

        Nope. See other e-mail...

> /Pontus Fuchs

        Let's get to the meat. I did a little patch of the Obex
library to fit my needs. Here is the changelog :
        o Full "accept" capability in OBEX Server (optional) :
                -> Keep server alive
                -> Detach receiver instance from server instance
        o Properly close all sockets (server + receiver) when Cleanup
        o Declare OBEX_GetFD() in obex.h
        o Updated irda.h to the latest
        o OBEX Server do tell IrDA stack to advertise OBEX hint bit
        o OBEX Client can do optional hint bit filtering of discovery log
        o OBEX Client can do optional IAS entry filtering of discovery log
        o Safer discovery log allocation

        I hope you will like it. I also hope you saw my fixes to
irdadump on the list a few days ago, I plan to add Ultra-Obex support
to it ;-)

        Now, I've got a few questions for you :
        o Do you have any example of GET ?
        o Do you have any example of authentication ?

        I think that's enough for today...
        Have fun ;-)

        Jean
diff -u -r -p openobex-snap-orig/lib/src/inobex.c openobex-snap/lib/src/inobex.c
--- openobex-snap-orig/lib/src/inobex.c Mon Aug 28 01:56:33 2000
+++ openobex-snap/lib/src/inobex.c      Fri Nov 10 11:36:55 2000
@@ -85,6 +85,8 @@ gint inobex_listen(obex_t *self, const c
  *
  *    Accept incoming connection.
  *
+ * Note : don't close the server socket here, so apps may want to continue
+ * using it...
  */
 gint inobex_accept(obex_t *self)
 {
@@ -93,9 +95,6 @@ gint inobex_accept(obex_t *self)
        self->fd = accept(self->serverfd, (struct sockaddr *) 
                &self->trans.peer.inet, &addrlen);
 
-       obex_delete_socket(self, self->serverfd);
-       self->serverfd = -1;
-
        if(self->fd < 0)
                return -1;
 
@@ -170,3 +169,19 @@ gint inobex_disconnect_request(obex_t *s
        return ret;     
 }
 
+/*
+ * Function inobex_transport_disconnect_server (self)
+ *
+ *    Close the server socket
+ *
+ * Used when we start handling a incomming request, or when the
+ * client just want to quit...
+ */
+gint inobex_disconnect_server(obex_t *self)
+{
+       gint ret;
+       DEBUG(4, G_GNUC_FUNCTION "()\n");
+       ret = obex_delete_socket(self, self->serverfd);
+       self->serverfd = -1;
+       return ret;     
+}
diff -u -r -p openobex-snap-orig/lib/src/inobex.h openobex-snap/lib/src/inobex.h
--- openobex-snap-orig/lib/src/inobex.h Mon Aug 28 01:56:42 2000
+++ openobex-snap/lib/src/inobex.h      Fri Nov 10 11:36:55 2000
@@ -35,5 +35,6 @@ gint inobex_listen(obex_t *self, const c
 gint inobex_accept(obex_t *self);
 gint inobex_connect_request(obex_t *self);
 gint inobex_disconnect_request(obex_t *self);
+gint inobex_disconnect_server(obex_t *self);
 
 #endif
diff -u -r -p openobex-snap-orig/lib/src/irda.h openobex-snap/lib/src/irda.h
--- openobex-snap-orig/lib/src/irda.h   Wed Aug  2 06:11:23 2000
+++ openobex-snap/lib/src/irda.h        Mon Nov 13 10:50:33 2000
@@ -1,12 +1,12 @@
 /*********************************************************************
  *                
  * Filename:      irda.h
- * Version:       1.0
+ * Version:       1.1
  * Description:   IrDA header file to be used by IrDA applications
  * Status:        Experimental.
  * Author:        Dag Brattli <[EMAIL PROTECTED]>
  * Created at:    Mon Mar  8 14:06:12 1999
- * Modified at:   Sat Dec 25 16:07:54 1999
+ * Modified at:   Sat Dec 25 16:06:42 1999
  * Modified by:   Dag Brattli <[EMAIL PROTECTED]>
  * 
  *     Copyright (c) 1999 Dag Brattli, All Rights Reserved.
@@ -80,22 +80,25 @@ enum {
 #define SOL_IRLMP      266 /* Same as SOL_IRDA for now */
 #define SOL_IRTTP      266 /* Same as SOL_IRDA for now */
 
-#define IRLMP_ENUMDEVICES        1
-#define IRLMP_IAS_SET            2
-#define IRLMP_IAS_QUERY          3
-#define IRLMP_HINTS_SET          4
+#define IRLMP_ENUMDEVICES        1     /* Return discovery log */
+#define IRLMP_IAS_SET            2     /* Set an attribute in local IAS */
+#define IRLMP_IAS_QUERY          3     /* Query remote IAS for attribute */
+#define IRLMP_HINTS_SET          4     /* Set hint bits advertised */
 #define IRLMP_QOS_SET            5
 #define IRLMP_QOS_GET            6
 #define IRLMP_MAX_SDU_SIZE       7
-#define IRLMP_IAS_GET            8
+#define IRLMP_IAS_GET            8     /* Get an attribute from local IAS */
+#define IRLMP_IAS_DEL           9      /* Remove attribute from local IAS */
+#define IRLMP_HINT_MASK_SET    10      /* Set discovery filter */
+#define IRLMP_WAITDEVICE       11      /* Wait for a new discovery */
 
 #define IRTTP_MAX_SDU_SIZE IRLMP_MAX_SDU_SIZE /* Compatibility */
 
 /* LM-IAS Limits */
-#define IAS_MAX_STRING        256
-#define IAS_MAX_OCTET_STRING 1024
-#define IAS_MAX_CLASSNAME      64
-#define IAS_MAX_ATTRIBNAME    256
+#define IAS_MAX_STRING         256
+#define IAS_MAX_OCTET_STRING  1024
+#define IAS_MAX_CLASSNAME       64
+#define IAS_MAX_ATTRIBNAME     256
 
 /* LM-IAS Attribute types */
 #define IAS_MISSING 0
@@ -106,18 +109,18 @@ enum {
 #define LSAP_ANY              0xff
 
 struct sockaddr_irda {
-       sa_family_t   sir_family;   /* AF_IRDA */
-       u_int8_t      sir_lsap_sel; /* LSAP selector */
-       u_int32_t     sir_addr;     /* Device address */
-       char          sir_name[25]; /* Usually <service>:IrDA:TinyTP */
+       sa_family_t     sir_family;   /* AF_IRDA */
+       u_int8_t        sir_lsap_sel; /* LSAP selector */
+       u_int32_t       sir_addr;     /* Device address */
+       char            sir_name[25]; /* Usually <service>:IrDA:TinyTP */
 };
 
 struct irda_device_info {
-       u_int32_t     saddr;    /* Address of local interface */
-       u_int32_t     daddr;    /* Address of remote device */
-       char          info[22]; /* Description */
-       u_int8_t      charset;  /* Charset used for description */
-       u_int8_t      hints[2]; /* Hint bits */
+       u_int32_t       saddr;    /* Address of local interface */
+       u_int32_t       daddr;    /* Address of remote device */
+       char            info[22]; /* Description */
+       u_int8_t        charset;  /* Charset used for description */
+       u_int8_t        hints[2]; /* Hint bits */
 };
 
 struct irda_device_list {
@@ -133,14 +136,15 @@ struct irda_ias_set {
                unsigned int irda_attrib_int;
                struct {
                        unsigned short len;
-                       u_char octet_seq[IAS_MAX_OCTET_STRING];
+                       u_int8_t octet_seq[IAS_MAX_OCTET_STRING];
                } irda_attrib_octet_seq;
                struct {
-                       unsigned char len;
-                       unsigned char charset;
-                       unsigned char string[IAS_MAX_STRING];
+                       u_int8_t len;
+                       u_int8_t charset;
+                       u_int8_t string[IAS_MAX_STRING];
                } irda_attrib_string;
        } attribute;
+       u_int32_t       daddr;    /* Address of device (for IAS query only) */
 };
 
 /* Some private IOCTL's (max 16) */
@@ -171,8 +175,8 @@ struct if_irda_qos {
 
 /* For setting RTS and DTR lines of a dongle */
 struct if_irda_line {
-       unsigned char dtr;
-       unsigned char rts;
+       u_int8_t dtr;
+       u_int8_t rts;
 };
 
 /* IrDA interface configuration (data part must not exceed 16 bytes) */
diff -u -r -p openobex-snap-orig/lib/src/irobex.c openobex-snap/lib/src/irobex.c
--- openobex-snap-orig/lib/src/irobex.c Mon Aug 28 01:58:56 2000
+++ openobex-snap/lib/src/irobex.c      Mon Nov 13 12:15:17 2000
@@ -38,9 +38,12 @@
 #include <irda_wrap.h>
 
 #else /* _WIN32 */
+/* Linux case */
 
 #include <string.h>
 #include <unistd.h>
+#include <stdio.h>             /* perror */
+#include <errno.h>             /* errno and EADDRNOTAVAIL */
 #include <netinet/in.h>
 #include <sys/socket.h>
 
@@ -108,6 +111,28 @@ gint irobex_listen(obex_t *self, const c
                goto out_freesock;
        }
 
+#ifndef _WIN32
+       /* Ask the IrDA stack to advertise the Obex hint bit - Jean II */
+       /* Under Linux, it's a regular socket option */
+       {
+               unsigned char   hints[4];       /* Hint be we advertise */
+
+               /* We want to advertise the OBEX hint bit */
+               hints[0] = HINT_EXTENSION;
+               hints[1] = HINT_OBEX;
+
+               /* Tell the stack about it */
+               if (setsockopt(self->serverfd, SOL_IRLMP, IRLMP_HINTS_SET,
+                              hints, sizeof(hints))) {
+                       perror("setsockopt:");
+                       return(-1);
+               }
+       }
+#else /* _WIN32 */
+       /* Ask the IrDA stack to advertise the Obex hint bit */
+       /* Under Windows, it's a complicated story */
+#endif /* _WIN32 */
+
        if (listen(self->serverfd, 1)) {
                DEBUG(0, G_GNUC_FUNCTION "() Error doing listen\n");
                goto out_freesock;
@@ -127,6 +152,8 @@ out_freesock:
  *
  *    Accept an incoming connection.
  *
+ * Note : don't close the server socket here, so apps may want to continue
+ * using it...
  */
 gint irobex_accept(obex_t *self)
 {
@@ -138,10 +165,6 @@ gint irobex_accept(obex_t *self)
        self->fd = accept(self->serverfd, (struct sockaddr *) &self->trans.peer.irda,
                          &addrlen);
 
-       // Now close the serversocket.
-       obex_delete_socket(self, self->serverfd);
-       self->serverfd = -1;
-
        if (self->fd < 0) {
                return -1;
        }
@@ -169,6 +192,127 @@ gint irobex_accept(obex_t *self)
        return 0;
 }
        
+/* Memory allocation for discovery */
+#define DISC_BUF_LEN   sizeof(struct irda_device_list) + \
+                       sizeof(struct irda_device_info) * (MAX_DEVICES)
+/*
+ * Function echo_discover_devices (self)
+ *
+ *    Try to discover some remote device(s) that we can connect to
+ *
+ * Note : we optionally can do a first filtering on the Obex hint bit,
+ * and then we can verify that the device does have the requested service...
+ * Note : in this function, the memory allocation for the discovery log
+ * is done "the right way", so that it's safe and we don't leak memory...
+ * Jean II
+ */
+static gint irobex_discover_devices(obex_t *self)
+{
+       struct irda_device_list *       list;
+       unsigned char           buf[DISC_BUF_LEN];
+       int ret = -1;
+       int err;
+       int len;
+       int i;
+
+#ifndef _WIN32
+       /* Hint bit filtering. Linux case */
+       if(self->filterhint) {
+               unsigned char   hints[4];       /* Hint be we filter on */
+
+               /* We want only devices that advertise OBEX hint */
+               hints[0] = HINT_EXTENSION;
+               hints[1] = HINT_OBEX;
+
+               /* Set the filter used for performing discovery */
+               if (setsockopt(self->fd, SOL_IRLMP, IRLMP_HINT_MASK_SET,
+                              hints, sizeof(hints))) {
+                       perror("setsockopt:");
+                       return(-1);
+               }
+       }
+#endif /* _WIN32 */
+
+       /* Set the list to point to the correct place */
+       list = (struct irda_device_list *) buf;
+       len = DISC_BUF_LEN;
+
+       /* Perform a discovery and get device list */
+       if (getsockopt(self->fd, SOL_IRLMP, IRLMP_ENUMDEVICES, buf, &len)) {
+               DEBUG(1, "Didn't find any devices!\n");
+               return(-1);
+       }
+
+       /* Did we got any ? (in some rare cases, this test is true) */
+       if (list->len <= 0) {
+               DEBUG(1, "Didn't find any devices!\n");
+               return(-1);
+       }
+
+#ifndef _WIN32
+       /* List all Obex devices : Linux case */
+       DEBUG(1, "Discovered %d devices :\n", list->len);
+       for(i = 0; i < list->len; i++) {
+               DEBUG(1, "  [%d] name:  %s, daddr: 0x%08x",
+                     i + 1, list->dev[i].info, list->dev[i].daddr);
+               //fflush(stdout);
+
+               /* Do we want to filter devices based on IAS ? */
+               if(self->filterias) {
+                       struct irda_ias_set ias_query;
+                       /* Ask if the requested service exist on this device */
+                       len = sizeof(ias_query);
+                       ias_query.daddr = list->dev[i].daddr;
+                       strcpy(ias_query.irda_class_name,
+                              self->trans.peer.irda.sir_name);
+                       strcpy(ias_query.irda_attrib_name,
+                              "IrDA:TinyTP:LsapSel");
+                       err = getsockopt(self->fd, SOL_IRLMP, IRLMP_IAS_QUERY,
+                                        &ias_query, &len);
+                       /* Check if we failed */
+                       if(err != 0) {
+                               if(errno != EADDRNOTAVAIL) {
+                                       DEBUG(1, " <can't query IAS>\n");
+                               } else {
+                                       DEBUG(1, ", doesn't have %s\n",
+                                             self->trans.peer.irda.sir_name);
+                               }
+                               /* Go back to for(;;) */
+                               continue;
+                       }
+                       DEBUG(1, ", has service %s\n",
+                             self->trans.peer.irda.sir_name);
+               }
+               else {
+                       DEBUG(1, "\n");
+               }
+
+               /* Pick this device */
+               self->trans.peer.irda.sir_addr = list->dev[i].daddr;
+               self->trans.self.irda.sir_addr = list->dev[i].saddr;
+               ret = 0;
+       }
+#else
+       /* List all Obex devices : Win32 case */
+       if (len > 0) {
+               DEBUG(1, "Discovered: (list len=%d)\n", list->numDevice);
+
+               for (i=0; i<(int)list->numDevice; i++) {
+                       DEBUG(1, "  name:  %s\n", list->Device[i].irdaDeviceName);
+                       DEBUG(1, "  daddr: %08x\n", list->Device[i].irdaDeviceID);
+                       memcpy(&self->trans.peer.irda.irdaDeviceID[0], 
+&list->Device[i].irdaDeviceID[0], 4);
+                       ret = 0;
+               }
+       }
+#endif /* _WIN32 */
+
+       if(ret <  0)
+               DEBUG(1, G_GNUC_FUNCTION "(), didn't find any OBEX devices!\n");
+       return(ret);
+}
+
+#if 0
+/* Deprecated by the above function. */
 /*
  * Function irobex_discover_devices (fd)
  *
@@ -232,6 +376,7 @@ static gint irobex_discover_devices(obex
        g_free(buf);
        return ret;
 }
+#endif /* 0 */
 
 /*
  * Function irobex_irda_connect_request (self)
@@ -303,6 +448,23 @@ gint irobex_disconnect_request(obex_t *s
        if(ret < 0)
                return ret;
        self->fd = -1;
+       return ret;     
+}
+
+/*
+ * Function irobex_link_disconnect_server (self)
+ *
+ *    Close the server socket
+ *
+ * Used when we start handling a incomming request, or when the
+ * client just want to quit...
+ */
+gint irobex_disconnect_server(obex_t *self)
+{
+       gint ret;
+       DEBUG(4, G_GNUC_FUNCTION "()\n");
+       ret = obex_delete_socket(self, self->serverfd);
+       self->serverfd = -1;
        return ret;     
 }
 
diff -u -r -p openobex-snap-orig/lib/src/irobex.h openobex-snap/lib/src/irobex.h
--- openobex-snap-orig/lib/src/irobex.h Mon Aug 28 01:58:49 2000
+++ openobex-snap/lib/src/irobex.h      Fri Nov 10 11:36:55 2000
@@ -38,5 +38,6 @@ gint irobex_listen(obex_t *self, const c
 gint irobex_connect_request(obex_t *self);
 gint irobex_disconnect_request(obex_t *self);
 gint irobex_accept(obex_t *self);
+gint irobex_disconnect_server(obex_t *self);
 
 #endif
diff -u -r -p openobex-snap-orig/lib/src/obex.c openobex-snap/lib/src/obex.c
--- openobex-snap-orig/lib/src/obex.c   Mon Aug 28 12:03:07 2000
+++ openobex-snap/lib/src/obex.c        Fri Nov 10 17:25:50 2000
@@ -97,6 +97,9 @@ obex_t *OBEX_Init(gint transport, obex_e
        if(flags & OBEX_FL_ASYNC) {
                self->async = 1;
        }
+       self->keepserver = (flags & OBEX_FL_KEEPSERVER) ? TRUE : FALSE;
+       self->filterhint = (flags & OBEX_FL_FILTERHINT) ? TRUE : FALSE;
+       self->filterias  = (flags & OBEX_FL_FILTERIAS ) ? TRUE : FALSE;
        self->fd = -1;
        self->serverfd = -1;
 
@@ -152,7 +155,8 @@ void OBEX_Cleanup(obex_t *self)
        g_return_if_fail(self != NULL);
        
        obex_transport_disconnect_request(self);
-       
+       obex_transport_disconnect_server(self);
+
        if (self->tx_msg)
                g_netbuf_free(self->tx_msg);
        
@@ -205,6 +209,80 @@ gint OBEX_ServerRegister(obex_t *self, c
 
 
 /*
+ * Function OBEX_ServerAccept (self, eventcb, data)
+ *
+ *    Accept an Obex connection
+ *
+ * Create a new Obex instance to handle the incomming connection.
+ * The old instance will continue to listen for new conenctions.
+ */
+obex_t *OBEX_ServerAccept(obex_t *server, obex_event_t eventcb, gpointer data)
+{
+       obex_t *self;
+
+       DEBUG(3, G_GNUC_FUNCTION "()\n");
+
+       g_return_val_if_fail(server != NULL, NULL);
+
+       /* We can accept only if both the server and the connection socket
+        * are active */
+       if((server->fd <= 0) || (server->serverfd <= 0))
+               return(NULL);
+
+       /* If we have started receiving something, it's too late... */
+       if(server->object != NULL)
+               return(NULL);
+
+       /* Allocate new instance */
+       self = (obex_t*) g_malloc(sizeof(obex_t));
+       if (!self) {
+               /* perror(G_GNUC_FUNCTION "()"); */
+               return(NULL);
+       }
+       memset(self, 0, sizeof(obex_t));
+
+       /* Set callback and callback data as needed */
+       if(eventcb != NULL)
+               self->eventcb = eventcb;
+       else
+               self->eventcb = server->eventcb;
+       if(data != NULL)
+               self->userdata = data;
+       else
+               self->userdata = server->userdata;
+
+       self->async = server->async;
+       self->keepserver = server->keepserver;
+
+       /* Copy transport data */
+       memcpy(&self->trans, &server->trans, sizeof(obex_transport_t));
+       memcpy(&self->ctrans, &server->ctrans, sizeof(obex_ctrans_t));
+
+       self->mtu_rx = server->mtu_rx;
+       self->mtu_tx = server->mtu_tx;
+
+       /* Allocate message buffers */
+       self->rx_msg = g_netbuf_new(self->mtu_rx);
+       if (self->rx_msg == NULL)
+               return NULL;
+
+       self->tx_msg = g_netbuf_new(self->mtu_tx);
+       if (self->tx_msg == NULL) {
+               g_netbuf_free(self->rx_msg);
+               return NULL;
+       }
+
+       /* Now, that's the interesting bit !
+        * We split the sockets apart, one for each instance */
+       self->fd = server->fd;
+       self->serverfd = -1;
+       server->fd = -1;
+
+       return self;
+}
+
+
+/*
  * Function OBEX_HandleInput (self, timeout)
  *
  *    Used when the client or server is working in synchronous mode.
@@ -579,4 +657,4 @@ GString* OBEX_GetResponseMessage(obex_t 
        g_return_val_if_fail(self != NULL, NULL);
        return obex_get_response_message(self, rsp);
 }
-       
\ No newline at end of file
+       
diff -u -r -p openobex-snap-orig/lib/src/obex.h openobex-snap/lib/src/obex.h
--- openobex-snap-orig/lib/src/obex.h   Mon Aug 28 02:29:31 2000
+++ openobex-snap/lib/src/obex.h        Fri Nov 10 11:36:55 2000
@@ -53,6 +53,7 @@ obex_t *OBEX_Init(gint transport, obex_e
 void    OBEX_Cleanup(obex_t *self);
 void OBEX_SetUserData(obex_t *self, gpointer data);
 gpointer OBEX_GetUserData(obex_t *self);
+gint OBEX_GetFD(obex_t *self);
 
 gint OBEX_RegisterCTransport(obex_t *self, obex_ctrans_t *ctrans);
 
@@ -62,6 +63,7 @@ gint    OBEX_CustomDataFeed(obex_t *self
 gint    OBEX_HandleInput(obex_t *self, gint timeout);
 
 gint    OBEX_ServerRegister(obex_t *self, const char *service);
+obex_t *OBEX_ServerAccept(obex_t *server, obex_event_t eventcb, gpointer data);
 gint    OBEX_Request(obex_t *self, obex_object_t *object);
 gint    OBEX_CancelRequest(obex_t *self);
 
diff -u -r -p openobex-snap-orig/lib/src/obex_const.h 
openobex-snap/lib/src/obex_const.h
--- openobex-snap-orig/lib/src/obex_const.h     Mon Aug 28 02:05:32 2000
+++ openobex-snap/lib/src/obex_const.h  Fri Nov 10 17:21:39 2000
@@ -57,9 +57,13 @@ typedef struct {
 #define OBEX_EV_REQDONE                3       /* Request has finished */
 #define OBEX_EV_LINKERR                4       /* Link has been disconnected */
 #define OBEX_EV_PARSEERR       5       /* Malformed data encountered */
+#define OBEX_EV_ACCEPTHINT     6       /* Connection accepted */
 
 /* For OBEX_Init() */
 #define OBEX_FL_ASYNC          0x01
+#define OBEX_FL_KEEPSERVER     0x02    /* Keep the server alive */
+#define OBEX_FL_FILTERHINT     0x04    /* Filter devices based on hint bit */
+#define OBEX_FL_FILTERIAS      0x08    /* Filter devices based on IAS entry */
 
 /* For OBEX_ObjectAddHeader */
 #define OBEX_FL_FIT_ONE_PACKET 0x01
diff -u -r -p openobex-snap-orig/lib/src/obex_main.h openobex-snap/lib/src/obex_main.h
--- openobex-snap-orig/lib/src/obex_main.h      Mon Oct 16 10:32:50 2000
+++ openobex-snap/lib/src/obex_main.h   Fri Nov 10 17:25:13 2000
@@ -93,6 +93,9 @@ struct obex {
        gint serverfd;
 
        gboolean async;
+       gboolean keepserver;            /* Keep server alive */
+       gboolean filterhint;            /* Filter devices based on hint bits */
+       gboolean filterias;             /* Filter devices based on IAS entry */
 
        GNetBuf *tx_msg;                /* Reusable transmit message */
        GNetBuf *rx_msg;                /* Reusable receive message */
diff -u -r -p openobex-snap-orig/lib/src/obex_transport.c 
openobex-snap/lib/src/obex_transport.c
--- openobex-snap-orig/lib/src/obex_transport.c Tue Aug 29 06:11:38 2000
+++ openobex-snap/lib/src/obex_transport.c      Fri Nov 10 11:36:55 2000
@@ -101,7 +101,18 @@ gint obex_transport_handle_input(obex_t 
 
                else if( (self->serverfd >= 0) && FD_ISSET(self->serverfd, &fdset)) {
                        DEBUG(4, G_GNUC_FUNCTION "() Data available on server 
socket\n");
+                       /* Accept : create the connected socket */
                        ret = obex_transport_accept(self);
+
+                       /* Tell the app to perform the OBEX_Accept() */
+                       if(self->keepserver)
+                               obex_deliver_event(self, OBEX_SERVER,
+                                                  OBEX_EV_ACCEPTHINT,
+                                                  0, 0, FALSE);
+                       /* Otherwise, just disconnect the server */
+                       if((ret >= 0) && (! self->keepserver)) {
+                               obex_transport_disconnect_server(self);
+                       }
                }
                else
                        ret = -1;
@@ -138,7 +149,7 @@ gint obex_transport_accept(obex_t *self)
        }
        return ret;
 }
-       
+
 
 
 /*
@@ -246,6 +257,36 @@ gint obex_transport_listen(obex_t *self,
                break;
        }
        return ret;
+}
+       
+/*
+ * Function obex_transport_disconnect_server (self)
+ *
+ *    Disconnect the listening server
+ *
+ * Used either after an accept, or directly at client request (app. exits)
+ * Note : obex_delete_socket() will catch the case when the socket
+ * doesn't exist (-1)...
+ */
+void obex_transport_disconnect_server(obex_t *self)
+{
+
+       switch (self->trans.type) {
+#ifdef HAVE_IRDA
+       case OBEX_TRANS_IRDA:
+               irobex_disconnect_server(self);
+               break;
+#endif /*HAVE_IRDA*/
+       case OBEX_TRANS_INET:
+               inobex_disconnect_server(self);
+               break;  
+       case OBEX_TRANS_CUST:
+               DEBUG(4, G_GNUC_FUNCTION "() Custom disconnect\n");
+               /* Fallback for now... */
+       default:
+               g_message(G_GNUC_FUNCTION "() Transport not implemented!\n");
+               break;
+       }
 }
 
 /*
diff -u -r -p openobex-snap-orig/lib/src/obex_transport.h 
openobex-snap/lib/src/obex_transport.h
--- openobex-snap-orig/lib/src/obex_transport.h Mon Aug 28 02:02:46 2000
+++ openobex-snap/lib/src/obex_transport.h      Fri Nov 10 11:36:55 2000
@@ -65,6 +65,7 @@ gint obex_transport_handle_input(obex_t 
 gint obex_transport_connect_request(obex_t *self);
 void obex_transport_disconnect_request(obex_t *self);
 gint obex_transport_listen(obex_t *self, const char *service);
+void obex_transport_disconnect_server(obex_t *self);
 gint obex_transport_write(obex_t *self, GNetBuf *msg);
 gint obex_transport_read(obex_t *self, guint8 *buf, gint buflen);
 

Reply via email to