1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 1998-2013 Licq developers <licq-dev@googlegroups.com>
4  *
5  * Licq is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * Licq is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Licq; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 
20 #include "config.h"
21 
22 #include <signal.h>
23 #include <cstdlib>
24 #include <cstring>
25 
26 #include <locale>
27 
28 #include "licq.h"
29 #include "plugin/pluginmanager.h"
30 #include "plugin/pluginthread.h"
31 
32 #ifdef USE_SOCKS5
33 #define SOCKS
34 #define INCLUDE_PROTOTYPES
35 extern "C" {
36 #include <socks.h>
37 }
38 #endif
39 
40 // Localization
41 #include "gettext.h"
42 
43 // sighandler.cpp
44 void licq_install_signal_handlers();
45 
46 using LicqDaemon::PluginThread;
47 
48 static int threadArgc;
49 static char** threadArgv;
threadMain(PluginThread::Ptr mainThread)50 static int threadMain(PluginThread::Ptr mainThread)
51 {
52   using LicqDaemon::gPluginManager;
53   gPluginManager.setGuiThread(mainThread);
54 
55   int ret = 1;
56   CLicq licq;
57   if (licq.Init(threadArgc, threadArgv))
58     ret = licq.Main();
59   else
60     gPluginManager.cancelAllPlugins();
61 
62   gPluginManager.setGuiThread(PluginThread::Ptr());
63   return ret;
64 }
65 
main(int argc,char ** argv)66 int main(int argc, char **argv)
67 {
68 #if ENABLE_NLS
69   // prepare daemon localization
70   setlocale(LC_ALL, "");
71   bindtextdomain(PACKAGE, LOCALEDIR);
72   textdomain(PACKAGE);
73 #endif
74 
75   // Make sure argv[0] is defined otherwise licq will crash if it is NULL
76   if (argv[0] == NULL)
77     argv[0] = strdup("licq");
78 #ifdef USE_SOCKS5
79    SOCKSinit(argv[0]);
80 #endif
81 
82   licq_install_signal_handlers();
83 
84   threadArgc = argc;
85   threadArgv = argv;
86 
87   // On some systems (e.g. Mac OS X) the GUI plugin must run in the main thread
88   // and the daemon will run in a new thread.
89 #if __APPLE__
90   return PluginThread::createWithCurrentThread(&threadMain);
91 #else
92   return threadMain(PluginThread::Ptr());
93 #endif
94 }
95