Changes in perlconfig.c [b9517cf:7dcef03]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perlconfig.c
rb9517cf r7dcef03 75 75 const char *type; 76 76 char *ptr, *utype, *blessas; 77 int i, j; 77 const char *f; 78 int i; 78 79 const owl_pair *pair; 79 80 const owl_filter *wrap; … … 91 92 owl_new_sv(owl_message_get_##field(m)), 0) 92 93 93 if (owl_message_ get_notice(m)) {94 if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) { 94 95 /* Handle zephyr-specific fields... */ 95 AV *av_zfields; 96 97 av_zfields = newAV(); 98 j=owl_zephyr_get_num_fields(owl_message_get_notice(m)); 99 for (i=0; i<j; i++) { 100 ptr=owl_zephyr_get_field_as_utf8(owl_message_get_notice(m), i+1); 101 av_push(av_zfields, owl_new_sv(ptr)); 102 g_free(ptr); 96 AV *av_zfields = newAV(); 97 if (owl_message_get_notice(m)) { 98 for (f = owl_zephyr_first_raw_field(owl_message_get_notice(m)); f != NULL; 99 f = owl_zephyr_next_raw_field(owl_message_get_notice(m), f)) { 100 ptr = owl_zephyr_field_as_utf8(owl_message_get_notice(m), f); 101 av_push(av_zfields, owl_new_sv(ptr)); 102 g_free(ptr); 103 } 104 (void)hv_store(h, "auth", strlen("auth"), 105 owl_new_sv(owl_zephyr_get_authstr(owl_message_get_notice(m))), 0); 106 } else { 107 /* Incoming zephyrs without a ZNotice_t are pseudo-logins. To appease 108 * existing styles, put in bogus 'auth' and 'fields' keys. */ 109 (void)hv_store(h, "auth", strlen("auth"), owl_new_sv("NO"), 0); 103 110 } 104 111 (void)hv_store(h, "fields", strlen("fields"), newRV_noinc((SV*)av_zfields), 0); 105 106 (void)hv_store(h, "auth", strlen("auth"),107 owl_new_sv(owl_zephyr_get_authstr(owl_message_get_notice(m))),0);108 112 } 109 113 … … 184 188 hash = (HV*)SvRV(msg); 185 189 186 m = g_ new(owl_message, 1);190 m = g_slice_new(owl_message); 187 191 owl_message_init(m); 188 192 … … 224 228 CALLER_OWN char *owl_perlconfig_call_with_message(const char *subname, const owl_message *m) 225 229 { 226 dSP ; 227 int count; 228 SV *msgref, *srv; 229 char *out; 230 231 ENTER ; 232 SAVETMPS; 233 234 PUSHMARK(SP) ; 230 SV *msgref, *rv; 231 char *out = NULL; 232 235 233 msgref = owl_perlconfig_message2hashref(m); 236 XPUSHs(sv_2mortal(msgref)); 237 PUTBACK ; 238 239 count = call_pv(subname, G_SCALAR|G_EVAL); 240 241 SPAGAIN ; 242 243 if (SvTRUE(ERRSV)) { 244 owl_function_error("Perl Error: '%s'", SvPV_nolen(ERRSV)); 245 /* and clear the error */ 246 sv_setsv (ERRSV, &PL_sv_undef); 247 } 248 249 if (count != 1) { 250 fprintf(stderr, "bad perl! no biscuit! returned wrong count!\n"); 251 abort(); 252 } 253 254 srv = POPs; 255 256 if (srv) { 257 out = g_strdup(SvPV_nolen(srv)); 258 } else { 259 out = NULL; 260 } 261 262 PUTBACK ; 263 FREETMPS ; 264 LEAVE ; 265 234 235 OWL_PERL_CALL((call_pv(subname, G_SCALAR|G_EVAL)) 236 , 237 XPUSHs(sv_2mortal(msgref)); 238 , 239 "Perl Error: '%s'" 240 , 241 false 242 , 243 false 244 , 245 rv = POPs; 246 if (rv && SvPOK(rv)) 247 out = g_strdup(SvPV_nolen(rv)); 248 ); 266 249 return out; 267 250 } … … 273 256 CALLER_OWN char *owl_perlconfig_message_call_method(const owl_message *m, const char *method, int argc, const char **argv) 274 257 { 275 dSP; 276 unsigned int count, i; 277 SV *msgref, *srv; 278 char *out; 258 SV *msgref, *rv; 259 char *out = NULL; 260 int i; 279 261 280 262 msgref = owl_perlconfig_message2hashref(m); 281 263 282 ENTER; 283 SAVETMPS; 284 285 PUSHMARK(SP); 286 XPUSHs(sv_2mortal(msgref)); 287 for(i=0;i<argc;i++) { 288 XPUSHs(sv_2mortal(owl_new_sv(argv[i]))); 289 } 290 PUTBACK; 291 292 count = call_method(method, G_SCALAR|G_EVAL); 293 294 SPAGAIN; 295 296 if(count != 1) { 297 fprintf(stderr, "perl returned wrong count %u\n", count); 298 abort(); 299 } 300 301 if (SvTRUE(ERRSV)) { 302 owl_function_error("Error: '%s'", SvPV_nolen(ERRSV)); 303 /* and clear the error */ 304 sv_setsv (ERRSV, &PL_sv_undef); 305 } 306 307 srv = POPs; 308 309 if (srv) { 310 out = g_strdup(SvPV_nolen(srv)); 311 } else { 312 out = NULL; 313 } 314 315 PUTBACK; 316 FREETMPS; 317 LEAVE; 318 264 OWL_PERL_CALL(call_method(method, G_SCALAR|G_EVAL) 265 , 266 XPUSHs(sv_2mortal(msgref)); 267 OWL_PERL_PUSH_ARGS(i, argc, argv); 268 , 269 "Perl Error: '%s'" 270 , 271 false 272 , 273 false 274 , 275 rv = POPs; 276 if (rv && SvPOK(rv)) 277 out = g_strdup(SvPV_nolen(rv)); 278 ); 319 279 return out; 320 280 } … … 327 287 char *err; 328 288 const char *args[4] = {"", "-e", "0;", NULL}; 289 const char *dlerr; 329 290 AV *inc; 330 291 char *path; … … 375 336 } 376 337 377 sv_setpv(get_sv("BarnOwl::VERSION", TRUE), OWL_VERSION_STRING);338 sv_setpv(get_sv("BarnOwl::VERSION", TRUE), version); 378 339 379 340 /* Add the system lib path to @INC */ … … 384 345 g_free(path); 385 346 347 /* Load up perl-Glib. */ 348 eval_pv("use Glib;", FALSE); 349 350 /* Now, before BarnOwl tries to use them, get the relevant function pointers out. */ 351 dlerr = owl_closure_init(); 352 if (dlerr) { 353 return g_strdup(dlerr); 354 } 355 356 /* And now it's safe to import BarnOwl. */ 386 357 eval_pv("use BarnOwl;", FALSE); 387 358 … … 455 426 void owl_perlconfig_new_command(const char *name) 456 427 { 457 dSP; 458 459 ENTER; 460 SAVETMPS; 461 462 PUSHMARK(SP); 463 XPUSHs(sv_2mortal(owl_new_sv(name))); 464 PUTBACK; 465 466 call_pv("BarnOwl::Hooks::_new_command", G_VOID|G_EVAL); 467 468 SPAGAIN; 469 470 if(SvTRUE(ERRSV)) { 471 owl_function_error("%s", SvPV_nolen(ERRSV)); 472 } 473 474 FREETMPS; 475 LEAVE; 428 OWL_PERL_CALL(call_pv("BarnOwl::Hooks::_new_command", G_VOID|G_EVAL); 429 , 430 XPUSHs(sv_2mortal(owl_new_sv(name))); 431 , 432 "Perl Error: '%s'" 433 , 434 false 435 , 436 true 437 , 438 ); 439 } 440 441 CALLER_OWN char *owl_perlconfig_perl_call(const char *method, int argc, const char *const *argv) 442 { 443 SV *rv; 444 char *out = NULL; 445 int i; 446 OWL_PERL_CALL(call_pv(method, G_SCALAR|G_EVAL) 447 , 448 OWL_PERL_PUSH_ARGS(i, argc, argv); 449 , 450 "Perl Error: '%s'" 451 , 452 false 453 , 454 false 455 , 456 rv = POPs; 457 if (rv && SvPOK(rv)) 458 out = g_strdup(SvPV_nolen(rv)); 459 ); 460 return out; 461 } 462 463 int owl_perlconfig_perl_call_int(const char *method, int argc, const char *const *argv) 464 { 465 SV *rv; 466 int ret = -1; 467 int i; 468 OWL_PERL_CALL(call_pv(method, G_SCALAR|G_EVAL) 469 , 470 OWL_PERL_PUSH_ARGS(i, argc, argv); 471 , 472 "Perl Error: '%s'" 473 , 474 false 475 , 476 false 477 , 478 rv = POPs; 479 if (rv && SvIOK(rv)) 480 ret = SvIV(rv); 481 ); 482 return ret; 483 } 484 485 bool owl_perlconfig_perl_call_bool(const char *method, int argc, const char *const *argv) 486 { 487 SV *rv; 488 bool ret = false; 489 int i; 490 OWL_PERL_CALL(call_pv(method, G_SCALAR|G_EVAL) 491 , 492 OWL_PERL_PUSH_ARGS(i, argc, argv); 493 , 494 "Perl Error: '%s'" 495 , 496 false 497 , 498 false 499 , 500 rv = POPs; 501 if (rv) 502 ret = SvTRUE(rv); 503 ); 504 return ret; 505 } 506 507 void owl_perlconfig_perl_call_norv(const char *method, int argc, const char *const *argv) 508 { 509 int i; 510 OWL_PERL_CALL(call_pv(method, G_DISCARD|G_EVAL) 511 , 512 OWL_PERL_PUSH_ARGS(i, argc, argv); 513 , 514 "Perl Error: '%s'" 515 , 516 false 517 , 518 true 519 , 520 ); 476 521 } 477 522 … … 479 524 CALLER_OWN char *owl_perlconfig_perlcmd(const owl_cmd *cmd, int argc, const char *const *argv) 480 525 { 481 int i, count; 482 char * ret = NULL; 483 SV *rv; 484 dSP; 485 486 ENTER; 487 SAVETMPS; 488 489 PUSHMARK(SP); 490 for(i=0;i<argc;i++) { 491 XPUSHs(sv_2mortal(owl_new_sv(argv[i]))); 492 } 493 PUTBACK; 494 495 count = call_sv(cmd->cmd_perl, G_SCALAR|G_EVAL); 496 497 SPAGAIN; 498 499 if(SvTRUE(ERRSV)) { 500 owl_function_error("%s", SvPV_nolen(ERRSV)); 501 (void)POPs; 502 } else { 503 if(count != 1) 504 croak("Perl command %s returned more than one value!", cmd->name); 505 rv = POPs; 506 if(SvTRUE(rv)) { 507 ret = g_strdup(SvPV_nolen(rv)); 508 } 509 } 510 511 FREETMPS; 512 LEAVE; 513 514 return ret; 526 int i; 527 SV* rv; 528 char *out = NULL; 529 530 OWL_PERL_CALL(call_sv(cmd->cmd_perl, G_SCALAR|G_EVAL) 531 , 532 OWL_PERL_PUSH_ARGS(i, argc, argv); 533 , 534 "Perl Error: '%s'" 535 , 536 false 537 , 538 false 539 , 540 rv = POPs; 541 if (rv && SvPOK(rv)) 542 out = g_strdup(SvPV_nolen(rv)); 543 ); 544 return out; 515 545 } 516 546 … … 520 550 } 521 551 522 void owl_perlconfig_edit_callback(owl_editwin *e )552 void owl_perlconfig_edit_callback(owl_editwin *e, bool success) 523 553 { 524 554 SV *cb = owl_editwin_get_cbdata(e); 525 SV *text; 526 dSP; 527 528 if(cb == NULL) { 555 SV *text = owl_new_sv(owl_editwin_get_text(e)); 556 557 if (cb == NULL) { 529 558 owl_function_error("Perl callback is NULL!"); 530 559 return; 531 560 } 532 text = owl_new_sv(owl_editwin_get_text(e)); 533 534 ENTER; 535 SAVETMPS; 536 537 PUSHMARK(SP); 538 XPUSHs(sv_2mortal(text)); 539 PUTBACK; 540 541 call_sv(cb, G_DISCARD|G_EVAL); 542 543 if(SvTRUE(ERRSV)) { 544 owl_function_error("%s", SvPV_nolen(ERRSV)); 545 } 546 547 FREETMPS; 548 LEAVE; 561 562 OWL_PERL_CALL(call_sv(cb, G_DISCARD|G_EVAL) 563 , 564 XPUSHs(sv_2mortal(text)); 565 XPUSHs(sv_2mortal(newSViv(success))); 566 , 567 "Perl Error: '%s'" 568 , 569 false 570 , 571 true 572 , 573 ); 549 574 } 550 575
Note: See TracChangeset
for help on using the changeset viewer.