rename mediaType to media_type, handle unknown langauges

master
teknomunk 1 year ago
parent b250dbfbf6
commit 7f73d77dd5

@ -91,7 +91,7 @@ struct ap_object* ap_object_dup( struct ap_object* act )
for( int i = 0; i < new_act->bcc.count; ++i ) {
new_act->bcc.items[i] = strdup(new_act->bcc.items[i]);
}
new_act->mediaType = safe_strdup(act->mediaType);
new_act->media_type = safe_strdup(act->media_type);
// PropertyValue-specific fields
new_act->value = safe_strdup(act->value);
@ -219,6 +219,7 @@ void ap_object_free_composite( struct ap_object* act )
free(act->bcc.items[i]);
}
free(act->bcc.items);
free( act->media_type );
free( act->state );

@ -199,7 +199,7 @@ struct ap_object
char** items;
int count;
} to, cc, bcc;
char* mediaType;
char* media_type;
// duration
// PropertyValue-specific fields

@ -23,6 +23,15 @@ static const char* langs[] = {
"ja",
};
const char* string_for_language( int lang )
{
if( lang == 0 ) { return NULL; }
if( lang == clang_unknown ) { return NULL; }
if( lang - 1 >= sizeof(langs)/sizeof(langs[0]) ) { return NULL; }
return langs[ lang - 1 ];
}
static bool context_eat( struct json_pull_parser* jpp, int* save )
{
json_pull_parser_read_value(jpp,NULL);
@ -121,9 +130,11 @@ static bool context_writer( struct json_writer* jw, const char* field_name, void
first = false;
json_write_string( jw->f, ctx->extra.items[i] );
}
if( ctx->language ) {
const char* lang_string = string_for_language( ctx->language );
if( lang_string ) {
if( !first ) { fprintf( jw->f, "," ); }
fprintf( jw->f, ",{ \"@language\":\"%s\"", langs[ctx->language-1] );
first = false;
fprintf( jw->f, "{\"@language\":\"%s\"}", lang_string );
}
if( items > 1 ) {

@ -197,7 +197,12 @@ struct json_object_field ap_object_layout[] = {
.type = &json_field_single_or_array_of,
.array_item_type = &json_field_string,
},
JSON_FIELD_STRING( mediaType, false ),
{
.key = "mediaType",
.offset = offsetof( OBJ_TYPE, media_type ),
.allow_drop_empty = true,
.type = &json_field_string,
},
// PropertyValue-specific fields
JSON_FIELD_STRING( value, false ),

Loading…
Cancel
Save