AirPlay: no realloc, safe TCB cleanup, tools convergence

This commit is contained in:
Philippe G
2021-12-17 10:54:25 -08:00
parent a266c07114
commit 3b6299dc1a
14 changed files with 144 additions and 59 deletions

View File

@@ -1,5 +1,5 @@
idf_component_register(SRCS operator.cpp utf8.c
REQUIRES esp_common pthread
idf_component_register(SRCS operator.cpp tools.c
REQUIRES esp_common pthread
INCLUDE_DIRS .
)

View File

@@ -1,17 +1,31 @@
/*
* (c) Philippe G. 20201, philippe_44@outlook.com
* see other copyrights below
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>
#include "tools.h"
#include "esp_log.h"
const static char TAG[] = "tools";
/****************************************************************************************
* UTF-8 tools
*/
// Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
// See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
// Copyright (c) 2017 ZephRay <zephray@outlook.com>
//
// utf8to1252 - almost equivalent to iconv -f utf-8 -t windows-1252, but better
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "esp_log.h"
#define TAG "aa"
#define UTF8_ACCEPT 0
#define UTF8_REJECT 1
@@ -90,4 +104,27 @@ void utf8_decode(char *src) {
}
*dst = '\0';
}
}
/****************************************************************************************
* URL tools
*/
static inline char from_hex(char ch) {
return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10;
}
void url_decode(char *url) {
char *p, *src = strdup(url);
for (p = src; *src; url++) {
*url = *src++;
if (*url == '%') {
*url = from_hex(*src++) << 4;
*url |= from_hex(*src++);
} else if (*url == '+') {
*url = ' ';
}
}
*url = '\0';
free(p);
}

View File

@@ -10,4 +10,13 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
void utf8_decode(char *src);
void url_decode(char *url);
#ifdef __cplusplus
}
#endif