1 /*  This file is part of the KDE project
2     SPDX-FileCopyrightText: 2008 Jarosław Staniek <staniek@kde.org>
3 
4     SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 // krazy:excludeall=null since used by SASL (C library)
8 
9 #pragma once
10 
11 #include <QDir>
12 #include <QFile>
13 #include <stdio.h>
14 
15 #ifdef Q_OS_WIN
16 #include <QCoreApplication>
17 #endif
18 
19 extern "C" {
20 #include <sasl/sasl.h>
21 }
22 
initSASL()23 inline bool initSASL()
24 {
25 #ifdef Q_OS_WIN // krazy:exclude=cpp
26     for (const auto &path : QCoreApplication::libraryPaths()) {
27         QDir dir(path);
28         if (dir.exists(QStringLiteral("sasl2"))) {
29             auto libInstallPath = QFile::encodeName(dir.absoluteFilePath(QStringLiteral("sasl2")));
30             if (sasl_set_path(SASL_PATH_TYPE_PLUGIN, libInstallPath.data()) != SASL_OK) {
31                 fprintf(stderr, "SASL path initialization failed!\n");
32                 return false;
33             }
34             break;
35         }
36     }
37 #endif
38 
39     if (sasl_client_init(nullptr) != SASL_OK) {
40         fprintf(stderr, "SASL library initialization failed!\n");
41         return false;
42     }
43     return true;
44 }
45 
46