MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / ensure_file_path

Function ensure_file_path

modules/event_flatstore/event_flatstore.c:650–745  ·  view source on GitHub ↗

Builds (or rebuilds) the suffixed pathname for a flat_file. * file – target structure * reset – if non-zero, force recreation: free old suffixed name, * clear pathname and build a fresh one * Returns: valid pathname */

Source from the content-addressed store, hash-verified

648 * clear pathname and build a fresh one
649 * Returns: valid pathname */
650static char *ensure_file_path(struct flat_file *file, int reset)
651{
652 str format;
653 char *filepath;
654 static struct sip_msg req;
655
656 if (reset) { /* free old pathname before saving a new one */
657 if (file->old_pathname &&
658 file->old_pathname != file->path.s &&
659 file->old_pathname != flat_empty_str) {
660
661 shm_free(file->old_pathname);
662 }
663 file->old_pathname = NULL;
664 }
665
666 /* reuse existing pathname when no reset requested */
667 if (!reset && file->pathname)
668 return file->pathname;
669
670 /* save current pathname before regenerating */
671 if (reset) {
672 if (file->pathname) {
673 size_t len = strlen(file->pathname);
674 char *dup = shm_malloc(len + 1);
675 if (!dup) {
676 LM_ERR("OOM while duplicating old pathname\n");
677 return NULL;
678 } else {
679 memcpy(dup, file->pathname, len + 1);
680 file->old_pathname = dup;
681 }
682 } else {
683 file->old_pathname = (char *)flat_empty_str;
684 }
685 }
686
687 /* drop current suffixed name if it was allocated */
688 if (reset && file->pathname && file->pathname != file->path.s) {
689 shm_free(file->pathname);
690 file->pathname = NULL;
691 }
692
693 /* if suffix disabled use original path */
694 if (!file_suffix_format) {
695 file->pathname = file->path.s;
696 return file->pathname;
697 }
698
699 req.first_line.u.request.method.s= "DUMMY";
700 req.first_line.u.request.method.len= 5;
701 req.first_line.u.request.uri.s= "sip:user@domain.com";
702 req.first_line.u.request.uri.len= 19;
703 req.rcv.src_ip.af = AF_INET;
704 req.rcv.dst_ip.af = AF_INET;
705
706 if (pv_printf_s(&req, file_suffix_format, &format) < 0) {
707 LM_ERR("could not print the file's format!\n");

Callers 4

mi_rotateFunction · 0.85
rotatingFunction · 0.85
event_flatstore_timerFunction · 0.85

Calls 4

shm_freeFunction · 0.85
shm_mallocFunction · 0.85
pv_printf_sFunction · 0.85
shm_reallocFunction · 0.85

Tested by

no test coverage detected