/**************************************************************************/ /* */ /* 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 contain functions related broadcasting - status broadcasting */ /* message broadcasting, alert broadcasting. This unit work with database */ /* directly to increase perfomance and reduce database queries */ /* */ /* $Id: broadcast.cpp,v 1.15 2005/01/07 14:12:04 regress Exp $ */ /**************************************************************************/ #include "includes.h" /**************************************************************************/ /* Purpose: online event broadcasting for users wanted this (by contact) */ /* This will cause 3 complex database queries (instead of (csz-ofn)*3+1) */ /**************************************************************************/ void broadcast_online( struct online_user &auser ) { PGresult *res; /* struct for database requests */ cstring dbcomm_str; /* string space for query */ int users_cnt; /* number of users to alert */ struct online_user to_user; /* structure for target user */ struct online_user *puser; /* first of all we should request online users that have target */ /* in their contacts and after that lock database rows */ PQclear( PQexec(users_dbconn, "BEGIN" )); /* Define query to avoid multistring literals */ /* This is query for non-invisible users */ #define BCST_NPAM54 \ "SELECT uin,ishm FROM online_users \ JOIN \ ( \ SELECT ouin FROM online_contacts \ WHERE (tuin=%lu) AND (type=%d) \ EXCEPT \ ( \ SELECT tuin FROM online_contacts \ WHERE (ouin=%lu) AND (type=%d) \ ) \ LIMIT %d \ ) \ AS TMP on uin=TMP.ouin \ WHERE active=1" /* Define query to avoid multistring literals */ /* This is query for invisible users */ #define BCST_PAM74 \ "SELECT uin,ishm FROM online_users \ JOIN \ ( \ SELECT ouin FROM online_contacts \ WHERE (tuin=%lu) AND (type=%d) \ INTERSECT \ ( \ SELECT tuin FROM online_contacts \ WHERE (ouin=%lu) AND (type=%d) \ ) \ LIMIT %d \ ) \ AS TMP on uin=TMP.ouin \ WHERE active=1" if (auser.status != ICQ_STATUS_PRIVATE) { slprintf(dbcomm_str, sizeof( dbcomm_str )-1, BCST_NPAM54, auser.uin, NORMAL_CONTACT, auser.uin, INVISIBLE_CONTACT, lp_v7_max_contact_size()); } else { slprintf(dbcomm_str, sizeof( dbcomm_str )-1, BCST_PAM74, auser.uin, NORMAL_CONTACT, auser.uin, VISIBLE_CONTACT, lp_v7_max_contact_size()); } res = PQexec(users_dbconn, dbcomm_str); if (PQresultStatus( res ) != PGRES_TUPLES_OK ) { handle_database_error(res, "[BROADCAST ONLINE]"); PQclear( PQexec(users_dbconn, "ABORT") ); return; } /* number of returned users (tuples with information) */ users_cnt = PQntuples( res ); DEBUG(100, ("Complex query return %d users to alert...\n", users_cnt)); /* now it is time to send online alert to all users in loop */ if ( PQnfields( res ) == 2 ) { for( int i=0; i