~ubuntu-branches/ubuntu/natty/ntop/natty

« back to all changes in this revision

Viewing changes to gdchart0.94c/gd-1.8.3/gd_io_ss.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2005-01-30 21:59:13 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050130215913-xc3ke963bw49b3k4
Tags: 2:3.0-5
* Updated README.Debian file so users will understand what to do at
  install, closes: #291794, #287802.
* Updated ntop init script to give better output.
* Also changed log directory from /var/lib/ntop to /var/log/ntop,
  closes: #252352.
* Quoted the interface list to allow whitespace, closes: #267248.
* Added a couple of logcheck ignores, closes: #269321, #269319.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
* io_ss.c
3
 
*
4
 
* Implements the Source/Sink interface.
5
 
*
6
 
* As will all I/O modules, most functions are for local use only (called
7
 
* via function pointers in the I/O context).
8
 
*
9
 
* The Source/Sink model is the primary 'user' interface for alternate data
10
 
* sources; the IOCtx interface is intended (at least in version 1.5) to be
11
 
* used internally until it settles down a bit.
12
 
*
13
 
* This module just layers the Source/Sink interface on top of the IOCtx; no
14
 
* support is provided for tell/seek, so GD2 writing is not possible, and 
15
 
* retrieving parts of GD2 files is also not possible.
16
 
*
17
 
* A new SS context does not need to be created with both a Source and a Sink.
18
 
*
19
 
* Written/Modified 1999, Philip Warner.
20
 
*
21
 
*/
22
 
 
23
 
#include <math.h>
24
 
#include <string.h>
25
 
#include <stdlib.h>
26
 
#include "gd.h"
27
 
 
28
 
/* this is used for creating images in main memory*/
29
 
 
30
 
typedef struct ssIOCtx {
31
 
  gdIOCtx               ctx;
32
 
  gdSourcePtr   src;
33
 
  gdSinkPtr     snk;
34
 
} ssIOCtx;
35
 
 
36
 
typedef struct ssIOCtx  *ssIOCtxPtr;
37
 
 
38
 
gdIOCtx* gdNewSSCtx(gdSourcePtr src, gdSinkPtr snk);
39
 
 
40
 
static int sourceGetbuf( gdIOCtx*, void *, int );
41
 
static int sourceGetchar( gdIOCtx* ctx);
42
 
static int sinkPutbuf( gdIOCtx* ctx, const void *buf, int size );
43
 
static void sinkPutchar( gdIOCtx* ctx, int a );
44
 
static void freeSsCtx(gdIOCtx *ctx);
45
 
 
46
 
/* return data as a dynamic pointer */
47
 
gdIOCtx* gdNewSSCtx (gdSourcePtr src, gdSinkPtr snk) {
48
 
  ssIOCtxPtr    ctx;
49
 
 
50
 
  ctx = (ssIOCtxPtr) malloc(sizeof(ssIOCtx));
51
 
  if (ctx == NULL) {
52
 
    return NULL;
53
 
  }
54
 
 
55
 
  ctx->src = src;
56
 
  ctx->snk = snk;
57
 
 
58
 
  ctx->ctx.getC = sourceGetchar;
59
 
  ctx->ctx.getBuf = sourceGetbuf;
60
 
 
61
 
  ctx->ctx.putC = sinkPutchar;
62
 
  ctx->ctx.putBuf = sinkPutbuf;
63
 
 
64
 
  ctx->ctx.tell = NULL;
65
 
  ctx->ctx.seek = NULL;
66
 
 
67
 
  ctx->ctx.free = freeSsCtx;
68
 
 
69
 
  return (gdIOCtx*)ctx;
70
 
}
71
 
 
72
 
static
73
 
void freeSsCtx(gdIOCtx *ctx)
74
 
{
75
 
  free(ctx);
76
 
}
77
 
 
78
 
 
79
 
static int
80
 
sourceGetbuf( gdIOCtx* ctx, void *buf, int size )
81
 
{
82
 
  ssIOCtx  *lctx;
83
 
  int  res;
84
 
 
85
 
  lctx = (ssIOCtx*) ctx;
86
 
 
87
 
  res = ((lctx->src->source)(lctx->src->context, buf, size));
88
 
 
89
 
/*
90
 
** Translate the return values from the Source object: 
91
 
** 0 is EOF, -1 is error
92
 
*/
93
 
 
94
 
  if (res == 0) {
95
 
    return EOF;
96
 
  } else if (res < 0) {
97
 
    return 0;
98
 
  } else {
99
 
    return res;
100
 
  };
101
 
 
102
 
}
103
 
 
104
 
static int sourceGetchar( gdIOCtx* ctx)
105
 
{
106
 
  int res;
107
 
  unsigned char buf;
108
 
 
109
 
  res = sourceGetbuf(ctx, &buf, 1);
110
 
 
111
 
  if (res == 1) {
112
 
    return buf;
113
 
  } else {
114
 
    return EOF;
115
 
  };
116
 
 
117
 
}
118
 
 
119
 
static int
120
 
sinkPutbuf( gdIOCtx* ctx, const void *buf, int size )
121
 
{
122
 
  ssIOCtxPtr    lctx;
123
 
  int           res;
124
 
 
125
 
  lctx = (ssIOCtx*) ctx;
126
 
 
127
 
  res = (lctx->snk->sink)(lctx->snk->context, buf, size);
128
 
 
129
 
  if (res <= 0) {
130
 
    return 0;
131
 
  } else {
132
 
    return res;
133
 
  };
134
 
 
135
 
}
136
 
 
137
 
static void
138
 
sinkPutchar( gdIOCtx* ctx, int a )
139
 
{
140
 
  unsigned      char b;
141
 
 
142
 
  b = a;
143
 
  sinkPutbuf(ctx, &b, 1);
144
 
 
145
 
}
146
 
 
147