Browse code

jsonrpcs: use json null value for c null char* or str*

Daniel-Constantin Mierla authored on 22/02/2021 10:29:39
Showing 1 changed files
... ...
@@ -472,6 +472,7 @@ static srjson_t* jsonrpc_print_value(jsonrpc_ctx_t* ctx, char fmt, va_list* ap)
472 472
 	time_t dt;
473 473
 	struct tm t;
474 474
 	str *sp;
475
+	char *cp;
475 476
 
476 477
 	switch(fmt) {
477 478
 	case 'd':
... ...
@@ -497,11 +498,20 @@ static srjson_t* jsonrpc_print_value(jsonrpc_ctx_t* ctx, char fmt, va_list* ap)
497 498
 		nj = srjson_CreateString(ctx->jrpl, buf);
498 499
 		break;
499 500
 	case 's':
500
-		nj = srjson_CreateString(ctx->jrpl, va_arg(*ap, char*));
501
+		cp = va_arg(*ap, char*);
502
+		if(cp!=NULL) {
503
+			nj = srjson_CreateString(ctx->jrpl, cp);
504
+		} else {
505
+			nj = srjson_CreateNull(ctx->jrpl);
506
+		}
501 507
 		break;
502 508
 	case 'S':
503 509
 		sp = va_arg(*ap, str*);
504
-		nj = srjson_CreateStr(ctx->jrpl, sp->s, sp->len);
510
+		if(sp!=NULL && sp->s!=NULL) {
511
+			nj = srjson_CreateStr(ctx->jrpl, sp->s, sp->len);
512
+		} else {
513
+			nj = srjson_CreateNull(ctx->jrpl);
514
+		}
505 515
 		break;
506 516
 	default:
507 517
 		LM_ERR("Invalid formatting character [%c]\n", fmt);