/***************************** {{{ LICENSE ********************************\ * dbobj, the relational object persistence module for PHP * * Copyright (C) 2006 Adam Banko * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * \***************************** LICENSE }}} ********************************/ #include "php_dbobj.h" #include "dbTypes.h" #include "dbType/char.h" #include "dbType/serial.h" #include "dbType/text.h" #include "dbType/int.h" typedef struct _dbType_modules_listItem { char* key; uint keyL; dbType_module* value; struct _dbType_modules_listItem* next; } *dbType_modules_listItem; /* names will be searhed in order, so order is important * inverse abc order ensures longer names are matched first */ dbType_modules_listItem dbType_modules = NULL; DBOBJ_API void dbType_register_module(dbType_module *module) { dbType_modules_listItem prev, curr, newitem; uint i; for(i = 0; i < module->namesL; i++ ) { newitem = pemalloc(sizeof(*newitem),1); newitem->key = module->names[i]; newitem->keyL = strlen(module->names[i]); newitem->value = module; for(prev=NULL, curr = dbType_modules; curr; curr = curr->next) { if(curr->keyL == newitem->keyL && strncmp(curr->key, newitem->key, newitem->keyL) < 0) break; prev = curr; } if(!prev) { newitem->next = dbType_modules; dbType_modules = newitem; } else { prev->next = newitem; newitem->next = curr; } } } DBOBJ_API dbType dbType_from_string(STRINGLD(s), char* key, char* tableName TSRMLS_DC) { dbType_modules_listItem p; for(p = dbType_modules; p; p = p->next) { if(strncmp(p->key, s, p->keyL) == 0) { return p->value->dbType_from_string(s, sL, key, tableName TSRMLS_CC); } } DBOBJ_ERROR("can't find handler for dbType '%s'",s); return NULL; } DBOBJ_API void php_dbobj_MINIT_dbTypes(TSRMLS_D) { dbType_register_module(&dbType_char_module); dbType_register_module(&dbType_serial_module); dbType_register_module(&dbType_text_module); dbType_register_module(&dbType_int_module); } /* * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */