mgxapp/lib/tools.c
/*
	The next few function take a buffer with existing json, add name/value pair to it where value
	is a string, int, float, bool.  Flags is  MT_FL_OPEN  or MT_FL_CLOSE which causes either a
	leading or trailing curly brace to be added. Len is the max size of the
	buffer being constructed.

	They all return a pointer to the buf as a convenience.

	These are NOT efficent as they perform a strlen() call on the existing string for
	each call.  The assumption is that the munckin isn't "high speed" and so this won't
	matter, but it shouldn not be too difficult to improve the performance down the road
	if it becomes necessary; suggisness was selected for ease of coding.
*/
The next few function take a buffer with existing json, add name/value pair to it where value
is a string, int, float, bool.  Flags is  MT_FL_OPEN  or MT_FL_CLOSE which causes either a
leading or trailing curly brace to be added. Len is the max size of the
buffer being constructed.

They all return a pointer to the buf as a convenience.

These are NOT efficent as they perform a strlen() call on the existing string for
each call.  The assumption is that the munckin isn't "high speed" and so this won't
matter, but it shouldn not be too difficult to improve the performance down the road
if it becomes necessary; suggisness was selected for ease of coding.
The next few function take a buffer with existing json add name / value pair to it where value is a string int float bool . Flags is MT_FL_OPEN or MT_FL_CLOSE which causes either a leading or trailing curly brace to be added . Len is the max size of the buffer being constructed . They all return a pointer to the buf as a convenience . These are NOT efficent as they perform a strlen () call on the existing string for each call . The assumption is that the munckin isn ' t " high speed " and so this won ' t matter but it shouldn not be too difficult to improve the performance down the road if it becomes necessary ; suggisness was selected for ease of coding .
extern char* json_add_string( char* buf, int len, const char* name, const char* value, int flags ) {
	char	newstr[1024];
	int		nlen = 0;
	if( name != NULL && value != NULL )  {
		set_ht( flags );
		nlen = mt_snprintf( newstr, sizeof( newstr ), "%s%q: %q%s", header, name, value, trailer );
		if( (strlen( buf ) + nlen + 1) < len ) {
			strcat( buf, newstr );
		}
	}
	return buf;
}
extern char * json_add_string ( char * buf , int len , const char * name , const char * value , int flags ) { char newstr [ 1024 ] ; int nlen = 0 ; if ( name != NULL && value != NULL ) { set_ht ( flags ) ; nlen = mt_snprintf ( newstr , sizeof ( newstr ) , " " , header , name , value , trailer ) ; if ( ( strlen ( buf ) + nlen + 1 ) < len ) { strcat ( buf , newstr ) ; } } return buf ; }
The next few function take a buffer with existing json, add name/value pair to it where value
is a string, int, float, bool.
The next few function take a buffer with existing json add name / value pair to it where value is a string int float bool .