]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/smux/handlers.cpp
Tariff users table index fixed
[stg.git] / projects / stargazer / plugins / other / smux / handlers.cpp
1 #include "stg/GetRequest-PDU.h"
2 #include "stg/GetResponse-PDU.h"
3 #include "stg/VarBindList.h"
4 #include "stg/VarBind.h"
5
6 #include "stg/common.h"
7
8 #include "utils.h"
9 #include "smux.h"
10
11 bool SMUX::CloseHandler(const SMUX_PDUs_t * pdus)
12 {
13 printfd(__FILE__, "SMUX::CloseHandler()\n");
14 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
15 return false;
16 }
17
18 bool SMUX::RegisterResponseHandler(const SMUX_PDUs_t * pdus)
19 {
20 printfd(__FILE__, "SMUX::RegisterResponseHandler()\n");
21 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
22 return false;
23 }
24
25 bool SMUX::PDUsRequestHandler(const SMUX_PDUs_t * pdus)
26 {
27 printfd(__FILE__, "SMUX::PDUsRequestHandler()\n");
28 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
29 PDUsHandlers::iterator it;
30 it = pdusHandlers.find(pdus->choice.pdus.present);
31 if (it != pdusHandlers.end())
32     {
33     return (this->*(it->second))(&pdus->choice.pdus);
34     }
35 else
36     {
37     switch (pdus->present)
38         {
39         case PDUs_PR_NOTHING:
40             printfd(__FILE__, "SMUX::PDUsRequestHandler() - nothing\n");
41             break;
42         case PDUs_PR_get_response:
43             printfd(__FILE__, "SMUX::PDUsRequestHandler() - get response\n");
44             break;
45         case PDUs_PR_trap:
46             printfd(__FILE__, "SMUX::PDUsRequestHandler() - trap\n");
47             break;
48         default:
49             printfd(__FILE__, "SMUX::PDUsRequestHandler() - undefined\n");
50         }
51     }
52 return false;
53 }
54
55 bool SMUX::CommitOrRollbackHandler(const SMUX_PDUs_t * pdus)
56 {
57 printfd(__FILE__, "SMUX::CommitOrRollbackHandler()\n");
58 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
59 return false;
60 }
61
62 bool SMUX::GetRequestHandler(const PDUs_t * pdus)
63 {
64 printfd(__FILE__, "SMUX::GetRequestHandler()\n");
65 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
66 const GetRequest_PDU_t * getRequest = &pdus->choice.get_request;
67 GetResponse_PDU_t msg;
68 VarBindList_t * varBindList = &msg.variable_bindings;
69 memset(&msg, 0, sizeof(msg));
70
71 msg.request_id = getRequest->request_id;
72 asn_long2INTEGER(&msg.error_status, 0);
73 asn_long2INTEGER(&msg.error_index, 0);
74
75 const VarBindList_t * vbl = &getRequest->variable_bindings; 
76 for (int i = 0; i < vbl->list.count; ++i)
77     {
78     VarBind_t * vb = getRequest->variable_bindings.list.array[i];
79     Sensors::iterator it;
80     it = sensors.find(OID(&vb->name));
81     if (it == sensors.end())
82         {
83         SendGetResponseErrorPDU(sock, getRequest,
84                                 PDU__error_status_noSuchName, i);
85         return true;
86         }
87
88     VarBind_t newVb;
89     memset(&newVb, 0, sizeof(newVb));
90
91     newVb.name = vb->name;
92     it->second->GetValue(&newVb.value);
93
94     ASN_SEQUENCE_ADD(varBindList, &newVb);
95     }
96
97 SendGetResponsePDU(sock, &msg);
98 asn_fprint(stderr, &asn_DEF_PDU, &msg);
99 return false;
100 }
101
102 bool SMUX::GetNextRequestHandler(const PDUs_t * pdus)
103 {
104 printfd(__FILE__, "SMUX::GetNextRequestHandler()\n");
105 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
106 const GetRequest_PDU_t * getRequest = &pdus->choice.get_request;
107 GetResponse_PDU_t msg;
108 VarBindList_t * varBindList = &msg.variable_bindings;
109 memset(&msg, 0, sizeof(msg));
110
111 msg.request_id = getRequest->request_id;
112 asn_long2INTEGER(&msg.error_status, 0);
113 asn_long2INTEGER(&msg.error_index, 0);
114
115 const VarBindList_t * vbl = &getRequest->variable_bindings; 
116 for (int i = 0; i < vbl->list.count; ++i)
117     {
118     VarBind_t * vb = getRequest->variable_bindings.list.array[i];
119     Sensors::iterator it;
120     it = sensors.upper_bound(OID(&vb->name));
121     if (it == sensors.end())
122         {
123         SendGetResponseErrorPDU(sock, getRequest,
124                                 PDU__error_status_noSuchName, i);
125         return true;
126         }
127
128     VarBind_t newVb;
129     memset(&newVb, 0, sizeof(newVb));
130
131     newVb.name = vb->name;
132     it->second->GetValue(&newVb.value);
133
134     ASN_SEQUENCE_ADD(varBindList, &newVb);
135     }
136
137 SendGetResponsePDU(sock, &msg);
138 asn_fprint(stderr, &asn_DEF_PDU, &msg);
139 return false;
140 }
141
142 bool SMUX::SetRequestHandler(const PDUs_t * pdus)
143 {
144 printfd(__FILE__, "SMUX::SetRequestHandler()\n");
145 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
146 SendGetResponseErrorPDU(sock, &pdus->choice.set_request,
147                         PDU__error_status_readOnly, 0);
148 return false;
149 }