コード例 #1
0
ファイル: zend_string.c プロジェクト: SiebelsTim/php-src
void zend_interned_strings_init(TSRMLS_D)
{
	zend_string *str;

#ifndef ZTS
	zend_hash_init(&CG(interned_strings), 1024, NULL, _str_dtor, 1);
	
	CG(interned_strings).nTableMask = CG(interned_strings).nTableSize - 1;
	CG(interned_strings).arData = (Bucket*) pecalloc(CG(interned_strings).nTableSize, sizeof(Bucket), 1);
	CG(interned_strings).arHash = (zend_uint*) pecalloc(CG(interned_strings).nTableSize, sizeof(zend_uint), 1);
	memset(CG(interned_strings).arHash, INVALID_IDX, CG(interned_strings).nTableSize * sizeof(zend_uint));

	/* interned empty string */
	str = STR_ALLOC(sizeof("")-1, 1);
	str->val[0] = '\000';
	CG(empty_string) = zend_new_interned_string_int(str TSRMLS_CC);
#else
	str = STR_ALLOC(sizeof("")-1, 1);
	str->val[0] = '\000';
	STR_HASH_VAL(str);
	str->gc.u.v.flags |= IS_STR_INTERNED;
	CG(empty_string) = str;
#endif

	/* one char strings (the actual interned strings are going to be created by ext/opcache) */
	memset(CG(one_char_string), 0, sizeof(CG(one_char_string)));

	zend_new_interned_string = zend_new_interned_string_int;
	zend_interned_strings_snapshot = zend_interned_strings_snapshot_int;
	zend_interned_strings_restore = zend_interned_strings_restore_int;
}
コード例 #2
0
ファイル: dwg.c プロジェクト: FihlaTV/DWG2000-SMS-API
_bool dwg_build_msg_header_with_header(dwg_msg_des_header_t *hdr, str_t *output)
{
	int offset = 0;

	STR_ALLOC((*output), DWG_MSG_HEADER_SIZE);
	if (!output->s)
	{
		LOG(L_ERROR, "%s: No more memory trying to allocate %d bytes\n", __FUNCTION__, DWG_MSG_HEADER_SIZE);
		return FALSE;
	}

	hdr->length		= swap_bytes_32(hdr->length);
	hdr->type		= swap_bytes_16(hdr->type);
	hdr->timestamp	= swap_bytes_32(hdr->timestamp);
	hdr->flag		= swap_bytes_16(hdr->flag);
	hdr->serial		= swap_bytes_32(hdr->serial);

	ADD_MSG_OFFSET(hdr->length, offset, output->s);
	//printf("offset: %d\n", offset);
	ADD_MSG_OFFSET(hdr->MAC, offset, output->s);
	//printf("offset: %d\n", offset);
	ADD_MSG_OFFSET(hdr->timestamp, offset, output->s);
	//printf("offset: %d\n", offset);
	ADD_MSG_OFFSET(hdr->serial, offset, output->s);
	//printf("offset: %d\n", offset);
	ADD_MSG_OFFSET(hdr->type, offset, output->s);
	//printf("offset: %d\n", offset);
	ADD_MSG_OFFSET(hdr->flag, offset, output->s);
	//printf("offset: %d\n", offset);

	return TRUE;
}
コード例 #3
0
ファイル: dwg.c プロジェクト: FihlaTV/DWG2000-SMS-API
_bool dwg_build_status_response(dwg_msg_des_header_t *original_hdr, str_t *output)
{
	str_t header;
	char response	= SMS_RC_SUCCEED;

	original_hdr->length	= 1; // update length
	original_hdr->type		= DWG_TYPE_STATUS_RESPONSE;
	dwg_build_msg_header_with_header(original_hdr, &header);

	STR_ALLOC((*output), header.len + 1);
	if (!output->s)
	{
		LOG(L_ERROR, "%s: No more memory trying to allocate %d bytes\n", __FUNCTION__, header.len + 1);
		return FALSE;
	}

	output->len	= header.len + 1;

//	hexdump(header.s, header.len);

	memcpy(output->s, header.s, header.len);
	memcpy(&output->s[header.len], &response, sizeof(char));

	STR_FREE_NON_0(header);
	return TRUE;
}
コード例 #4
0
ファイル: dwg.c プロジェクト: FihlaTV/DWG2000-SMS-API
static _bool dwg_serialize_sms_req(dwg_sms_request_t *msg, str_t *output)
{
	int offset	= 0,
		size	= sizeof(dwg_sms_request_t) - sizeof(str_t) /* str_t content */ + msg->content.len;

	STR_ALLOC((*output), size);
	if (!output->s)
	{
		LOG(L_ERROR, "%s: No more memory trying to allocate %d bytes\n", __FUNCTION__, size);
		return FALSE;
	}

	ADD_MSG_OFFSET(msg->port, offset, output->s);
	ADD_MSG_OFFSET(msg->encoding, offset, output->s);
	ADD_MSG_OFFSET(msg->type, offset, output->s);
	ADD_MSG_OFFSET(msg->count_of_number, offset, output->s);
	ADD_MSG_OFFSET(msg->number, offset, output->s);
	ADD_MSG_OFFSET(msg->content_length, offset, output->s);

	memcpy(&output->s[offset], msg->content.s, msg->content.len);
	offset += msg->content.len;

	output->len	= offset;

	return TRUE;
}
コード例 #5
0
ファイル: url.c プロジェクト: SiebelsTim/php-src
/* {{{ php_url_encode
 */
