61 | | LOG("Policy Engine:: Waiting for Policy Check Request.\n"); |
62 | | |
63 | | int32_t decision_array[10]; |
64 | | struct Parameter pList[10]; |
65 | | struct CE_Info ce_info; |
66 | | |
67 | | // TODO should this be a GetRequest call or something else? |
68 | | if(GetRequest(commandSocketFD, pList, &ce_info)) { |
69 | | LOG("Policy Engine:: Validating Transmission Parameters.\n"); |
70 | | ValidateParameters(pList, &ce_info, decision_array); |
71 | | |
72 | | LOG("Policy Engine:: Sending Policy decision to Server.\n"); |
73 | | SendPEDecision(pList, &ce_info, decision_array); |
| 77 | char buffer[256]; |
| 78 | |
| 79 | while(true) { |
| 80 | memset(buffer, 0, 256); |
| 81 | |
| 82 | ReadMessage(commandSocketFD, buffer); |
| 83 | |
| 84 | // TODO this is ugly... is there a better way? Doesn't strcmp compare the |
| 85 | // whole string? We only need to compare until we find a single different |
| 86 | // byte... |
| 87 | if(strcmp(buffer, "validate_parameters") == 0) { |
| 88 | ValidateParameters(); |
| 89 | } |
| 90 | else if(strcmp(buffer, "query_component_type") == 0) { |
| 91 | SendComponentType(); |
| 92 | } |
| 93 | else if(strcmp(buffer, "connect_sml") == 0) { |
| 94 | /* This command implies that we are disconnecting from the shell and |
| 95 | * connecting to a SML component. */ |
| 96 | char serverName[256]; |
| 97 | char serverPort[256]; |
| 98 | // TODO is this going to end up being too slow? |
| 99 | memset(serverName, 0, 256); |
| 100 | memset(serverPort, 0, 256); |
| 101 | |
| 102 | ReadMessage(commandSocketFD, serverName); |
| 103 | ReadMessage(commandSocketFD, serverPort); |
| 104 | |
| 105 | /* Only continue if we are currently connected to a shell. */ |
| 106 | if(!SML_present) { |
| 107 | DeregisterComponent(); |
| 108 | |
| 109 | shutdown(commandSocketFD, 2); |
| 110 | close(commandSocketFD); |
| 111 | |
| 112 | SML_present = true; |
| 113 | |
| 114 | ConnectToRemoteComponent(serverName, serverPort); |
| 115 | } |
| 116 | } |
| 117 | else if(strcmp(buffer, "disconnect_sml") == 0) { |
| 118 | /* This command implies that we are disconnecting from the SML and |
| 119 | * connecting to a shell component. */ |
| 120 | char serverName[256]; |
| 121 | char serverPort[256]; |
| 122 | // TODO is this going to end up being too slow? |
| 123 | memset(serverName, 0, 256); |
| 124 | memset(serverPort, 0, 256); |
| 125 | |
| 126 | ReadMessage(commandSocketFD, serverName); |
| 127 | ReadMessage(commandSocketFD, serverPort); |
| 128 | |
| 129 | /* We only want to do this if we are actually connected to an SML |
| 130 | * currently. */ |
| 131 | if(SML_present) { |
| 132 | DeregisterServices(); |
| 133 | |
| 134 | shutdown(commandSocketFD, 2); |
| 135 | close(commandSocketFD); |
| 136 | |
| 137 | SML_present = false; |
| 138 | |
| 139 | ConnectToRemoteComponent(serverName, serverPort); |
| 140 | } |
| 141 | } |
| 142 | else if(strcmp(buffer, "relead_engine_configs") == 0) { |
| 143 | ReloadPolicies(); |
| 144 | } |
| 145 | else if(strcmp(buffer, "reset_engine_policy") == 0) { |
| 146 | Reset(); |
| 147 | } |
| 148 | else if(strcmp(buffer, "shutdown_engine_policy") == 0) { |
| 149 | Shutdown(); |
| 150 | } |
165 | | PolicyEngine::ValidateParameters(struct Parameter pList[], \ |
166 | | struct CE_Info *ce_info, int decision_array[]) |
167 | | { |
168 | | LOG("Policy Engine:: Policies Validated.\n"); |
169 | | for (size_t i = 0; i < ce_info->numParameters; i++) |
170 | | decision_array[i] = 1; |
171 | | } |
172 | | |
| 244 | PolicyEngine::ValidateParameters() |
| 245 | { |
| 246 | LOG("Policy Engine:: Preparing to receive parameters for validation....\n"); |
| 247 | |
| 248 | int32_t decision_array[10]; |
| 249 | struct Parameter pList[10]; |
| 250 | struct CE_Info ce_info; |
| 251 | |
| 252 | if(GetRequest(commandSocketFD, pList, &ce_info)) { |
| 253 | LOG("Policy Engine:: Validating Transmission Parameters.\n"); |
| 254 | for (size_t i = 0; i < ce_info.numParameters; i++) |
| 255 | decision_array[i] = 1; |
| 256 | |
| 257 | LOG("Policy Engine:: Sending Policy decision to Server.\n"); |
| 258 | SendPEDecision(pList, &ce_info, decision_array); |
| 259 | |
| 260 | LOG("Policy Engine:: Policies Validated.\n"); |
| 261 | } |
| 262 | else |
| 263 | ERROR(1, "Call to GetRequest in ValidateParameters failed.\n"); |
| 264 | |
| 265 | } |
| 266 | |