added qse_awk_http_range_int_t
This commit is contained in:
parent
c380388718
commit
79370202bc
@ -21,13 +21,16 @@
|
||||
#ifndef _QSE_NET_HTTP_H_
|
||||
#define _QSE_NET_HTTP_H_
|
||||
|
||||
/** @file
|
||||
* This file provides basic data types and functions for the http protocol.
|
||||
*/
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
#include <qse/cmn/str.h>
|
||||
#include <qse/cmn/htb.h>
|
||||
#include <qse/cmn/time.h>
|
||||
|
||||
/*typedef qse_byte_t qse_htoc_t;*/
|
||||
typedef qse_mchar_t qse_htoc_t;
|
||||
|
||||
/* octet buffer */
|
||||
@ -36,14 +39,20 @@ typedef qse_mbs_t qse_htob_t;
|
||||
/* octet string */
|
||||
typedef qse_mxstr_t qse_htos_t;
|
||||
|
||||
/**
|
||||
* The qse_http_version_t type defines http version.
|
||||
*/
|
||||
struct qse_http_version_t
|
||||
{
|
||||
short major;
|
||||
short minor;
|
||||
short major; /**< major version */
|
||||
short minor; /**< minor version */
|
||||
};
|
||||
|
||||
typedef struct qse_http_version_t qse_http_version_t;
|
||||
|
||||
/**
|
||||
* The qse_http_method_t type defines http methods .
|
||||
*/
|
||||
enum qse_http_method_t
|
||||
{
|
||||
QSE_HTTP_GET,
|
||||
@ -58,11 +67,44 @@ enum qse_http_method_t
|
||||
|
||||
typedef enum qse_http_method_t qse_http_method_t;
|
||||
|
||||
/**
|
||||
* The #qse_http_range_int_t type defines an integer that can represent
|
||||
* a range offset. Depening on the size of #qse_foff_t, it is defined to
|
||||
* either #qse_foff_t or #qse_ulong_t.
|
||||
*/
|
||||
#if defined(QSE_SIZEOF_FOFF_T) && \
|
||||
defined(QSE_SIZEOF_ULONG_T) && \
|
||||
(QSE_SIZEOF_FOFF_T > QSE_SIZEOF_ULONG_T)
|
||||
typedef qse_foff_t qse_http_range_int_t;
|
||||
#else
|
||||
typedef qse_ulong_t qse_http_range_int_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The qse_http_range_t type defines a structure that can represent
|
||||
* a value for the @b Range: http header.
|
||||
*
|
||||
* If suffix is non-zero, 'from' is meaningleass and 'to' indicates
|
||||
* the number of bytes from the back.
|
||||
* - -500 => last 500 bytes
|
||||
*
|
||||
* You should adjust a range when the size that this range belongs to is
|
||||
* made known. See this code:
|
||||
* @code
|
||||
* range.from = total_size - range.to;
|
||||
* range.to = range.to + range.from - 1;
|
||||
* @endcode
|
||||
*
|
||||
* If suffix is zero, 'from' and 'to' represents a proper range where
|
||||
* the value of 0 indicates the first byte. This doesn't require any adjustment.
|
||||
* - 0-999 => first 1000 bytes
|
||||
* - 99- => from the 100th bytes to the end.
|
||||
*/
|
||||
struct qse_http_range_t
|
||||
{
|
||||
int suffix;
|
||||
qse_ulong_t from;
|
||||
qse_ulong_t to;
|
||||
int suffix; /**< suffix indicator */
|
||||
qse_http_range_int_t from; /**< starting offset */
|
||||
qse_http_range_int_t to; /**< ending offset */
|
||||
};
|
||||
typedef struct qse_http_range_t qse_http_range_t;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: types.h 510 2011-07-20 16:17:16Z hyunghwan.chung $
|
||||
* $Id: types.h 524 2011-07-26 15:41:20Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -164,6 +164,11 @@ typedef enum qse_tri_t qse_tri_t;
|
||||
typedef __uint8_t qse_uint8_t;
|
||||
#endif
|
||||
|
||||
#ifdef QSE_HAVE_INT32_T
|
||||
# define QSE_SIZEOF_INT16_T 1
|
||||
# define QSE_SIZEOF_UINT16_T 1
|
||||
#endif
|
||||
|
||||
/** @typedef qse_int16_t
|
||||
* The qse_int16_t defines an 16-bit signed integer type.
|
||||
*/
|
||||
@ -187,6 +192,11 @@ typedef enum qse_tri_t qse_tri_t;
|
||||
typedef __uint16_t qse_uint16_t;
|
||||
#endif
|
||||
|
||||
#ifdef QSE_HAVE_INT32_T
|
||||
# define QSE_SIZEOF_INT16_T 2
|
||||
# define QSE_SIZEOF_UINT16_T 2
|
||||
#endif
|
||||
|
||||
/** @typedef qse_int32_t
|
||||
* The qse_int32_t defines an 32-bit signed integer type.
|
||||
*/
|
||||
@ -215,6 +225,11 @@ typedef enum qse_tri_t qse_tri_t;
|
||||
typedef __uint32_t qse_uint32_t;
|
||||
#endif
|
||||
|
||||
#ifdef QSE_HAVE_INT32_T
|
||||
# define QSE_SIZEOF_INT32_T 4
|
||||
# define QSE_SIZEOF_UINT32_T 4
|
||||
#endif
|
||||
|
||||
/** @typedef qse_int64_t
|
||||
* The qse_int64_t defines an 64-bit signed integer type.
|
||||
*/
|
||||
@ -248,6 +263,11 @@ typedef enum qse_tri_t qse_tri_t;
|
||||
typedef __uint64_t qse_uint64_t;
|
||||
#endif
|
||||
|
||||
#ifdef QSE_HAVE_INT64_T
|
||||
# define QSE_SIZEOF_INT64_T 8
|
||||
# define QSE_SIZEOF_UINT64_T 8
|
||||
#endif
|
||||
|
||||
#if QSE_SIZEOF_INT == 16
|
||||
# define QSE_HAVE_INT128_T
|
||||
# define QSE_HAVE_UINT128_T
|
||||
@ -275,6 +295,11 @@ typedef enum qse_tri_t qse_tri_t;
|
||||
typedef __uint128_t qse_uint128_t;
|
||||
#endif
|
||||
|
||||
#ifdef QSE_HAVE_INT128_T
|
||||
# define QSE_SIZEOF_INT128_T 16
|
||||
# define QSE_SIZEOF_UINT128_T 16
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The qse_byte_t defines a byte type.
|
||||
*/
|
||||
@ -511,8 +536,8 @@ typedef struct qse_wcstr_t qse_wcstr_t;
|
||||
*/
|
||||
struct qse_cptl_t
|
||||
{
|
||||
const void* ptr;
|
||||
qse_size_t len;
|
||||
const void* ptr; /**< pointer */
|
||||
qse_size_t len; /**< length */
|
||||
};
|
||||
typedef struct qse_cptl_t qse_cptl_t;
|
||||
|
||||
@ -521,19 +546,19 @@ typedef struct qse_cptl_t qse_cptl_t;
|
||||
*/
|
||||
struct qse_xptl_t
|
||||
{
|
||||
void* ptr;
|
||||
qse_size_t len;
|
||||
void* ptr; /**< pointer */
|
||||
qse_size_t len; /**< length */
|
||||
};
|
||||
typedef struct qse_xptl_t qse_xptl_t;
|
||||
|
||||
/**
|
||||
* allocate a memory chunk of the size @a n.
|
||||
* @return a pointer to a memory chunk on success, QSE_NULL on failure.
|
||||
* @return pointer to a memory chunk on success, QSE_NULL on failure.
|
||||
*/
|
||||
typedef void* (*qse_mmgr_alloc_t) (void* udd, qse_size_t n);
|
||||
/**
|
||||
* resize a memory chunk pointed to by @a ptr to the size @a n.
|
||||
* @return a pointer to a memory chunk on success, QSE_NULL on failure.
|
||||
* @return pointer to a memory chunk on success, QSE_NULL on failure.
|
||||
*/
|
||||
typedef void* (*qse_mmgr_realloc_t) (void* udd, void* ptr, qse_size_t n);
|
||||
/**
|
||||
@ -561,21 +586,32 @@ struct qse_mmgr_t
|
||||
};
|
||||
typedef struct qse_mmgr_t qse_mmgr_t;
|
||||
|
||||
/* file offset */
|
||||
/**
|
||||
* The #qse_foff_t type defines an integer that can represent a file offset.
|
||||
* Depending on your system, it's defined to one of #qse_int64_t, #qse_int32_t,
|
||||
* and #qse_int16_t.
|
||||
*/
|
||||
#if defined(QSE_HAVE_INT64_T) && (QSE_SIZEOF_OFF64_T==8)
|
||||
typedef qse_int64_t qse_foff_t;
|
||||
# define QSE_SIZEOF_FOFF_T QSE_SIZEOF_INT64_T
|
||||
#elif defined(QSE_HAVE_INT64_T) && (QSE_SIZEOF_OFF_T==8)
|
||||
typedef qse_int64_t qse_foff_t;
|
||||
# define QSE_SIZEOF_FOFF_T QSE_SIZEOF_INT64_T
|
||||
#elif defined(QSE_HAVE_INT32_T) && (QSE_SIZEOF_OFF_T==4)
|
||||
typedef qse_int32_t qse_foff_t;
|
||||
# define QSE_SIZEOF_FOFF_T QSE_SIZEOF_INT32_T
|
||||
#elif defined(QSE_HAVE_INT16_T) && (QSE_SIZEOF_OFF_T==2)
|
||||
typedef qse_int16_t qse_foff_t;
|
||||
# define QSE_SIZEOF_FOFF_T QSE_SIZEOF_INT16_T
|
||||
#else
|
||||
typedef qse_int32_t qse_foff_t; /* this line is for doxygen */
|
||||
# error Unsupported platform
|
||||
#endif
|
||||
|
||||
/* The qse_ubi_t type defines a union type that includes most of built-in
|
||||
* data types and numeric types defined in the library. */
|
||||
/**
|
||||
* The qse_ubi_t type defines a union type that includes most of built-in
|
||||
* data types and numeric types defined in the library.
|
||||
*/
|
||||
union qse_ubi_t
|
||||
{
|
||||
char c;
|
||||
@ -634,6 +670,4 @@ union qse_ubi_t
|
||||
};
|
||||
typedef union qse_ubi_t qse_ubi_t;
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -141,7 +141,7 @@ int qse_parsehttprange (const qse_mchar_t* str, qse_http_range_t* range)
|
||||
/* NOTE: this function does not support a range set
|
||||
* like bytes=1-20,30-50 */
|
||||
|
||||
qse_ulong_t from, to;
|
||||
qse_http_range_int_t from, to;
|
||||
int suffix = 0;
|
||||
|
||||
if (str[0] != QSE_MT('b') ||
|
||||
|
Loading…
Reference in New Issue
Block a user