PHPAPI zend_string *php_url_encode(char const *s, int len)
{
	register unsigned char c;
	unsigned char *to;
	unsigned char const *from, *end;
	zend_string *start;
	
	from = (unsigned char *)s;
	end = (unsigned char *)s + len;
	start = STR_ALLOC(3 * len, 0);
	to = (unsigned char*)start->val;

	while (from < end) {
		c = *from++;

		if (c == ' ') {
			*to++ = '+';
#ifndef CHARSET_EBCDIC
		} else if ((c < '0' && c != '-' && c != '.') ||
				   (c < 'A' && c > '9') ||
				   (c > 'Z' && c < 'a' && c != '_') ||
				   (c > 'z')) {
			to[0] = '%';
			to[1] = hexchars[c >> 4];
			to[2] = hexchars[c & 15];
			to += 3;
#else /*CHARSET_EBCDIC*/
		} else if (!isalnum(c) && strchr("_-.", c) == NULL) {
コード例 #6
0
ファイル: at_clcc.c プロジェクト: Falasifah/answering-machine
void at_clcc_query_all(at_command_t *cmd)
{
	STR_ALLOC(cmd->str_cmd, sizeof("AT+CLCC") + 3 /* \r\n\0 */);
	strcpy(cmd->str_cmd.s, "AT+CLCC\r\n");

	cmd->id		= AT_CLCC;
	cmd->type	= AT_TYPE_QUERY_ALL;
}
コード例 #7
0
void at_ddsetex_assign(str_t *value, at_command_t *cmd)
{
	STR_ALLOC(cmd->str_cmd, sizeof("AT^DDSETEX=") + value->len + 3 /* \r\n\0 */);
	snprintf(cmd->str_cmd.s, cmd->str_cmd.len, "AT^DDSETEX=%s\r\n", value->s);

	cmd->id				= AT_DDSETEX;
	cmd->type			= AT_TYPE_ASSIGN;
}
コード例 #8
0
ファイル: str.c プロジェクト: jeffpc/libjeffpc
struct str *str_vprintf(const char *fmt, va_list args)
{
	char *tmp;
	int ret;

	ret = vasprintf(&tmp, fmt, args);
	if (ret < 0)
		return ERR_PTR(-errno);
	if (ret == 0)
		return NULL;

	return STR_ALLOC(tmp);
}
コード例 #9
0
ファイル: metaphone.c プロジェクト: SiebelsTim/php-src
/* {{{ metaphone
 */
static int metaphone(unsigned char *word, int word_len, long max_phonemes, zend_string **phoned_word, int traditional)
{
	int w_idx = 0;				/* point in the phonization we're at. */
	int p_idx = 0;				/* end of the phoned phrase */
	int max_buffer_len = 0;		/* maximum length of the destination buffer */

/*-- Parameter checks --*/
	/* Negative phoneme length is meaningless */

	if (max_phonemes < 0)
		return -1;

	/* Empty/null string is meaningless */
	/* Overly paranoid */
	/* assert(word != NULL && word[0] != '\0'); */

	if (word == NULL)
		return -1;

/*-- Allocate memory for our phoned_phrase --*/
	if (max_phonemes == 0) {	/* Assume largest possible */
		max_buffer_len = word_len;
		*phoned_word = STR_ALLOC(sizeof(char) * word_len + 1, 0);
	} else {
		max_buffer_len = max_phonemes;
		*phoned_word = STR_ALLOC(sizeof(char) * max_phonemes + 1, 0);
	}


/*-- The first phoneme has to be processed specially. --*/
	/* Find our first letter */
	for (; !isalpha(Curr_Letter); w_idx++) {
		/* On the off chance we were given nothing but crap... */
		if (Curr_Letter == '\0') {
			End_Phoned_Word
				return SUCCESS;	/* For testing */
		}
	}
コード例 #10
0
ファイル: dwg.c プロジェクト: FihlaTV/DWG2000-SMS-API
dwg_msg_des_header_t dwg_deserialize_message(str_t *input, str_t *body)
{
	dwg_msg_header_t header;
	dwg_msg_des_header_t des_header;
	//int length, type, result;

/*	printf("hdr!!!\n");
	hexdump(input->s, 24);
*/
	dwg_get_msg_header(input, &header);

	memcpy(&des_header.length, header.length, sizeof(header.length));
	memcpy(&des_header.type, header.type, sizeof(header.type));
	memcpy(&des_header.serial, header.ID.serial_number, sizeof(header.ID.serial_number));
	memcpy(&des_header.MAC, header.ID.MAC, sizeof(header.ID.MAC));
	memcpy(&des_header.timestamp, header.ID.time, sizeof(header.ID.time));
	memcpy(&des_header.flag, header.flag, sizeof(header.flag));

	des_header.length	= swap_bytes_32(des_header.length);
	des_header.type		= swap_bytes_16(des_header.type);
	des_header.serial	= swap_bytes_32(des_header.serial);
	//des_header.MAC		= swap_bytes_64(des_header.MAC);
	des_header.timestamp= swap_bytes_32(des_header.timestamp);
	des_header.flag		= swap_bytes_16(des_header.flag);

//	printf("length: %d\n", des_header.length);
//	printf("type: %d\n", des_header.type);
//	printf("A\n");
	STR_ALLOC((*body), des_header.length);

	if (body->s == NULL)
	{
		LOG(L_ERROR, "%s: No more memory trying to allocate %d bytes\n", __FUNCTION__, des_header.length);
		body->s	= NULL;
		return des_header;
	}

//	printf("B\n");
	memcpy(body->s, &input->s[DWG_MSG_HEADER_SIZE], des_header.length);

//	printf("after memcpy\n");

	return des_header;
}
コード例 #11
0
ファイル: var_unserializer.c プロジェクト: SiebelsTim/php-src
static zend_string *unserialize_str(const unsigned char **p, size_t len, size_t maxlen)
{
	size_t i, j;
	zend_string *str = STR_ALLOC(len, 0);
	unsigned char *end = *(unsigned char **)p+maxlen;

	if (end < *p) {
		STR_FREE(str);
		return NULL;
	}

	for (i = 0; i < len; i++) {
		if (*p >= end) {
			STR_FREE(str);
			return NULL;
		}
		if (**p != '\\') {
			str->val[i] = (char)**p;
		} else {
			unsigned char ch = 0;

			for (j = 0; j < 2; j++) {
				(*p)++;
				if (**p >= '0' && **p <= '9') {
					ch = (ch << 4) + (**p -'0');
				} else if (**p >= 'a' && **p <= 'f') {
					ch = (ch << 4) + (**p -'a'+10);
				} else if (**p >= 'A' && **p <= 'F') {
					ch = (ch << 4) + (**p -'A'+10);
				} else {
					STR_FREE(str);
					return NULL;
				}
			}
			str->val[i] = (char)ch;
		}
		(*p)++;
	}
	str->val[i] = 0;
	str->len = i;
	return str;
}
コード例 #12
0
ファイル: dwg.c プロジェクト: FihlaTV/DWG2000-SMS-API
_bool dwg_build_ussd(str_t *content, int port, int type, str_t *output)
{
	dwg_ussd_request_t request;
	str_t body, header;
	short length_16;

	request.port	= port;
	request.type	= type;

	length_16		= swap_bytes_16(content->len);
	memcpy(request.content_length, &length_16, sizeof(request.content_length));

	str_copy(request.content, (*content));

	if (!request.content.s)
	{
		LOG(L_ERROR, "%s.%d: No more memory trying to allocate %d bytes\n", __FUNCTION__, __LINE__, content->len);
		return FALSE;
	}

	dwg_serialize_ussd_req(&request, &body);
	dwg_build_msg_header(body.len, DWG_TYPE_SEND_USSD, &header);

	STR_ALLOC((*output), (header.len + body.len));
	if (!output->s)
	{
		LOG(L_ERROR, "%s.%d: No more memory trying to allocate %d bytes\n", __FUNCTION__, __LINE__, header.len + body.len);
		return FALSE;
	}

	memcpy(output->s, header.s, header.len);
	memcpy(&output->s[header.len], body.s, body.len);

	STR_FREE_NON_0(body);
	STR_FREE_NON_0(request.content);

	return TRUE;
}
コード例 #13
0
ファイル: quot_print.c プロジェクト: SiebelsTim/php-src
PHPAPI zend_string *php_quot_print_decode(const unsigned char *str, size_t length, int replace_us_by_ws) /* {{{ */
{
	register unsigned int i;
	register unsigned const char *p1;
	register unsigned char *p2;
	register unsigned int h_nbl, l_nbl;

	size_t decoded_len, buf_size;
	zend_string *retval;

	static unsigned int hexval_tbl[256] = {
		64, 64, 64, 64, 64, 64, 64, 64, 64, 32, 16, 64, 64, 16, 64, 64,
		64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
		32, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
		 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 64, 64, 64, 64, 64, 64,
		64, 10, 11, 12, 13, 14, 15, 64, 64, 64, 64, 64, 64, 64, 64, 64,
		64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
		64, 10, 11, 12, 13, 14, 15, 64, 64, 64, 64, 64, 64, 64, 64, 64,
		64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
		64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
		64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
		64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
		64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
		64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
		64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
		64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
		64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
	};

	if (replace_us_by_ws) {
		replace_us_by_ws = '_';
	}

	i = length, p1 = str; buf_size = length;

	while (i > 1 && *p1 != '\0') {
		if (*p1 == '=') {
			buf_size -= 2;
			p1++;
			i--;
		}
		p1++;
		i--;
	}

	retval = STR_ALLOC(buf_size, 0);
	i = length; p1 = str; p2 = (unsigned char*)retval->val;
	decoded_len = 0;

	while (i > 0 && *p1 != '\0') {
		if (*p1 == '=') {
			i--, p1++;
			if (i == 0 || *p1 == '\0') {
				break;
			}
			h_nbl = hexval_tbl[*p1];
			if (h_nbl < 16) {
				/* next char should be a hexadecimal digit */
				if ((--i) == 0 || (l_nbl = hexval_tbl[*(++p1)]) >= 16) {
					efree(retval);
					return NULL;
				}
				*(p2++) = (h_nbl << 4) | l_nbl, decoded_len++;
				i--, p1++;
			} else if (h_nbl < 64) {
				/* soft line break */
				while (h_nbl == 32) {
					if (--i == 0 || (h_nbl = hexval_tbl[*(++p1)]) == 64) {
						efree(retval);
						return NULL;
					}
				}
				if (p1[0] == '\r' && i >= 2 && p1[1] == '\n') {
					i--, p1++;
				}
				i--, p1++;
			} else {
				efree(retval);
				return NULL;
			}
		} else {
			*(p2++) = (replace_us_by_ws == *p1 ? '\x20': *p1);
			i--, p1++, decoded_len++;
		}
	}

	*p2 = '\0';
	retval->len = decoded_len;
	return retval;
}
コード例 #14
0
ファイル: dwg.c プロジェクト: FihlaTV/DWG2000-SMS-API
_bool dwg_deserialize_ussd_received(str_t *msg_body, dwg_ussd_received_t *received)
{
	int offset	= 0;
	str_t ussd_content;

	received->port	= (int) msg_body->s[offset];
	offset++;

	received->status= (int) msg_body->s[offset];
	offset++;

	short aux	= 0;
	memcpy(&aux, &msg_body->s[offset], 2);
	aux	= swap_bytes_16(aux);
	offset += 2;

	if (aux < 0)
	{
		LOG(L_ERROR, "%s: error getting message length. Original length: %d, swapped length: %d. Using workaround to fix it\n", __FUNCTION__, swap_bytes_16(aux), aux);
		aux	= msg_body->len - DWG_USSD_HEADER_SIZE;

		if (aux < 0)
		{
			LOG(L_ERROR, "%s: Couldn't be able to fix message length\n", __FUNCTION__);
			return FALSE;
		}

		LOG(L_ERROR, "%s: fixed length is: %d\n", __FUNCTION__, aux);
	}

	received->encoding	= (int) msg_body->s[offset];
	offset++;

	STR_ALLOC(ussd_content, aux + 1);
	if (!ussd_content.s)
	{
		LOG(L_ERROR, "%s: No more memory trying to allocate %d bytes\n", __FUNCTION__, aux + 1);
		return FALSE;
	}

	ussd_content.len--;

	memcpy(ussd_content.s, &msg_body->s[offset], aux);
	ussd_content.s[aux] = '\0';

	received->message	= ussd_content;

	if (_is_api_2_0 && (received->encoding == DWG_ENCODING_ASCII))
	{
		LOG(L_ERROR, "%s: encoding gsm7bit not supported\n", __FUNCTION__);
//		STR_FREE(sms_content);
		return FALSE;
	}

	if (received->encoding == DWG_ENCODING_ASCII)
	{
//		STR_FREE(sms_content);
		return TRUE;
	}

	dwg_unicode2ascii(&ussd_content, &received->message);

	STR_FREE(ussd_content);
	return TRUE;
}
コード例 #15
0
ファイル: dwg.c プロジェクト: FihlaTV/DWG2000-SMS-API
_bool dwg_deserialize_sms_received(str_t *msg_body, dwg_sms_received_t *received)
{
	int offset	= 0;
	str_t sms_content;

	memset(received->number, 0, sizeof(received->number));
	memcpy(received->number, msg_body->s, sizeof(received->number));
	offset += sizeof(received->number);

	received->str_number.s	= received->number;
	received->str_number.len= strlen(received->number);

	received->type	= (int) msg_body->s[offset];
	offset++;

	received->port	= (int) msg_body->s[offset];
	offset++;

	memset(received->timestamp, 0, sizeof(received->timestamp));
	memcpy(received->timestamp, &msg_body->s[offset], sizeof(received->timestamp) - 1 /* exclude the null terminator extra space*/);
	offset += sizeof(received->timestamp) - 1;

	received->timezone	= (int) msg_body->s[offset];
	offset++;

	received->encoding	= (int) msg_body->s[offset];
	offset++;

	short aux	= 0;
	memcpy(&aux, &msg_body->s[offset], 2);
	aux	= swap_bytes_16(aux);
	offset += 2;

	if (aux < 0)
	{
		LOG(L_ERROR, "%s: error getting message length. Original length: %d, swapped length: %d. Using workaround to fix it\n", __FUNCTION__, swap_bytes_16(aux), aux);
		aux	= msg_body->len - DWG_SMS_HEADER_SIZE;

		if (aux < 0)
		{
			LOG(L_ERROR, "%s: Couldn't be able to fix message length\n", __FUNCTION__);
			return FALSE;
		}

		LOG(L_ERROR, "%s: fixed length is: %d\n", __FUNCTION__, aux);
	}

//	ascii2unicode(&ascii_number, &received->unicode_number);

	STR_ALLOC(sms_content, aux + 1);
	if (!sms_content.s)
	{
		LOG(L_ERROR, "%s: No more memory trying to allocate %d bytes\n", __FUNCTION__, aux + 1);
		return FALSE;
	}

	sms_content.len--;

	memcpy(sms_content.s, &msg_body->s[offset], aux);
	sms_content.s[aux] = '\0';

	received->message	= sms_content;

	if (_is_api_2_0 && (received->encoding == DWG_ENCODING_ASCII))
	{
		LOG(L_ERROR, "%s: encoding gsm7bit not supported\n", __FUNCTION__);
//		STR_FREE(sms_content);
		return FALSE;
	}

	if (received->encoding == DWG_ENCODING_ASCII)
	{
//		STR_FREE(sms_content);
		return TRUE;
	}

	dwg_unicode2ascii(&sms_content, &received->message);

	STR_FREE(sms_content);
	return TRUE;
}
コード例 #16
0
ファイル: str.c プロジェクト: jeffpc/libjeffpc
struct str *str_cat(size_t n, ...)
{
	size_t totallen;
	char *buf, *out;
	struct val **vals;
	size_t *len;
	va_list ap;
	size_t i;

	if (!n)
		return &empty_string;

	if (n == 1) {
		struct val *val;
		struct str *ret;

		va_start(ap, n);
		val = va_arg(ap, struct val *);
		va_end(ap);

		if (val->type == VT_STR)
			return val_cast_to_str(val);

		ret = STR_DUP(val_cstr(val));
		val_putref(val);
		return ret;
	}

	totallen = 0;
	len = alloca(sizeof(size_t) * n);
	vals = alloca(sizeof(struct val *) * n);

	va_start(ap, n);
	for (i = 0; i < n; i++) {
		struct val *val = va_arg(ap, struct val *);

		if (!val) {
			len[i] = 0;
			vals[i] = NULL;
		} else {
			len[i] = get_len(val);
			vals[i] = val;

			totallen += len[i];
		}
	}
	va_end(ap);

	buf = malloc(totallen + 1);
	ASSERT(buf);

	buf[0] = '\0';

	out = buf;

	for (i = 0; i < n; i++) {
		struct val *val = vals[i];

		if (!val)
			continue;

		strcpy(out, val_cstr(val));

		out += len[i];

		val_putref(val);
	}

	return STR_ALLOC(buf);
}
コード例 #17
0
ファイル: dwg.c プロジェクト: FihlaTV/DWG2000-SMS-API
_bool dwg_build_sms(sms_t *sms, int port, str_t *output)
{
	dwg_sms_request_t request;
	str_t body, header;
	short length_16;

	request.port			= port;
	request.encoding		= (_is_api_2_0) ? DWG_ENCODING_UNICODE : DWG_ENCODING_ASCII;
//	request.encoding		= DWG_ENCODING_GSM7BIT;
//	request.encoding		= DWG_ENCODING_UNICODE;
	request.type			= DWG_MSG_TYPE_SMS;
	request.count_of_number	= 1;

	memset(request.number, 0, sizeof(request.number));
	memcpy(request.number, sms->destination.s, sms->destination.len);

	if (request.encoding == DWG_ENCODING_ASCII)
	{
		str_t gsm7bit;

		dwg_ascii2gsm7bit(&sms->content, &gsm7bit);

		length_16	= swap_bytes_16((short) sms->content.len);
		memcpy(request.content_length, &length_16, sizeof(request.content_length));

		STR_ALLOC(request.content, sms->content.len);
		if (!request.content.s)
		{
			LOG(L_ERROR, "%s.%d: No more memory trying to allocate %d bytes\n", __FUNCTION__, __LINE__, sms->content.len);
			return FALSE;
		}

//		memcpy(request.content.s, sms->content.s, sms->content.len);
		memcpy(request.content.s, gsm7bit.s, gsm7bit.len);
	}
	else
	{
		str_t unicode;

		dwg_ascii2unicode(&sms->content, &unicode);
		length_16	= swap_bytes_16((short) unicode.len);
		memcpy(request.content_length, &length_16, sizeof(request.content_length));

		STR_ALLOC(request.content, unicode.len);
		if (!request.content.s)
		{
			LOG(L_ERROR, "%s.%d: No more memory trying to allocate %d bytes\n", __FUNCTION__, __LINE__, unicode.len);
			return FALSE;
		}

		memcpy(request.content.s, unicode.s, unicode.len);

		STR_FREE_NON_0(unicode);
	}

	dwg_serialize_sms_req(&request, &body);
	dwg_build_msg_header(body.len, DWG_TYPE_SEND_SMS, &header);

	STR_ALLOC((*output), (header.len + body.len));
	if (!output->s)
	{
		LOG(L_ERROR, "%s.%d: No more memory trying to allocate %d bytes\n", __FUNCTION__, __LINE__, header.len + body.len);
		return FALSE;
	}

	memcpy(output->s, header.s, header.len);
	memcpy(&output->s[header.len], body.s, body.len);

	STR_FREE_NON_0(body);
	STR_FREE_NON_0(request.content);

//	printf("---------------------\n");
//	hexdump(output->s, output->len);
//	printf("---------------------\n");
	
	return TRUE;
}
コード例 #18
0
ファイル: idn.c プロジェクト: SiebelsTim/php-src
static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS,
		const char *domain, int domain_len, uint32_t option, int mode, zval *idna_info)
{
	UErrorCode	  status = U_ZERO_ERROR;
	UIDNA		  *uts46;
	int32_t		  len;
	int32_t		  buffer_capac = 255; /* no domain name may exceed this */
	zend_string	  *buffer = STR_ALLOC(buffer_capac, 0);
	UIDNAInfo	  info = UIDNA_INFO_INITIALIZER;
	int			  buffer_used = 0;
	
	uts46 = uidna_openUTS46(option, &status);
	if (php_intl_idn_check_status(status, "failed to open UIDNA instance",
			mode TSRMLS_CC) == FAILURE) {
		STR_FREE(buffer);
		RETURN_FALSE;
	}

	if (mode == INTL_IDN_TO_ASCII) {
		len = uidna_nameToASCII_UTF8(uts46, domain, (int32_t)domain_len,
				buffer->val, buffer_capac, &info, &status);
	} else {
		len = uidna_nameToUnicodeUTF8(uts46, domain, (int32_t)domain_len,
				buffer->val, buffer_capac, &info, &status);
	}
	if (php_intl_idn_check_status(status, "failed to convert name",
			mode TSRMLS_CC) == FAILURE) {
		uidna_close(uts46);
		STR_FREE(buffer);
		RETURN_FALSE;
	}
	if (len >= 255) {
		php_error_docref(NULL TSRMLS_CC, E_ERROR, "ICU returned an unexpected length");
	}

	buffer->val[len] = '\0';
	buffer->len = len;

	if (info.errors == 0) {
		RETVAL_STR(buffer);
		buffer_used = 1;
	} else {
		RETVAL_FALSE;
	}

	if (idna_info) {
		if (buffer_used) { /* used in return_value then */
			zval_addref_p(return_value);
			add_assoc_zval_ex(idna_info, "result", sizeof("result")-1, return_value);
		} else {
			zval zv;
			ZVAL_STR(&zv, buffer);
			buffer_used = 1;
			add_assoc_zval_ex(idna_info, "result", sizeof("result")-1, &zv);
		}
		add_assoc_bool_ex(idna_info, "isTransitionalDifferent",
				sizeof("isTransitionalDifferent")-1, info.isTransitionalDifferent);
		add_assoc_long_ex(idna_info, "errors", sizeof("errors")-1, (long)info.errors);
	}

	if (!buffer_used) {
		STR_FREE(buffer);
	}

	uidna_close(uts46);
}