Back to index

libcitadel  8.12
Classes | Defines | Functions | Variables
Variable substitution type stuff

Copyright (c) 1987-2011 by the citadel.org team. More...

Classes

struct  JsonValue

Defines

#define JSON_STRING   0
#define JSON_NUM   1
#define JSON_NULL   2
#define JSON_BOOL   3
#define JSON_ARRAY   4
#define JSON_OBJECT   7

Functions

void DeleteJSONValue (void *vJsonValue)
JsonValueNewJsonObject (const char *Key, long keylen)
JsonValueNewJsonArray (const char *Key, long keylen)
JsonValueNewJsonNumber (const char *Key, long keylen, long Number)
JsonValueNewJsonBigNumber (const char *Key, long keylen, double Number)
JsonValueNewJsonString (const char *Key, long keylen, StrBuf *CopyMe)
JsonValueNewJsonPlainString (const char *Key, long keylen, const char *CopyMe, long len)
JsonValueNewJsonNull (const char *Key, long keylen)
JsonValueNewJsonBool (const char *Key, long keylen, int value)
void JsonArrayAppend (JsonValue *Array, JsonValue *Val)
void JsonObjectAppend (JsonValue *Array, JsonValue *Val)
void SerializeJson (StrBuf *Target, JsonValue *Val, int FreeVal)

Variables

int JsonValue::Type
StrBufJsonValue::Name
StrBufJsonValue::Value
HashListJsonValue::SubValues

Detailed Description

Copyright (c) 1987-2011 by the citadel.org team.

This program is open source software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

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


Class Documentation

struct JsonValue

Definition at line 44 of file json.c.

Collaboration diagram for JsonValue:
Class Members
StrBuf * Name
HashList * SubValues
int Type
StrBuf * Value

Define Documentation

#define JSON_ARRAY   4

Definition at line 41 of file json.c.

#define JSON_BOOL   3

Definition at line 40 of file json.c.

#define JSON_NULL   2

Definition at line 39 of file json.c.

#define JSON_NUM   1

Definition at line 38 of file json.c.

#define JSON_OBJECT   7

Definition at line 42 of file json.c.

#define JSON_STRING   0

Definition at line 37 of file json.c.


Function Documentation

void DeleteJSONValue ( void *  vJsonValue)

Definition at line 52 of file json.c.

