Back to index

php5  5.3.10
Classes | Functions
inifile.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  key_type
struct  val_type
struct  line_type
struct  inifile

Functions

val_type inifile_fetch (inifile *dba, const key_type *key, int skip TSRMLS_DC)
int inifile_firstkey (inifile *dba TSRMLS_DC)
int inifile_nextkey (inifile *dba TSRMLS_DC)
int inifile_delete (inifile *dba, const key_type *key TSRMLS_DC)
int inifile_replace (inifile *dba, const key_type *key, const val_type *val TSRMLS_DC)
int inifile_append (inifile *dba, const key_type *key, const val_type *val TSRMLS_DC)
char * inifile_version ()
key_type inifile_key_split (const char *group_name)
char * inifile_key_string (const key_type *key)
void inifile_key_free (key_type *key)
void inifile_val_free (val_type *val)
void inifile_line_free (line_type *ln)
inifileinifile_alloc (php_stream *fp, int readonly, int persistent TSRMLS_DC)
void inifile_free (inifile *dba, int persistent)

Class Documentation

struct key_type

Definition at line 24 of file inifile.h.

Class Members
char * group
char * name
struct val_type

Definition at line 29 of file inifile.h.

Class Members
char * value
struct line_type

Definition at line 33 of file inifile.h.

Collaboration diagram for line_type:
Class Members
key_type key
size_t pos
val_type val
struct inifile

Definition at line 39 of file inifile.h.

Collaboration diagram for inifile:
Class Members
line_type curr
php_stream * fp
int lockfd
char * lockfn
line_type next
int readonly

Function Documentation

inifile* inifile_alloc ( php_stream *  fp,
int  readonly,
int persistent  TSRMLS_DC 
)

Definition at line 83 of file inifile.c.

{
       inifile *dba;

       if (!readonly) {
              if (!php_stream_truncate_supported(fp)) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't truncate this stream");
                     return NULL;
              }
       }
 
       dba = pemalloc(sizeof(inifile), persistent);
       memset(dba, 0, sizeof(inifile));
       dba->fp = fp;
       dba->readonly = readonly;
       return dba;
}

Here is the caller graph for this function:

int inifile_append ( inifile dba,
const key_type key,
const val_type *val  TSRMLS_DC 
)
int inifile_delete ( inifile dba,
const key_type *key  TSRMLS_DC 
)

Definition at line 565 of file inifile.c.

{
       return inifile_delete_replace_append(dba, key, NULL, 0 TSRMLS_CC);
}      

Here is the call graph for this function:

val_type inifile_fetch ( inifile dba,
const key_type key,
int skip  TSRMLS_DC 
)

Definition at line 246 of file inifile.c.

                                                                              {
       line_type ln = {{NULL,NULL},{NULL}};
       val_type val;
       int res, grp_eq = 0;

       if (skip == -1 && dba->next.key.group && dba->next.key.name && !inifile_key_cmp(&dba->next.key, key TSRMLS_CC)) {
              /* we got position already from last fetch */
              php_stream_seek(dba->fp, dba->next.pos, SEEK_SET);
       } else {
              /* specific instance or not same key -> restart search */
              /* the slow way: restart and seacrch */
              php_stream_rewind(dba->fp);
              inifile_line_free(&dba->next);
       }
       if (skip == -1) {
              skip = 0;
       }
       while(inifile_read(dba, &ln TSRMLS_CC)) {
              if (!(res=inifile_key_cmp(&ln.key, key TSRMLS_CC))) {
                     if (!skip) {
                            val.value = estrdup(ln.val.value ? ln.val.value : "");
                            /* allow faster access by updating key read into next */
                            inifile_line_free(&dba->next);
                            dba->next = ln;
                            dba->next.pos = php_stream_tell(dba->fp);
                            return val;
                     }
                     skip--;
              } else if (res == 1) {
                     grp_eq = 1;
              } else if (grp_eq) {
                     /* we are leaving group now: that means we cannot find the key */
                     break;
              }
       }
       inifile_line_free(&ln);
       dba->next.pos = php_stream_tell(dba->fp);
       return ln.val;
}

Here is the call graph for this function:

int inifile_firstkey ( inifile *dba  TSRMLS_DC)

Definition at line 289 of file inifile.c.

                                             {
       inifile_line_free(&dba->curr);
       dba->curr.pos = 0;
       return inifile_nextkey(dba TSRMLS_CC);
}

Here is the call graph for this function:

void inifile_free ( inifile dba,
int  persistent 
)

Definition at line 103 of file inifile.c.

{
       if (dba) {
              inifile_line_free(&dba->curr);
              inifile_line_free(&dba->next);
              pefree(dba, persistent);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void inifile_key_free ( key_type key)

Definition at line 51 of file inifile.c.

{
       if (key->group) {
              efree(key->group);
       }
       if (key->name) {
              efree(key->name);
       }
       memset(key, 0, sizeof(key_type));
}

Here is the caller graph for this function:

key_type inifile_key_split ( const char *  group_name)

Definition at line 114 of file inifile.c.

{
       key_type key;
       char *name;
       
       if (group_name[0] == '[' && (name = strchr(group_name, ']')) != NULL) {
              key.group = estrndup(group_name+1, name - (group_name + 1));
              key.name = estrdup(name+1);
       } else {
              key.group = estrdup("");
              key.name = estrdup(group_name);
       }
       return key;
}
char* inifile_key_string ( const key_type key)

Definition at line 131 of file inifile.c.

{
       if (key->group && *key->group) {
              char *result;
              spprintf(&result, 0, "[%s]%s", key->group, key->name ? key->name : "");
              return result;
       } else if (key->name) {
              return estrdup(key->name);
       } else {
              return NULL;
       }
}

Here is the call graph for this function:

void inifile_line_free ( line_type ln)

Definition at line 74 of file inifile.c.

{
       inifile_key_free(&ln->key);
       inifile_val_free(&ln->val);
       ln->pos = 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int inifile_nextkey ( inifile *dba  TSRMLS_DC)

Definition at line 298 of file inifile.c.

                                            {
       line_type ln = {{NULL,NULL},{NULL}};

       /*inifile_line_free(&dba->next); ??? */
       php_stream_seek(dba->fp, dba->curr.pos, SEEK_SET);
       ln.key.group = estrdup(dba->curr.key.group ? dba->curr.key.group : "");
       inifile_read(dba, &ln TSRMLS_CC);
       inifile_line_free(&dba->curr);
       dba->curr = ln;
       return ln.key.group || ln.key.name;
}      

Here is the call graph for this function:

Here is the caller graph for this function:

int inifile_replace ( inifile dba,
const key_type key,
const val_type *val  TSRMLS_DC 
)
void inifile_val_free ( val_type val)

Definition at line 64 of file inifile.c.

{
       if (val->value) {
              efree(val->value);
       }
       memset(val, 0, sizeof(val_type));
}

Here is the caller graph for this function:

char* inifile_version ( )

Definition at line 44 of file inifile.c.

{
       return "1.0, $Revision: 293036 $";
}