# HG changeset patch # User Mark Doliner # Date 1153076911 0 # Node ID 614c566224532c4d4d6f1e5a7a1497f93e4c7e1d # Parent da767c69d8b7ddbd8621dcbe2df63666c2ade9e2 [gaim-migrate @ 16496] Rename gaim_buffer.c and .h to circbuffer.c and .h committer: Tailor Script diff -r da767c69d8b7 -r 614c56622453 src/Makefile.am --- a/src/Makefile.am Sun Jul 16 16:59:10 2006 +0000 +++ b/src/Makefile.am Sun Jul 16 19:08:31 2006 +0000 @@ -70,6 +70,7 @@ blist.c \ buddyicon.c \ cipher.c \ + circbuffer.c \ cmds.c \ connection.c \ conversation.c \ @@ -78,7 +79,6 @@ desktopitem.c \ eventloop.c \ ft.c \ - gaim_buffer.c \ idle.c \ imgstore.c \ log.c \ @@ -117,6 +117,7 @@ blist.h \ buddyicon.h \ cipher.h \ + circbuffer.h \ cmds.h \ connection.h \ conversation.h \ @@ -126,7 +127,6 @@ desktopitem.h \ eventloop.h \ ft.h \ - gaim_buffer.h \ idle.h \ imgstore.h \ log.h \ diff -r da767c69d8b7 -r 614c56622453 src/Makefile.mingw --- a/src/Makefile.mingw Sun Jul 16 16:59:10 2006 +0000 +++ b/src/Makefile.mingw Sun Jul 16 19:08:31 2006 +0000 @@ -89,6 +89,7 @@ blist.c \ buddyicon.c \ cipher.c \ + circbuffer.c \ cmds.c \ connection.c \ conversation.c \ @@ -97,7 +98,6 @@ dnssrv.c \ eventloop.c \ ft.c \ - gaim_buffer.c \ gtkaccount.c \ gtkblist.c \ gtkconn.c \ diff -r da767c69d8b7 -r 614c56622453 src/circbuffer.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/circbuffer.c Sun Jul 16 19:08:31 2006 +0000 @@ -0,0 +1,142 @@ +/* + * @file circbuffer.h Buffer Utility Functions + * @ingroup core + * + * Gaim is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "internal.h" + +#include "circbuffer.h" + +#define DEFAULT_BUF_SIZE 256 + +GaimCircBuffer * +gaim_circ_buffer_new(gsize growsize) { + GaimCircBuffer *buf = g_new0(GaimCircBuffer, 1); + buf->growsize = growsize ? growsize : DEFAULT_BUF_SIZE; + return buf; +} + +void gaim_circ_buffer_destroy(GaimCircBuffer *buf) { + g_return_if_fail(buf); + g_free(buf->buffer); + g_free(buf); +} + +static void grow_circ_buffer(GaimCircBuffer *buf, gsize len) { + int in_offset = 0, out_offset = 0; + int start_buflen = buf->buflen; + + while ((buf->buflen - buf->bufused) < len) + buf->buflen += buf->growsize; + + if (buf->inptr != NULL) { + in_offset = buf->inptr - buf->buffer; + out_offset = buf->outptr - buf->buffer; + } + buf->buffer = g_realloc(buf->buffer, buf->buflen); + + /* adjust the fill and remove pointer locations */ + if (buf->inptr == NULL) { + buf->inptr = buf->outptr = buf->buffer; + } else { + buf->inptr = buf->buffer + in_offset; + buf->outptr = buf->buffer + out_offset; + } + + /* If the fill pointer is wrapped to before the remove + * pointer, we need to shift the data */ + if (in_offset < out_offset) { + int shift_n = MIN(buf->buflen - start_buflen, + in_offset); + memcpy(buf->buffer + start_buflen, buf->buffer, + shift_n); + + /* If we couldn't fit the wrapped read buffer + * at the end */ + if (shift_n < in_offset) { + memmove(buf->buffer, + buf->buffer + shift_n, + in_offset - shift_n); + buf->inptr = buf->buffer + + (in_offset - shift_n); + } else { + buf->inptr = buf->buffer + + start_buflen + in_offset; + } + } +} + +void gaim_circ_buffer_append(GaimCircBuffer *buf, gconstpointer src, gsize len) { + + int len_stored; + + /* Grow the buffer, if necessary */ + if ((buf->buflen - buf->bufused) < len) + grow_circ_buffer(buf, len); + + /* If there is not enough room to copy all of src before hitting + * the end of the buffer then we will need to do two copies. + * One copy from inptr to the end of the buffer, and the + * second copy from the start of the buffer to the end of src. */ + if (buf->inptr >= buf->outptr) + len_stored = MIN(len, buf->buflen + - (buf->inptr - buf->buffer)); + else + len_stored = len; + + memcpy(buf->inptr, src, len_stored); + + if (len_stored < len) { + memcpy(buf->buffer, src + len_stored, len - len_stored); + buf->inptr = buf->buffer + (len - len_stored); + } else if ((buf->buffer - buf->inptr) == len_stored) { + buf->inptr = buf->buffer; + } else { + buf->inptr += len_stored; + } + + buf->bufused += len; +} + +gsize gaim_circ_buffer_get_max_read(GaimCircBuffer *buf) { + int max_read; + + if (buf->bufused == 0) + max_read = 0; + else if ((buf->outptr - buf->inptr) >= 0) + max_read = buf->buflen - (buf->outptr - buf->buffer); + else + max_read = buf->inptr - buf->outptr; + + return max_read; +} + +gboolean gaim_circ_buffer_mark_read(GaimCircBuffer *buf, gsize len) { + g_return_val_if_fail(gaim_circ_buffer_get_max_read(buf) >= len, FALSE); + + buf->outptr += len; + buf->bufused -= len; + /* wrap to the start if we're at the end */ + if ((buf->outptr - buf->buffer) == buf->buflen) + buf->outptr = buf->buffer; + + return TRUE; +} + diff -r da767c69d8b7 -r 614c56622453 src/circbuffer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/circbuffer.h Sun Jul 16 19:08:31 2006 +0000 @@ -0,0 +1,117 @@ +/* + * @file circbuffer.h Buffer Utility Functions + * @ingroup core + * + * Gaim is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef _CIRCBUFFER_H +#define _CIRCBUFFER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _GaimCircBuffer { + + /** A pointer to the starting address of our chunk of memory. */ + gchar *buffer; + + /** The incremental amount to increase this buffer by when + * the buffer is not big enough to hold incoming data, in bytes. */ + gsize growsize; + + /** The length of this buffer, in bytes. */ + gsize buflen; + + /** The number of bytes of this buffer that contain unread data. */ + gsize bufused; + + /** A pointer to the next byte where new incoming data is + * buffered to. */ + gchar *inptr; + + /** A pointer to the next byte of buffered data that should be + * read by the consumer. */ + gchar *outptr; + +} GaimCircBuffer; + +/** + * Creates a new circular buffer. This will not allocate any memory for the + * actual buffer until data is appended to it. + * + * @param growsize The amount that the buffer should grow the first time data + * is appended and every time more space is needed. Pass in + * "0" to use the default of 256 bytes. + * + * @return The new GaimCircBuffer. This should be freed with + * gaim_circ_buffer_destroy when you are done with it + */ +GaimCircBuffer *gaim_circ_buffer_new(gsize growsize); + +/** + * Dispose of the GaimCircBuffer and free any memory used by it (including any + * memory used by the internal buffer). + * + * @param buf The GaimCircBuffer to free + */ +void gaim_circ_buffer_destroy(GaimCircBuffer *buf); + +/** + * Append data to the GaimCircBuffer. This will grow the internal + * buffer to fit the added data, if needed. + * + * @param buf The GaimCircBuffer to which to append the data + * @param src pointer to the data to copy into the buffer + * @param len number of bytes to copy into the buffer + */ +void gaim_circ_buffer_append(GaimCircBuffer *buf, gconstpointer src, gsize len); + +/** + * Determine the maximum number of contiguous bytes that can be read from the + * GaimCircBuffer. + * Note: This may not be the total number of bytes that are buffered - a + * subsequent call after calling gaim_circ_buffer_mark_read() may indicate more + * data is available to read. + * + * @param buf the GaimCircBuffer for which to determine the maximum contiguous + * bytes that can be read. + * + * @return the number of bytes that can be read from the GaimCircBuffer + */ +gsize gaim_circ_buffer_get_max_read(GaimCircBuffer *buf); + +/** + * Mark the number of bytes that have been read from the buffer. + * + * @param buf The GaimCircBuffer to mark bytes read from + * @param len The number of bytes to mark as read + * + * @return TRUE if we successfully marked the bytes as having been read, FALSE + * otherwise. + */ +gboolean gaim_circ_buffer_mark_read(GaimCircBuffer *buf, gsize len); + +#ifdef __cplusplus +} +#endif + +#endif /* _CIRCBUFFER_H */ diff -r da767c69d8b7 -r 614c56622453 src/gaim_buffer.c --- a/src/gaim_buffer.c Sun Jul 16 16:59:10 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +0,0 @@ -/* - * @file gaim_buffer.h Buffer Utility Functions - * @ingroup core - * - * Gaim is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include "internal.h" - -#include "gaim_buffer.h" - -#define DEFAULT_BUF_SIZE 256 - -GaimCircBuffer * -gaim_circ_buffer_new(gsize growsize) { - GaimCircBuffer *buf = g_new0(GaimCircBuffer, 1); - buf->growsize = growsize ? growsize : DEFAULT_BUF_SIZE; - return buf; -} - -void gaim_circ_buffer_destroy(GaimCircBuffer *buf) { - g_return_if_fail(buf); - g_free(buf->buffer); - g_free(buf); -} - -static void grow_circ_buffer(GaimCircBuffer *buf, gsize len) { - int in_offset = 0, out_offset = 0; - int start_buflen = buf->buflen; - - while ((buf->buflen - buf->bufused) < len) - buf->buflen += buf->growsize; - - if (buf->inptr != NULL) { - in_offset = buf->inptr - buf->buffer; - out_offset = buf->outptr - buf->buffer; - } - buf->buffer = g_realloc(buf->buffer, buf->buflen); - - /* adjust the fill and remove pointer locations */ - if (buf->inptr == NULL) { - buf->inptr = buf->outptr = buf->buffer; - } else { - buf->inptr = buf->buffer + in_offset; - buf->outptr = buf->buffer + out_offset; - } - - /* If the fill pointer is wrapped to before the remove - * pointer, we need to shift the data */ - if (in_offset < out_offset) { - int shift_n = MIN(buf->buflen - start_buflen, - in_offset); - memcpy(buf->buffer + start_buflen, buf->buffer, - shift_n); - - /* If we couldn't fit the wrapped read buffer - * at the end */ - if (shift_n < in_offset) { - memmove(buf->buffer, - buf->buffer + shift_n, - in_offset - shift_n); - buf->inptr = buf->buffer + - (in_offset - shift_n); - } else { - buf->inptr = buf->buffer + - start_buflen + in_offset; - } - } -} - -void gaim_circ_buffer_append(GaimCircBuffer *buf, gconstpointer src, gsize len) { - - int len_stored; - - /* Grow the buffer, if necessary */ - if ((buf->buflen - buf->bufused) < len) - grow_circ_buffer(buf, len); - - /* If there is not enough room to copy all of src before hitting - * the end of the buffer then we will need to do two copies. - * One copy from inptr to the end of the buffer, and the - * second copy from the start of the buffer to the end of src. */ - if (buf->inptr >= buf->outptr) - len_stored = MIN(len, buf->buflen - - (buf->inptr - buf->buffer)); - else - len_stored = len; - - memcpy(buf->inptr, src, len_stored); - - if (len_stored < len) { - memcpy(buf->buffer, src + len_stored, len - len_stored); - buf->inptr = buf->buffer + (len - len_stored); - } else if ((buf->buffer - buf->inptr) == len_stored) { - buf->inptr = buf->buffer; - } else { - buf->inptr += len_stored; - } - - buf->bufused += len; -} - -gsize gaim_circ_buffer_get_max_read(GaimCircBuffer *buf) { - int max_read; - - if (buf->bufused == 0) - max_read = 0; - else if ((buf->outptr - buf->inptr) >= 0) - max_read = buf->buflen - (buf->outptr - buf->buffer); - else - max_read = buf->inptr - buf->outptr; - - return max_read; -} - -gboolean gaim_circ_buffer_mark_read(GaimCircBuffer *buf, gsize len) { - g_return_val_if_fail(gaim_circ_buffer_get_max_read(buf) >= len, FALSE); - - buf->outptr += len; - buf->bufused -= len; - /* wrap to the start if we're at the end */ - if ((buf->outptr - buf->buffer) == buf->buflen) - buf->outptr = buf->buffer; - - return TRUE; -} - diff -r da767c69d8b7 -r 614c56622453 src/gaim_buffer.h --- a/src/gaim_buffer.h Sun Jul 16 16:59:10 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,115 +0,0 @@ -/* - * @file gaim_buffer.h Buffer Utility Functions - * @ingroup core - * - * Gaim is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef _GAIM_BUFFER_H -#define _GAIM_BUFFER_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _GaimCircBuffer { - - /** A pointer to the starting address of our chunk of memory. */ - gchar *buffer; - - /** The incremental amount to increase this buffer by when - * the buffer is not big enough to hold incoming data, in bytes. */ - gsize growsize; - - /** The length of this buffer, in bytes. */ - gsize buflen; - - /** The number of bytes of this buffer that contain unread data. */ - gsize bufused; - - /** A pointer to the next byte where new incoming data is - * buffered to. */ - gchar *inptr; - - /** A pointer to the next byte of buffered data that should be - * read by the consumer. */ - gchar *outptr; - -} GaimCircBuffer; - -/** - * Creates a new circular buffer. This will not allocate any memory for the - * actual buffer until data is appended to it. - * - * @param growsize The amount that the buffer should grow the first time data - * is appended and every time more space is needed. Pass in - * "0" to use the default of 256 bytes. - * - * @return The new GaimCircBuffer. This should be freed with - * gaim_circ_buffer_destroy when you are done with it - */ -GaimCircBuffer *gaim_circ_buffer_new(gsize growsize); - -/** - * Dispose of the GaimCircBuffer and free any memory used by it (including any - * memory used by the internal buffer). - * - * @param buf The GaimCircBuffer to free - */ -void gaim_circ_buffer_destroy(GaimCircBuffer *buf); - -/** - * Append data to the GaimCircBuffer. This will grow the internal - * buffer to fit the added data, if needed. - * - * @param buf The GaimCircBuffer to which to append the data - * @param src pointer to the data to copy into the buffer - * @param len number of bytes to copy into the buffer - */ -void gaim_circ_buffer_append(GaimCircBuffer *buf, gconstpointer src, gsize len); - -/** - * Determine the maximum number of contiguous bytes that can be read from the - * GaimCircBuffer. - * Note: This may not be the total number of bytes that are buffered - a - * subsequent call after calling gaim_circ_buffer_mark_read() may indicate more - * data is available to read. - * - * @param buf the GaimCircBuffer for which to determine the maximum contiguous - * bytes that can be read. - * - * @return the number of bytes that can be read from the GaimCircBuffer - */ -gsize gaim_circ_buffer_get_max_read(GaimCircBuffer *buf); - -/** - * Mark the number of bytes that have been read from the buffer. - * - * @param buf The GaimCircBuffer to mark bytes read from - * @param len The number of bytes to mark as read - * - * @return TRUE if we successfully marked the bytes as having been read, FALSE - * otherwise. - */ -gboolean gaim_circ_buffer_mark_read(GaimCircBuffer *buf, gsize len); - -#ifdef __cplusplus -} -#endif - -#endif /* _GAIM_BUFFER_H */ diff -r da767c69d8b7 -r 614c56622453 src/protocols/irc/irc.h --- a/src/protocols/irc/irc.h Sun Jul 16 16:59:10 2006 +0000 +++ b/src/protocols/irc/irc.h Sun Jul 16 19:08:31 2006 +0000 @@ -25,8 +25,8 @@ #include +#include "circbuffer.h" #include "ft.h" -#include "gaim_buffer.h" #include "roomlist.h" #include "sslconn.h" diff -r da767c69d8b7 -r 614c56622453 src/protocols/jabber/jabber.h --- a/src/protocols/jabber/jabber.h Sun Jul 16 16:59:10 2006 +0000 +++ b/src/protocols/jabber/jabber.h Sun Jul 16 19:08:31 2006 +0000 @@ -26,10 +26,10 @@ #include #endif #include +#include "circbuffer.h" #include "connection.h" #include "roomlist.h" #include "sslconn.h" -#include "gaim_buffer.h" #include "jutil.h" #include "xmlnode.h" diff -r da767c69d8b7 -r 614c56622453 src/protocols/msn/httpconn.h --- a/src/protocols/msn/httpconn.h Sun Jul 16 16:59:10 2006 +0000 +++ b/src/protocols/msn/httpconn.h Sun Jul 16 19:08:31 2006 +0000 @@ -26,8 +26,8 @@ typedef struct _MsnHttpConn MsnHttpConn; +#include "circbuffer.h" #include "servconn.h" -#include "gaim_buffer.h" /** * An HTTP Connection. diff -r da767c69d8b7 -r 614c56622453 src/protocols/oscar/oscar.h --- a/src/protocols/oscar/oscar.h Sun Jul 16 16:59:10 2006 +0000 +++ b/src/protocols/oscar/oscar.h Sun Jul 16 19:08:31 2006 +0000 @@ -29,9 +29,9 @@ #ifndef _OSCAR_H_ #define _OSCAR_H_ +#include "circbuffer.h" #include "debug.h" #include "eventloop.h" -#include "gaim_buffer.h" #include "internal.h" #include diff -r da767c69d8b7 -r 614c56622453 src/protocols/sametime/sametime.c --- a/src/protocols/sametime/sametime.c Sun Jul 16 16:59:10 2006 +0000 +++ b/src/protocols/sametime/sametime.c Sun Jul 16 19:08:31 2006 +0000 @@ -32,25 +32,25 @@ #include /* gaim includes */ -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "internal.h" +#include "gaim.h" +#include "config.h" + +#include "account.h" +#include "accountopt.h" +#include "circbuffer.h" +#include "conversation.h" +#include "debug.h" +#include "ft.h" +#include "imgstore.h" +#include "mime.h" +#include "notify.h" +#include "plugin.h" +#include "privacy.h" +#include "prpl.h" +#include "request.h" +#include "util.h" +#include "version.h" /* meanwhile includes */ #include diff -r da767c69d8b7 -r 614c56622453 src/protocols/simple/simple.h --- a/src/protocols/simple/simple.h Sun Jul 16 16:59:10 2006 +0000 +++ b/src/protocols/simple/simple.h Sun Jul 16 19:08:31 2006 +0000 @@ -26,9 +26,9 @@ #include #include -#include -#include -#include +#include "cipher.h" +#include "circbuffer.h" +#include "prpl.h" #include "sipmsg.h" diff -r da767c69d8b7 -r 614c56622453 src/protocols/yahoo/yahoo.h --- a/src/protocols/yahoo/yahoo.h Sun Jul 16 16:59:10 2006 +0000 +++ b/src/protocols/yahoo/yahoo.h Sun Jul 16 19:08:31 2006 +0000 @@ -25,8 +25,8 @@ #ifndef _YAHOO_H_ #define _YAHOO_H_ +#include "circbuffer.h" #include "prpl.h" -#include "gaim_buffer.h" #define YAHOO_PAGER_HOST "scs.msg.yahoo.com" #define YAHOO_PAGER_PORT 5050