{
       JsonValue *Val = (JsonValue*) vJsonValue;
       FreeStrBuf(&Val->Name);
       FreeStrBuf(&Val->Value);
       DeleteHash(&Val->SubValues);
       free(Val);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void JsonArrayAppend ( JsonValue Array,
JsonValue Val 
)

Definition at line 173 of file json.c.

{
       long n;
       if (Array->Type != JSON_ARRAY)
              return; /* todo assert! */

       n = GetCount(Array->SubValues);
       Put(Array->SubValues, (const char*) &n, sizeof(n), Val, DeleteJSONValue);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void JsonObjectAppend ( JsonValue Array,
JsonValue Val 
)

Definition at line 183 of file json.c.

{
       if ((Array->Type != JSON_OBJECT) || (Val->Name == NULL))
              return; /* todo assert! */

       Put(Array->SubValues, SKEY(Val->Name), Val, DeleteJSONValue);
}

Here is the call graph for this function:

Here is the caller graph for this function:

JsonValue* NewJsonArray ( const char *  Key,
long  keylen 
)

Definition at line 74 of file json.c.

{
       JsonValue *Ret;

       Ret = (JsonValue*) malloc(sizeof(JsonValue));
       memset(Ret, 0, sizeof(JsonValue));
       Ret->Type = JSON_ARRAY;
       if (Key != NULL)
              Ret->Name = NewStrBufPlain(Key, keylen);
       Ret->SubValues = NewHash(1, Flathash);
       return Ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JsonValue* NewJsonBigNumber ( const char *  Key,
long  keylen,
double  Number 
)

Definition at line 104 of file json.c.

{
       JsonValue *Ret;

       Ret = (JsonValue*) malloc(sizeof(JsonValue));
       memset(Ret, 0, sizeof(JsonValue));
       Ret->Type = JSON_NUM;
       if (Key != NULL)
              Ret->Name = NewStrBufPlain(Key, keylen);
       Ret->Value = NewStrBufPlain(NULL, 128);
       StrBufPrintf(Ret->Value, "%f", Number);
       return Ret;
}

Here is the call graph for this function:

JsonValue* NewJsonBool ( const char *  Key,
long  keylen,
int  value 
)

Definition at line 157 of file json.c.

{
       JsonValue *Ret;

       Ret = (JsonValue*) malloc(sizeof(JsonValue));
       memset(Ret, 0, sizeof(JsonValue));
       Ret->Type = JSON_BOOL;
       if (Key != NULL)
              Ret->Name = NewStrBufPlain(Key, keylen);
       if (value)
              Ret->Value = NewStrBufPlain(HKEY("true"));
       else
              Ret->Value = NewStrBufPlain(HKEY("false"));
       return Ret;
}

Here is the call graph for this function:

JsonValue* NewJsonNull ( const char *  Key,
long  keylen 
)

Definition at line 144 of file json.c.

{
       JsonValue *Ret;

       Ret = (JsonValue*) malloc(sizeof(JsonValue));
       memset(Ret, 0, sizeof(JsonValue));
       Ret->Type = JSON_NULL;
       if (Key != NULL)
              Ret->Name = NewStrBufPlain(Key, keylen);
       Ret->Value = NewStrBufPlain(HKEY("nulll"));
       return Ret;
}

Here is the call graph for this function:

JsonValue* NewJsonNumber ( const char *  Key,
long  keylen,
long  Number 
)

Definition at line 88 of file json.c.

{
       JsonValue *Ret;

       Ret = (JsonValue*) malloc(sizeof(JsonValue));
       memset(Ret, 0, sizeof(JsonValue));
       Ret->Type = JSON_NUM;
       if (Key != NULL)
              Ret->Name = NewStrBufPlain(Key, keylen);
       Ret->Value = NewStrBufPlain(NULL, 64);
       StrBufPrintf(Ret->Value, "%ld", Number);
       return Ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JsonValue* NewJsonObject ( const char *  Key,
long  keylen 
)

Definition at line 61 of file json.c.

{
       JsonValue *Ret;

       Ret = (JsonValue*) malloc(sizeof(JsonValue));
       memset(Ret, 0, sizeof(JsonValue));
       Ret->Type = JSON_OBJECT;
       if (Key != NULL)
              Ret->Name = NewStrBufPlain(Key, keylen);
       Ret->SubValues = NewHash(1, NULL);
       return Ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JsonValue* NewJsonPlainString ( const char *  Key,
long  keylen,
const char *  CopyMe,
long  len 
)

Definition at line 131 of file json.c.

{
       JsonValue *Ret;

       Ret = (JsonValue*) malloc(sizeof(JsonValue));
       memset(Ret, 0, sizeof(JsonValue));
       Ret->Type = JSON_STRING;
       if (Key != NULL)
              Ret->Name = NewStrBufPlain(Key, keylen);
       Ret->Value = NewStrBufPlain(CopyMe, len);
       return Ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JsonValue* NewJsonString ( const char *  Key,
long  keylen,
StrBuf CopyMe 
)

Definition at line 118 of file json.c.

{
       JsonValue *Ret;

       Ret = (JsonValue*) malloc(sizeof(JsonValue));
       memset(Ret, 0, sizeof(JsonValue));
       Ret->Type = JSON_STRING;
       if (Key != NULL)
              Ret->Name = NewStrBufPlain(Key, keylen);
       Ret->Value = NewStrBufDup(CopyMe);
       return Ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void SerializeJson ( StrBuf Target,
JsonValue Val,
int  FreeVal 
)

Definition at line 195 of file json.c.

{
       void *vValue, *vPrevious;
       JsonValue *SubVal;
       HashPos *It;
       const char *Key;
       long keylen;


       switch (Val->Type) {
       case JSON_STRING:
              StrBufAppendBufPlain(Target, HKEY("\""), 0);
              StrECMAEscAppend(Target, Val->Value, NULL);
              StrBufAppendBufPlain(Target, HKEY("\""), 0);
              break;
       case JSON_NUM:
              StrBufAppendBuf(Target, Val->Value, 0);
              break;
       case JSON_BOOL:
              StrBufAppendBuf(Target, Val->Value, 0);
              break;
       case JSON_NULL:
              StrBufAppendBuf(Target, Val->Value, 0);
              break;
       case JSON_ARRAY:
              vPrevious = NULL;
              StrBufAppendBufPlain(Target, HKEY("["), 0);
              It = GetNewHashPos(Val->SubValues, 0);
              while (GetNextHashPos(Val->SubValues, 
                                  It,
                                  &keylen, &Key, 
                                  &vValue)){
                     if (vPrevious != NULL) 
                            StrBufAppendBufPlain(Target, HKEY(","), 0);

                     SubVal = (JsonValue*) vValue;
                     SerializeJson(Target, SubVal, 0);
                     vPrevious = vValue;
              }
              StrBufAppendBufPlain(Target, HKEY("]"), 0);
              DeleteHashPos(&It);
              break;
       case JSON_OBJECT:
              vPrevious = NULL;
              StrBufAppendBufPlain(Target, HKEY("{"), 0);
              It = GetNewHashPos(Val->SubValues, 0);
              while (GetNextHashPos(Val->SubValues, 
                                  It,
                                  &keylen, &Key, 
                                  &vValue)){
                     SubVal = (JsonValue*) vValue;

                     if (vPrevious != NULL) {
                            StrBufAppendBufPlain(Target, HKEY(","), 0);
                     }
                     StrBufAppendBufPlain(Target, HKEY("\""), 0);
                     StrBufAppendBuf(Target, SubVal->Name, 0);
                     StrBufAppendBufPlain(Target, HKEY("\":"), 0);

                     SerializeJson(Target, SubVal, 0);
                     vPrevious = vValue;
              }
              StrBufAppendBufPlain(Target, HKEY("}"), 0);
              DeleteHashPos(&It);
              break;
       }
       if(FreeVal) {
              DeleteJSONValue(Val);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 46 of file json.c.

Definition at line 48 of file json.c.

Definition at line 45 of file json.c.

Definition at line 47 of file json.c.