From: Eduardo P. H. <eha...@ra...> - 2006-04-25 13:59:44
|
Hi, On Tue, Apr 25, 2006 at 05:37:48PM +0400, Alex Kanavin wrote: > On Tue, 25 Apr 2006, Marcel Holtmann wrote: >=20 > >Do we need the slist thing to be a separate file? I think it can go into > >databuffer.c as static function. >=20 > slist is used in other files too, so it's now in databuffer.c but not as= =20 > static. If it is used by other files, is there a reason to mix it with the databuffer-specific code? I would keep them in slist.c, even if the only user of the functions was databuffer.c. >=20 > >Other comments please, but I think it looks good. >=20 > Check the attachment with all the fixes. >=20 > Alexander >=20 > Homepage: http://www.sensi.org/~ak/ > diff -uNr openobex/lib/Makefile.am openobex.test/lib/Makefile.am > --- openobex/lib/Makefile.am 2006-03-07 19:56:20.000000000 +0200 > +++ openobex.test/lib/Makefile.am 2006-04-25 16:10:14.000000000 +0300 > @@ -13,7 +13,7 @@ > irobex.c irobex.h \ > inobex.c inobex.h \ > btobex.c btobex.h \ > - netbuf.c netbuf.h \ > + databuffer.c databuffer.h \ > irda.h irda_wrap.h \ > usbobex.c usbobex.h > =20 > diff -uNr openobex/lib/databuffer.c openobex.test/lib/databuffer.c > --- openobex/lib/databuffer.c 1970-01-01 02:00:00.000000000 +0200 > +++ openobex.test/lib/databuffer.c 2006-04-25 16:30:32.000000000 +0300 > @@ -0,0 +1,320 @@ > +/***********************************************************************= ** > + * > + * Filename: databuffer.c > + * Version: 0.3 > + * Description: Network buffer handling routines. > + * Status: Experimental. > + * Author: Herton Ronaldo Krzesinski <he...@co...> > + * Created at: Tue Jun 21 11:22:44 2005 > + * Modified at: Mon Aug 15 19:12:29 2005 > + * > + * Copyright (c) 2005 Herton Ronaldo Krzesinski, All Rights Reserved. > + * > + * This library is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2 of the License, or (at your option) any later version. > + * > + * This library is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with this library; if not, write to the Free Softwa= re > + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, > + * MA 02111-1307 USA > + * > + ***********************************************************************= **/ > + > +#include <databuffer.h> > +#include <assert.h> > +#include <stdlib.h> > +#include <stdio.h> > +#include <string.h> > + > +slist_t *slist_append(slist_t *list, void *element)=20 > +{ > + slist_t *node, *p; > + > + node =3D malloc(sizeof(slist_t)); > + assert(node !=3D NULL); > + node->data =3D element; > + node->next =3D NULL; > + if (!list) > + return node; > + p =3D list; > + while (p->next) > + p =3D p->next; > + p->next =3D node; > + return list; > +} > + > +slist_t *slist_remove(slist_t *list, void *element)=20 > +{ > + if (list) { > + slist_t *prev, *next; > + prev =3D list; > + next =3D list; > + while (next !=3D NULL) { > + if (next->data =3D=3D element) { > + /* if first element, update list pointer */ > + if (next =3D=3D list) { > + list =3D list->next; > + prev =3D list; > + free(next); > + next =3D prev; > + } > + else { > + prev->next =3D next->next; > + free(next); > + next =3D prev->next; > + } > + continue; > + } > + prev =3D next; > + next =3D next->next; > + } > + } > + return list; > +} > + > +buf_t *buf_new(size_t default_size)=20 > +{ > + buf_t *p; > + > + p =3D malloc(sizeof(buf_t)); > + if (!p) > + goto out; > + p->buffer =3D malloc(sizeof(uint8_t) * default_size); > + if (!p->buffer) { > + free(p); > + p =3D NULL; > + goto out; > + } > + p->data =3D p->buffer; > + p->head_avail =3D 0; > + p->data_avail =3D default_size; > + p->tail_avail =3D 0; > + p->data_size =3D 0; > +out: > + return p; > +} > + > +size_t buf_total_size(buf_t *p)=20 > +{ > + return p->head_avail + p->data_avail + p->tail_avail + p->data_size; > +} > + > +void buf_resize(buf_t *p, size_t new_size)=20 > +{ > + uint8_t *tmp; > + int bSize; > + > + if (!p) > + goto out; > + bSize =3D buf_total_size(p); > + if (new_size < bSize) { > + int itRem =3D bSize - new_size; > + if (itRem > p->data_avail) { > + itRem -=3D p->data_avail; > + p->data_avail =3D 0; > + } > + else { > + p->data_avail -=3D itRem; > + itRem =3D 0; > + } > + if (itRem > p->tail_avail) { > + itRem -=3D p->tail_avail; > + p->tail_avail =3D 0; > + } > + else { > + p->tail_avail -=3D itRem; > + itRem =3D 0; > + } > + /* When deallocating data from header we need to move > + * the data used to the beginning after the header new > + * allocated space, so we need to do memmove here */ > + if (itRem > p->head_avail) { > + itRem -=3D p->head_avail; > + memmove(p->buffer, p->buffer + p->head_avail, p->data_size); > + p->head_avail =3D 0; > + } > + else { > + p->head_avail -=3D itRem; > + memmove(p->buffer + p->head_avail, p->buffer + p->head_avail + itRem,= p->data_size); > + itRem =3D 0; > + } > + if (itRem > p->data_size) { > + p->data_size =3D 0; > + } > + else { > + p->data_size -=3D itRem; > + } > + bSize =3D 0; > + } > + else > + bSize =3D new_size - bSize; > + tmp =3D realloc(p->buffer, new_size); > + if (!new_size) { > + p->buffer =3D NULL; > + p->data =3D NULL; > + p->head_avail =3D 0; > + p->data_avail =3D 0; > + p->tail_avail =3D 0; > + p->data_size =3D 0; > + goto out; > + } > + if (!tmp) > + goto out; > + p->data_avail +=3D bSize; > + p->buffer =3D tmp; > + p->data =3D p->buffer + p->head_avail; > +out: > + return; > +} > + > +buf_t *buf_reuse(buf_t *p)=20 > +{ > + if (!p) > + goto out; > + p->data_avail =3D buf_total_size(p); > + p->head_avail =3D 0; > + p->tail_avail =3D 0; > + p->data_size =3D 0; > + p->data =3D p->buffer; > +out: > + return p; > +} > + > +void *buf_reserve_begin(buf_t *p, size_t data_size)=20 > +{ > + if (p->head_avail >=3D data_size) { > + p->head_avail -=3D data_size; > + p->data_size +=3D data_size; > + p->data =3D p->buffer + p->head_avail; > + return p->buffer + p->head_avail; > + } > + else { > + if (data_size > p->head_avail + p->data_avail) { > + int tmp; > + tmp =3D p->data_avail; > + buf_resize(p, buf_total_size(p) + data_size - > + p->head_avail - p->data_avail); > + if (tmp =3D=3D p->data_avail) > + return NULL; > + p->data_avail =3D 0; > + } > + else > + p->data_avail -=3D data_size - p->head_avail; > + memmove(p->buffer + data_size, p->buffer + p->head_avail, p->data_size= ); > + p->head_avail =3D 0; > + p->data =3D p->buffer; > + p->data_size +=3D data_size; > + return p->buffer; > + } > +} > + > +void *buf_reserve_end(buf_t *p, size_t data_size)=20 > +{ > + void *t; > + > + if (p->tail_avail >=3D data_size) > + p->tail_avail -=3D data_size; > + else { > + if (data_size > p->tail_avail + p->data_avail) { > + int tmp; > + tmp =3D p->data_avail; > + buf_resize(p, buf_total_size(p) + data_size - > + p->tail_avail - p->data_avail); > + if (tmp =3D=3D p->data_avail) > + return NULL; > + p->data_avail =3D 0; > + } > + else > + p->data_avail -=3D data_size - p->tail_avail; > + p->tail_avail =3D 0; > + } > + t =3D p->buffer + p->head_avail + p->data_size; > + p->data_size +=3D data_size; > + p->data =3D p->buffer + p->head_avail; > + return t; > +} > + > +void buf_insert_begin(buf_t *p, uint8_t *data, size_t data_size)=20 > +{ > + uint8_t *dest; > + > + dest =3D (uint8_t *) buf_reserve_begin(p, data_size); > + assert(dest !=3D NULL); > + memcpy(dest, data, data_size); > +} > + > +void buf_insert_end(buf_t *p, uint8_t *data, size_t data_size)=20 > +{ > + uint8_t *dest; > + > + dest =3D (uint8_t *) buf_reserve_end(p, data_size); > + assert(dest !=3D NULL); > + memcpy(dest, data, data_size); > +} > + > +void buf_remove_begin(buf_t *p, size_t data_size)=20 > +{ > + if (data_size < p->data_size) { > + p->head_avail +=3D data_size; > + p->data_size -=3D data_size; > + } > + else { > + p->head_avail +=3D p->data_size; > + p->data_size =3D 0; > + } > + p->data =3D p->buffer + p->head_avail; > +} > + > +void buf_remove_end(buf_t *p, size_t data_size)=20 > +{ > + if (data_size < p->data_size) { > + p->tail_avail +=3D data_size; > + p->data_size -=3D data_size; > + } > + else { > + p->tail_avail +=3D p->data_size; > + p->data_size =3D 0; > + } > +} > + > +void buf_dump(buf_t *p, const char *label)=20 > +{ > + int i, n; > + > + n =3D 0; > + for (i =3D 0; i < p->data_size; ++i) { > +#ifndef OBEX_SYSLOG > + if (n =3D=3D 0) > + fprintf(stderr, "%s: ", label); > + fprintf(stderr, "%02X ", p->data[i]); > + if (n >=3D 25 || i =3D=3D p->data_size - 1) { > + fprintf(stderr, "\n"); > +#else > + if (n =3D=3D 0) > + syslog(LOG_DEBUG, "OpenObex: %s: ", label); > + syslog(LOG_DEBUG, "%02X ", p->data[i]); > + if (n >=3D 25 || i =3D=3D p->data_size - 1) { > + syslog(LOG_DEBUG, "\n"); > +#endif > + n =3D -1; > + } > + n++; > + } > +} > + > +void buf_free(buf_t *p)=20 > +{ > + if (p) { > + if (p->buffer) { > + free(p->buffer); > + } > + free(p); > + } > +} > diff -uNr openobex/lib/databuffer.h openobex.test/lib/databuffer.h > --- openobex/lib/databuffer.h 1970-01-01 02:00:00.000000000 +0200 > +++ openobex.test/lib/databuffer.h 2006-04-25 16:30:47.000000000 +0300 > @@ -0,0 +1,70 @@ > +/***********************************************************************= ** > + * > + * Filename: databuffer.h > + * Version: 0.3 > + * Description: Network buffer handling routines. > + * Status: Experimental. > + * Author: Herton Ronaldo Krzesinski <he...@co...> > + * Created at: Tue Jun 21 11:22:44 2005 > + * Modified at: Mon Aug 15 19:12:29 2005 > + * > + * Copyright (c) 2005 Herton Ronaldo Krzesinski, All Rights Reserved. > + * > + * This library is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2 of the License, or (at your option) any later version. > + * > + * This library is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with this library; if not, write to the Free Softwa= re > + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, > + * MA 02111-1307 USA > + * > + ***********************************************************************= **/ > + > +#ifndef DATABUFFER_H > +#define DATABUFFER_H > + > +#define __need_size_t > +#include <stddef.h> > +#include <stdint.h> > + > +/* > + * Implements a single linked list > + */ > +typedef struct _slist_t { > + void *data; > + struct _slist_t *next; > +} slist_t; > + > +typedef struct { > + uint8_t *buffer; // buffer containing the allocated space > + uint8_t *data; // pointer to the location of *buffer where there is val= id data > + size_t head_avail; // number of allocated space available in front of b= uffer > + size_t data_avail; // allocated space available not specific for head o= r tail > + size_t tail_avail; // number of allocated space available at end of buf= fer > + size_t data_size; // number of allocated space used > +} buf_t; > + > +buf_t *buf_new(size_t default_size); > +size_t buf_total_size(buf_t *p); > +void buf_resize(buf_t *p, size_t new_size); > +buf_t *buf_reuse(buf_t *p); > +void *buf_reserve_begin(buf_t *p, size_t data_size); > +void *buf_reserve_end(buf_t *p, size_t data_size); > +void buf_insert_begin(buf_t *p, uint8_t *data, size_t data_size); > +void buf_insert_end(buf_t *p, uint8_t *data, size_t data_size); > +void buf_remove_begin(buf_t *p, size_t data_size); > +void buf_remove_end(buf_t *p, size_t data_size); > +void buf_dump(buf_t *p, const char *label); > +void buf_free(buf_t *p); > + > +slist_t *slist_append(slist_t *list, void *element); > +slist_t *slist_remove(slist_t *list, void *element); > + > +#endif > diff -uNr openobex/lib/obex.c openobex.test/lib/obex.c > --- openobex/lib/obex.c 2005-12-25 05:48:00.000000000 +0200 > +++ openobex.test/lib/obex.c 2006-04-25 16:02:05.000000000 +0300 > @@ -144,12 +144,12 @@ > =20 > /* Allocate message buffers */ > /* It's safe to allocate them smaller than OBEX_MAXIMUM_MTU > - * because netbuf will realloc data as needed. - Jean II */ > - self->rx_msg =3D g_netbuf_new(self->mtu_rx); > + * because buf_t will realloc data as needed. - Jean II */ > + self->rx_msg =3D buf_new(self->mtu_rx); > if (self->rx_msg =3D=3D NULL) > goto out_err; > =20 > - self->tx_msg =3D g_netbuf_new(self->mtu_tx_max); > + self->tx_msg =3D buf_new(self->mtu_tx_max); > if (self->tx_msg =3D=3D NULL) > goto out_err; > =20 > @@ -162,9 +162,9 @@ > =20 > out_err: > if (self->tx_msg !=3D NULL) > - g_netbuf_free(self->tx_msg); > + buf_free(self->tx_msg); > if (self->rx_msg !=3D NULL) > - g_netbuf_free(self->rx_msg); > + buf_free(self->rx_msg); > free(self); > return NULL; > } > @@ -201,10 +201,10 @@ > obex_transport_disconnect_server(self); > =20 > if (self->tx_msg) > - g_netbuf_free(self->tx_msg); > + buf_free(self->tx_msg); > =09 > if (self->rx_msg) > - g_netbuf_free(self->rx_msg); > + buf_free(self->rx_msg); > =20 > OBEX_FreeInterfaces(self); > free(self); > @@ -283,10 +283,10 @@ > self->mtu_rx =3D mtu_rx; > self->mtu_tx_max =3D mtu_tx_max; > /* Reallocate transport buffers */ > - self->rx_msg =3D g_netbuf_realloc(self->rx_msg, self->mtu_rx); > + buf_resize(self->rx_msg, self->mtu_rx); > if (self->rx_msg =3D=3D NULL) > return -ENOMEM; > - self->tx_msg =3D g_netbuf_realloc(self->tx_msg, self->mtu_tx_max); > + buf_resize(self->tx_msg, self->mtu_tx_max); > if (self->tx_msg =3D=3D NULL) > return -ENOMEM; > return 0; > @@ -384,12 +384,12 @@ > self->mtu_tx_max =3D server->mtu_tx_max; > =20 > /* Allocate message buffers */ > - self->rx_msg =3D g_netbuf_new(self->mtu_rx); > + self->rx_msg =3D buf_new(self->mtu_rx); > if (self->rx_msg =3D=3D NULL) > goto out_err; > =20 > /* Note : mtu_tx not yet negociated, so let's be safe here - Jean II */ > - self->tx_msg =3D g_netbuf_new(self->mtu_tx_max); > + self->tx_msg =3D buf_new(self->mtu_tx_max); > if (self->tx_msg =3D=3D NULL) > goto out_err; > =20 > @@ -405,9 +405,9 @@ > =20 > out_err: > if (self->tx_msg !=3D NULL) > - g_netbuf_free(self->tx_msg); > + buf_free(self->tx_msg); > if (self->rx_msg !=3D NULL) > - g_netbuf_free(self->rx_msg); > + buf_free(self->rx_msg); > free(self); > return NULL; > } > @@ -755,7 +755,7 @@ > return 0; > =20 > *buffer =3D object->rx_nonhdr_data->data; > - return object->rx_nonhdr_data->len; > + return object->rx_nonhdr_data->data_size; > } > =20 > /** > @@ -777,11 +777,11 @@ > if(object->tx_nonhdr_data) > return -1; > =20 > - object->tx_nonhdr_data =3D g_netbuf_new(len); > + object->tx_nonhdr_data =3D buf_new(len); > if(object->tx_nonhdr_data =3D=3D NULL) > return -1; > =20 > - g_netbuf_put_data(object->tx_nonhdr_data, (uint8_t *)buffer, len); > + buf_insert_end(object->tx_nonhdr_data, (uint8_t *)buffer, len); > return 1; > } > =20 > diff -uNr openobex/lib/obex_client.c openobex.test/lib/obex_client.c > --- openobex/lib/obex_client.c 2005-12-02 20:53:24.000000000 +0200 > +++ openobex.test/lib/obex_client.c 2006-04-25 16:02:05.000000000 +0300 > @@ -44,7 +44,7 @@ > * Handle client operations > * > */ > -int obex_client(obex_t *self, GNetBuf *msg, int final) > +int obex_client(obex_t *self, buf_t *msg, int final) > { > obex_common_hdr_t *response =3D NULL; > int rsp =3D OBEX_RSP_BAD_REQUEST, ret; > diff -uNr openobex/lib/obex_client.h openobex.test/lib/obex_client.h > --- openobex/lib/obex_client.h 2002-10-28 23:51:18.000000000 +0200 > +++ openobex.test/lib/obex_client.h 2006-04-25 16:02:05.000000000 +0300 > @@ -30,6 +30,6 @@ > #ifndef OBEX_CLIENT_H > #define OBEX_CLIENT_H > =20 > -int obex_client(obex_t *self, GNetBuf *msg, int final); > +int obex_client(obex_t *self, buf_t *msg, int final); > =20 > #endif > diff -uNr openobex/lib/obex_connect.c openobex.test/lib/obex_connect.c > --- openobex/lib/obex_connect.c 2002-11-22 21:06:10.000000000 +0200 > +++ openobex.test/lib/obex_connect.c 2006-04-25 16:02:05.000000000 +0300 > @@ -53,14 +53,13 @@ > =20 > DEBUG(4, "\n"); > =20 > - object->tx_nonhdr_data =3D g_netbuf_new(4); > + object->tx_nonhdr_data =3D buf_new(4); > if(!object->tx_nonhdr_data)=20 > return -1; > - conn_hdr =3D (obex_connect_hdr_t *) object->tx_nonhdr_data->data; > + conn_hdr =3D (obex_connect_hdr_t *) buf_reserve_end(object->tx_nonhdr_d= ata, 4); > conn_hdr->version =3D OBEX_VERSION;=20 > conn_hdr->flags =3D 0x00; /* Flags */ > conn_hdr->mtu =3D htons(self->mtu_rx); /* Max packet size */ > - g_netbuf_put(object->tx_nonhdr_data, 4); > return 0; > } > =20 > @@ -70,7 +69,7 @@ > * Parse a Connect > * > */ > -int obex_parse_connect_header(obex_t *self, GNetBuf *msg) > +int obex_parse_connect_header(obex_t *self, buf_t *msg) > { > obex_connect_hdr_t *conn_hdr; > obex_common_hdr_t *common_hdr; > @@ -92,8 +91,8 @@ > if( (opcode !=3D (OBEX_RSP_SUCCESS | OBEX_FINAL)) && (opcode !=3D (OBEX= _CMD_CONNECT | OBEX_FINAL))) > return 1; > =20 > - DEBUG(4, "Len: %d\n", msg->len); > - if(msg->len >=3D 7) { > + DEBUG(4, "Len: %d\n", msg->data_size); > + if(msg->data_size >=3D 7) { > /* Get what we need */ > conn_hdr =3D (obex_connect_hdr_t *) ((msg->data) + 3); > version =3D conn_hdr->version; > diff -uNr openobex/lib/obex_connect.h openobex.test/lib/obex_connect.h > --- openobex/lib/obex_connect.h 2002-10-28 23:51:18.000000000 +0200 > +++ openobex.test/lib/obex_connect.h 2006-04-25 16:02:05.000000000 +0300 > @@ -33,7 +33,7 @@ > #include "obex_main.h" > =20 > int obex_insert_connectframe(obex_t *self, obex_object_t *object); > -int obex_parse_connect_header(obex_t *self, GNetBuf *msg); > +int obex_parse_connect_header(obex_t *self, buf_t *msg); > =20 > #endif > =20 > diff -uNr openobex/lib/obex_header.c openobex.test/lib/obex_header.c > --- openobex/lib/obex_header.c 2005-09-30 14:48:27.000000000 +0300 > +++ openobex.test/lib/obex_header.c 2006-04-25 16:02:05.000000000 +0300 > @@ -45,19 +45,19 @@ > * identifier if the header ID which is supposed to consist of > * both the header enconding and type > */ > -int insert_uint_header(GNetBuf *msg, uint8_t identifier, uint32_t value) > +int insert_uint_header(buf_t *msg, uint8_t identifier, uint32_t value) > { > struct obex_uint_hdr *hdr; > =20 > DEBUG(4, "\n"); > obex_return_val_if_fail(msg !=3D NULL, -1); > =20 > - hdr =3D (struct obex_uint_hdr *) g_netbuf_put(msg, 5); > + hdr =3D (struct obex_uint_hdr *) buf_reserve_end(msg, sizeof(struct obe= x_uint_hdr)); > =20 > hdr->hi =3D identifier; > hdr->hv =3D htonl(value); > =09 > - return 5; > + return sizeof(struct obex_uint_hdr); > } > =20 > /* > @@ -65,19 +65,19 @@ > * > * Insert a byte unsigned header. > */ > -int insert_ubyte_header(GNetBuf *msg, uint8_t identifier, uint8_t value) > +int insert_ubyte_header(buf_t *msg, uint8_t identifier, uint8_t value) > { > struct obex_ubyte_hdr *hdr; > =20 > DEBUG(4, "\n"); > obex_return_val_if_fail(msg !=3D NULL, -1); > =20 > - hdr =3D (struct obex_ubyte_hdr *) g_netbuf_put(msg, 2); > + hdr =3D (struct obex_ubyte_hdr *) buf_reserve_end(msg, sizeof(struct ob= ex_ubyte_hdr)); > =20 > hdr->hi =3D identifier; > hdr->hv =3D value; > =09 > - return 2; > + return sizeof(struct obex_ubyte_hdr); > } > =20 > /* > @@ -86,7 +86,7 @@ > * Insert a char string into the buffer > * > */ > -int insert_unicode_header(GNetBuf *msg, uint8_t opcode,=20 > +int insert_unicode_header(buf_t *msg, uint8_t opcode,=20 > const uint8_t *text, int size) > { > struct obex_unicode_hdr *hdr; > @@ -95,14 +95,13 @@ > obex_return_val_if_fail(msg !=3D NULL, -1); > obex_return_val_if_fail(text !=3D NULL || size =3D=3D 0, -1); > =20 > - hdr =3D (struct obex_unicode_hdr *) g_netbuf_put(msg, size + 3); > + hdr =3D (struct obex_unicode_hdr *) buf_reserve_end(msg, size + sizeof(= struct obex_unicode_hdr)); > =20 > hdr->hi =3D opcode; > - hdr->hl =3D htons((uint16_t)(size + 3)); > + hdr->hl =3D htons((uint16_t)(size + sizeof(struct obex_unicode_hdr))); > memcpy(hdr->hv, text, size); > =20 > - return size+3; > - > + return size + sizeof(struct obex_unicode_hdr); > } > =20 > /* > @@ -111,7 +110,7 @@ > * Insert a byte stream into the buffer > * > */ > -int insert_byte_stream_header(GNetBuf *msg, uint8_t opcode, > +int insert_byte_stream_header(buf_t *msg, uint8_t opcode, > const uint8_t *stream, int size) > { > struct obex_byte_stream_hdr *hdr; > @@ -120,16 +119,16 @@ > obex_return_val_if_fail(msg !=3D NULL, -1); > obex_return_val_if_fail(stream !=3D NULL || size =3D=3D 0, -1); > =09 > - hdr =3D (struct obex_byte_stream_hdr *) g_netbuf_put(msg, size+3); > + hdr =3D (struct obex_byte_stream_hdr *) buf_reserve_end(msg, size + siz= eof(struct obex_byte_stream_hdr)); > if (hdr =3D=3D 0) { > DEBUG(4, "put failed!\n"); > return 0; > } > =20 > hdr->hi =3D opcode; > - hdr->hl =3D htons(size+3); > + hdr->hl =3D htons(size + sizeof(struct obex_byte_stream_hdr)); > =20 > memcpy(hdr->hv, stream, size); > -=09 > - return size+3; > + > + return size + sizeof(struct obex_byte_stream_hdr); > } > diff -uNr openobex/lib/obex_header.h openobex.test/lib/obex_header.h > --- openobex/lib/obex_header.h 2002-11-13 21:51:42.000000000 +0200 > +++ openobex.test/lib/obex_header.h 2006-04-25 16:02:05.000000000 +0300 > @@ -110,14 +110,14 @@ > } t; > } obex_header_t; > =20 > -int insert_uint_header(GNetBuf *msg, uint8_t identifier, uint32_t value); > -int insert_ubyte_header(GNetBuf *msg, uint8_t identifier, uint8_t value); > -int insert_unicode_header(GNetBuf *msg, uint8_t opcode, const uint8_t *t= ext, > +int insert_uint_header(buf_t *msg, uint8_t identifier, uint32_t value); > +int insert_ubyte_header(buf_t *msg, uint8_t identifier, uint8_t value); > +int insert_unicode_header(buf_t *msg, uint8_t opcode, const uint8_t *tex= t, > int size); > =20 > -int insert_byte_stream_header(GNetBuf *msg, uint8_t opcode,=20 > +int insert_byte_stream_header(buf_t *msg, uint8_t opcode,=20 > const uint8_t *stream, int size); > =20 > -int obex_extract_header(GNetBuf *msg, obex_header_t *header); > +int obex_extract_header(buf_t *msg, obex_header_t *header); > =20 > #endif > diff -uNr openobex/lib/obex_main.c openobex.test/lib/obex_main.c > --- openobex/lib/obex_main.c 2006-01-03 20:36:15.000000000 +0200 > +++ openobex.test/lib/obex_main.c 2006-04-25 16:02:05.000000000 +0300 > @@ -186,12 +186,11 @@ > */ > void obex_response_request(obex_t *self, uint8_t opcode) > { > - GNetBuf *msg; > + buf_t *msg; > =20 > obex_return_if_fail(self !=3D NULL); > =20 > - msg =3D g_netbuf_recycle(self->tx_msg); > - g_netbuf_reserve(msg, sizeof(obex_common_hdr_t)); > + msg =3D buf_reuse(self->tx_msg); > =20 > obex_data_request(self, msg, opcode | OBEX_FINAL); > } > @@ -202,7 +201,7 @@ > * Send response or command code along with optional headers/data. > * > */ > -int obex_data_request(obex_t *self, GNetBuf *msg, int opcode) > +int obex_data_request(obex_t *self, buf_t *msg, int opcode) > { > obex_common_hdr_t *hdr; > int actual =3D 0; > @@ -211,13 +210,13 @@ > obex_return_val_if_fail(msg !=3D NULL, -1); > =20 > /* Insert common header */ > - hdr =3D (obex_common_hdr_t *) g_netbuf_push(msg, sizeof(obex_common_hdr= _t)); > + hdr =3D (obex_common_hdr_t *) buf_reserve_begin(msg, sizeof(obex_common= _hdr_t)); > =20 > hdr->opcode =3D opcode; > - hdr->len =3D htons((uint16_t)msg->len); > + hdr->len =3D htons((uint16_t)msg->data_size); > =20 > DUMPBUFFER(1, "Tx", msg); > - DEBUG(1, "len =3D %d bytes\n", msg->len); > + DEBUG(1, "len =3D %d bytes\n", msg->data_size); > =20 > actual =3D obex_transport_write(self, msg); > return actual; > @@ -232,7 +231,7 @@ > int obex_data_indication(obex_t *self, uint8_t *buf, int buflen) > { > obex_common_hdr_t *hdr; > - GNetBuf *msg; > + buf_t *msg; > int final; > int actual =3D 0; > unsigned int size; > @@ -245,8 +244,8 @@ > msg =3D self->rx_msg; > =09 > /* First we need 3 bytes to be able to know how much data to read */ > - if(msg->len < 3) { > - actual =3D obex_transport_read(self, 3 - (msg->len), buf, buflen); > + if(msg->data_size < 3) { > + actual =3D obex_transport_read(self, 3 - (msg->data_size), buf, buflen= ); > =09 > DEBUG(4, "Got %d bytes\n", actual); > =20 > @@ -257,18 +256,17 @@ > } > buf +=3D actual; > buflen -=3D actual; > - g_netbuf_put(msg, actual); > } > =20 > /* If we have 3 bytes data we can decide how big the packet is */ > - if(msg->len >=3D 3) { > + if(msg->data_size >=3D 3) { > hdr =3D (obex_common_hdr_t *) msg->data; > size =3D ntohs(hdr->len); > =20 > actual =3D 0; > - if(msg->len !=3D (int) ntohs(hdr->len)) { > + if(msg->data_size !=3D (int) ntohs(hdr->len)) { > =20 > - actual =3D obex_transport_read(self, size - msg->len, buf, > + actual =3D obex_transport_read(self, size - msg->data_size, buf, > buflen); > =20 > /* Check if we are still connected */ > @@ -280,14 +278,13 @@ > } > else { > /* Wait until we have at least 3 bytes data */ > - DEBUG(3, "Need at least 3 bytes got only %d!\n", msg->len); > + DEBUG(3, "Need at least 3 bytes got only %d!\n", msg->data_size); > return actual; > } > =20 > =20 > /* New data has been inserted at the end of message */ > - g_netbuf_put(msg, actual); > - DEBUG(1, "Got %d bytes msg len=3D%d\n", actual, msg->len); > + DEBUG(1, "Got %d bytes msg len=3D%d\n", actual, msg->data_size); > =20 > /* > * Make sure that the buffer we have, actually has the specified > @@ -296,28 +293,28 @@ > */ > =20 > /* Make sure we have a whole packet */ > - if (size > msg->len) { > + if (size > msg->data_size) { > DEBUG(3, "Need more data, size=3D%d, len=3D%d!\n", > - size, msg->len); > + size, msg->data_size); > =20 > /* I'll be back! */ > - return msg->len; > + return msg->data_size; > } > =20 > DUMPBUFFER(2, "Rx", msg); > =20 > - actual =3D msg->len; > + actual =3D msg->data_size; > final =3D hdr->opcode & OBEX_FINAL; /* Extract final bit */ > =20 > /* Dispatch to the mode we are in */ > if(self->state & MODE_SRV) { > ret =3D obex_server(self, msg, final); > - g_netbuf_recycle(msg); > + buf_reuse(msg); > =09 > } > else { > ret =3D obex_client(self, msg, final); > - g_netbuf_recycle(msg); > + buf_reuse(msg); > } > /* Check parse errors */ > if(ret < 0) > @@ -341,8 +338,8 @@ > if (!nice) { > /* Deliver event will delete the object */ > obex_deliver_event(self, OBEX_EV_ABORT, 0, 0, TRUE); > - g_netbuf_recycle(self->tx_msg); > - g_netbuf_recycle(self->rx_msg); > + buf_reuse(self->tx_msg); > + buf_reuse(self->rx_msg); > /* Since we didn't send ABORT to peer we are out of sync > and need to disconnect transport immediately, so we signal > link error to app */ > diff -uNr openobex/lib/obex_main.h openobex.test/lib/obex_main.h > --- openobex/lib/obex_main.h 2006-01-18 16:25:13.000000000 +0200 > +++ openobex.test/lib/obex_main.h 2006-04-25 16:02:05.000000000 +0300 > @@ -59,7 +59,7 @@ > =20 > #include "obex_object.h" > #include "obex_transport.h" > -#include "netbuf.h" > +#include "databuffer.h" > =20 > #ifdef OBEX_SYSLOG > #include <syslog.h> > @@ -90,7 +90,7 @@ > =20 > # if OBEX_DUMP > extern int obex_dump; > -# define DUMPBUFFER(n, label, msg) if (obex_dump & (n)) g_netbuf_print(= label, msg); > +# define DUMPBUFFER(n, label, msg) if (obex_dump & (n)) buf_dump(msg, l= abel); > # else > # define DUMPBUFFER(n, label, msg) > # endif /* OBEX_DUMP !=3D 0 */ > @@ -120,20 +120,20 @@ > =20 > struct obex { > uint16_t mtu_tx; /* Maximum OBEX TX packet size */ > - uint16_t mtu_rx; /* Maximum OBEX RX packet size */ > + uint16_t mtu_rx; /* Maximum OBEX RX packet size */ > uint16_t mtu_tx_max; /* Maximum TX we can accept */ > =20 > int fd; /* Socket descriptor */ > int serverfd; > int writefd; /* write descriptor - only OBEX_TRANS_FD */ > - unsigned int state; > + unsigned int state; > =09 > int keepserver; /* Keep server alive */ > int filterhint; /* Filter devices based on hint bits */ > int filterias; /* Filter devices based on IAS entry */ > =20 > - GNetBuf *tx_msg; /* Reusable transmit message */ > - GNetBuf *rx_msg; /* Reusable receive message */ > + buf_t *tx_msg; /* Reusable transmit message */ > + buf_t *rx_msg; /* Reusable receive message */ > =20 > obex_object_t *object; /* Current object being transfered */ =20 > obex_event_t eventcb; /* Event-callback */ > @@ -155,7 +155,7 @@ > int obex_data_indication(obex_t *self, uint8_t *buf, int buflen); > =20 > void obex_response_request(obex_t *self, uint8_t opcode); > -int obex_data_request(obex_t *self, GNetBuf *msg, int opcode); > +int obex_data_request(obex_t *self, buf_t *msg, int opcode); > int obex_cancelrequest(obex_t *self, int nice); > =20 > char *obex_response_to_string(int rsp); > diff -uNr openobex/lib/obex_object.c openobex.test/lib/obex_object.c > --- openobex/lib/obex_object.c 2006-02-26 16:49:55.000000000 +0200 > +++ openobex.test/lib/obex_object.c 2006-04-25 16:02:05.000000000 +0300 > @@ -73,7 +73,7 @@ > while(*q !=3D NULL) { > h =3D (*q)->data; > *q =3D slist_remove(*q, h); > - g_netbuf_free(h->buf); > + buf_free(h->buf); > free(h); > } > =20 > @@ -97,13 +97,13 @@ > free_headerq(&object->rx_headerq_rm); > =20 > /* Free tx and rx msgs */ > - g_netbuf_free(object->tx_nonhdr_data); > + buf_free(object->tx_nonhdr_data); > object->tx_nonhdr_data =3D NULL; > =20 > - g_netbuf_free(object->rx_nonhdr_data); > + buf_free(object->rx_nonhdr_data); > object->rx_nonhdr_data =3D NULL; > =09 > - g_netbuf_free(object->rx_body); > + buf_free(object->rx_body); > object->rx_body =3D NULL; > =09 > free(object); > @@ -208,7 +208,7 @@ > case OBEX_INT: > DEBUG(2, "4BQ header %d\n", hv.bq4); > =09 > - element->buf =3D g_netbuf_new(sizeof(struct obex_uint_hdr)); > + element->buf =3D buf_new(sizeof(struct obex_uint_hdr)); > if(element->buf) { > element->length =3D (unsigned int) sizeof(struct obex_uint_hdr); > ret =3D insert_uint_header(element->buf, hi, hv.bq4); > @@ -218,7 +218,7 @@ > case OBEX_BYTE: > DEBUG(2, "1BQ header %d\n", hv.bq1); > =20 > - element->buf =3D g_netbuf_new(sizeof(struct obex_ubyte_hdr)); > + element->buf =3D buf_new(sizeof(struct obex_ubyte_hdr)); > if(element->buf) { > element->length =3D sizeof(struct obex_ubyte_hdr); > ret =3D insert_ubyte_header(element->buf, hi, hv.bq1); > @@ -228,7 +228,7 @@ > case OBEX_BYTE_STREAM: > DEBUG(2, "BS header size %d\n", hv_size); > =20 > - element->buf =3D g_netbuf_new(hv_size + sizeof(struct obex_byte_stream= _hdr) ); > + element->buf =3D buf_new(hv_size + sizeof(struct obex_byte_stream_hdr)= ); > if(element->buf) { > element->length =3D hv_size + sizeof(struct obex_byte_stream_hdr); > ret =3D insert_byte_stream_header(element->buf, hi, hv.bs, hv_size); > @@ -238,7 +238,7 @@ > case OBEX_UNICODE: > DEBUG(2, "Unicode header size %d\n", hv_size); > =20 > - element->buf =3D g_netbuf_new(hv_size + sizeof(struct obex_unicode_hdr= ) ); > + element->buf =3D buf_new(hv_size + sizeof(struct obex_unicode_hdr) ); > if(element->buf) { > element->length =3D hv_size + sizeof(struct obex_unicode_hdr); > ret =3D insert_unicode_header(element->buf, hi, hv.bs, hv_size); > @@ -264,7 +264,7 @@ > object->tx_headerq =3D slist_append(object->tx_headerq, element); > ret =3D 1; > } else { > - g_netbuf_free(element->buf); > + buf_free(element->buf); > free(element); > } > =20 > @@ -280,7 +280,7 @@ > */ > static int send_stream(obex_t *self, > struct obex_header_element *h, > - GNetBuf *txmsg, unsigned int tx_left) > + buf_t *txmsg, unsigned int tx_left) > { > obex_object_t *object; > struct obex_byte_stream_hdr *body_txh; > @@ -291,7 +291,7 @@ > object =3D self->object; > =09 > /* Fill in length and header type later, but reserve space for it */ > - body_txh =3D (struct obex_byte_stream_hdr*) g_netbuf_put(txmsg, > + body_txh =3D (struct obex_byte_stream_hdr*) buf_reserve_end(txmsg, > sizeof(struct obex_byte_stream_hdr) ); > tx_left -=3D sizeof(struct obex_byte_stream_hdr); > actual =3D sizeof(struct obex_byte_stream_hdr); > @@ -323,7 +323,7 @@ > /*=E2=95=90There is more data left in buffer than tx_left */ > DEBUG(4, "More data than tx_left. Buffer will not be empty\n"); > =09 > - g_netbuf_put_data(txmsg, (uint8_t*) object->s_buf + object->s_offset,= tx_left); > + buf_insert_end(txmsg, (uint8_t*) object->s_buf + object->s_offset, tx= _left); > object->s_len -=3D tx_left; > object->s_offset +=3D tx_left; > actual +=3D tx_left; > @@ -332,7 +332,7 @@ > else { > /* There less data in buffer than tx_left */ > DEBUG(4, "Less data that tx_left. Buffer will be empty\n"); > - g_netbuf_put_data(txmsg, (uint8_t*) object->s_buf + object->s_offset,= object->s_len); > + buf_insert_end(txmsg, (uint8_t*) object->s_buf + object->s_offset, ob= ject->s_len); > tx_left -=3D object->s_len; > object->s_offset +=3D object->s_len; > actual +=3D object->s_len; > @@ -349,7 +349,7 @@ > /* We are done. Remove header from tx-queue */ > object->tx_headerq =3D slist_remove(object->tx_headerq, h); > body_txh->hi =3D OBEX_HDR_BODY_END; > - g_netbuf_free(h->buf); > + buf_free(h->buf); > free(h); > } > =09 > @@ -366,34 +366,33 @@ > */ > static int send_body(obex_object_t *object, > struct obex_header_element *h, > - GNetBuf *txmsg, unsigned int tx_left) > + buf_t *txmsg, unsigned int tx_left) > { > struct obex_byte_stream_hdr *body_txh; > unsigned int actual; > - =09 > - body_txh =3D (struct obex_byte_stream_hdr*) txmsg->tail; > - =09 > + > + body_txh =3D (struct obex_byte_stream_hdr*) buf_reserve_end(txmsg, size= of(struct obex_byte_stream_hdr)); > + > if(!h->body_touched) { > /* This is the first time we try to send this header > obex_object_addheaders has added a struct_byte_stream_hdr > before the actual body-data. We shall send this in every fragment > so we just remove it for now.*/ > =20 > - g_netbuf_pull(h->buf, sizeof(struct obex_byte_stream_hdr) ); > + buf_remove_begin(h->buf, sizeof(struct obex_byte_stream_hdr) ); > h->body_touched =3D TRUE; > } > =09 > - if(tx_left < ( h->buf->len + > + if(tx_left < ( h->buf->data_size + > sizeof(struct obex_byte_stream_hdr) ) ) { > DEBUG(4, "Add BODY header\n"); > body_txh->hi =3D OBEX_HDR_BODY; > body_txh->hl =3D htons((uint16_t)tx_left); > =20 > - g_netbuf_put(txmsg, sizeof(struct obex_byte_stream_hdr) ); > - g_netbuf_put_data(txmsg, h->buf->data, tx_left > + buf_insert_end(txmsg, h->buf->data, tx_left > - sizeof(struct obex_byte_stream_hdr) ); > =20 > - g_netbuf_pull(h->buf, tx_left > + buf_remove_begin(h->buf, tx_left > - sizeof(struct obex_byte_stream_hdr) ); > /* We have completely filled the tx-buffer */ > actual =3D tx_left; > @@ -402,13 +401,12 @@ > DEBUG(4, "Add BODY_END header\n"); > =20 > body_txh->hi =3D OBEX_HDR_BODY_END; > - body_txh->hl =3D htons((uint16_t) (h->buf->len + sizeof(struct obex_by= te_stream_hdr))); > - g_netbuf_put(txmsg, sizeof(struct obex_byte_stream_hdr) ); > - g_netbuf_put_data(txmsg, h->buf->data, h->buf->len); > - actual =3D h->buf->len; > + body_txh->hl =3D htons((uint16_t) (h->buf->data_size + sizeof(struct o= bex_byte_stream_hdr))); > + buf_insert_end(txmsg, h->buf->data, h->buf->data_size); > + actual =3D h->buf->data_size; > =09 > object->tx_headerq =3D slist_remove(object->tx_headerq, h); > - g_netbuf_free(h->buf); > + buf_free(h->buf); > free(h); > } > return actual; > @@ -427,7 +425,7 @@ > int allowfinalcmd, int forcefinalbit) > { > struct obex_header_element *h; > - GNetBuf *txmsg; > + buf_t *txmsg; > int actual, finished =3D 0; > uint16_t tx_left; > int addmore =3D TRUE; > @@ -452,17 +450,14 @@ > } > =20 > /* Reuse transmit buffer */ > - txmsg =3D g_netbuf_recycle(self->tx_msg); > -=09 > - /* Reserve space for common header */ > - g_netbuf_reserve(txmsg, sizeof(obex_common_hdr_t)); > + txmsg =3D buf_reuse(self->tx_msg); > =20 > /* Add nonheader-data first if any (SETPATH, CONNECT)*/ > if(object->tx_nonhdr_data) { > - DEBUG(4, "Adding %d bytes of non-headerdata\n", object->tx_nonhdr_data= ->len); > - g_netbuf_put_data(txmsg, object->tx_nonhdr_data->data, object->tx_nonh= dr_data->len); > + DEBUG(4, "Adding %d bytes of non-headerdata\n", object->tx_nonhdr_data= ->data_size); > + buf_insert_end(txmsg, object->tx_nonhdr_data->data, object->tx_nonhdr_= data->data_size); > =09 > - g_netbuf_free(object->tx_nonhdr_data); > + buf_free(object->tx_nonhdr_data); > object->tx_nonhdr_data =3D NULL; > } > =20 > @@ -498,14 +493,14 @@ > else if(h->length <=3D tx_left) { > /* There is room for more data in tx msg */ > DEBUG(4, "Adding non-body header\n"); > - g_netbuf_put_data(txmsg, h->buf->data, h->length); > + buf_insert_end(txmsg, h->buf->data, h->length); > tx_left -=3D h->length; > if(h->flags & OBEX_FL_SUSPEND) > object->suspend =3D 1; > =09 > /* Remove from tx-queue */ > object->tx_headerq =3D slist_remove(object->tx_headerq, h); > - g_netbuf_free(h->buf); > + buf_free(h->buf); > free(h); > } > else if(h->length > self->mtu_tx) { > @@ -684,7 +679,7 @@ > * Handle receiving of body > * > */ > -static int obex_object_receive_body(obex_object_t *object, GNetBuf *msg,= uint8_t hi, > +static int obex_object_receive_body(obex_object_t *object, buf_t *msg, u= int8_t hi, > uint8_t *source, unsigned int len) > { > struct obex_header_element *element; > @@ -692,10 +687,10 @@ > DEBUG(4, "This is a body-header. Len=3D%d\n", len); > =20 > =20 > - if(len > msg->len) { > + if(len > msg->data_size) { > DEBUG(1, "Header %d to big. HSize=3D%d Buffer=3D%d\n", hi, > len, > - msg->len); > + msg->data_size); > return -1; > } > =20 > @@ -705,28 +700,30 @@ > alloclen =3D object->hinted_body_len; > =20 > DEBUG(4, "Allocating new body-buffer. Len=3D%d\n", alloclen); > - if(! (object->rx_body =3D g_netbuf_new(alloclen))) > + if(! (object->rx_body =3D buf_new(alloclen))) > return -1; > } > =20 > - /* Reallocate body-netbuf if needed */=20 > - if(g_netbuf_tailroom(object->rx_body) < (int)len) { > + /* Reallocate body buffer if needed */=20 > + if(object->rx_body->data_avail + object->rx_body->tail_avail < (int)len= ) { > + int t; > DEBUG(4, "Buffer too small. Go realloc\n"); > - if(! (object->rx_body =3D g_netbuf_realloc(object->rx_body, > - object->rx_body->truesize + OBEX_OBJECT_ALLOCATIONTRESHOLD + len) ) = ) { > + t =3D buf_total_size(object->rx_body); > + buf_resize(object->rx_body, t + OBEX_OBJECT_ALLOCATIONTRESHOLD + len); > + if(buf_total_size(object->rx_body) !=3D t + OBEX_OBJECT_ALLOCATIONTRES= HOLD + len) { > DEBUG(1, "Can't realloc rx_body\n"); > return -1; > // FIXME: Handle this in a nice way... > } > } > =20 > - g_netbuf_put_data(object->rx_body, source, len); > + buf_insert_end(object->rx_body, source, len); > =20 > if(hi =3D=3D OBEX_HDR_BODY_END) { > DEBUG(4, "Body receive done\n"); > if( (element =3D malloc(sizeof(struct obex_header_element)) ) ) { > memset(element, 0, sizeof(struct obex_header_element)); > - element->length =3D object->rx_body->len; > + element->length =3D object->rx_body->data_size; > element->hi =3D OBEX_HDR_BODY; > element->buf =3D object->rx_body; > =20 > @@ -734,7 +731,7 @@ > object->rx_headerq =3D slist_append(object->rx_headerq, element); > } > else { > - g_netbuf_free(object->rx_body); > + buf_free(object->rx_body); > } > =09 > object->rx_body =3D NULL; > @@ -752,7 +749,7 @@ > * Add any incoming headers to headerqueue. > * > */ > -int obex_object_receive(obex_t *self, GNetBuf *msg) > +int obex_object_receive(obex_t *self, buf_t *msg) > { > obex_object_t *object; > struct obex_header_element *element; > @@ -772,20 +769,20 @@ > object =3D self->object; > =20 > /* Remove command from buffer */ > - g_netbuf_pull(msg, sizeof(struct obex_common_hdr)); > + buf_remove_begin(msg, sizeof(struct obex_common_hdr)); > =20 > /* Copy any non-header data (like in CONNECT and SETPATH) */ > if(object->headeroffset) { > - object->rx_nonhdr_data =3D g_netbuf_new(object->headeroffset); > + object->rx_nonhdr_data =3D buf_new(object->headeroffset); > if(!object->rx_nonhdr_data) > return -1; > - g_netbuf_put_data(object->rx_nonhdr_data, msg->data, object->headeroff= set); > - DEBUG(4, "Command has %d bytes non-headerdata\n", object->rx_nonhdr_da= ta->len); > - g_netbuf_pull(msg, object->headeroffset); > + buf_insert_end(object->rx_nonhdr_data, msg->data, object->headeroffset= ); > + DEBUG(4, "Command has %d bytes non-headerdata\n", object->rx_nonhdr_da= ta->data_size); > + buf_remove_begin(msg, object->headeroffset); > object->headeroffset =3D 0; > } > =20 > - while ((msg->len > 0) && (!err)) { > + while ((msg->data_size > 0) && (!err)) { > hi =3D msg->data[0]; > DEBUG(4, "Header: %02x\n", hi); > switch (hi & OBEX_HI_MASK) { > @@ -838,10 +835,10 @@ > } > =20 > /* Make sure that the msg is big enough for header */ > - if(len > msg->len) { > + if(len > msg->data_size) { > DEBUG(1, "Header %d to big. HSize=3D%d Buffer=3D%d\n", hi, > len, > - msg->len); > + msg->data_size); > source =3D NULL; > err =3D -1; > } > @@ -864,13 +861,13 @@ > // This might not be an optimal way, but it works. > if(len =3D=3D 0) { > DEBUG(4, "Got empty header. Allocating dummy buffer anyway\n"); > - element->buf =3D g_netbuf_new(1); > + element->buf =3D buf_new(1); > } > else { > - element->buf =3D g_netbuf_new(len); > + element->buf =3D buf_new(len); > if(element->buf) { > DEBUG(4, "Copying %d bytes\n", len); > - g_netbuf_put_data(element->buf, source, len); > + buf_insert_end(element->buf, source, len); > } > } > =20 > @@ -894,7 +891,7 @@ > return err; > =20 > DEBUG(4, "Pulling %d bytes\n", hlen); > - g_netbuf_pull(msg, hlen); > + buf_remove_begin(msg, hlen); > } > =20 > return 1; > diff -uNr openobex/lib/obex_object.h openobex.test/lib/obex_object.h > --- openobex/lib/obex_object.h 2006-03-07 00:36:19.000000000 +0200 > +++ openobex.test/lib/obex_object.h 2006-04-25 16:32:09.000000000 +0300 > @@ -32,14 +32,14 @@ > #define OBEX_OBJECT_H > =20 > #include "obex_main.h" > -#include "netbuf.h" > +#include "databuffer.h" > =20 > /* If an object has no expected length we have to=20 > reallocated every OBEX_OBJECT_ALLOCATIONTRESHOLD bytes */ > #define OBEX_OBJECT_ALLOCATIONTRESHOLD 10240 > =20 > struct obex_header_element { > - GNetBuf *buf; > + buf_t *buf; > uint8_t hi; > unsigned int flags; > unsigned int length; > @@ -54,9 +54,9 @@ > slist_t *tx_headerq; /* List of headers to transmit*/ > slist_t *rx_headerq; /* List of received headers */ > slist_t *rx_headerq_rm; /* List of recieved header already read by the= app */ > - GNetBuf *rx_body; /* The rx body header need some extra help */ > - GNetBuf *tx_nonhdr_data; /* Data before of headers (like CONNECT and SE= TPATH) */ > - GNetBuf *rx_nonhdr_data; /* -||- */ > + buf_t *rx_body; /* The rx body header need some extra help */ > + buf_t *tx_nonhdr_data; /* Data before of headers (like CONNECT and SETP= ATH) */ > + buf_t *rx_nonhdr_data; /* -||- */ > =20 > uint8_t cmd; /* The command of this object */ > =20 > @@ -97,7 +97,7 @@ > int obex_object_setrsp(obex_object_t *object, uint8_t rsp, uint8_t lastr= sp); > int obex_object_send(obex_t *self, obex_object_t *object, > int allowfinalcmd, int forcefinalbit); > -int obex_object_receive(obex_t *self, GNetBuf *msg); > +int obex_object_receive(obex_t *self, buf_t *msg); > int obex_object_readstream(obex_t *self, obex_object_t *object, const ui= nt8_t **buf); > int obex_object_suspend(obex_object_t *object); > int obex_object_resume(obex_t *self, obex_object_t *object); > diff -uNr openobex/lib/obex_server.c openobex.test/lib/obex_server.c > --- openobex/lib/obex_server.c 2006-03-07 00:36:19.000000000 +0200 > +++ openobex.test/lib/obex_server.c 2006-04-25 16:02:05.000000000 +0300 > @@ -45,7 +45,7 @@ > * Handle server-operations > * > */ > -int obex_server(obex_t *self, GNetBuf *msg, int final) > +int obex_server(obex_t *self, buf_t *msg, int final) > { > obex_common_hdr_t *request; > int cmd, ret, deny =3D 0; > diff -uNr openobex/lib/obex_server.h openobex.test/lib/obex_server.h > --- openobex/lib/obex_server.h 2002-10-28 23:51:18.000000000 +0200 > +++ openobex.test/lib/obex_server.h 2006-04-25 16:02:05.000000000 +0300 > @@ -30,6 +30,6 @@ > #ifndef OBEX_SERVER_H > #define OBEX_SERVER_H > =20 > -int obex_server(obex_t *self, GNetBuf *msg, int final); > +int obex_server(obex_t *self, buf_t *msg, int final); > =20 > #endif > diff -uNr openobex/lib/obex_transport.c openobex.test/lib/obex_transport.c > --- openobex/lib/obex_transport.c 2006-01-03 20:36:15.000000000 +0200 > +++ openobex.test/lib/obex_transport.c 2006-04-25 16:02:05.000000000 +0300 > @@ -358,17 +358,17 @@ > /* > * does fragmented write > */ > -static int do_write(int fd, GNetBuf *msg, int mtu) > +static int do_write(int fd, buf_t *msg, int mtu) > { > int actual =3D -1; > int size; > =20 > /* Send and fragment if necessary */ > - while (msg->len) { > - if (msg->len > mtu) > + while (msg->data_size) { > + if (msg->data_size > mtu) > size =3D mtu; > else > - size =3D msg->len; > + size =3D msg->data_size; > DEBUG(1, "sending %d bytes\n", size); > =20 > actual =3D write(fd, msg->data, size); > @@ -376,7 +376,7 @@ > return actual; > =09 > /* Hide sent data */ > - g_netbuf_pull(msg, actual); > + buf_remove_begin(msg, actual); > } > return actual; > } > @@ -387,7 +387,7 @@ > * Do the writing > * > */ > -int obex_transport_write(obex_t *self, GNetBuf *msg) > +int obex_transport_write(obex_t *self, buf_t *msg) > { > int actual =3D -1; > =20 > @@ -413,13 +413,13 @@ > DEBUG(4, "Endpoint %d\n", self->trans.self.usb.data_endpoint_write); > actual =3D usb_bulk_write(self->trans.self.usb.dev_data,=20 > self->trans.self.usb.data_endpoint_write, > - (char *) msg->data, msg->len, USB_OBEX_TIMEOUT); > + (char *) msg->data, msg->data_size, USB_OBEX_TIMEOUT); > break; > #endif /*HAVE_USB*/=20 > case OBEX_TRANS_CUSTOM: > DEBUG(4, "Custom write\n"); > if(self->ctrans.write) > - actual =3D self->ctrans.write(self, self->ctrans.customdata, msg->dat= a, msg->len); > + actual =3D self->ctrans.write(self, self->ctrans.customdata, msg->dat= a, msg->data_size); > else > DEBUG(4, "No write-callback exist!\n"); > break; > @@ -439,7 +439,7 @@ > int obex_transport_read(obex_t *self, int max, uint8_t *buf, int buflen) > { > int actual =3D -1; > - GNetBuf *msg =3D self->rx_msg; > + buf_t *msg =3D self->rx_msg; > =20 > DEBUG(4, "Request to read max %d bytes\n", max); > =20 > @@ -452,7 +452,8 @@ > #endif /*HAVE_BLUETOOTH*/ > case OBEX_TRANS_INET: > case OBEX_TRANS_FD: > - actual =3D read(self->fd, msg->tail, max); > + actual =3D read(self->fd, buf_reserve_end(msg, max), max); > + buf_remove_end(msg, max - actual); > break; > #ifdef HAVE_USB=20 > case OBEX_TRANS_USB: > @@ -461,16 +462,18 @@ > DEBUG(4, "Endpoint %d\n", self->trans.self.usb.data_endpoint_read); > actual =3D usb_bulk_read(self->trans.self.usb.dev_data,=20 > self->trans.self.usb.data_endpoint_read, > - (char *) msg->tail, self->mtu_rx, USB_OBEX_TIMEOUT); > + buf_reserve_end(msg, self->mtu_rx), self->mtu_rx,=20 > + USB_OBEX_TIMEOUT); > + buf_remove_end(msg, self->mtu_rx - actual); > break; > #endif /*HAVE_USB*/=20 > case OBEX_TRANS_CUSTOM: > if(buflen > max) { > - memcpy(msg->tail, buf, max); > + memcpy(buf_reserve_end(msg, max), buf, max); > actual =3D max; > } > else { > - memcpy(msg->tail, buf, buflen); > + memcpy(buf_reserve_end(msg, buflen), buf, buflen); > actual =3D buflen; > } > break; > diff -uNr openobex/lib/obex_transport.h openobex.test/lib/obex_transport.h > --- openobex/lib/obex_transport.h 2006-01-03 20:36:15.000000000 +0200 > +++ openobex.test/lib/obex_transport.h 2006-04-25 16:02:05.000000000 +0300 > @@ -78,7 +78,7 @@ > void obex_transport_disconnect_request(obex_t *self); > int obex_transport_listen(obex_t *self); > void obex_transport_disconnect_server(obex_t *self); > -int obex_transport_write(obex_t *self, GNetBuf *msg); > +int obex_transport_write(obex_t *self, buf_t *msg); > int obex_transport_read(obex_t *self, int count, uint8_t *buf, int bufle= n); > =20 > #endif /* OBEX_TRANSPORT_H */ --=20 Eduardo |