PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/dba - dba_flatfile.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 67 73 91.8 %
Date: 2014-10-24 Functions: 11 11 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 5                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2014 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Author: Marcus Boerger <helly@php.net>                               |
      16             :    +----------------------------------------------------------------------+
      17             :  */
      18             : 
      19             : /* $Id$ */
      20             : 
      21             : #ifdef HAVE_CONFIG_H
      22             : #include "config.h"
      23             : #endif
      24             : 
      25             : #include "php.h"
      26             : 
      27             : #if DBA_FLATFILE
      28             : #include "php_flatfile.h"
      29             : 
      30             : #include "libflatfile/flatfile.h"
      31             : 
      32             : #ifdef HAVE_UNISTD_H
      33             : #include <unistd.h>
      34             : #endif
      35             : #include <sys/types.h>
      36             : #include <sys/stat.h>
      37             : #include <fcntl.h>
      38             : 
      39             : #define FLATFILE_DATA flatfile *dba = info->dbf
      40             : #define FLATFILE_GKEY datum gkey; gkey.dptr = (char *) key; gkey.dsize = keylen
      41             : 
      42          36 : DBA_OPEN_FUNC(flatfile)
      43             : {
      44          36 :         info->dbf = pemalloc(sizeof(flatfile), info->flags&DBA_PERSISTENT);
      45          36 :         memset(info->dbf, 0, sizeof(flatfile));
      46             : 
      47          36 :         ((flatfile*)info->dbf)->fp = info->fp;
      48             : 
      49          36 :         return SUCCESS;
      50             : }
      51             : 
      52          36 : DBA_CLOSE_FUNC(flatfile)
      53             : {
      54          36 :         FLATFILE_DATA;
      55             : 
      56          36 :         if (dba->nextkey.dptr) {
      57           0 :                 efree(dba->nextkey.dptr);
      58             :         }
      59          36 :         pefree(dba, info->flags&DBA_PERSISTENT);
      60          36 : }
      61             : 
      62          34 : DBA_FETCH_FUNC(flatfile)
      63             : {
      64             :         datum gval;
      65          34 :         char *new = NULL;
      66             : 
      67          34 :         FLATFILE_DATA;
      68          34 :         FLATFILE_GKEY;
      69             : 
      70          34 :         gval = flatfile_fetch(dba, gkey TSRMLS_CC);
      71          34 :         if (gval.dptr) {
      72          34 :                 if (newlen) {
      73          34 :                         *newlen = gval.dsize;
      74             :                 }
      75          34 :                 new = estrndup(gval.dptr, gval.dsize);
      76          34 :                 efree(gval.dptr);
      77             :         }
      78          34 :         return new;
      79             : }
      80             : 
      81          66 : DBA_UPDATE_FUNC(flatfile)
      82             : {
      83             :         datum gval;
      84             : 
      85          66 :         FLATFILE_DATA;
      86          66 :         FLATFILE_GKEY;
      87          66 :         gval.dptr = (char *) val;
      88          66 :         gval.dsize = vallen;
      89             :         
      90          66 :         switch(flatfile_store(dba, gkey, gval, mode==1 ? FLATFILE_INSERT : FLATFILE_REPLACE TSRMLS_CC)) {
      91             :         case -1:
      92           0 :                 php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Operation not possible");
      93           0 :                 return FAILURE;
      94             :         default:
      95             :         case 0:
      96          62 :                 return SUCCESS;
      97             :         case 1:
      98           4 :                 php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Key already exists");
      99           4 :                 return FAILURE;
     100             :         }
     101             : }
     102             : 
     103          41 : DBA_EXISTS_FUNC(flatfile)
     104             : {
     105             :         datum gval;
     106          41 :         FLATFILE_DATA;
     107          41 :         FLATFILE_GKEY;
     108             :         
     109          41 :         gval = flatfile_fetch(dba, gkey TSRMLS_CC);
     110          41 :         if (gval.dptr) {
     111          30 :                 efree(gval.dptr);
     112          30 :                 return SUCCESS;
     113             :         }
     114          11 :         return FAILURE;
     115             : }
     116             : 
     117          14 : DBA_DELETE_FUNC(flatfile)
     118             : {
     119          14 :         FLATFILE_DATA;
     120          14 :         FLATFILE_GKEY;
     121          14 :         return(flatfile_delete(dba, gkey TSRMLS_CC) == -1 ? FAILURE : SUCCESS);
     122             : }
     123             : 
     124          13 : DBA_FIRSTKEY_FUNC(flatfile)
     125             : {
     126          13 :         FLATFILE_DATA;
     127             : 
     128          13 :         if (dba->nextkey.dptr) {
     129           0 :                 efree(dba->nextkey.dptr);
     130             :         }
     131          13 :         dba->nextkey = flatfile_firstkey(dba TSRMLS_CC);
     132          13 :         if (dba->nextkey.dptr) {
     133          13 :                 if (newlen)  {
     134          13 :                         *newlen = dba->nextkey.dsize;
     135             :                 }
     136          13 :                 return estrndup(dba->nextkey.dptr, dba->nextkey.dsize);
     137             :         }
     138           0 :         return NULL;
     139             : }
     140             : 
     141          42 : DBA_NEXTKEY_FUNC(flatfile)
     142             : {
     143          42 :         FLATFILE_DATA;
     144             :         
     145          42 :         if (!dba->nextkey.dptr) {
     146           0 :                 return NULL;
     147             :         }
     148             :         
     149          42 :         if (dba->nextkey.dptr) {
     150          42 :                 efree(dba->nextkey.dptr);
     151             :         }
     152          42 :         dba->nextkey = flatfile_nextkey(dba TSRMLS_CC);
     153          42 :         if (dba->nextkey.dptr) {
     154          29 :                 if (newlen) {
     155          29 :                         *newlen = dba->nextkey.dsize;
     156             :                 }
     157          29 :                 return estrndup(dba->nextkey.dptr, dba->nextkey.dsize);
     158             :         }
     159          13 :         return NULL;
     160             : }
     161             : 
     162           1 : DBA_OPTIMIZE_FUNC(flatfile)
     163             : {
     164             :         /* dummy */
     165           1 :         return SUCCESS;
     166             : }
     167             : 
     168           1 : DBA_SYNC_FUNC(flatfile)
     169             : {
     170             :         /* dummy */
     171           1 :         return SUCCESS;
     172             : }
     173             : 
     174           2 : DBA_INFO_FUNC(flatfile)
     175             : {
     176           2 :         return estrdup(flatfile_version());
     177             : }
     178             : 
     179             : #endif
     180             : 
     181             : /*
     182             :  * Local variables:
     183             :  * tab-width: 4
     184             :  * c-basic-offset: 4
     185             :  * End:
     186             :  * vim600: sw=4 ts=4 fdm=marker
     187             :  * vim<600: sw=4 ts=4
     188             :  */

Generated by: LCOV version 1.10

Generated at Fri, 24 Oct 2014 05:21:45 +0000 (15 hours ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.