instructions.h (3394B)
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#ifndef GUACLOG_INSTRUCTIONS_H 21#define GUACLOG_INSTRUCTIONS_H 22 23#include "config.h" 24#include "state.h" 25 26/** 27 * A callback function which, when invoked, handles a particular Guacamole 28 * instruction. The opcode of the instruction is implied (as it is expected 29 * that there will be a 1:1 mapping of opcode to callback function), while the 30 * arguments for that instruction are included in the parameters given to the 31 * callback. 32 * 33 * @param state 34 * The current state of the Guacamole input log interpreter. 35 * 36 * @param argc 37 * The number of arguments (excluding opcode) passed to the instruction 38 * being handled by the callback. 39 * 40 * @param argv 41 * All arguments (excluding opcode) associated with the instruction being 42 * handled by the callback. 43 * 44 * @return 45 * Zero if the instruction was handled successfully, non-zero if an error 46 * occurs. 47 */ 48typedef int guaclog_instruction_handler(guaclog_state* state, 49 int argc, char** argv); 50 51/** 52 * Mapping of instruction opcode to corresponding handler function. 53 */ 54typedef struct guaclog_instruction_handler_mapping { 55 56 /** 57 * The opcode of the instruction that the associated handler function 58 * should be invoked for. 59 */ 60 const char* opcode; 61 62 /** 63 * The handler function to invoke whenever an instruction having the 64 * associated opcode is parsed. 65 */ 66 guaclog_instruction_handler* handler; 67 68} guaclog_instruction_handler_mapping; 69 70/** 71 * Array of all opcode/handler mappings for all supported opcodes, terminated 72 * by an entry with a NULL opcode. All opcodes not listed here can be safely 73 * ignored. 74 */ 75extern guaclog_instruction_handler_mapping guaclog_instruction_handler_map[]; 76 77/** 78 * Handles the instruction having the given opcode and arguments, updating 79 * the state of the interpreter accordingly. 80 * 81 * @param state 82 * The current state of the Guacamole input log interpreter. 83 * 84 * @param opcode 85 * The opcode of the instruction being handled. 86 * 87 * @param argc 88 * The number of arguments (excluding opcode) passed to the instruction 89 * being handled by the callback. 90 * 91 * @param argv 92 * All arguments (excluding opcode) associated with the instruction being 93 * handled by the callback. 94 * 95 * @return 96 * Zero if the instruction was handled successfully, non-zero if an error 97 * occurs. 98 */ 99int guaclog_handle_instruction(guaclog_state* state, 100 const char* opcode, int argc, char** argv); 101 102/** 103 * Handler for the Guacamole "key" instruction. 104 */ 105guaclog_instruction_handler guaclog_handle_key; 106 107#endif 108