Browse code

core: skip \n in the rpc uptime result values

Daniel-Constantin Mierla authored on 06/12/2016 10:53:50
Showing 1 changed files
... ...
@@ -238,7 +238,7 @@ static const char* system_listMethods_doc[] = {
238 238
 static void system_listMethods(rpc_t* rpc, void* c)
239 239
 {
240 240
 	int i;
241
-	
241
+
242 242
 	for(i=0; i<rpc_sarray_crt_size; i++){
243 243
 		if (rpc->add(c, "s", rpc_sarray[i]->name) < 0) return;
244 244
 	}
... ...
@@ -359,7 +359,7 @@ static const char* core_info_doc[] = {
359 359
 static void core_info(rpc_t* rpc, void* c)
360 360
 {
361 361
 	void* s;
362
-	
362
+
363 363
 	if (rpc->add(c, "{", &s) < 0) return;
364 364
 	rpc->struct_printf(s, "version", "%s %s", ver_name, ver_version);
365 365
 	rpc->struct_add(s, "s", "id", ver_id);
... ...
@@ -371,7 +371,7 @@ static void core_info(rpc_t* rpc, void* c)
371 371
 
372 372
 
373 373
 static const char* core_uptime_doc[] = {
374
-	"Returns uptime of SER server.",  /* Documentation string */
374
+	"Returns uptime of SIP server.",  /* Documentation string */
375 375
 	0                                 /* Method signature(s) */
376 376
 };
377 377
 
... ...
@@ -380,11 +380,17 @@ static void core_uptime(rpc_t* rpc, void* c)
380 380
 {
381 381
 	void* s;
382 382
 	time_t now;
383
+	str snow;
383 384
 
384 385
 	time(&now);
385 386
 
386 387
 	if (rpc->add(c, "{", &s) < 0) return;
387
-	rpc->struct_add(s, "s", "now", ctime(&now));
388
+	snow.s = ctime(&now);
389
+	if(snow.s) {
390
+		snow.len = strlen(snow.s);
391
+		if(snow.len>2 && snow.s[snow.len-1]=='\n') snow.len--;
392
+		rpc->struct_add(s, "S", "now", &snow);
393
+	}
388 394
 	rpc->struct_add(s, "s", "up_since", up_since_ctime);
389 395
 	/* no need for a float here (unless you're concerned that your uptime)
390 396
 	rpc->struct_add(s, "f", "uptime",  difftime(now, up_since));
... ...
@@ -395,7 +401,7 @@ static void core_uptime(rpc_t* rpc, void* c)
395 401
 
396 402
 
397 403
 static const char* core_ps_doc[] = {
398
-	"Returns the description of running SER processes.",  /* Documentation string */
404
+	"Returns the description of running processes.",  /* Documentation string */
399 405
 	0                                                     /* Method signature(s) */
400 406
 };
401 407
 
... ...
@@ -411,7 +417,7 @@ static void core_ps(rpc_t* rpc, void* c)
411 417
 }
412 418
 
413 419
 static const char* core_psx_doc[] = {
414
-	"Returns the detailed description of running SER processes.",
420
+	"Returns the detailed description of running processes.",
415 421
 		/* Documentation string */
416 422
 	0	/* Method signature(s) */
417 423
 };
... ...
@@ -433,8 +439,8 @@ static void core_psx(rpc_t* rpc, void* c)
433 439
 
434 440
 
435 441
 static const char* core_pwd_doc[] = {
436
-	"Returns the working directory of SER server.",    /* Documentation string */
437
-	0                                                  /* Method signature(s) */
442
+	"Returns the working directory of server.",    /* Documentation string */
443
+	0                                              /* Method signature(s) */
438 444
 };
439 445
 
440 446
 
... ...
@@ -461,8 +467,8 @@ static void core_pwd(rpc_t* rpc, void* c)
461 467
 
462 468
 
463 469
 static const char* core_arg_doc[] = {
464
-	"Returns the list of command line arguments used on SER startup.",  /* Documentation string */
465
-	0                                                                   /* Method signature(s) */
470
+	"Returns the list of command line arguments used on startup.",  /* Documentation string */
471
+	0                                                               /* Method signature(s) */
466 472
 };
467 473
 
468 474
 
... ...
@@ -477,8 +483,8 @@ static void core_arg(rpc_t* rpc, void* c)
477 483
 
478 484
 
479 485
 static const char* core_kill_doc[] = {
480
-	"Sends the given signal to SER.",  /* Documentation string */
481
-	0                                  /* Method signature(s) */
486
+	"Sends the given signal to server.",  /* Documentation string */
487
+	0                                     /* Method signature(s) */
482 488
 };
483 489
 
484 490
 
... ...
@@ -896,7 +902,7 @@ static void core_aliases_list(rpc_t* rpc, void* c)
896 902
  */
897 903
 static const char* core_sockets_list_doc[] = {
898 904
 	"List local SIP server listen sockets",    /* Documentation string */
899
-	0                                     /* Method signature(s) */
905
+	0                                          /* Method signature(s) */
900 906
 };
901 907
 
902 908
 /**
... ...
@@ -1055,7 +1061,7 @@ static rpc_export_t core_rpc_methods[] = {
1055 1061
 int register_core_rpcs(void)
1056 1062
 {
1057 1063
 	int i;
1058
-	
1064
+
1059 1065
 	i=rpc_register_array(core_rpc_methods);
1060 1066
 	if (i<0){
1061 1067
 		BUG("failed to register core RPCs\n");
... ...
@@ -1080,6 +1086,15 @@ int rpc_init_time(void)
1080 1086
 		ERR("Too long data %d\n", (int)strlen(t));
1081 1087
 		return -1;
1082 1088
 	}
1083
-	memcpy(up_since_ctime,t,strlen(t)+1);
1089
+	strcpy(up_since_ctime, t);
1090
+	t = up_since_ctime + strlen(up_since_ctime);
1091
+	while(t>up_since_ctime) {
1092
+		if(*t=='\0' || *t=='\r' || *t=='\n') {
1093
+			*t = '\0';
1094
+		} else {
1095
+			break;
1096
+		}
1097
+		t--;
1098
+	}
1084 1099
 	return 0;
1085 1100
 }