Kannel: Open Source WAP and SMS gateway  svn-r5335
wsstream_data.c File Reference
#include "wmlscript/wsint.h"

Go to the source code of this file.

Data Structures

struct  WsStreamDataInputCtxRec
 

Typedefs

typedef struct WsStreamDataInputCtxRec WsStreamDataInputCtx
 

Functions

static size_t data_input (void *context, WsUInt32 *buf, size_t buflen)
 
static void data_close (void *context)
 
WsStreamws_stream_new_data_input (const unsigned char *data, size_t data_len)
 

Typedef Documentation

◆ WsStreamDataInputCtx

Definition at line 81 of file wsstream_data.c.

Function Documentation

◆ data_close()

static void data_close ( void *  context)
static

Definition at line 99 of file wsstream_data.c.

References ws_free().

Referenced by ws_stream_new_data_input().

100 {
102 
103  ws_free(ctx);
104 }
Definition: parse.c:65
void ws_free(void *ptr)
Definition: wsalloc.c:139

◆ data_input()

static size_t data_input ( void *  context,
WsUInt32 buf,
size_t  buflen 
)
static

Definition at line 85 of file wsstream_data.c.

References WsStreamDataInputCtxRec::data, WsStreamDataInputCtxRec::data_len, and WsStreamDataInputCtxRec::data_pos.

Referenced by ws_stream_new_data_input().

86 {
88  size_t read;
89 
90  for (read = 0;
91  read < buflen && ctx->data_pos < ctx->data_len;
92  read++, ctx->data_pos++)
93  buf[read] = ctx->data[ctx->data_pos];
94 
95  return read;
96 }
Definition: parse.c:65
const unsigned char * data
Definition: wsstream_data.c:76

◆ ws_stream_new_data_input()

WsStream* ws_stream_new_data_input ( const unsigned char *  data,
size_t  data_len 
)

Definition at line 108 of file wsstream_data.c.

References WsStreamDataInputCtxRec::data, data_close(), data_input(), WsStreamDataInputCtxRec::data_len, ws_calloc(), and ws_stream_new().

Referenced by ws_compile_data().

109 {
110  WsStreamDataInputCtx *ctx = ws_calloc(1, sizeof(*ctx));
111  WsStream *stream;
112 
113  if (ctx == NULL)
114  return NULL;
115 
116  ctx->data = data;
117  ctx->data_len = data_len;
118 
119  stream = ws_stream_new(ctx, data_input, NULL, data_close);
120 
121  if (stream == NULL)
122  /* The stream creation failed. Close the stream context. */
123  data_close(ctx);
124 
125  return stream;
126 }
void * ws_calloc(size_t num, size_t size)
Definition: wsalloc.c:83
WsStream * ws_stream_new(void *context, WsStreamIOProc io, WsStreamFlushProc flush, WsStreamCloseProc close)
Definition: wsstream.c:126
static size_t data_input(void *context, WsUInt32 *buf, size_t buflen)
Definition: wsstream_data.c:85
static void data_close(void *context)
Definition: wsstream_data.c:99
const unsigned char * data
Definition: wsstream_data.c:76
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.