summaryrefslogtreecommitdiffstats
blob: 4c9f557be650ff2f3bbb6df3b6ec2eed37396346 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Copyright (c) 2015 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#pragma once

#include <string>

#include <Windows.h>

#include <Swiften/Base/API.h>

namespace Swift {
    /*
     * This represents the SPN used on Windows to identify a service
     * instance.
     */
    class SWIFTEN_API WindowsServicePrincipalName {
        public:
            /*
             * This assigns the provided service name,
             * "xmpp" service class, no instance name or referrer,
             * and default port. All of these (except the service
             * name) can be set to other values using the provided
             * methods.
             * If the constructor is called with the service name
             * "hostname.example.com" and the provided methods are
             * not used to change the defaults, then toString()
             * will return the SPN "xmpp/hostname.example.com".
             */
            WindowsServicePrincipalName(const std::string& serviceName);

            ~WindowsServicePrincipalName();

            void setServiceClass(const std::string& serviceClass);

            void setInstanceName(const std::string& instanceName);

            void setReferrer(const std::string& referrer);

            /*
             * This sets a non-default port for the service. Note
             * that the default value is 0 which indicates the
             * default port for the service. So if the XMPP service
             * is using the default port of 5222 for client
             * connections, then do not set the port to 5222 but let
             * it remain 0 to indicate that the default port is
             * used.
             */
            void setInstancePort(short int instancePort) { instancePort_ = instancePort; }

            /*
             * This follows the rules of SPN creation on Windows and
             * returns the SPN string constructed from the set
             * values.
             */
            std::string toString();

        private:
            DWORD dsMakeSpn(DWORD* length, wchar_t* value);

        private:
            std::wstring serviceClass_;
            std::wstring serviceName_;
            std::wstring instanceName_;
            USHORT instancePort_;
            std::wstring referrer_;
    };
}