X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=sim%2Fo1-interface.git;a=blobdiff_plain;f=ntsimulator%2Fntsim-ng%2Futils%2Frand_utils.c;h=6b1fd6ff81894f4a8cba5fc6a90ffb3f53729f47;hp=28222e698e0f33a010260a5c7e707ca3e8891db5;hb=96526af57d1c3026430e11cfe899e50629a91296;hpb=db05cb943f111d47e9a715f602a1942b925ba675 diff --git a/ntsimulator/ntsim-ng/utils/rand_utils.c b/ntsimulator/ntsim-ng/utils/rand_utils.c index 28222e6..6b1fd6f 100644 --- a/ntsimulator/ntsim-ng/utils/rand_utils.c +++ b/ntsimulator/ntsim-ng/utils/rand_utils.c @@ -472,27 +472,44 @@ char *rand_regex(const char *regexp) { char *cmd = 0; static int run_time = 0; + char *regexp64 = b64_encode((const unsigned char*)regexp, strlen(regexp)); + if(regexp64 == 0) { + log_error("b64_encode failed"); + return 0; + } + if(framework_arguments.no_rand) { run_time++; - asprintf(&cmd, "regxstring %d '%s'", run_time, regexp); + asprintf(&cmd, "regxstring %d '%s'", run_time, regexp64); } else { - asprintf(&cmd, "regxstring '%s'", regexp); + asprintf(&cmd, "regxstring '%s'", regexp64); } + free(regexp64); - FILE* pipe = popen(cmd, "r"); - free(cmd); - - if (!pipe) { - log_error("popen() failed"); + if(cmd == 0) { + log_error("asprintf failed"); return 0; } - fgets(buffer, sizeof(buffer), pipe); - pclose(pipe); - + char last_char = ' '; + while(last_char == ' ') { + FILE* pipe = popen(cmd, "r"); + if (!pipe) { + log_error("popen() failed"); + free(cmd); + return 0; + } + + fgets(buffer, sizeof(buffer), pipe); + pclose(pipe); + + buffer[strlen(buffer) - 1] = 0; //remove trailing \n + last_char = buffer[strlen(buffer) - 1]; + } + char *ret = strdup(buffer); - ret[strlen(ret) - 1] = 0; //remove trailing \n + free(cmd); return ret; }