+
+# $1: code; $2: isrequest; $3: frame to start searching: direction depends on isrequest (1: downwards, 0: upwards)
+search_xml () {
+ local code=$1
+ local isrequest=$2
+ local this_frame=$3
+ local frames=()
+
+ if [ $isrequest -eq 1 ]
+ then
+ # requests shall be before frame
+ frames=( $(ls *.*metadata | cut -d\. -f1 | sort -rn | awk -v frame=$this_frame '{ if($1 < frame) print $1 }') )
+ else
+ # answers shall be after frame
+ frames=( $(ls *.*metadata | cut -d\. -f1 | sort -n | awk -v frame=$this_frame '{ if($1 > frame) print $1 }') )
+ fi
+
+ local frame=
+ local mtd=
+ local found=
+ local _code=
+ local _isrequest=
+ for frame in ${frames[@]}
+ do
+ mtd=${frame}.metadata
+ [ ! -f $mtd ] && _exit "Unexpected error: can't found '$mtd' file !!"
+
+ _code=$(grep ^code $mtd | cut -d= -f2)
+ _isrequest=$(grep ^isrequest $mtd | cut -d= -f2)
+
+ [ $_code -ne $code -o $_isrequest -ne $isrequest ] && continue
+
+ found="$(ls ${frame}.*.xml 2>/dev/null)"
+ [ -z "$found" ] && _exit "Unexpected error: can't found xml file for frame '${frame}' file !!"
+ echo $found
+ return 0
+ done
+
+ return 1
+}