Class: FCGI::Stream

Inherits:
Object
  • Object
show all
Defined in:
ext/fcgi/fcgi.c

Defined Under Namespace

Classes: CallSeqError, Error, ParamsError, ProtocolError, UnsupportedVersionError

Instance Method Summary collapse

Instance Method Details

#<<(str) ⇒ Object



306
307
308
309
310
# File 'ext/fcgi/fcgi.c', line 306

static VALUE fcgi_stream_addstr(VALUE out, VALUE str)
{
  fcgi_stream_write(out, str);
  return out;
}

#binmodeObject



466
467
468
469
470
471
472
# File 'ext/fcgi/fcgi.c', line 466

static VALUE fcgi_stream_binmode(VALUE self)
{
  if (rb_safe_level() >= 4 && !OBJ_TAINTED(self)) {
    rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
  }
  return self;
}

#closeObject



445
446
447
448
449
450
451
452
453
454
455
456
# File 'ext/fcgi/fcgi.c', line 445

static VALUE fcgi_stream_close(VALUE self)
{
  FCGX_Stream *stream;

  if (rb_safe_level() >= 4 && !OBJ_TAINTED(self)) {
    rb_raise(rb_eSecurityError, "Insecure: can't close");
  }
  Data_Get_Struct(self, FCGX_Stream, stream);
  if (FCGX_FClose(stream) == EOF)
    CHECK_STREAM_ERROR(stream);
  return Qnil;
}

#closed?Boolean

Returns:

  • (Boolean)


458
459
460
461
462
463
464
# File 'ext/fcgi/fcgi.c', line 458

static VALUE fcgi_stream_closed(VALUE self)
{
  FCGX_Stream *stream;

  Data_Get_Struct(self, FCGX_Stream, stream);
  return stream->isClosed ? Qtrue : Qfalse;
}

#eofObject



434
435
436
437
438
439
440
441
442
443
# File 'ext/fcgi/fcgi.c', line 434

static VALUE fcgi_stream_eof(VALUE self)
{
  FCGX_Stream *stream;

  if (rb_safe_level() >= 4 && !OBJ_TAINTED(self)) {
    rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
  }
  Data_Get_Struct(self, FCGX_Stream, stream);
  return FCGX_HasSeenEOF(stream) ? Qtrue : Qfalse;
}

#eof?Boolean

Returns:

  • (Boolean)


434
435
436
437
438
439
440
441
442
443
# File 'ext/fcgi/fcgi.c', line 434

static VALUE fcgi_stream_eof(VALUE self)
{
  FCGX_Stream *stream;

  if (rb_safe_level() >= 4 && !OBJ_TAINTED(self)) {
    rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
  }
  Data_Get_Struct(self, FCGX_Stream, stream);
  return FCGX_HasSeenEOF(stream) ? Qtrue : Qfalse;
}

#flushObject



312
313
314
315
316
317
318
319
320
# File 'ext/fcgi/fcgi.c', line 312

static VALUE fcgi_stream_flush(VALUE self)
{
  FCGX_Stream *stream;

  Data_Get_Struct(self, FCGX_Stream, stream);
  if (FCGX_FFlush(stream) == EOF)
    CHECK_STREAM_ERROR(stream);
  return Qnil;
}

#getcObject



322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'ext/fcgi/fcgi.c', line 322

static VALUE fcgi_stream_getc(VALUE self)
{
  FCGX_Stream *stream;
  int c;

  Data_Get_Struct(self, FCGX_Stream, stream);
  if ((c = FCGX_GetChar(stream)) == EOF) {
    CHECK_STREAM_ERROR(stream);
    return Qnil;
  }
  else {
    return INT2NUM(c);
  }
}

#getsObject



351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'ext/fcgi/fcgi.c', line 351

static VALUE fcgi_stream_gets(VALUE self)
{
  FCGX_Stream *stream;
  char buff[BUFSIZ];
  VALUE str = rb_str_new("", 0);
  OBJ_TAINT(str);

  if (rb_safe_level() >= 4 && !OBJ_TAINTED(self)) {
    rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
  }

  Data_Get_Struct(self, FCGX_Stream, stream);

  for (;;) {
    if (FCGX_GetLine(buff, BUFSIZ, stream) == NULL) {
      CHECK_STREAM_ERROR(stream);
      break;
    }
    rb_str_cat(str, buff, strlen(buff));
    if (strchr(buff, '\n')) break;
  }
  if (RSTRING(str)->len > 0)
    return str;
  else
    return Qnil;
}

#isattyObject



474
475
476
477
478
479
480
# File 'ext/fcgi/fcgi.c', line 474

static VALUE fcgi_stream_isatty(VALUE self)
{
  if (rb_safe_level() >= 4 && !OBJ_TAINTED(self)) {
    rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
  }
  return Qfalse;
}


220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'ext/fcgi/fcgi.c', line 220

static VALUE fcgi_stream_print(int argc, VALUE *argv, VALUE out)
{
  int i;
  VALUE line;

  /* if no argument given, print `$_' */
  if (argc == 0) {
    argc = 1;
    line = rb_lastline_get();
    argv = &line;
  }
  for (i=0; i<argc; i++) {
    if (!NIL_P(rb_output_fs) && i>0) {
      fcgi_stream_write(out, rb_output_fs);
    }
    switch (TYPE(argv[i])) {
    case T_NIL:
      fcgi_stream_write(out, rb_str_new2("nil"));
      break;
    default:
      fcgi_stream_write(out, argv[i]);
      break;
    }
  }
  if (!NIL_P(rb_output_rs)) {
    fcgi_stream_write(out, rb_output_rs);
  }

  return Qnil;
}

