Fork of my MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:45:51 2017 +0000
Revision:
0:f1d3878b8dd9
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vpcola 0:f1d3878b8dd9 1 /*
vpcola 0:f1d3878b8dd9 2 * Copyright (c) 2014-2015 ARM Limited. All rights reserved.
vpcola 0:f1d3878b8dd9 3 * SPDX-License-Identifier: Apache-2.0
vpcola 0:f1d3878b8dd9 4 * Licensed under the Apache License, Version 2.0 (the License); you may
vpcola 0:f1d3878b8dd9 5 * not use this file except in compliance with the License.
vpcola 0:f1d3878b8dd9 6 * You may obtain a copy of the License at
vpcola 0:f1d3878b8dd9 7 *
vpcola 0:f1d3878b8dd9 8 * http://www.apache.org/licenses/LICENSE-2.0
vpcola 0:f1d3878b8dd9 9 *
vpcola 0:f1d3878b8dd9 10 * Unless required by applicable law or agreed to in writing, software
vpcola 0:f1d3878b8dd9 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
vpcola 0:f1d3878b8dd9 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
vpcola 0:f1d3878b8dd9 13 * See the License for the specific language governing permissions and
vpcola 0:f1d3878b8dd9 14 * limitations under the License.
vpcola 0:f1d3878b8dd9 15 */
vpcola 0:f1d3878b8dd9 16
vpcola 0:f1d3878b8dd9 17 #include <stdarg.h>
vpcola 0:f1d3878b8dd9 18 #include <stdint.h>
vpcola 0:f1d3878b8dd9 19 #include <stdio.h>
vpcola 0:f1d3878b8dd9 20 #include <string.h>
vpcola 0:f1d3878b8dd9 21
vpcola 0:f1d3878b8dd9 22 #include "mbed_error.h"
vpcola 0:f1d3878b8dd9 23
vpcola 0:f1d3878b8dd9 24 size_t BufferedSerialThunk(void *buf_serial, const void *s, size_t length);
vpcola 0:f1d3878b8dd9 25
vpcola 0:f1d3878b8dd9 26 int BufferedPrintfC(void *stream, int size, const char* format, va_list arg)
vpcola 0:f1d3878b8dd9 27 {
vpcola 0:f1d3878b8dd9 28 int r;
vpcola 0:f1d3878b8dd9 29 char buffer[512];
vpcola 0:f1d3878b8dd9 30 if (size >= 512) {
vpcola 0:f1d3878b8dd9 31 return -1;
vpcola 0:f1d3878b8dd9 32 }
vpcola 0:f1d3878b8dd9 33 memset(buffer, 0, size);
vpcola 0:f1d3878b8dd9 34 r = vsprintf(buffer, format, arg);
vpcola 0:f1d3878b8dd9 35 // this may not hit the heap but should alert the user anyways
vpcola 0:f1d3878b8dd9 36 if(r > (int32_t) size) {
vpcola 0:f1d3878b8dd9 37 error("%s %d buffer overwrite (max_buf_size: %d exceeded: %d)!\r\n", __FILE__, __LINE__, size, r);
vpcola 0:f1d3878b8dd9 38 return 0;
vpcola 0:f1d3878b8dd9 39 }
vpcola 0:f1d3878b8dd9 40 if ( r > 0 ) {
vpcola 0:f1d3878b8dd9 41 BufferedSerialThunk(stream, buffer, r);
vpcola 0:f1d3878b8dd9 42 }
vpcola 0:f1d3878b8dd9 43 return r;
vpcola 0:f1d3878b8dd9 44 }