Fork of my original MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:43:14 2017 +0000
Revision:
0:a1734fe1ec4b
Initial commit

Who changed what in which revision?

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