#printf(*args) ⇒ Object



251
252
253
254
255
# File 'ext/fcgi/fcgi.c', line 251

static VALUE fcgi_stream_printf(int argc, VALUE *argv, VALUE out)
{
  fcgi_stream_write(out, rb_f_sprintf(argc, argv));
  return Qnil;
}

#putc(ch) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
# File 'ext/fcgi/fcgi.c', line 195

static VALUE fcgi_stream_putc(VALUE self, VALUE ch)
{
  FCGX_Stream *stream;
  int c;

  rb_secure(4);
  Data_Get_Struct(self, FCGX_Stream, stream);
  if ((c = FCGX_PutChar(NUM2INT(ch), stream)) == EOF)
    CHECK_STREAM_ERROR(stream);
  return INT2NUM(c);
}

#puts(*args) ⇒ Object



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'ext/fcgi/fcgi.c', line 274

static VALUE fcgi_stream_puts(int argc, VALUE *argv, VALUE out)
{
  int i;
  VALUE line;

  /* if no argument given, print newline. */
  if (argc == 0) {
    fcgi_stream_write(out, rb_default_rs);
    return Qnil;
  }
  for (i=0; i<argc; i++) {
    switch (TYPE(argv[i])) {
    case T_NIL:
      line = rb_str_new2("nil");
      break;
    case T_ARRAY:
      rb_protect_inspect(fcgi_stream_puts_ary, argv[i], out);
      continue;
    default:
      line = argv[i];
      break;
    }
    line = rb_obj_as_string(line);
    fcgi_stream_write(out, line);
    if (RSTRING(line)->ptr[RSTRING(line)->len-1] != '\n') {
      fcgi_stream_write(out, rb_default_rs);
    }
  }

  return Qnil;
}

#read(*args) ⇒ Object



378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'ext/fcgi/fcgi.c', line 378

static VALUE fcgi_stream_read(int argc, VALUE *argv, VALUE self)
{
  VALUE num,str;
  FCGX_Stream *stream;
  char *buff;
  int n;

  if (rb_safe_level() >= 4 && !OBJ_TAINTED(self)) {
    rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
  }

  Data_Get_Struct(self, FCGX_Stream, stream);

  if (argc==0) {
    buff = ALLOC_N(char, 16384);
    n = FCGX_GetStr(buff, 16384, stream);
    CHECK_STREAM_ERROR(stream);
    if (n == 0) {
      free(buff);
      return  Qnil;
    }
    str = rb_str_new(buff, n);
    OBJ_TAINT(str);
    
    while(!FCGX_HasSeenEOF(stream)) {
      n = FCGX_GetStr(buff, 16384, stream);
      CHECK_STREAM_ERROR(stream);
      if (n > 0) {
        rb_str_cat(str, buff, n);
      } else {
        free(buff);
        return Qnil;
      }
    }
    free(buff);
    return str;
  }

  num = argv[0];
  n = NUM2INT(num);

  buff = ALLOC_N(char, n);
  n = FCGX_GetStr(buff, n, stream);
  CHECK_STREAM_ERROR(stream);
  if (n > 0) {
    str = rb_str_new(buff, n);
    OBJ_TAINT(str);
    free(buff);
    return str;
  }
  else {
    free(buff);
    return Qnil;
  }
}

#syncObject



482
483
484
485
486
487
488
# File 'ext/fcgi/fcgi.c', line 482

static VALUE fcgi_stream_sync(VALUE self)
{
  if (rb_safe_level() >= 4 && !OBJ_TAINTED(self)) {
    rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
  }
  return Qfalse;
}

#sync=(sync) ⇒ Object



490
491
492
493
494
495
496
# File 'ext/fcgi/fcgi.c', line 490

static VALUE fcgi_stream_setsync(VALUE self,VALUE sync)
{
  if (rb_safe_level() >= 4 && !OBJ_TAINTED(self)) {
    rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
  }
  return Qfalse;
}

#tty?Boolean

Returns:

  • (Boolean)


474
475
476
477
478
479
480
# File 'ext/fcgi/fcgi.c', line 474

static VALUE fcgi_stream_isatty(VALUE self)
{
  if (rb_safe_level() >= 4 && !OBJ_TAINTED(self)) {
    rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
  }
  return Qfalse;
}

#ungetc(ch) ⇒ Object



337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'ext/fcgi/fcgi.c', line 337

static VALUE fcgi_stream_ungetc(VALUE self, VALUE ch)
{
  FCGX_Stream *stream;
  int c;

  if (rb_safe_level() >= 4 && !OBJ_TAINTED(self)) {
    rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
  }
  Data_Get_Struct(self, FCGX_Stream, stream);
  c = FCGX_UnGetChar(NUM2INT(ch), stream);
  CHECK_STREAM_ERROR(stream);
  return INT2NUM(c);
}

#write(str) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
# File 'ext/fcgi/fcgi.c', line 207

static VALUE fcgi_stream_write(VALUE self, VALUE str)
{
  FCGX_Stream *stream;
  int len;

  rb_secure(4);
  Data_Get_Struct(self, FCGX_Stream, stream);
  str = rb_obj_as_string(str);
  len = FCGX_PutStr(RSTRING(str)->ptr, RSTRING(str)->len, stream);
  if (len == EOF) CHECK_STREAM_ERROR(stream);
  return INT2NUM(len);
}