-/* -*- mode: C; c-file-style: "gnu" -*- */
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* desktop-file.c .desktop file parser
*
* Copyright (C) 2003 CodeFactory AB
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
+
+#include <config.h>
#include <dbus/dbus-sysdeps.h>
#include <dbus/dbus-internals.h>
#include "desktop-file.h"
#define VALID_KEY_CHAR 1
#define VALID_LOCALE_CHAR 2
-unsigned char valid[256] = {
+static unsigned char valid[256] = {
0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ,
0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ,
0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x3 , 0x2 , 0x0 ,
line = §ion->lines[section->n_lines++];
- memset (line, 0, sizeof (BusDesktopFileLine));
+ _DBUS_ZERO(*line);
return line;
}
static void
parse_comment_or_blank (BusDesktopFileParser *parser)
{
- int line_end;
+ int line_end, eol_len;
- if (!_dbus_string_find (&parser->data, parser->pos, "\n", &line_end))
+ if (!_dbus_string_find_eol (&parser->data, parser->pos, &line_end, &eol_len))
line_end = parser->len;
if (line_end == parser->len)
parser->pos = parser->len;
else
- parser->pos = line_end + 1;
+ parser->pos = line_end + eol_len;
parser->line_num += 1;
}
static dbus_bool_t
parse_section_start (BusDesktopFileParser *parser, DBusError *error)
{
- int line_end;
+ int line_end, eol_len;
char *section_name;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
- if (!_dbus_string_find (&parser->data, parser->pos, "\n", &line_end))
+
+ if (!_dbus_string_find_eol (&parser->data, parser->pos, &line_end, &eol_len))
line_end = parser->len;
if (line_end - parser->pos <= 2 ||
if (line_end == parser->len)
parser->pos = parser->len;
else
- parser->pos = line_end + 1;
+ parser->pos = line_end + eol_len;
parser->line_num += 1;
static dbus_bool_t
parse_key_value (BusDesktopFileParser *parser, DBusError *error)
{
- int line_end;
+ int line_end, eol_len;
int key_start, key_end;
int value_start;
int p;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- if (!_dbus_string_find (&parser->data, parser->pos, "\n", &line_end))
+ if (!_dbus_string_find_eol (&parser->data, parser->pos, &line_end, &eol_len))
line_end = parser->len;
p = parser->pos;
if (line_end == parser->len)
parser->pos = parser->len;
else
- parser->pos = line_end + 1;
+ parser->pos = line_end + eol_len;
parser->line_num += 1;
if (line_end == parser->len)
parser->pos = parser->len;
else
- parser->pos = line_end + 1;
+ parser->pos = line_end + eol_len;
parser->line_num += 1;
else if (is_blank_line (&parser) ||
_dbus_string_get_byte (&parser.data, parser.pos) == '#')
parse_comment_or_blank (&parser);
+ else if (parser.current_section < 0)
+ {
+ dbus_set_error(error, DBUS_ERROR_FAILED,
+ "invalid service file: key=value before [Section]");
+ return NULL;
+ }
else
{
if (!parse_key_value (&parser, error))