/**************************************************************************/ /* */ /* Copyright (c) 2000-2005 by Alexandr V. Shutko, Khabarovsk, Russia */ /* All rights reserved. */ /* */ /* Redistribution and use in source and binary forms, with or without */ /* modification, are permitted provided that the following conditions */ /* are met: */ /* 1. Redistributions of source code must retain the above copyright */ /* notice, this list of conditions and the following disclaimer. */ /* 2. Redistributions in binary form must reproduce the above copyright */ /* notice, this list of conditions and the following disclaimer in */ /* the documentation and/or other materials provided with the */ /* distribution. */ /* */ /* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND */ /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE */ /* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS */ /* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, */ /* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT */ /* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */ /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, */ /* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* */ /* This unit implements database functions related contacts processing */ /* */ /* $Id: contacts_db.cpp,v 1.11 2005/01/07 14:00:19 regress Exp $ */ /**************************************************************************/ #include "includes.h" /**************************************************************************/ /* This func delete all online contacts from database */ /**************************************************************************/ int db_contacts_clear() { PGresult *res; res = PQexec(users_dbconn, "DELETE FROM Online_Contacts"); if (PQresultStatus(res) != PGRES_COMMAND_OK) { handle_database_error(res, "[Clear contacts]"); return(-1); } PQclear(res); return(0); } /**************************************************************************/ /* Insert new contact list in contact database */ /**************************************************************************/ int db_contact_insert(unsigned long uin, int number, unsigned long *contact, int type, unsigned long rid) { /* There is two ways to add contact list to database */ /* 1. Use copy from stdin (int_db_contact_insert_c) */ /* 2. Use set of inserts (int_db_contact_insert_i) */ /* first is much faster than second */ int_db_contact_insert_c(uin, number, contact, type, rid); return(0); } /**************************************************************************/ /* This is the internal function to add user contact list to database */ /* It use copy from stdin statement */ /**************************************************************************/ int int_db_contact_insert_c(unsigned long uin, int number, unsigned long *contact, int type, unsigned long rid) { PGresult *res; cstring dbcomm_str; DEBUG(100, ("Copy %d records for %lu to contact database.\n", number, uin)); res = PQexec(users_dbconn, "COPY Online_Contacts FROM stdin"); if (PQresultStatus(res) != PGRES_COPY_IN) { handle_database_error(res, "[DB_CONTACT_COPY_IN]"); return(-1); } else { PQclear(res); } for (int i=0; i 0) { if (PQnfields(res) < 1) { LOG_SYS(0, ("Corrypted table structure in db: \"%s\"\n", lp_db_users())); exit(EXIT_ERROR_DB_STRUCTURE); } *contact = (unsigned long *)malloc(sizeof(unsigned long)*number); DEBUG(200, ("Trying to malloc %d bytes for %d records (result: %06X)\n", (sizeof(unsigned long)*number), number, (unsigned int)*contact)); for (int i=0;i