| 1 |
/* -*- Mode: c; c-basic-offset: 2 -*- |
| 2 |
* |
| 3 |
* redland-post.i - PHP SWIG helper routines |
| 4 |
* |
| 5 |
*/ |
| 6 |
|
| 7 |
|
| 8 |
#if PHP_MAJOR_VERSION >= 5 |
| 9 |
/* This file seems to have been added in PHP5 */ |
| 10 |
#include "zend_exceptions.h" |
| 11 |
#endif |
| 12 |
|
| 13 |
|
| 14 |
static librdf_world* librdf_php_get_world(void); |
| 15 |
|
| 16 |
/* When in PHP when being compiled by C */ |
| 17 |
static librdf_world* librdf_php_world; |
| 18 |
|
| 19 |
|
| 20 |
static librdf_world* |
| 21 |
librdf_php_get_world(void) |
| 22 |
{ |
| 23 |
return librdf_php_world; |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
static librdf_node* |
| 28 |
librdf_php_get_null_node(void) |
| 29 |
{ |
| 30 |
return NULL; |
| 31 |
} |
| 32 |
|
| 33 |
static librdf_uri* |
| 34 |
librdf_php_get_null_uri(void) |
| 35 |
{ |
| 36 |
return NULL; |
| 37 |
} |
| 38 |
|
| 39 |
static raptor_locator librdf_php_locator; |
| 40 |
static int librdf_php_log_level=0; |
| 41 |
static int librdf_php_log_code=0; |
| 42 |
static char* librdf_php_log_message=NULL; |
| 43 |
|
| 44 |
static zend_class_entry* redland_exception_ptr=NULL; |
| 45 |
|
| 46 |
static int |
| 47 |
librdf_php_last_log_level(void) |
| 48 |
{ |
| 49 |
return librdf_php_log_level; |
| 50 |
} |
| 51 |
|
| 52 |
static int |
| 53 |
librdf_php_last_log_code(void) |
| 54 |
{ |
| 55 |
return librdf_php_log_code; |
| 56 |
} |
| 57 |
|
| 58 |
static char* |
| 59 |
librdf_php_last_log_message(void) |
| 60 |
{ |
| 61 |
return librdf_php_log_message; |
| 62 |
} |
| 63 |
|
| 64 |
void |
| 65 |
librdf_php_free_last_log(void) |
| 66 |
{ |
| 67 |
librdf_php_log_level=0; |
| 68 |
librdf_php_log_code=0; |
| 69 |
if(librdf_php_log_message) |
| 70 |
free(librdf_php_log_message); |
| 71 |
librdf_php_log_message=NULL; |
| 72 |
} |
| 73 |
|
| 74 |
static int |
| 75 |
librdf_php_logger_handler(void *user_data, librdf_log_message *log_msg) |
| 76 |
{ |
| 77 |
raptor_locator* locator = log_msg->locator; |
| 78 |
|
| 79 |
if(librdf_php_locator.file) |
| 80 |
free((char*)librdf_php_locator.file); |
| 81 |
if(librdf_php_locator.uri) |
| 82 |
raptor_free_uri(librdf_php_locator.uri); |
| 83 |
if(librdf_php_log_message) |
| 84 |
free(librdf_php_log_message); |
| 85 |
|
| 86 |
if(locator) { |
| 87 |
memcpy(&librdf_php_locator, locator, sizeof(raptor_locator)); |
| 88 |
if(locator->file) |
| 89 |
librdf_php_locator.file=strdup(locator->file); |
| 90 |
if(locator->uri) |
| 91 |
librdf_php_locator.uri=raptor_uri_copy(locator->uri); |
| 92 |
} else |
| 93 |
memset(&librdf_php_locator, '\0', sizeof(raptor_locator)); |
| 94 |
|
| 95 |
librdf_php_log_level=log_msg->level; |
| 96 |
librdf_php_log_code=log_msg->code; |
| 97 |
librdf_php_log_message=strdup(log_msg->message); |
| 98 |
|
| 99 |
return 1; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
void |
| 104 |
librdf_php_check_exception(void) |
| 105 |
{ |
| 106 |
if(!librdf_php_log_message) |
| 107 |
return; |
| 108 |
|
| 109 |
#if PHP_MAJOR_VERSION >= 5 |
| 110 |
if(librdf_php_log_level >= LIBRDF_LOG_WARN) |
| 111 |
zend_throw_exception(redland_exception_ptr, |
| 112 |
librdf_php_log_message, |
| 113 |
librdf_php_log_code TSRMLS_CC); |
| 114 |
#endif |
| 115 |
|
| 116 |
librdf_php_log_code=0; |
| 117 |
librdf_php_log_message=NULL; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
void |
| 122 |
librdf_php_world_init(void) |
| 123 |
{ |
| 124 |
if(!librdf_php_world) { |
| 125 |
zend_class_entry ee_ce; |
| 126 |
zend_class_entry *exception_ce; |
| 127 |
|
| 128 |
librdf_php_world=librdf_new_world(); |
| 129 |
librdf_world_open(librdf_php_world); |
| 130 |
|
| 131 |
#if PHP_MAJOR_VERSION >= 5 |
| 132 |
exception_ce = zend_exception_get_default(); |
| 133 |
INIT_CLASS_ENTRY(ee_ce, "RedlandException", NULL); |
| 134 |
redland_exception_ptr = zend_register_internal_class_ex(&ee_ce, |
| 135 |
exception_ce, |
| 136 |
NULL TSRMLS_CC); |
| 137 |
#endif |
| 138 |
|
| 139 |
memset(&librdf_php_locator, '\0', sizeof(raptor_locator)); |
| 140 |
librdf_php_log_code=0; |
| 141 |
librdf_php_log_message=NULL; |
| 142 |
|
| 143 |
librdf_world_set_logger(librdf_php_world, NULL, librdf_php_logger_handler); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
void |
| 148 |
librdf_php_world_set_logger(librdf_world *world) |
| 149 |
{ |
| 150 |
librdf_world_set_logger(world, NULL, librdf_php_logger_handler); |
| 151 |
} |
| 152 |
|
| 153 |
void |
| 154 |
librdf_php_world_finish(void) |
| 155 |
{ |
| 156 |
if(librdf_php_world) { |
| 157 |
librdf_free_world(librdf_php_world); |
| 158 |
librdf_php_world=NULL; |
| 159 |
} |
| 160 |
} |