|
| #define | MUPNP_CONTROLPOINT_SSDP_DEFAULT_SEARCH_MX 3 |
| |
| #define | MUPNP_CONTROLPOINT_SSDP_MIN_DELAY 20 |
| |
| #define | MUPNP_CONTROLPOINT_SSDP_RESPONSE_DEFAULT_PORT 39400 |
| |
| #define | MUPNP_CONTROLPOINT_SSDP_RESPONSE_PORT_MAX_TRIES_INDEX 80 |
| |
| #define | MUPNP_CONTROLPOINT_HTTP_EVENT_DEFAULT_PORT 39500 |
| |
| #define | MUPNP_CONTROLPOINT_HTTP_EVENTSUB_URI "/eventSub" |
| |
| #define | mupnp_controlpoint_getssdpserverlist(ctrlPoint) |
| |
| #define | mupnp_controlpoint_getssdpresponseserverlist(ctrlPoint) |
| |
| #define | mupnp_controlpoint_gethttpserverlist(ctrlPoint) |
| |
| #define | mupnp_controlpoint_setssdplistener(ctrlPoint, func) |
| |
| #define | mupnp_controlpoint_getssdplistener(ctrlPoint) |
| |
| #define | mupnp_controlpoint_setssdpresponselistener(ctrlPoint, func) |
| |
| #define | mupnp_controlpoint_getssdpresponselistener(ctrlPoint) |
| |
| #define | mupnp_controlpoint_setdevicelistener(ctrlPoint, func) |
| |
| #define | mupnp_controlpoint_getdevicelistener(ctrlPoint) |
| |
| #define | mupnp_controlpoint_addeventlistener(ctrlPoint, listener) |
| |
| #define | mupnp_controlpoint_removeeventlistener(ctrlPoint, listener) |
| |
| #define | mupnp_controlpoint_geteventlistener(ctrlPoint) |
| |
| #define | mupnp_controlpoint_geteventlisteners(ctrlPoint) |
| |
| #define | mupnp_controlpoint_setssdpresponseport(ctrlPoint, port) |
| |
| #define | mupnp_controlpoint_getssdpresponseport(ctrlPoint) |
| |
| #define | mupnp_controlpoint_seteventport(ctrlPoint, port) |
| |
| #define | mupnp_controlpoint_geteventport(ctrlPoint) |
| |
| #define | mupnp_controlpoint_seteventsuburi(ctrlPoint, uri) |
| |
| #define | mupnp_controlpoint_geteventsuburi(ctrlPoint) |
| |
| #define | mupnp_controlpoint_setssdpsearchmx(ctrlPoint, value) |
| |
| #define | mupnp_controlpoint_getssdpsearchmx(ctrlPoint) |
| |
| #define | mupnp_controlpoint_sethttplistener(ctrlPoint, func) |
| |
| #define | mupnp_controlpoint_gethttplistener(ctrlPoint) |
| |
| #define | mupnp_controlpoint_setuserdata(ctrlPoint, value) |
| |
| #define | mupnp_controlpoint_getuserdata(ctrlPoint) |
| |
| #define | mupnp_controlpoint_getdevices(ctrlPoint) |
| |
| #define | mupnp_controlpoint_getndevices(ctrlPoint) |
| |
| #define | mupnp_controlpoint_getdevice(ctrlPoint, index) |
| |
| #define | mupnp_controlpoint_adddevice(ctrlPoint, dev) |
| |
|
| mUpnpControlPoint * | mupnp_controlpoint_new (void) |
| | Create a new control point instance.
|
| |
| void | mupnp_controlpoint_delete (mUpnpControlPoint *ctrlPoint) |
| | Destroy a control point and free all associated resources.
|
| |
| bool | mupnp_controlpoint_start (mUpnpControlPoint *ctrlPoint) |
| | Activate the control point and start network listeners.
|
| |
| bool | mupnp_controlpoint_stop (mUpnpControlPoint *ctrlPoint) |
| | Stop the control point and shut down network listeners.
|
| |
| bool | mupnp_controlpoint_isrunning (mUpnpControlPoint *ctrlPoint) |
| | Check if the control point is currently active.
|
| |
| bool | mupnp_controlpoint_lock (mUpnpControlPoint *ctrlPoint) |
| |
| bool | mupnp_controlpoint_unlock (mUpnpControlPoint *ctrlPoint) |
| |
| mUpnpDevice * | mupnp_controlpoint_getdevicebyexacttype (mUpnpControlPoint *ctrlPoint, const char *exacttype) |
| | Find a device by exact type string including version.
|
| |
| mUpnpDevice * | mupnp_controlpoint_getdevicebytype (mUpnpControlPoint *ctrlPoint, const char *type) |
| | Find a device by type, ignoring version number.
|
| |
| mUpnpDevice * | mupnp_controlpoint_getdevicebyudn (mUpnpControlPoint *ctrlPoint, const char *udn) |
| | Find a device by its Unique Device Name (UDN)
|
| |
| bool | mupnp_controlpoint_seteventlistener (mUpnpControlPoint *ctrlPoint, MUPNP_EVENT_LISTENER evlistener) |
| |
| bool | mupnp_controlpoint_search (mUpnpControlPoint *ctrlPoint, const char *target) |
| | Send an M-SEARCH multicast message to discover UPnP devices.
|
| |
| void | mupnp_controlpoint_httprequestreceived (mUpnpHttpRequest *httpReq) |
| |
| void | mupnp_controlpoint_updatestatetablefromproperty (mUpnpService *service, mUpnpProperty *prop) |
| |
| bool | mupnp_controlpoint_parsescservicescpd (mUpnpService *service) |
| |
| bool | mupnp_controlpoint_parseservicesfordevice (mUpnpDevice *dev, mUpnpSSDPPacket *ssdpPkt) |
| |
| void | mupnp_controlpoint_adddevicebyssdppacket (mUpnpControlPoint *ctrlPoint, mUpnpSSDPPacket *ssdpPkt) |
| |
| void | mupnp_controlpoint_removedevicebyssdppacket (mUpnpControlPoint *ctrlPoint, mUpnpSSDPPacket *ssdpPkt) |
| |
| bool | mupnp_controlpoint_subscribe (mUpnpControlPoint *ctrlPoint, mUpnpService *service, long timeout) |
| | Subscribe to a UPnP service's event notifications.
|
| |
| bool | mupnp_controlpoint_resubscribe (mUpnpControlPoint *ctrlPoint, mUpnpService *service, long timeout) |
| |
| bool | mupnp_controlpoint_unsubscribe (mUpnpControlPoint *ctrlPoint, mUpnpService *service) |
| |
| bool | mupnp_controlpoint_subscribeall (mUpnpControlPoint *ctrlPoint, mUpnpDevice *dev, long timeout) |
| |
| bool | mupnp_controlpoint_resubscribeall (mUpnpControlPoint *ctrlPoint, mUpnpDevice *dev, long timeout) |
| |
| bool | mupnp_controlpoint_unsubscribeall (mUpnpControlPoint *ctrlPoint, mUpnpDevice *dev) |
| |
| void | mupnp_controlpoint_expirationhandler (mUpnpThread *thread) |
| |
| bool | mupnp_controlpoint_ipchanged (mUpnpControlPoint *ctrlpoint) |
| |
| const char * | mupnp_controlpoint_geteventsubcallbackurl (mUpnpControlPoint *ctrlPoint, char *ifaddr, char *buf, size_t bufLen) |
| |
Destroy a control point and free all associated resources.
Releases all resources associated with the control point, including:
- All discovered devices and their descriptions
- Network listeners (SSDP, HTTP)
- Internal mutexes and threads
- Cached network interface information
If the control point is still running when this function is called, it will be stopped automatically before resources are freed.
- Parameters
-
| ctrlPoint | The control point to destroy. May be NULL (no-op if NULL). |
- Note
- After calling this function, the ctrlPoint pointer is invalid and must not be used.
-
This function will block until all internal threads have terminated.
-
Thread-safe: Must not be called concurrently with other operations on the same control point. The caller is responsible for ensuring exclusive access.
- Warning
- Do not call this function while holding locks or from within event callbacks, as this may cause deadlocks.
- See also
- mupnp_controlpoint_new()
-
mupnp_controlpoint_stop()
Destroy the given control point
- Parameters
-
| ctrlPoint | The control point struct to destroy |
Find a device by exact type string including version.
Searches the control point's device list for a device whose complete type string matches the given type, including the version number. This performs an exact string comparison.
The search includes embedded devices (child devices within root devices).
- Parameters
-
| ctrlPoint | The control point to search. Must not be NULL. |
| exacttype | The exact device type to match, including version. Must not be NULL. Format: "urn:schemas-upnp-org:device:<deviceType>:<ver>" Example: "urn:schemas-upnp-org:device:MediaServer:2" |
- Returns
- Pointer to the first matching device, or NULL if not found or if parameters are NULL.
- Note
- Thread-safe: The control point should be locked with mupnp_controlpoint_lock() before calling this function and accessing the returned device pointer. Release with mupnp_controlpoint_unlock() as soon as possible.
-
Do not cache the returned pointer. Devices may be removed from the list at any time when the control point is unlocked.
-
If multiple devices match, only the first one found is returned.
- Warning
- The returned pointer is only valid while the control point is locked.
- See also
- mupnp_controlpoint_getdevicebytype()
-
mupnp_controlpoint_getdevicebyudn()
-
mupnp_controlpoint_lock()
ctrlPoint, "urn:schemas-upnp-org:device:MediaServer:2");
if (dev != NULL) {
printf("Found device: %s\n", friendlyName);
}
bool mupnp_controlpoint_unlock(mUpnpControlPoint *ctrlPoint)
Definition controlpoint.c:372
bool mupnp_controlpoint_lock(mUpnpControlPoint *ctrlPoint)
Definition controlpoint.c:356
mUpnpDevice * mupnp_controlpoint_getdevicebyexacttype(mUpnpControlPoint *ctrlPoint, const char *exacttype)
Find a device by exact type string including version.
Definition controlpoint.c:396
#define mupnp_device_getfriendlyname(dev)
Definition device.h:486
The generic UPnP device structure.
Definition device.h:122
Find a device from the control point by the exact type of the device. This function searches for devices, whose complete type string matches the given string, including version number. For example: "urn:schemas-upnp-org:device:FooDevice:1". If you need to disregard the version, use mupnp_controlpoint_getdevicebytype
- Parameters
-
| ctrlPoint | Controlpoint in question |
| exacttype | Type of the device |
Find a device by type, ignoring version number.
Searches the control point's device list for a device whose type matches the given string, excluding the version suffix. This allows matching devices regardless of their version number.
The search includes embedded devices (child devices within root devices).
- Parameters
-
| ctrlPoint | The control point to search. Must not be NULL. |
| type | The device type to match, without version. Must not be NULL. Format: "urn:schemas-upnp-org:device:<deviceType>" Example: "urn:schemas-upnp-org:device:MediaServer" This will match "...MediaServer:1", "...MediaServer:2", etc. |
- Returns
- Pointer to the first matching device, or NULL if not found or if parameters are NULL.
- Note
- Thread-safe: The control point should be locked with mupnp_controlpoint_lock() before calling this function.
-
To get the actual version of the matched device, use mupnp_devicetype_getversion() on the device's type string.
-
If multiple devices of different versions match, the first one found is returned (no specific ordering guaranteed).
- See also
- mupnp_controlpoint_getdevicebyexacttype()
-
mupnp_devicetype_getversion()
-
mupnp_controlpoint_lock()
Find a device from the controlpoint by the type of the device. This function searches for devices, whose type part (i.e. not including the version) of the device type string matches the given string. For example: "urn:schemas-upnp-org:device:FooDevice". If you need to know the version of a device, use mupnp_devicetype_getversion
- Parameters
-
| ctrlPoint | Controlpoint in question |
| type | Type of the device |
Find a device by its Unique Device Name (UDN)
Searches the control point's device list for a device with the specified UDN. The UDN uniquely identifies a device instance, even if multiple devices of the same type exist on the network.
The search includes embedded devices (child devices within root devices).
- Parameters
-
| ctrlPoint | The control point to search. Must not be NULL. |
| udn | The Unique Device Name to search for. Must not be NULL. Format: "uuid:<device-UUID>" Example: "uuid:12345678-1234-1234-1234-123456789abc" |
- Returns
- Pointer to the matching device, or NULL if not found or if parameters are NULL.
- Note
- Thread-safe: The control point should be locked with mupnp_controlpoint_lock() before calling this function.
-
UDNs are unique per device instance, so at most one device will match.
-
The UDN persists across device restarts if properly implemented by the device manufacturer.
- See also
- mupnp_controlpoint_getdevicebytype()
-
mupnp_device_getudn()
-
mupnp_controlpoint_lock()
Find a device from the controlpoint by the UDN of the device.
- Parameters
-
| ctrlPoint | Controlpoint in question |
| udn | Type of the device |
Send an M-SEARCH multicast message to discover UPnP devices.
Broadcasts an SSDP M-SEARCH request on all network interfaces to discover UPnP devices matching the specified search target. Devices that match will respond with unicast M-SEARCH responses, which are processed asynchronously.
The control point must be started (mupnp_controlpoint_start()) before calling this function. Discovered devices trigger the device listener callback if set.
Common search targets:
- "ssdp:all" - All devices and services
- "upnp:rootdevice" - Root devices only
- "urn:schemas-upnp-org:device:<deviceType>:<version>" - Specific device type
- "urn:schemas-upnp-org:service:<serviceType>:<version>" - Specific service type
- "uuid:<device-UUID>" - Specific device by UUID
The MX (Maximum Wait) header determines how long devices should wait before responding (default: 3 seconds). Set with mupnp_controlpoint_setssdpsearchmx().
- Parameters
-
| ctrlPoint | The control point to use. Must not be NULL and must be running. |
| target | The Search Target (ST) string. Must not be NULL or empty. See UPnP Device Architecture specification for valid values. |
- Return values
-
| true | M-SEARCH successfully sent on at least one interface |
| false | Failed to send (ctrlPoint is NULL, not running, or network error) |
- Note
- Thread-safe: Can be called from any thread.
-
Devices may take up to MX seconds to respond. Responses are handled asynchronously via the device listener callback.
-
Multiple M-SEARCH requests can be sent without waiting for responses.
-
Not all devices respond to M-SEARCH; some only advertise via periodic ssdp:alive messages.
- See also
- mupnp_controlpoint_setdevicelistener()
-
mupnp_controlpoint_setssdpsearchmx()
-
mupnp_controlpoint_start()
printf("M-SEARCH sent, waiting for responses...\n");
sleep(5);
}
Do an M-SEARCH to look for devices in the network.
- Parameters
-
| ctrlPoint | The control point in question |
| target | The Search Target parameter (ex. "ssdp:all") |
Activate the control point and start network listeners.
Starts all network services required for UPnP operation:
- SSDP multicast listeners on all network interfaces
- SSDP unicast response servers (default port: 39400)
- HTTP event notification servers (default port: 39500)
- Device expiration monitoring thread
After successful activation, the control point will:
- Receive and process SSDP advertisements (ssdp:alive, ssdp:byebye)
- Respond to M-SEARCH requests if configured
- Accept event subscriptions and notifications
- Automatically remove expired devices
The control point must be started before performing any network operations such as device discovery or action invocations.
- Parameters
-
| ctrlPoint | The control point to activate. Must not be NULL. |
- Return values
-
| true | Successfully started all services |
| false | Failed to start (e.g., port already in use, network error, insufficient permissions, or ctrlPoint is NULL) |
- Note
- This function may fail if the required ports are already in use. Use mupnp_controlpoint_setssdpresponseport() and mupnp_controlpoint_seteventport() to configure alternative ports before calling start if needed.
-
Thread-safe: Can be called from any thread, but must not be called concurrently on the same control point.
-
Calling this function on an already-running control point has no effect and returns true.
- Warning
- On some platforms, binding to multicast addresses may require elevated privileges (e.g., root/administrator).
- See also
- mupnp_controlpoint_stop()
-
mupnp_controlpoint_isrunning()
-
mupnp_controlpoint_search()
Activate the control point. Starts listening for SSDP messages etc. You must call this function before you can actually use a control point.
- Parameters
-
| ctrlPoint | The control point to start |
- Returns
- true if successful; otherwise false
Stop the control point and shut down network listeners.
Gracefully shuts down all network services:
- Closes all SSDP multicast listeners
- Closes SSDP unicast response servers
- Closes HTTP event notification servers
- Terminates the device expiration monitoring thread
After stopping, the control point will no longer:
- Receive SSDP advertisements or M-SEARCH requests
- Accept event notifications
- Monitor device expirations
However, the device list is retained and can be accessed after stopping. The control point can be restarted with mupnp_controlpoint_start().
- Parameters
-
| ctrlPoint | The control point to stop. Must not be NULL. |
- Return values
-
| true | Successfully stopped all services |
| false | Failed to stop (unlikely), or ctrlPoint is NULL |
- Note
- This function blocks until all listener threads have terminated. This may take up to a few seconds.
-
Calling this function on an already-stopped control point has no effect and returns true.
-
Thread-safe: Can be called from any thread, but must not be called concurrently on the same control point.
-
Active event subscriptions are not automatically cancelled. The application should explicitly unsubscribe before stopping if cleanup is required.
- See also
- mupnp_controlpoint_start()
-
mupnp_controlpoint_isrunning()
-
mupnp_controlpoint_delete()
Stop the control point. Stops sending/receiveing/responding to any messages.
- Parameters
-
| ctrlPoint | The control point to stop |
- Returns
- true if successful; otherwise false
Subscribe to a UPnP service's event notifications.
Sends a SUBSCRIBE request to the service's event subscription URL to receive notifications when the service's state variables change. The service will send an initial event message with current values, followed by updates whenever evented state variables change.
The subscription is identified by a Subscription ID (SID) returned by the service and stored in the service object. Event notifications are received on the control point's HTTP event server and dispatched to registered event listeners.
Subscriptions must be renewed before they expire using mupnp_controlpoint_resubscribe() or they will be automatically cancelled by the service.
- Parameters
-
| ctrlPoint | The control point to use. Must not be NULL and must be running. |
| service | The service to subscribe to. Must not be NULL and must have a valid event subscription URL. |
| timeout | The requested subscription duration in seconds. Use 0 or negative value for infinite duration (if supported by the service). Typical values: 300-1800 seconds. The service may grant a different duration than requested. |
- Return values
-
| true | Subscription successful. Check service's SID for subscription ID. |
| false | Subscription failed due to:
- NULL parameters
- Control point not running
- Network error
- Service doesn't support eventing
- Service rejected subscription (e.g., too many subscribers)
|
- Note
- Thread-safe: Can be called from any thread, but the control point should be locked if accessing device/service pointers.
-
Side effect: Updates the service's subscriptionSid and subscriptionTimeout fields on success.
-
Event notifications are delivered asynchronously via event listener callbacks. Set listeners with mupnp_controlpoint_addeventlistener().
-
The initial event notification (containing all evented state variables) should arrive shortly after subscription.
- Warning
- Always unsubscribe before destroying the control point to avoid orphaned subscriptions on the service side.
- See also
- mupnp_controlpoint_resubscribe()
-
mupnp_controlpoint_unsubscribe()
-
mupnp_controlpoint_addeventlistener()
-
mupnp_service_getsubscriptionsid()
if (dev) {
if (service) {
printf("Subscribed with SID: %s\n",
}
}
}
mUpnpDevice * mupnp_controlpoint_getdevicebytype(mUpnpControlPoint *ctrlPoint, const char *type)
Find a device by type, ignoring version number.
Definition controlpoint.c:438
bool mupnp_controlpoint_subscribe(mUpnpControlPoint *ctrlPoint, mUpnpService *service, long timeout)
Subscribe to a UPnP service's event notifications.
Definition controlpoint_event.c:241
mUpnpService * mupnp_device_getservicebytype(mUpnpDevice *dev, const char *type)
Definition device.c:1621
#define mupnp_service_getsubscriptionsid(service)
Definition service.h:710