Class: LSAPI
- Inherits:
-
Object
- Object
- LSAPI
- Defined in:
- ext/lsapi/lsruby.c
Class Method Summary collapse
Instance Method Summary collapse
- #<<(str) ⇒ Object
-
#binmode ⇒ Object
rb_define_method(cLSAPI, “closed?”, lsapi_closed, 0);.
- #close ⇒ Object
- #eof ⇒ Object
- #eof? ⇒ Boolean
- #flush ⇒ Object
- #getc ⇒ Object
-
#gets ⇒ Object
rb_define_method(cLSAPI, “ungetc”, lsapi_ungetc, 1);.
- #isatty ⇒ Object
- #print(*args) ⇒ Object
- #printf(*args) ⇒ Object
- #process ⇒ Object
-
#putc(c) ⇒ Object
rb_define_method(cLSAPI, “initialize”, lsapi_initialize, 0);.
- #puts(*args) ⇒ Object
- #read(*args) ⇒ Object
- #reopen(*args) ⇒ Object
- #sync ⇒ Object
- #sync=(sync) ⇒ Object
- #tty? ⇒ Boolean
- #write(str) ⇒ Object
Class Method Details
.accept ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'ext/lsapi/lsruby.c', line 171
static VALUE lsapi_s_accept( VALUE self )
{
if ( LSAPI_Prefork_Accept_r( &g_req ) == -1 )
return Qnil;
else
{
setup_cgi_env( s_req_data );
return s_req;
}
}
|
Instance Method Details
#<<(str) ⇒ Object
350 351 352 353 354 |
# File 'ext/lsapi/lsruby.c', line 350
static VALUE lsapi_addstr(VALUE out, VALUE str)
{
lsapi_write(out, str);
return out;
}
|
#binmode ⇒ Object
rb_define_method(cLSAPI, “closed?”, lsapi_closed, 0);
468 469 470 471 |
# File 'ext/lsapi/lsruby.c', line 468
static VALUE lsapi_binmode(VALUE self)
{
return self;
}
|
#close ⇒ Object
488 489 490 491 492 |
# File 'ext/lsapi/lsruby.c', line 488
static VALUE lsapi_close(VALUE self)
{
LSAPI_Flush_r( &g_req );
return Qnil;
}
|
#eof ⇒ Object
454 455 456 457 458 459 460 461 462 463 464 465 466 |
# File 'ext/lsapi/lsruby.c', line 454
static VALUE lsapi_eof(VALUE self)
{
/*
lsapi_data *data;
if (rb_safe_level() >= 4 && !OBJ_TAINTED(self))
{
rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
}
Data_Get_Struct(self, lsapi_data, data);
*/
return (LSAPI_GetReqBodyRemain( &g_req ) <= 0) ? Qtrue : Qfalse;
}
|
#eof? ⇒ Boolean
454 455 456 457 458 459 460 461 462 463 464 465 466 |
# File 'ext/lsapi/lsruby.c', line 454
static VALUE lsapi_eof(VALUE self)
{
/*
lsapi_data *data;
if (rb_safe_level() >= 4 && !OBJ_TAINTED(self))
{
rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
}
Data_Get_Struct(self, lsapi_data, data);
*/
return (LSAPI_GetReqBodyRemain( &g_req ) <= 0) ? Qtrue : Qfalse;
}
|
#flush ⇒ Object
356 357 358 359 360 361 362 363 364 |
# File 'ext/lsapi/lsruby.c', line 356
static VALUE lsapi_flush( VALUE self )
{
/*
lsapi_data *data;
Data_Get_Struct(self,lsapi_data, data);
*/
LSAPI_Flush_r( &g_req );
return Qnil;
}
|
#getc ⇒ Object
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'ext/lsapi/lsruby.c', line 366
static VALUE lsapi_getc( VALUE self )
{
int ch;
/*
lsapi_data *data;
Data_Get_Struct(self,lsapi_data, data);
*/
if (rb_safe_level() >= 4 && !OBJ_TAINTED(self))
{
rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
}
ch = LSAPI_ReqBodyGetChar_r( &g_req );
if ( ch == EOF )
return Qnil;
return INT2NUM( ch );
}
|
#gets ⇒ Object
rb_define_method(cLSAPI, “ungetc”, lsapi_ungetc, 1);
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 |
# File 'ext/lsapi/lsruby.c', line 383
static VALUE lsapi_gets( VALUE self )
{
VALUE str;
int getLF = 0;
char buff[4096];
int len;
if (rb_safe_level() >= 4 && !OBJ_TAINTED(self))
{
rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
}
if ( LSAPI_GetReqBodyRemain_r( &g_req ) <= 0 )
return Qnil;
str = rb_str_buf_new( 1024 );
OBJ_TAINT(str);
while( !getLF )
{
len = LSAPI_ReqBodyGetLine_r( &g_req, buff, 4096, &getLF );
if ( len > 0 )
rb_str_buf_cat( str, buff, len );
}
if (RSTRING(str)->len == 0)
return Qnil;
return str;
}
|
#isatty ⇒ Object
473 474 475 476 |
# File 'ext/lsapi/lsruby.c', line 473
static VALUE lsapi_isatty(VALUE self)
{
return Qfalse;
}
|
#print(*args) ⇒ Object
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'ext/lsapi/lsruby.c', line 252
static VALUE lsapi_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)
{
lsapi_write(out, rb_output_fs);
}
switch (TYPE(argv[i]))
{
case T_NIL:
lsapi_write(out, rb_str_new2("nil"));
break;
default:
lsapi_write(out, argv[i]);
break;
}
}
if (!NIL_P(rb_output_rs))
{
lsapi_write(out, rb_output_rs);
}
return Qnil;
}
|
#printf(*args) ⇒ Object
288 289 290 291 292 |
# File 'ext/lsapi/lsruby.c', line 288
static VALUE lsapi_printf(int argc, VALUE *argv, VALUE out)
{
lsapi_write(out, rb_f_sprintf(argc, argv));
return Qnil;
}
|
#process ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'ext/lsapi/lsruby.c', line 211
static VALUE lsapi_process( VALUE self )
{
lsapi_data *data;
const char * pScriptPath;
Data_Get_Struct(self,lsapi_data, data);
pScriptPath = LSAPI_GetScriptFileName_r( data->req );
/*
if ( chdir_file( pScriptPath ) == -1 )
{
lsapi_send_error( 404 );
}
rb_load_file( pScriptPath );
*/
return Qnil;
}
|
#putc(c) ⇒ Object
rb_define_method(cLSAPI, “initialize”, lsapi_initialize, 0);
228 229 230 231 232 233 234 235 236 237 |
# File 'ext/lsapi/lsruby.c', line 228
static VALUE lsapi_putc(VALUE self, VALUE c)
{
char ch = NUM2CHR(c);
lsapi_data *data;
Data_Get_Struct(self,lsapi_data, data);
if ( (*data->fn_write)( data->req, &ch, 1 ) == 1 )
return c;
else
return INT2NUM( EOF );
}
|
#puts(*args) ⇒ Object
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'ext/lsapi/lsruby.c', line 313
static VALUE lsapi_puts(int argc, VALUE *argv, VALUE out)
{
int i;
VALUE line;
/* if no argument given, print newline. */
if (argc == 0)
{
lsapi_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(lsapi_puts_ary, argv[i], out);
continue;
default:
line = argv[i];
break;
}
line = rb_obj_as_string(line);
lsapi_write(out, line);
if (RSTRING(line)->ptr[RSTRING(line)->len-1] != '\n')
{
lsapi_write(out, rb_default_rs);
}
}
return Qnil;
}
|
#read(*args) ⇒ Object
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 443 444 445 446 447 448 449 450 451 452 |
# File 'ext/lsapi/lsruby.c', line 410
static VALUE lsapi_read(int argc, VALUE *argv, VALUE self)
{
VALUE str;
int n;
int remain;
char buff[8192];
if (rb_safe_level() >= 4 && !OBJ_TAINTED(self))
{
rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
}
remain = LSAPI_GetReqBodyRemain_r( &g_req );
if ( remain <= 0 )
return Qnil;
if (argc != 0)
{
n = NUM2INT(argv[0]);
if ( remain > n )
remain = n;
}
str = rb_str_buf_new( remain );
OBJ_TAINT(str);
while( remain > 0 )
{
n = LSAPI_ReadReqBody_r(&g_req, buff,
(remain > 8192)?8192:remain );
if ( n > 0 )
{
rb_str_buf_cat( str, buff, n );
remain -= n;
}
else if ( n <= 0 )
{
/* FIXME: broken connection */
break;
}
}
if (RSTRING(str)->len == 0)
return Qnil;
return str;
}
|
#reopen(*args) ⇒ Object
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
# File 'ext/lsapi/lsruby.c', line 495
static VALUE lsapi_reopen( int argc, VALUE *argv, VALUE self)
{
VALUE orig_verbose;
if ( self == s_req_stderr )
{
/* constant silence hack */
orig_verbose = (VALUE)ruby_verbose;
ruby_verbose = Qnil;
rb_define_global_const("STDERR", orig_stderr);
ruby_verbose = (VALUE)orig_verbose;
return rb_funcall( orig_stderr, rb_intern( "reopen" ), 2, argc, argv );
}
return self;
}
|
#sync ⇒ Object
478 479 480 481 |
# File 'ext/lsapi/lsruby.c', line 478
static VALUE lsapi_sync(VALUE self)
{
return Qfalse;
}
|
#sync=(sync) ⇒ Object
483 484 485 486 |
# File 'ext/lsapi/lsruby.c', line 483
static VALUE lsapi_setsync(VALUE self,VALUE sync)
{
return Qfalse;
}
|
#tty? ⇒ Boolean
473 474 475 476 |
# File 'ext/lsapi/lsruby.c', line 473
static VALUE lsapi_isatty(VALUE self)
{
return Qfalse;
}
|
#write(str) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 |
# File 'ext/lsapi/lsruby.c', line 240
static VALUE lsapi_write( VALUE self, VALUE str )
{
lsapi_data *data;
int len;
Data_Get_Struct(self,lsapi_data, data);
/* len = LSAPI_Write_r( data->req, RSTRING(str)->ptr, RSTRING(str)->len ); */
if (TYPE(str) != T_STRING)
str = rb_obj_as_string(str);
len = (*data->fn_write)( data->req, RSTRING(str)->ptr, RSTRING(str)->len );
return INT2NUM( len );
}
|