UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
upnptools.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 GPL 3 and higher by Ingo Höft, <Ingo@Hoeft-online.de>
2// Redistribution only with this Copyright remark. Last modified: 2024-08-18
10
11namespace {
12
19 int rc;
20 const char* rcError;
21};
22
31 {UPNP_E_SUCCESS, "UPNP_E_SUCCESS"},
32 {UPNP_E_INVALID_HANDLE, "UPNP_E_INVALID_HANDLE"},
33 {UPNP_E_INVALID_PARAM, "UPNP_E_INVALID_PARAM"},
34 {UPNP_E_OUTOF_HANDLE, "UPNP_E_OUTOF_HANDLE"},
35 // {UPNP_E_OUTOF_CONTEXT, "UPNP_E_OUTOF_CONTEXT"},
36 {UPNP_E_OUTOF_MEMORY, "UPNP_E_OUTOF_MEMORY"},
37 {UPNP_E_INIT, "UPNP_E_INIT"},
38 // {UPNP_E_BUFFER_TOO_SMALL, "UPNP_E_BUFFER_TOO_SMALL"},
39 {UPNP_E_INVALID_DESC, "UPNP_E_INVALID_DESC"},
40 {UPNP_E_INVALID_URL, "UPNP_E_INVALID_URL"},
41 // {UPNP_E_INVALID_SID, "UPNP_E_INVALID_SID"},
42 // {UPNP_E_INVALID_DEVICE, "UPNP_E_INVALID_DEVICE"},
43 {UPNP_E_INVALID_SERVICE, "UPNP_E_INVALID_SERVICE"},
44 {UPNP_E_BAD_RESPONSE, "UPNP_E_BAD_RESPONSE"},
45 // {UPNP_E_BAD_REQUEST, "UPNP_E_BAD_REQUEST"},
46 {UPNP_E_INVALID_ACTION, "UPNP_E_INVALID_ACTION"},
47 {UPNP_E_FINISH, "UPNP_E_FINISH"},
48 {UPNP_E_INIT_FAILED, "UPNP_E_INIT_FAILED"},
49 {UPNP_E_URL_TOO_BIG, "UPNP_E_URL_TOO_BIG"},
50 {UPNP_E_BAD_HTTPMSG, "UPNP_E_BAD_HTTPMSG"},
51 {UPNP_E_ALREADY_REGISTERED, "UPNP_E_ALREADY_REGISTERED"},
52 {UPNP_E_INVALID_INTERFACE, "UPNP_E_INVALID_INTERFACE"},
53 {UPNP_E_NETWORK_ERROR, "UPNP_E_NETWORK_ERROR"},
54 {UPNP_E_SOCKET_WRITE, "UPNP_E_SOCKET_WRITE"},
55 {UPNP_E_SOCKET_READ, "UPNP_E_SOCKET_READ"},
56 {UPNP_E_SOCKET_BIND, "UPNP_E_SOCKET_BIND"},
57 {UPNP_E_SOCKET_CONNECT, "UPNP_E_SOCKET_CONNECT"},
58 {UPNP_E_OUTOF_SOCKET, "UPNP_E_OUTOF_SOCKET"},
59 {UPNP_E_LISTEN, "UPNP_E_LISTEN"},
60 {UPNP_E_TIMEDOUT, "UPNP_E_TIMEDOUT"},
61 {UPNP_E_SOCKET_ERROR, "UPNP_E_SOCKET_ERROR"},
62 // {UPNP_E_FILE_WRITE_ERROR, "UPNP_E_FILE_WRITE_ERROR"},
63 {UPNP_E_CANCELED, "UPNP_E_CANCELED"},
64 {UPNP_E_SOCKET_ACCEPT, "UPNP_E_SOCKET_ACCEPT"},
65 // {UPNP_E_EVENT_PROTOCOL, "UPNP_E_EVENT_PROTOCOL"},
66 {UPNP_E_SUBSCRIBE_UNACCEPTED, "UPNP_E_SUBSCRIBE_UNACCEPTED"},
67 {UPNP_E_UNSUBSCRIBE_UNACCEPTED, "UPNP_E_UNSUBSCRIBE_UNACCEPTED"},
68 {UPNP_E_NOTIFY_UNACCEPTED, "UPNP_E_NOTIFY_UNACCEPTED"},
69 {UPNP_E_INVALID_ARGUMENT, "UPNP_E_INVALID_ARGUMENT"},
70 {UPNP_E_FILE_NOT_FOUND, "UPNP_E_FILE_NOT_FOUND"},
71 {UPNP_E_FILE_READ_ERROR, "UPNP_E_FILE_READ_ERROR"},
72 {UPNP_E_EXT_NOT_XML, "UPNP_E_EXT_NOT_XML"},
73 // {UPNP_E_NO_WEB_SERVER, "UPNP_E_NO_WEB_SERVER"},
74 // {UPNP_E_OUTOF_BOUNDS, "UPNP_E_OUTOF_BOUNDS"},
75 {UPNP_E_NOT_FOUND, "UPNP_E_NOT_FOUND"},
76 {UPNP_E_INTERNAL_ERROR, "UPNP_E_INTERNAL_ERROR"},
77};
78
79} // namespace
80
81namespace UPnPsdk {
82
86const std::string errStr(const int error) {
87 size_t i;
88 std::string error_msg = "UPNPLIB_E_UNKNOWN";
89
90 for (i = 0; i < sizeof(ErrorMessages) / sizeof(ErrorMessages[0]); ++i) {
91 if (error == ErrorMessages[i].rc) {
92 error_msg = ErrorMessages[i].rcError;
93 break;
94 }
95 }
96 return error_msg + "(" + std::to_string(error) + ")";
97}
98
103const std::string errStrEx(const int error, const int success) {
104 size_t i;
105 std::string error_msg = "UPNPLIB_E_UNKNOWN";
106 std::string success_msg = "UPNPLIB_E_UNKNOWN";
107
108 for (i = 0; i < sizeof(ErrorMessages) / sizeof(ErrorMessages[0]); ++i) {
109 if (error == ErrorMessages[i].rc) {
110 error_msg = ErrorMessages[i].rcError;
111 break;
112 }
113 }
114 for (i = 0; i < sizeof(ErrorMessages) / sizeof(ErrorMessages[0]); ++i) {
115 if (success == ErrorMessages[i].rc) {
116 success_msg = ErrorMessages[i].rcError;
117 break;
118 }
119 }
120 return " # Should be " + success_msg + "(" + std::to_string(success) +
121 "), but not " + error_msg + "(" + std::to_string(error) + ").";
122}
123
124} // namespace UPnPsdk
const char * rcError
Definition upnptools.cpp:62
struct ErrorString ErrorMessages[]
Array of error structures.
Definition upnptools.cpp:68
General usable free function tools and helper.
Definition of the UPNP_E_* error messages.
#define UPNP_E_SOCKET_CONNECT
The SDK had a problem connecting to a remote host.
Definition messages.hpp:209
#define UPNP_E_OUTOF_HANDLE
The SDK does not have any more space for additional handles.
Definition messages.hpp:47
#define UPNP_E_ALREADY_REGISTERED
A client or a device is already registered.
Definition messages.hpp:154
#define UPNP_E_NOT_FOUND
The response to a SOAP request did not contain the required XML constructs.
Definition messages.hpp:313
#define UPNP_E_SOCKET_ERROR
Generic socket error code for conditions not covered by other error codes.
Definition messages.hpp:243
#define UPNP_E_LISTEN
The SDK had a problem setting the socket to listen for incoming connections.
Definition messages.hpp:227
#define UPNP_E_NETWORK_ERROR
A network error occurred.
Definition messages.hpp:169
#define UPNP_E_SOCKET_BIND
The SDK had a problem binding a socket to a network interface.
Definition messages.hpp:199
#define UPNP_E_INVALID_ARGUMENT
One or more of the parameters passed to a function is invalid.
Definition messages.hpp:287
#define UPNP_E_INVALID_HANDLE
The handle passed to a function is not a recognized as a valid handle.
Definition messages.hpp:32
#define UPNP_E_TIMEDOUT
Too much time elapsed before the required number of bytes were sent or received over a socket.
Definition messages.hpp:235
#define UPNP_E_FILE_READ_ERROR
An error happened while reading a file.
Definition messages.hpp:298
#define UPNP_E_INVALID_INTERFACE
The interface provided to UpnpInit2 is unknown or does not have a valid IPv4 or IPv6 address configur...
Definition messages.hpp:160
#define UPNP_E_BAD_HTTPMSG
The HTTP message contains invalid message headers.
Definition messages.hpp:146
#define UPNP_E_FILE_NOT_FOUND
The filename passed to one of the device registration functions was not found or was not accessible.
Definition messages.hpp:293
#define UPNP_E_SUCCESS
The operation completed successfully.
Definition messages.hpp:27
#define UPNP_E_SUBSCRIBE_UNACCEPTED
A subscription request was rejected from the remote side.
Definition messages.hpp:269
#define UPNP_E_OUTOF_SOCKET
The SDK cannot create any more sockets.
Definition messages.hpp:219
#define UPNP_E_OUTOF_MEMORY
Not enough resources are currently available to complete the operation.
Definition messages.hpp:57
#define UPNP_E_SOCKET_ACCEPT
The SDK had a problem accepting a network connection.
Definition messages.hpp:262
#define UPNP_E_INVALID_URL
An URL passed into the function is invalid.
Definition messages.hpp:83
#define UPNP_E_INVALID_ACTION
The SOAP action message is invalid.
Definition messages.hpp:113
#define UPNP_E_SOCKET_WRITE
An error happened while writing to a socket.
Definition messages.hpp:179
#define UPNP_E_FINISH
UpnpInit2 has not been called, or UpnpFinish has already been called.
Definition messages.hpp:121
#define UPNP_E_INIT_FAILED
UpnpInit2 cannot complete.
Definition messages.hpp:128
#define UPNP_E_UNSUBSCRIBE_UNACCEPTED
An unsubscribe request was rejected from the remote side.
Definition messages.hpp:274
#define UPNP_E_NOTIFY_UNACCEPTED
The remote host did not accept the notify sent from the local device.
Definition messages.hpp:279
#define UPNP_E_CANCELED
The operation was canceled.
Definition messages.hpp:252
#define UPNP_E_SOCKET_READ
An error happened while reading from a socket.
Definition messages.hpp:189
#define UPNP_E_INVALID_SERVICE
The device ID/service ID pair does not refer to a valid service.
Definition messages.hpp:95
#define UPNP_E_INVALID_DESC
The description document passed to UpnpRegisterRootDevice, UpnpRegisterRootDevice2 UpnpRegisterRootDe...
Definition messages.hpp:74
#define UPNP_E_INVALID_PARAM
One or more of the parameters passed to the function is not valid.
Definition messages.hpp:40
#define UPNP_E_URL_TOO_BIG
The URL passed into a function is too long.
Definition messages.hpp:135
#define UPNP_E_INTERNAL_ERROR
Generic error code for internal conditions not covered by other error codes.
Definition messages.hpp:319
#define UPNP_E_BAD_RESPONSE
The response received from the remote side of a connection is not correct for the protocol.
Definition messages.hpp:103
#define UPNP_E_INIT
The SDK has already been initialized.
Definition messages.hpp:65
#define UPNP_E_EXT_NOT_XML
The file name of the description document passed to UpnpRegisterRootDevice2 does not end in "....
Definition messages.hpp:304
Reengineered Object Oriented UPnP+ program code.
UPnPsdk_VIS const std::string errStr(int error)
Get error name string.
Definition upnptools.cpp:86
UPnPsdk_VIS const std::string errStrEx(const int error, const int success)
Get extended error name string.
const char * rcError
Error description.
Definition upnptools.cpp:20
Sample: assign {UPNP_E_SUCCESS, "UPNP_E_SUCCESS"}.
Definition upnptools.cpp:18