instructions.c (1975B)
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20#include "config.h" 21#include "state.h" 22#include "instructions.h" 23#include "log.h" 24 25#include <string.h> 26 27guaclog_instruction_handler_mapping guaclog_instruction_handler_map[] = { 28 {"key", guaclog_handle_key}, 29 {NULL, NULL} 30}; 31 32int guaclog_handle_instruction(guaclog_state* state, const char* opcode, 33 int argc, char** argv) { 34 35 /* Search through mapping for instruction handler having given opcode */ 36 guaclog_instruction_handler_mapping* current = guaclog_instruction_handler_map; 37 while (current->opcode != NULL) { 38 39 /* Invoke handler if opcode matches (if defined) */ 40 if (strcmp(current->opcode, opcode) == 0) { 41 42 /* Invoke defined handler */ 43 guaclog_instruction_handler* handler = current->handler; 44 if (handler != NULL) 45 return handler(state, argc, argv); 46 47 /* Log defined but unimplemented instructions */ 48 guaclog_log(GUAC_LOG_DEBUG, "\"%s\" not implemented", opcode); 49 return 0; 50 51 } 52 53 /* Next candidate handler */ 54 current++; 55 56 } /* end opcode search */ 57 58 /* Ignore any unknown instructions */ 59 return 0; 60 61} 62