Class: FCGI::Stream
- Inherits:
-
Object
- Object
- FCGI::Stream
- Defined in:
- ext/fcgi/fcgi.c
Defined Under Namespace
Classes: CallSeqError, Error, ParamsError, ProtocolError, UnsupportedVersionError
Instance Method Summary collapse
- #<<(str) ⇒ Object
- #binmode ⇒ Object
- #close ⇒ Object
- #closed? ⇒ Boolean
- #eof ⇒ Object
- #eof? ⇒ Boolean
- #flush ⇒ Object
- #getc ⇒ Object
- #gets ⇒ Object
- #isatty ⇒ Object
- #print(*args) ⇒ Object
- #printf(*args) ⇒ Object
- #putc(ch) ⇒ Object
- #puts(*args) ⇒ Object
- #read(*args) ⇒ Object
- #sync ⇒ Object
- #sync=(sync) ⇒ Object
- #tty? ⇒ Boolean
- #ungetc(ch) ⇒ Object
- #write(str) ⇒ Object
Instance Method Details
#<<(str) ⇒ Object
316 317 318 319 320 |
# File 'ext/fcgi/fcgi.c', line 316
static VALUE fcgi_stream_addstr(VALUE out, VALUE str)
{
fcgi_stream_write(out, str);
return out;
}
|
#binmode ⇒ Object
476 477 478 479 480 481 482 |
# File 'ext/fcgi/fcgi.c', line 476
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;
}
|
#close ⇒ Object
455 456 457 458 459 460 461 462 463 464 465 466 |
# File 'ext/fcgi/fcgi.c', line 455
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
468 469 470 471 472 473 474 |
# File 'ext/fcgi/fcgi.c', line 468
static VALUE fcgi_stream_closed(VALUE self)
{
FCGX_Stream *stream;
Data_Get_Struct(self, FCGX_Stream, stream);
return stream->isClosed ? Qtrue : Qfalse;
}
|
#eof ⇒ Object
444 445 446 447 448 449 450 451 452 453 |
# File 'ext/fcgi/fcgi.c', line 444
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
444 445 446 447 448 449 450 451 452 453 |
# File 'ext/fcgi/fcgi.c', line 444
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;
}
|
#flush ⇒ Object
322 323 324 325 326 327 328 329 330 |
# File 'ext/fcgi/fcgi.c', line 322
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;
}
|
#getc ⇒ Object
332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'ext/fcgi/fcgi.c', line 332
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);
}
}
|
#gets ⇒ Object
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'ext/fcgi/fcgi.c', line 361
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;
}
|
#isatty ⇒ Object
484 485 486 487 488 489 490 |
# File 'ext/fcgi/fcgi.c', line 484
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;
}
|
#print(*args) ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'ext/fcgi/fcgi.c', line 230
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
261 262 263 264 265 |
# File 'ext/fcgi/fcgi.c', line 261
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
205 206 207 208 209 210 211 212 213 214 215 |
# File 'ext/fcgi/fcgi.c', line 205
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
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'ext/fcgi/fcgi.c', line 284
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
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 433 434 435 436 437 438 439 440 441 442 |
# File 'ext/fcgi/fcgi.c', line 388
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;
}
}
|
#sync ⇒ Object
492 493 494 495 496 497 498 |
# File 'ext/fcgi/fcgi.c', line 492
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
500 501 502 503 504 505 506 |
# File 'ext/fcgi/fcgi.c', line 500
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
484 485 486 487 488 489 490 |
# File 'ext/fcgi/fcgi.c', line 484
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
347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'ext/fcgi/fcgi.c', line 347
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
217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'ext/fcgi/fcgi.c', line 217
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);
}
|