1 /* 2 * %CopyrightBegin% 3 * 4 * Copyright Ericsson AB 2003-2016. All Rights Reserved. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * %CopyrightEnd% 19 */ 20 21 typedef struct { 22 char *key; 23 char *value; /* Key and value points into same buffer */ 24 } InitEntry; 25 26 typedef struct { 27 int num_entries; 28 int size_entries; 29 char *section_name; 30 InitEntry **entries; 31 } InitSection; 32 33 typedef struct { 34 int num_sections; 35 int size_sections; 36 InitSection **sections; 37 } InitFile; 38 39 /* Load a file structure from a disk file */ 40 InitFile *load_init_file(wchar_t *filename); 41 42 /* Stores a file structure into a disk file */ 43 int store_init_file(InitFile *inif, wchar_t *filename); 44 45 /* Create an empty file structure */ 46 InitFile *create_init_file(void); 47 48 /* Free a file structure and everything associateed (including sections,keys 49 and values and anything looked up but not copied) */ 50 void free_init_file(InitFile *inif); 51 52 /* Create empty section */ 53 InitSection *create_init_section(char *section_name); 54 55 /* Add section to file Overwrites and destroys old sections with same key */ 56 int add_init_section(InitFile *inif, InitSection *inis); 57 58 /* Kills a named section from a file. Destroys so that previously looked up 59 sections (with this key) need to be copied before the delete */ 60 int delete_init_section(InitFile *inif, char *section_name); 61 62 /* lookup returns pointer into existing data. If data is to be preserved 63 across deletes or overwrites, it has to be copied */ 64 InitSection *lookup_init_section(InitFile *inif, char *section_name); 65 66 /* Returns the name of the nth init section, n is >= 0, ret NULL when done */ 67 char *nth_init_section_name(InitFile *inif, int n); 68 69 /* To save an init section so that delete or overwrite does not destroy it, 70 one needs to copy it */ 71 InitSection *copy_init_section(InitSection *inis, char *new_name); 72 73 /* Frees up everything in the section, keys and values as well. */ 74 void free_init_section(InitSection *inis); 75 76 /* Key and value are copied in add_entry */ 77 int add_init_entry(InitSection *inis, char *key, char *value); 78 79 /* Returns pointer into internal string, use strcpy to save across 80 updates/deletes */ 81 char *lookup_init_entry(InitSection *inis, char *key); 82 83 /* Returns the name of the nth entry key, n is >= 0, ret NULL when done */ 84 char *nth_init_entry_key(InitSection *inis, int n); 85 86 /* Destroys entry, prevoiusly looked up entries need be 87 copied before deleted */ 88 int delete_init_entry(InitSection *inis, char *key); 89 90 #define INIT_FILE_NO_ERROR 0 91 #define INIT_FILE_OPEN_ERROR -1 92 #define INIT_FILE_WRITE_ERROR -2 93 #define INIT_FILE_PRESENT 0 94 #define INIT_FILE_NOT_PRESENT 1 95