~vanvugt/ubuntu/oneiric/mediatomb/fix-770964-784431

« back to all changes in this revision

Viewing changes to tombupnp/upnp/src/gena/gena_callback2.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2008-02-02 01:42:48 UTC
  • Revision ID: james.westby@ubuntu.com-20080202014248-cjouolddb8gi2zkz
Tags: upstream-0.10.0.dfsg1
ImportĀ upstreamĀ versionĀ 0.10.0.dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#if EXCLUDE_GENA == 0
 
34
#include "gena.h"
 
35
#include "gena_device.h"
 
36
#include "gena_ctrlpt.h"
 
37
 
 
38
#include "httpparser.h"
 
39
#include "httpreadwrite.h"
 
40
#include "statcodes.h"
 
41
#include "unixutil.h"
 
42
 
 
43
/************************************************************************
 
44
* Function : error_respond                                                                      
 
45
*                                                                                                                                       
 
46
* Parameters:                                                                                                           
 
47
*       IN SOCKINFO *info: Structure containing information about the socket
 
48
*       IN int error_code: error code that will be in the GENA response
 
49
*       IN http_message_t* hmsg: GENA request Packet 
 
50
*
 
51
* Description:                                                                                                          
 
52
*       This function send an error message to the control point in the case
 
53
*       incorrect GENA requests.
 
54
*
 
55
* Returns: int
 
56
*       UPNP_E_SUCCESS if successful else appropriate error
 
57
***************************************************************************/
 
58
void
 
59
error_respond( IN SOCKINFO * info,
 
60
               IN int error_code,
 
61
               IN http_message_t * hmsg )
 
62
{
 
63
    int major,
 
64
      minor;
 
65
 
 
66
    // retrieve the minor and major version from the GENA request
 
67
    http_CalcResponseVersion( hmsg->major_version,
 
68
                              hmsg->minor_version, &major, &minor );
 
69
 
 
70
    http_SendStatusResponse( info, error_code, major, minor );
 
71
}
 
72
 
 
73
/************************************************************************
 
74
* Function : genaCallback                                                                       
 
75
*                                                                                                                                       
 
76
* Parameters:                                                                                                           
 
77
*       IN http_parser_t *parser: represents the parse state of the request
 
78
*       IN http_message_t* request: HTTP message containing GENA request
 
79
*       INOUT SOCKINFO *info: Structure containing information about the socket
 
80
*
 
81
* Description:                                                                                                          
 
82
*       This is the callback function called by the miniserver to handle 
 
83
*       incoming GENA requests. 
 
84
*
 
85
* Returns: int
 
86
*       UPNP_E_SUCCESS if successful else appropriate error
 
87
***************************************************************************/
 
88
void
 
89
genaCallback( IN http_parser_t * parser,
 
90
              IN http_message_t * request,
 
91
              INOUT SOCKINFO * info )
 
92
{
 
93
    xboolean found_function = FALSE;
 
94
 
 
95
    if( request->method == HTTPMETHOD_SUBSCRIBE ) {
 
96
        DEVICEONLY( found_function = TRUE;
 
97
                    if( httpmsg_find_hdr( request, HDR_NT, NULL ) == NULL )
 
98
                    {
 
99
                    // renew subscription
 
100
                    gena_process_subscription_renewal_request
 
101
                    ( info, request );}
 
102
                    else
 
103
                    {
 
104
                    // subscribe
 
105
                    gena_process_subscription_request( info, request );}
 
106
 
 
107
                    DBGONLY( UpnpPrintf
 
108
                             ( UPNP_ALL, GENA, __FILE__, __LINE__,
 
109
                               "got subscription request\n" ); )
 
110
             )
 
111
            }
 
112
            else
 
113
        if( request->method == HTTPMETHOD_UNSUBSCRIBE ) {
 
114
            DEVICEONLY( found_function = TRUE;
 
115
                        // unsubscribe
 
116
                        gena_process_unsubscribe_request( info,
 
117
                                                          request ); )
 
118
        } else if( request->method == HTTPMETHOD_NOTIFY ) {
 
119
            CLIENTONLY( found_function = TRUE;
 
120
                        // notify
 
121
                        gena_process_notification_event( info, request ); )
 
122
        }
 
123
 
 
124
        if( !found_function ) {
 
125
            // handle missing functions of device or ctrl pt
 
126
            error_respond( info, HTTP_NOT_IMPLEMENTED, request );
 
127
        }
 
128
    }
 
129
#endif // EXCLUDE_GENA