/src/pupnp/upnp/src/gena/gena_callback2.c
Line | Count | Source |
1 | | /******************************************************************************* |
2 | | * |
3 | | * Copyright (c) 2000-2003 Intel Corporation |
4 | | * All rights reserved. |
5 | | * |
6 | | * Redistribution and use in source and binary forms, with or without |
7 | | * modification, are permitted provided that the following conditions are met: |
8 | | * |
9 | | * - Redistributions of source code must retain the above copyright notice, |
10 | | * this list of conditions and the following disclaimer. |
11 | | * - Redistributions in binary form must reproduce the above copyright notice, |
12 | | * this list of conditions and the following disclaimer in the documentation |
13 | | * and/or other materials provided with the distribution. |
14 | | * - Neither name of Intel Corporation nor the names of its contributors |
15 | | * may be used to endorse or promote products derived from this software |
16 | | * without specific prior written permission. |
17 | | * |
18 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 | | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 | | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 | | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR |
22 | | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
23 | | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
24 | | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
25 | | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
26 | | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
27 | | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
28 | | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | | * |
30 | | ******************************************************************************/ |
31 | | |
32 | | #include "config.h" |
33 | | #include "sock.h" |
34 | | #include "upnpdebug.h" |
35 | | #if EXCLUDE_GENA == 0 |
36 | | #include "gena.h" |
37 | | #include "gena_ctrlpt.h" |
38 | | #include "gena_device.h" |
39 | | |
40 | | #include "httpparser.h" |
41 | | #include "httpreadwrite.h" |
42 | | #include "statcodes.h" |
43 | | #include "upnpdebug_internal.h" |
44 | | |
45 | | /************************************************************************ |
46 | | * Function : error_respond |
47 | | * |
48 | | * Parameters: |
49 | | * IN SOCKINFO *info: Structure containing information about the socket |
50 | | * IN int error_code: error code that will be in the GENA response |
51 | | * IN http_message_t* hmsg: GENA request Packet |
52 | | * |
53 | | * Description: |
54 | | * This function send an error message to the control point in the case |
55 | | * incorrect GENA requests. |
56 | | * |
57 | | * Returns: int |
58 | | * UPNP_E_SUCCESS if successful else appropriate error |
59 | | ***************************************************************************/ |
60 | | void error_respond(SOCKINFO *info, int error_code, http_message_t *hmsg) |
61 | 3.26k | { |
62 | 3.26k | int major, minor; |
63 | | |
64 | | /* retrieve the minor and major version from the GENA request */ |
65 | 3.26k | http_CalcResponseVersion( |
66 | 3.26k | hmsg->major_version, hmsg->minor_version, &major, &minor); |
67 | | |
68 | 3.26k | http_SendStatusResponse(info, error_code, major, minor); |
69 | 3.26k | } |
70 | | |
71 | | /************************************************************************ |
72 | | * Function : genaCallback |
73 | | * |
74 | | * Parameters: |
75 | | * IN http_parser_t *parser: represents the parse state of the request |
76 | | * IN http_message_t* request: HTTP message containing GENA request |
77 | | * INOUT SOCKINFO *info: Structure containing information about the socket |
78 | | * |
79 | | * Description: |
80 | | * This is the callback function called by the miniserver to handle |
81 | | * incoming GENA requests. |
82 | | * |
83 | | * Returns: int |
84 | | * UPNP_E_SUCCESS if successful else appropriate error |
85 | | ***************************************************************************/ |
86 | | void genaCallback( |
87 | | http_parser_t *parser, http_message_t *request, SOCKINFO *info) |
88 | 3.26k | { |
89 | 3.26k | int found_function = 0; |
90 | 3.26k | (void)parser; |
91 | | |
92 | 3.26k | if (request->method == HTTPMETHOD_SUBSCRIBE) { |
93 | 63 | #ifdef INCLUDE_DEVICE_APIS |
94 | 63 | found_function = 1; |
95 | 63 | if (httpmsg_find_hdr(request, HDR_NT, NULL) == NULL) { |
96 | | /* renew subscription */ |
97 | 25 | gena_process_subscription_renewal_request( |
98 | 25 | info, request); |
99 | 38 | } else { |
100 | | /* subscribe */ |
101 | 38 | gena_process_subscription_request(info, request); |
102 | 38 | } |
103 | 63 | UpnpPrintf(UPNP_ALL, |
104 | 63 | GENA, |
105 | 63 | __FILE__, |
106 | 63 | __LINE__, |
107 | 63 | "got subscription request\n"); |
108 | 3.20k | } else if (request->method == HTTPMETHOD_UNSUBSCRIBE) { |
109 | 24 | found_function = 1; |
110 | | /* unsubscribe */ |
111 | 24 | gena_process_unsubscribe_request(info, request); |
112 | 24 | #endif |
113 | 3.18k | } else if (request->method == HTTPMETHOD_NOTIFY) { |
114 | 3.18k | #ifdef INCLUDE_CLIENT_APIS |
115 | 3.18k | found_function = 1; |
116 | | /* notify */ |
117 | 3.18k | gena_process_notification_event(info, request); |
118 | 3.18k | #endif |
119 | 3.18k | } |
120 | | |
121 | 3.26k | if (!found_function) { |
122 | | /* handle missing functions of device or ctrl pt */ |
123 | 0 | error_respond(info, HTTP_NOT_IMPLEMENTED, request); |
124 | 0 | } |
125 | 3.26k | return; |
126 | 3.26k | } |
127 | | #endif /* EXCLUDE_GENA */ |