1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) many different people. If you wrote this, please
6 * acknowledge your work.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29 * Gets the next package field from package_buffer, seperated into the field name
30 * and field value, it returns the int offset to the first character of the next field
32 int read_package_field(const char *package_buffer, char **field_name, char **field_value)
34 int offset_name_start = 0;
35 int offset_name_end = 0;
36 int offset_value_start = 0;
37 int offset_value_end = 0;
42 int exit_flag = FALSE;
44 if (package_buffer == NULL) {
50 next_offset = offset + 1;
51 switch (package_buffer[offset]) {
56 if (offset_name_end == 0) {
57 offset_name_end = offset;
58 offset_value_start = next_offset;
60 /* TODO: Name might still have trailing spaces if ':' isnt
61 * immediately after name */
64 /* TODO: The char next_offset may be out of bounds */
65 if (package_buffer[next_offset] != ' ') {
71 /* increment the value start point if its a just filler */
72 if (offset_name_start == offset) {
75 if (offset_value_start == offset) {
80 if (exit_flag == TRUE) {
81 /* Check that the names are valid */
82 offset_value_end = offset;
83 name_length = offset_name_end - offset_name_start;
84 value_length = offset_value_end - offset_value_start;
85 if (name_length == 0) {
88 if ((name_length > 0) && (value_length > 0)) {
92 /* If not valid, start fresh with next field */
94 offset_name_start = offset + 1;
96 offset_value_start = offset + 1;
97 offset_value_end = offset + 1;
102 if (name_length == 0) {
105 *field_name = xstrndup(&package_buffer[offset_name_start], name_length);
107 if (value_length > 0) {
108 *field_value = xstrndup(&package_buffer[offset_value_start], value_length);