File: portlistingparse.h

package info (click to toggle)
miniupnpc 2.3.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 992 kB
  • sloc: ansic: 7,885; makefile: 325; xml: 207; python: 170; sh: 161; java: 89
file content (91 lines) | stat: -rw-r--r-- 2,729 bytes parent folder | download | duplicates (2)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* $Id: portlistingparse.h,v 1.12 2025/02/08 23:15:17 nanard Exp $ */
/* MiniUPnP project
 * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
 * (c) 2011-2025 Thomas Bernard
 * This software is subject to the conditions detailed
 * in the LICENCE file provided within the distribution */
#ifndef PORTLISTINGPARSE_H_INCLUDED
#define PORTLISTINGPARSE_H_INCLUDED

/*! \file portlistingparse.h
 * \brief Parsing of the list of port mappings
 *
 * As returned by GetListOfPortMappings.
 * Sample of PortMappingEntry :
 *
 *     <p:PortMappingEntry>
 *       <p:NewRemoteHost>202.233.2.1</p:NewRemoteHost>
 *       <p:NewExternalPort>2345</p:NewExternalPort>
 *       <p:NewProtocol>TCP</p:NewProtocol>
 *       <p:NewInternalPort>2345</p:NewInternalPort>
 *       <p:NewInternalClient>192.168.1.137</p:NewInternalClient>
 *       <p:NewEnabled>1</p:NewEnabled>
 *       <p:NewDescription>dooom</p:NewDescription>
 *       <p:NewLeaseTime>345</p:NewLeaseTime>
 *     </p:PortMappingEntry>
 */
#include "miniupnpc_declspec.h"
/* for the definition of UNSIGNED_INTEGER */
#include "miniupnpctypes.h"

#ifdef __cplusplus
extern "C" {
#endif

/*!
 * \brief enum of all XML elements
 */
typedef enum { PortMappingEltNone,
       PortMappingEntry, NewRemoteHost,
       NewExternalPort, NewProtocol,
       NewInternalPort, NewInternalClient,
       NewEnabled, NewDescription,
       NewLeaseTime } portMappingElt;

/*!
 * \brief linked list of port mappings
 */
struct PortMapping {
	struct PortMapping * l_next;	/*!< \brief next list element */
	UNSIGNED_INTEGER leaseTime;	/*!< \brief in seconds */
	unsigned short externalPort;	/*!< \brief external port */
	unsigned short internalPort;	/*!< \brief internal port */
	char remoteHost[64];	/*!< \brief empty for wildcard */
	char internalClient[64];	/*!< \brief internal IP address */
	char description[64];	/*!< \brief description */
	char protocol[4];		/*!< \brief `TCP` or `UDP` */
	unsigned char enabled;	/*!< \brief 0 (false) or 1 (true) */
};

/*!
 * \brief structure for ParsePortListing()
 */
struct PortMappingParserData {
	struct PortMapping * l_head;	/*!< \brief list head */
	portMappingElt curelt;			/*!< \brief currently parsed element */
};

/*!
 * \brief parse the NewPortListing part of GetListOfPortMappings response
 *
 * \param[in] buffer XML data
 * \param[in] bufsize length of XML data
 * \param[out] pdata Parsed data
 */
MINIUPNP_LIBSPEC void
ParsePortListing(const char * buffer, int bufsize,
                 struct PortMappingParserData * pdata);

/*!
 * \brief free parsed data structure
 *
 * \param[in] pdata Parsed data to free
 */
MINIUPNP_LIBSPEC void
FreePortListing(struct PortMappingParserData * pdata);

#ifdef __cplusplus
}
#endif

#endif