/* Monolith chat library. * - by Richard W.M. Jones * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id: lib.c,v 1.3 2003/02/22 15:34:27 rich Exp $ */ #include "config.h" #include #include #include #include #include #include void chat_fill_buffer (io_handle io, ml_session session, const char *conninfo) { int userid; int bufsize; db_handle dbh; st_handle sth; int i; /* Calculate the size of the buffer. Anonymous users always get * the default, which is 4096 bytes. For other users, we go to the * database. (We always need to go to the database to cope with the * case of multiple rws instances ... doh!) */ userid = ml_session_userid (session); if (userid == 0) bufsize = 4096; else { dbh = get_db_handle (conninfo, DBI_THROW_ERRORS); sth = st_prepare_cached (dbh, "select fill_buffer from ml_chat_userprefs where userid = ?", DBI_INT); st_execute (sth, userid); st_bind (sth, 0, bufsize, DBI_INT); if (!st_fetch (sth)) bufsize = 4096; /* Default. */ put_db_handle (dbh); } /* Send the fill buffer back to the user. */ for (i = 0; i < bufsize; ++i) io_fputc (' ', io); io_fflush (io); }