Statistics
| Branch: | Tag: | Revision:

one / src / rm / RequestManagerGroupInfo.cc @ ae53d437

History | View | Annotate | Download (3.39 KB)

1
/* -------------------------------------------------------------------------- */
2
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)             */
3
/*                                                                            */
4
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
5
/* not use this file except in compliance with the License. You may obtain    */
6
/* a copy of the License at                                                   */
7
/*                                                                            */
8
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
9
/*                                                                            */
10
/* Unless required by applicable law or agreed to in writing, software        */
11
/* distributed under the License is distributed on an "AS IS" BASIS,          */
12
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
13
/* See the License for the specific language governing permissions and        */
14
/* limitations under the License.                                             */
15
/* -------------------------------------------------------------------------- */
16

    
17
#include "RequestManager.h"
18
#include "NebulaLog.h"
19

    
20
#include "AuthManager.h"
21

    
22
/* -------------------------------------------------------------------------- */
23
/* -------------------------------------------------------------------------- */
24

    
25
void RequestManager::GroupInfo::execute(
26
    xmlrpc_c::paramList const& paramList,
27
    xmlrpc_c::value *   const  retval)
28
{
29
    string          session;
30

    
31
    Group *         group;
32
    ostringstream   oss;
33

    
34
    int             id;
35
    int             rc;
36

    
37
    const string   method_name = "GroupInfo";
38

    
39

    
40
    /*   -- RPC specific vars --  */
41
    vector<xmlrpc_c::value> arrayData;
42
    xmlrpc_c::value_array * arrayresult;
43

    
44
    NebulaLog::log("ReM",Log::DEBUG,"GroupInfo method invoked");
45

    
46
    // Get the parameters
47
    session      = xmlrpc_c::value_string(paramList.getString(0));
48
    id           = xmlrpc_c::value_int   (paramList.getInt(1));
49

    
50
    //Authenticate the user
51
    rc = GroupInfo::upool->authenticate(session);
52

    
53
    if ( rc == -1 )
54
    {
55
        goto error_authenticate;
56
    }
57

    
58
    // TODO: perform authorization with INFO ?
59

    
60
    // Get the group
61
    group = GroupInfo::gpool->get(id,true);
62

    
63
    if ( group == 0 )
64
    {
65
        goto error_get;
66
    }
67

    
68
    oss << *group;
69

    
70
    group->unlock();
71

    
72
    // All nice, return the group info to the client
73
    arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
74
    arrayData.push_back(xmlrpc_c::value_string(oss.str()));
75

    
76
    // Copy arrayresult into retval mem space
77
    arrayresult = new xmlrpc_c::value_array(arrayData);
78
    *retval = *arrayresult;
79

    
80
    delete arrayresult; // and get rid of the original
81

    
82
    return;
83

    
84
error_authenticate:
85
    oss.str(authenticate_error(method_name));
86
    goto error_common;
87

    
88
error_get:
89
    oss.str(get_error(method_name, "GROUP", id));
90
    goto error_common;
91

    
92
error_common:
93

    
94
    arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
95
    arrayData.push_back(xmlrpc_c::value_string(oss.str()));
96

    
97
    NebulaLog::log("ReM",Log::ERROR,oss);
98

    
99
    xmlrpc_c::value_array arrayresult_error(arrayData);
100

    
101
    *retval = arrayresult_error;
102

    
103
    return;
104
}
105

    
106
/* -------------------------------------------------------------------------- */
107
/* -------------------------------------------------------------------------- */