source: lib/json_util.c @ 286cd48

Last change on this file since 286cd48 was 0e788f5, checked in by Wilmer van der Gaast <wilmer@…>, at 2013-02-21T19:15:59Z

I'm still bored on a long flight. Wrote a script to automatically update
my copyright mentions since some were getting pretty stale. Left files not
touched since before 2012 alone so that this change doesn't touch almost
EVERY source file.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/***************************************************************************\
2*                                                                           *
3*  BitlBee - An IRC to IM gateway                                           *
4*  Helper functions for json.c                                              *
5*                                                                           *
6*  Copyright 2012-2012 Wilmer van der Gaast <wilmer@gaast.net>              *
7*                                                                           *
8*  This library is free software; you can redistribute it and/or            *
9*  modify it under the terms of the GNU Lesser General Public               *
10*  License as published by the Free Software Foundation, version            *
11*  2.1.                                                                     *
12*                                                                           *
13*  This library is distributed in the hope that it will be useful,          *
14*  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
15*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        *
16*  Lesser General Public License for more details.                          *
17*                                                                           *
18*  You should have received a copy of the GNU Lesser General Public License *
19*  along with this library; if not, write to the Free Software Foundation,  *
20*  Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA           *
21*                                                                           *
22****************************************************************************/
23
24#include <stdlib.h>
25#include <string.h>
26#include <glib.h>
27
28#include "json_util.h"
29
30json_value *json_o_get( const json_value *obj, const json_char *name )
31{ 
32        int i;
33       
34        if( !obj || obj->type != json_object )
35                return NULL;
36
37        for( i = 0; i < obj->u.object.length; ++ i)
38                if( strcmp( obj->u.object.values[i].name, name ) == 0 )
39                        return obj->u.object.values[i].value;
40
41        return NULL;
42}
43
44const char *json_o_str( const json_value *obj, const json_char *name )
45{ 
46        json_value *ret = json_o_get( obj, name );
47       
48        if( ret && ret->type == json_string )
49                return ret->u.string.ptr;
50        else
51                return NULL;
52}
53
54char *json_o_strdup( const json_value *obj, const json_char *name )
55{
56        json_value *ret = json_o_get( obj, name );
57       
58        if( ret && ret->type == json_string && ret->u.string.ptr )
59                return g_memdup( ret->u.string.ptr, ret->u.string.length + 1 );
60        else
61                return NULL;
62}
Note: See TracBrowser for help on using the repository browser.