2018-02-23 00:56:05 +00:00
|
|
|
/*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "ttymode.h"
|
|
|
|
|
2018-03-08 14:32:19 +00:00
|
|
|
#include <stdarg.h>
|
2018-02-25 13:41:14 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2018-03-08 14:32:19 +00:00
|
|
|
int guac_ssh_ttymodes_init(char opcode_array[], const int array_size,
|
|
|
|
const int num_opcodes, ...) {
|
2018-02-25 13:41:14 +00:00
|
|
|
|
2018-03-08 14:32:19 +00:00
|
|
|
/* Initialize the variable argument list. */
|
|
|
|
va_list args;
|
|
|
|
va_start(args, num_opcodes);
|
2018-02-27 20:49:57 +00:00
|
|
|
|
2018-03-08 14:32:19 +00:00
|
|
|
/* Check to make sure the array has enough space.
|
|
|
|
We need one extra byte at the end for the ending opcode. */
|
|
|
|
if ((num_opcodes * GUAC_SSH_TTY_OPCODE_SIZE) >= (array_size))
|
|
|
|
return 1;
|
2018-02-25 13:41:14 +00:00
|
|
|
|
2018-03-24 19:50:11 +00:00
|
|
|
char *current = opcode_array;
|
2018-03-08 14:32:19 +00:00
|
|
|
for (int i = 0; i < num_opcodes; i++) {
|
2018-02-25 13:41:14 +00:00
|
|
|
|
2018-03-08 14:32:19 +00:00
|
|
|
/* Get the next argument to this function */
|
2018-03-24 19:50:11 +00:00
|
|
|
guac_ssh_ttymode* ttymode = va_arg(args, guac_ssh_ttymode*);
|
2018-02-25 13:41:14 +00:00
|
|
|
|
2018-03-08 14:32:19 +00:00
|
|
|
/* Place opcode and value in array */
|
2018-03-24 19:50:11 +00:00
|
|
|
*(current++) = ttymode->opcode;
|
|
|
|
*(current++) = (ttymode->value >> 24) & 0xFF;
|
|
|
|
*(current++) = (ttymode->value >> 16) & 0xFF;
|
|
|
|
*(current++) = (ttymode->value >> 8) & 0xFF;
|
|
|
|
*(current++) = ttymode->value & 0xFF;
|
2018-03-08 14:32:19 +00:00
|
|
|
}
|
2018-02-27 14:13:01 +00:00
|
|
|
|
2018-03-08 14:32:19 +00:00
|
|
|
/* Put the end opcode in the last opcode space */
|
2018-03-24 19:50:11 +00:00
|
|
|
*(current) = GUAC_SSH_TTY_OP_END;
|
2018-02-25 13:41:14 +00:00
|
|
|
|
2018-03-08 14:32:19 +00:00
|
|
|
return 0;
|
2018-02-25 13:41:14 +00:00
|
|
|
|
|
|
|
}
|