Select Git revision
smsq.c 24.59 KiB
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2004 - 2005
*
* SMS queuing application for use with asterisk app_sms
* by Adrian Kennard
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*** MODULEINFO
<support_level>extended</support_level>
***/
#include "asterisk.h"
#include <popt.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
#include <ctype.h>
#include <time.h>
#if !defined(POPT_ARGFLAG_SHOW_DEFAULT)
#define POPT_ARGFLAG_SHOW_DEFAULT 0x00800000
#endif
/*!
* \brief reads next USC character from null terminated UTF-8 string and advanced pointer
* for non valid UTF-8 sequences.
* \return character as is Does \b NOT advance pointer for null termination
*/
static int utf8decode (unsigned char **pp)
{
unsigned char *p = *pp;
if (!*p)
return 0; /* null termination of string */
(*pp)++;
if (*p < 0xC0)
return *p; /* ascii or continuation character */
if (*p < 0xE0)
{
if (*p < 0xC2 || (p[1] & 0xC0) != 0x80)
return *p; /* not valid UTF-8 */
(*pp)++;
return ((*p & 0x1F) << 6) + (p[1] & 0x3F);
}
if (*p < 0xF0)
{
if ((*p == 0xE0 && p[1] < 0xA0) || (p[1] & 0xC0) != 0x80 || (p[2] & 0xC0) != 0x80)
return *p; /* not valid UTF-8 */
(*pp) += 2;
return ((*p & 0x0F) << 12) + ((p[1] & 0x3F) << 6) + (p[2] & 0x3F);
}
if (*p < 0xF8)
{
if ((*p == 0xF0 && p[1] < 0x90) || (p[1] & 0xC0) != 0x80 || (p[2] & 0xC0) != 0x80 || (p[3] & 0xC0) != 0x80)
return *p; /* not valid UTF-8 */
(*pp) += 3;
return ((*p & 0x07) << 18) + ((p[1] & 0x3F) << 12) + ((p[2] & 0x3F) << 6) + (p[3] & 0x3F);