diff options
| author | 2008-12-01 21:23:58 +0100 | |
|---|---|---|
| committer | 2008-12-01 21:23:58 +0100 | |
| commit | 7563917755cf58cee80fbd5bc56a1ab0f563963a (patch) | |
| tree | b393259faad8a7f6c1e6e89764b0e25ce118765a /src/plist.c | |
| parent | 36eff97cba9049ce7ec194cb4f8926c7876368eb (diff) | |
| download | libimobiledevice-7563917755cf58cee80fbd5bc56a1ab0f563963a.tar.gz libimobiledevice-7563917755cf58cee80fbd5bc56a1ab0f563963a.tar.bz2 | |
cleanup unused functions.
Diffstat (limited to 'src/plist.c')
| -rw-r--r-- | src/plist.c | 153 |
1 files changed, 8 insertions, 145 deletions
diff --git a/src/plist.c b/src/plist.c index 1c00cc6..5d8fc0e 100644 --- a/src/plist.c +++ b/src/plist.c | |||
| @@ -101,151 +101,6 @@ void free_plist(xmlDocPtr plist) | |||
| 101 | xmlFreeDoc(plist); | 101 | xmlFreeDoc(plist); |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | /** Adds a new node as a child to a given node. | ||
| 105 | * | ||
| 106 | * This is a lower level function so you probably want to use | ||
| 107 | * add_key_str_dict_element, add_key_dict_node or add_key_data_dict_element | ||
| 108 | * instead. | ||
| 109 | * | ||
| 110 | * @param plist The plist XML document to which the to_node belongs. | ||
| 111 | * @param name The name of the new node. | ||
| 112 | * @param content The string containing the text node of the new node. | ||
| 113 | * @param to_node The node to attach the child node to. If none is given, the | ||
| 114 | * root node of the given document is used. | ||
| 115 | * @param depth The number of tabs to indent the new node. | ||
| 116 | * | ||
| 117 | * @return The newly created node. | ||
| 118 | */ | ||
| 119 | xmlNode *add_child_to_plist(xmlDocPtr plist, const char *name, const char *content, xmlNode * to_node, int depth) | ||
| 120 | { | ||
| 121 | int i = 0; | ||
| 122 | xmlNode *child; | ||
| 123 | |||
| 124 | if (!plist) | ||
| 125 | return NULL; | ||
| 126 | assert(depth >= 0); | ||
| 127 | if (!to_node) | ||
| 128 | to_node = xmlDocGetRootElement(plist); | ||
| 129 | |||
| 130 | for (i = 0; i < depth; i++) { | ||
| 131 | xmlNodeAddContent(to_node, "\t"); | ||
| 132 | } | ||
| 133 | child = xmlNewChild(to_node, NULL, name, content); | ||
| 134 | xmlNodeAddContent(to_node, "\n"); | ||
| 135 | |||
| 136 | return child; | ||
| 137 | } | ||
| 138 | |||
| 139 | /** Adds a string key-pair to a plist XML document. | ||
| 140 | * | ||
| 141 | * @param plist The plist XML document to add the new node to. | ||
| 142 | * @param dict The dictionary node within the plist XML document to add the new node to. | ||
| 143 | * @param key The string containing the key value. | ||
| 144 | * @param value The string containing the value. | ||
| 145 | * @param depth The number of tabs to indent the new node. | ||
| 146 | * | ||
| 147 | * @return The newly created key node. | ||
| 148 | */ | ||
| 149 | xmlNode *add_key_str_dict_element(xmlDocPtr plist, xmlNode * dict, const char *key, const char *value, int depth) | ||
| 150 | { | ||
| 151 | xmlNode *keyPtr; | ||
| 152 | |||
| 153 | keyPtr = add_child_to_plist(plist, "key", key, dict, depth); | ||
| 154 | add_child_to_plist(plist, "string", value, dict, depth); | ||
| 155 | |||
| 156 | return keyPtr; | ||
| 157 | } | ||
| 158 | |||
| 159 | /** Adds a new dictionary key-pair to a plist XML document. | ||
| 160 | * | ||
| 161 | * @param plist The plist XML document to add the new node to. | ||
| 162 | * @param dict The dictionary node within the plist XML document to add the new node to. | ||
| 163 | * @param key The string containing the key value. | ||
| 164 | * @param value The string containing the value. | ||
| 165 | * @param depth The number of tabs to indent the new node. | ||
| 166 | * | ||
| 167 | * @return The newly created dict node. | ||
| 168 | */ | ||
| 169 | xmlNode *add_key_dict_node(xmlDocPtr plist, xmlNode * dict, const char *key, const char *value, int depth) | ||
| 170 | { | ||
| 171 | xmlNode *child; | ||
| 172 | |||
| 173 | add_child_to_plist(plist, "key", key, dict, depth); | ||
| 174 | child = add_child_to_plist(plist, "dict", value, dict, depth); | ||
| 175 | |||
| 176 | return child; | ||
| 177 | } | ||
| 178 | |||
| 179 | /** Adds a new data dictionary key-pair to a plist XML document. | ||
| 180 | * | ||
| 181 | * @param plist The plist XML document to add the new node to. | ||
| 182 | * @param dict The dictionary node within the plist XML document to add the new node to. | ||
| 183 | * @param key The string containing the key value. | ||
| 184 | * @param value The string containing the value. | ||
| 185 | * @param depth The number of tabs to indent the new node. | ||
| 186 | * | ||
| 187 | * @return The newly created key node. | ||
| 188 | */ | ||
| 189 | xmlNode *add_key_data_dict_element(xmlDocPtr plist, xmlNode * dict, const char *key, const char *value, int depth) | ||
| 190 | { | ||
| 191 | xmlNode *keyPtr; | ||
| 192 | |||
| 193 | keyPtr = add_child_to_plist(plist, "key", key, dict, depth); | ||
| 194 | add_child_to_plist(plist, "data", format_string(value, 60, depth), dict, depth); | ||
| 195 | |||
| 196 | return keyPtr; | ||
| 197 | } | ||
| 198 | |||
| 199 | /** Reads a set of keys and strings into an array from a plist XML document. | ||
| 200 | * | ||
| 201 | * @param dict The root XMLNode of a plist XML document to be read. | ||
| 202 | * | ||
| 203 | * @return An array where each even number is a key and the odd numbers are | ||
| 204 | * values. If the odd number is \0, that's the end of the list. | ||
| 205 | */ | ||
| 206 | char **read_dict_element_strings(xmlNode * dict) | ||
| 207 | { | ||
| 208 | char **return_me = NULL, **old = NULL; | ||
| 209 | int current_length = 0; | ||
| 210 | int current_pos = 0; | ||
| 211 | xmlNode *dict_walker; | ||
| 212 | |||
| 213 | for (dict_walker = dict->children; dict_walker; dict_walker = dict_walker->next) { | ||
| 214 | if (!xmlStrcmp(dict_walker->name, "key")) { | ||
| 215 | current_length += 2; | ||
| 216 | old = return_me; | ||
| 217 | return_me = realloc(return_me, sizeof(char *) * current_length); | ||
| 218 | if (!return_me) { | ||
| 219 | free(old); | ||
| 220 | return NULL; | ||
| 221 | } | ||
| 222 | return_me[current_pos++] = xmlNodeGetContent(dict_walker); | ||
| 223 | return_me[current_pos++] = xmlNodeGetContent(dict_walker->next->next); | ||
| 224 | } | ||
| 225 | } | ||
| 226 | |||
| 227 | old = return_me; | ||
| 228 | return_me = realloc(return_me, sizeof(char *) * (current_length + 1)); | ||
| 229 | return_me[current_pos] = NULL; | ||
| 230 | |||
| 231 | return return_me; | ||
| 232 | } | ||
| 233 | |||
| 234 | /** Destroys a dictionary as returned by read_dict_element_strings | ||
| 235 | */ | ||
| 236 | void free_dictionary(char **dictionary) | ||
| 237 | { | ||
| 238 | int i = 0; | ||
| 239 | |||
| 240 | if (!dictionary) | ||
| 241 | return; | ||
| 242 | |||
| 243 | for (i = 0; dictionary[i]; i++) { | ||
| 244 | free(dictionary[i]); | ||
| 245 | } | ||
| 246 | |||
| 247 | free(dictionary); | ||
| 248 | } | ||
| 249 | 104 | ||
| 250 | /* | 105 | /* |
| 251 | * Binary propertylist code follows | 106 | * Binary propertylist code follows |
| @@ -357,6 +212,14 @@ void plist_new_array_in_plist(plist_t plist, int length, plist_type type, void * | |||
| 357 | { | 212 | { |
| 358 | } | 213 | } |
| 359 | 214 | ||
| 215 | /** Adds a new key pair to a dict. | ||
| 216 | * | ||
| 217 | * @param dict The dict node in the plist. | ||
| 218 | * @param key the key name of the key pair. | ||
| 219 | * @param type The the type of the value in the key pair. | ||
| 220 | * @param value a pointer to the actual buffer containing the value. WARNING : the buffer is supposed to match the type of the value | ||
| 221 | * | ||
| 222 | */ | ||
| 360 | void plist_add_dict_element(dict_t dict, char *key, plist_type type, void *value) | 223 | void plist_add_dict_element(dict_t dict, char *key, plist_type type, void *value) |
| 361 | { | 224 | { |
| 362 | if (!dict || !key || !value) | 225 | if (!dict || !key || !value) |
