Class: LSAPI

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.acceptObject



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'ext/lsapi/lsruby.c', line 177

static VALUE lsapi_s_accept( VALUE self )
{
    int pid;
    if ( LSAPI_Prefork_Accept_r( &g_req ) == -1 )
        return Qnil;
    else
    {

        pid = getpid();
        if ( pid != s_pid )
        {
            s_pid = pid;
            rb_funcall( Qnil, rb_intern( "srand" ), 0 );
        }

        setup_cgi_env( s_req_data );
        return s_req;
    }
   
}

Instance Method Details

#<<(str) ⇒ Object



390
391
392
393
394
# File 'ext/lsapi/lsruby.c', line 390

static VALUE lsapi_addstr(VALUE out, VALUE str)
{
    lsapi_write(out, str);
    return out;
}

#binmodeObject

rb_define_method(cLSAPI, “closed?”, lsapi_closed, 0);



508
509
510
511
# File 'ext/lsapi/lsruby.c', line 508

static VALUE lsapi_binmode(VALUE self)
{
    return self;
}

#closeObject



528
529
530
531
532
# File 'ext/lsapi/lsruby.c', line 528

static VALUE lsapi_close(VALUE self)
{
    LSAPI_Flush_r( &g_req );    
    return Qnil;
}

#eofObject



494
495
496
497
498
499
500
501
502
503
504
505
506
# File 'ext/lsapi/lsruby.c', line 494

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_r( &g_req ) <= 0) ? Qtrue : Qfalse;
}

#eof?Boolean

Returns:

  • (Boolean)


494
495
496
497
498
499
500
501
502
503
504
505
506
# File 'ext/lsapi/lsruby.c', line 494

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_r( &g_req ) <= 0) ? Qtrue : Qfalse;
}

#flushObject



396
397
398
399
400
401
402
403
404
# File 'ext/lsapi/lsruby.c', line 396

static VALUE lsapi_flush( VALUE self )
{
/*
    lsapi_data *data;
    Data_Get_Struct(self,lsapi_data, data);
*/
    LSAPI_Flush_r( &g_req ); 
    return Qnil;
}

#getcObject



406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'ext/lsapi/lsruby.c', line 406

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 );
}

#getsObject

rb_define_method(cLSAPI, “ungetc”, lsapi_ungetc, 1);



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
# File 'ext/lsapi/lsruby.c', line 423

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_LEN(str) == 0)
        return Qnil;
    return str;
}

#isattyObject



513
514
515
516
# File 'ext/lsapi/lsruby.c', line 513

static VALUE lsapi_isatty(VALUE self)
{
    return Qfalse;
}


266
267
268
269
270
271
272
273
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
# File 'ext/lsapi/lsruby.c', line 266

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



302
303
304
305
306
# File 'ext/lsapi/lsruby.c', line 302

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

#processObject



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'ext/lsapi/lsruby.c', line 225

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);



242
243
244
245
246
247
248
249
250
251
# File 'ext/lsapi/lsruby.c', line 242

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



349
350
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
377
378
379
380
381
382
383
384
385
386
387
# File 'ext/lsapi/lsruby.c', line 349

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:
#if defined( RUBY_19 ) || defined( RUBY_2 )
            rb_exec_recursive(lsapi_puts_ary, argv[i], out);
#else
            rb_protect_inspect(lsapi_puts_ary, argv[i], out);
#endif
            continue;
        default:
            line = argv[i];
            break;
        }
        line = rb_obj_as_string(line);
        lsapi_write(out, line);
        if (*( RSTRING_PTR(line) + RSTRING_LEN(line) - 1 ) != '\n')
        {
            lsapi_write(out, rb_default_rs);
        }
    }

    return Qnil;
}

#read(*args) ⇒ Object

rb_define_method(cLSAPI, “readline”, lsapi_gets, 0);



450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
# File 'ext/lsapi/lsruby.c', line 450

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_LEN(str) == 0)
        return Qnil;
    return str;
}

#reopen(*args) ⇒ Object



535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
# File 'ext/lsapi/lsruby.c', line 535

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_funcall2( orig_stderr, rb_intern( "reopen" ), argc, argv );

    }
    return self;
}

#syncObject



518
519
520
521
# File 'ext/lsapi/lsruby.c', line 518

static VALUE lsapi_sync(VALUE self)
{
    return Qfalse;
}

#sync=(sync) ⇒ Object



523
524
525
526
# File 'ext/lsapi/lsruby.c', line 523

static VALUE lsapi_setsync(VALUE self,VALUE sync)
{
    return Qfalse;
}

#tty?Boolean

Returns:

  • (Boolean)


513
514
515
516
# File 'ext/lsapi/lsruby.c', line 513

static VALUE lsapi_isatty(VALUE self)
{
    return Qfalse;
}

#write(str) ⇒ Object



254
255
256
257
258
259
260
261
262
263
264
# File 'ext/lsapi/lsruby.c', line 254

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_PTR(str), RSTRING_LEN(str) ); */
    if (TYPE(str) != T_STRING)
      str = rb_obj_as_string(str);
    len = (*data->fn_write)( data->req, RSTRING_PTR(str), RSTRING_LEN(str) );
    return INT2NUM( len );
}