instructions.c (2542B)
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 "display.h" 22#include "instructions.h" 23#include "log.h" 24 25#include <guacamole/client.h> 26 27#include <string.h> 28 29guacenc_instruction_handler_mapping guacenc_instruction_handler_map[] = { 30 {"blob", guacenc_handle_blob}, 31 {"img", guacenc_handle_img}, 32 {"end", guacenc_handle_end}, 33 {"mouse", guacenc_handle_mouse}, 34 {"sync", guacenc_handle_sync}, 35 {"cursor", guacenc_handle_cursor}, 36 {"copy", guacenc_handle_copy}, 37 {"transfer", guacenc_handle_transfer}, 38 {"size", guacenc_handle_size}, 39 {"rect", guacenc_handle_rect}, 40 {"cfill", guacenc_handle_cfill}, 41 {"move", guacenc_handle_move}, 42 {"shade", guacenc_handle_shade}, 43 {"dispose", guacenc_handle_dispose}, 44 {NULL, NULL} 45}; 46 47int guacenc_handle_instruction(guacenc_display* display, const char* opcode, 48 int argc, char** argv) { 49 50 /* Search through mapping for instruction handler having given opcode */ 51 guacenc_instruction_handler_mapping* current = guacenc_instruction_handler_map; 52 while (current->opcode != NULL) { 53 54 /* Invoke handler if opcode matches (if defined) */ 55 if (strcmp(current->opcode, opcode) == 0) { 56 57 /* Invoke defined handler */ 58 guacenc_instruction_handler* handler = current->handler; 59 if (handler != NULL) 60 return handler(display, argc, argv); 61 62 /* Log defined but unimplemented instructions */ 63 guacenc_log(GUAC_LOG_DEBUG, "\"%s\" not implemented", opcode); 64 return 0; 65 66 } 67 68 /* Next candidate handler */ 69 current++; 70 71 } /* end opcode search */ 72 73 /* Ignore any unknown instructions */ 74 return 0; 75 76} 77