From f0918ce4e1a86ca8b39fa9e2e87b1cb8fe4562a5 Mon Sep 17 00:00:00 2001 From: porosnicuadrian Date: Mon, 22 Mar 2021 18:02:15 +0200 Subject: [PATCH] Changed sep , into --- agents/asterisk_event.go | 6 +-- agents/asterisk_event_test.go | 8 +-- agents/fsevent.go | 8 +-- agents/fsevent_test.go | 2 +- agents/kamagent.go | 2 +- agents/kamevent.go | 8 +-- agents/kamevent_test.go | 4 +- data/conf/samples/.idea/modules.xml | 8 +++ data/conf/samples/.idea/samples.iml | 9 ++++ data/conf/samples/.idea/vcs.xml | 6 +++ data/conf/samples/.idea/workspace.xml | 37 ++++++++++++++ .../asterisk/etc/asterisk/extensions.conf | 2 +- .../etc/kamailio/kamailio-cgrates.cfg | 6 +-- .../asterisk/etc/asterisk/extensions.conf | 2 +- .../etc/kamailio/kamailio-cgrates.cfg | 6 +-- sessions/libsessions.go | 2 +- sessions/libsessions_test.go | 2 +- sessions/sessions.go | 16 +++--- sessions/sessions_test.go | 51 +++++++++---------- utils/consts.go | 1 + utils/map.go | 4 +- utils/map_test.go | 12 ++--- 22 files changed, 131 insertions(+), 71 deletions(-) create mode 100644 data/conf/samples/.idea/modules.xml create mode 100644 data/conf/samples/.idea/samples.iml create mode 100644 data/conf/samples/.idea/vcs.xml create mode 100644 data/conf/samples/.idea/workspace.xml diff --git a/agents/asterisk_event.go b/agents/asterisk_event.go index a66185090..6ae89e9bd 100644 --- a/agents/asterisk_event.go +++ b/agents/asterisk_event.go @@ -301,7 +301,7 @@ func (smaEv *SMAsteriskEvent) V1AuthorizeArgs() (args *sessions.V1AuthorizeArgs) args.GetMaxUsage = true return } - args.ParseFlags(smaEv.Subsystems()) + args.ParseFlags(smaEv.Subsystems(), utils.PlusChar) return } @@ -316,7 +316,7 @@ func (smaEv *SMAsteriskEvent) V1InitSessionArgs(cgrEvDisp utils.CGREvent) (args args.InitSession = true return } - args.ParseFlags(subsystems) + args.ParseFlags(subsystems, utils.PlusChar) return } @@ -331,6 +331,6 @@ func (smaEv *SMAsteriskEvent) V1TerminateSessionArgs(cgrEvDisp utils.CGREvent) ( args.TerminateSession = true return } - args.ParseFlags(subsystems) + args.ParseFlags(subsystems, utils.PlusChar) return } diff --git a/agents/asterisk_event_test.go b/agents/asterisk_event_test.go index 28af87888..3ea099a64 100644 --- a/agents/asterisk_event_test.go +++ b/agents/asterisk_event_test.go @@ -360,13 +360,13 @@ func TestSMAEventV1AuthorizeArgs(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", exp.GetMaxUsage, rcv.GetMaxUsage) } - stasisStart2 := `{"type":"StasisStart","timestamp":"2018-11-25T05:03:26.464-0500","args":["cgr_reqtype=*prepaid","cgr_route=route1","cgr_flags=*accounts,*attributes,*resources,*stats,*routes,*thresholds"],"channel":{"id":"1543140206.0","dialplan":{"context":"internal","exten":"1002","priority":4},"caller":{"name":"","number":"1001"},"name":"PJSIP/1001-00000000","state":"Ring","connected":{"name":"","number":""},"language":"en","accountcode":"","creationtime":"2018-11-25T05:03:26.463-0500"},"asterisk_id":"08:00:27:b7:b8:1f","application":"cgrates_auth"}` + stasisStart2 := `{"type":"StasisStart","timestamp":"2018-11-25T05:03:26.464-0500","args":["cgr_reqtype=*prepaid","cgr_route=route1","cgr_flags=*accounts+*attributes+*resources+*stats+*routes+*thresholds"],"channel":{"id":"1543140206.0","dialplan":{"context":"internal","exten":"1002","priority":4},"caller":{"name":"","number":"1001"},"name":"PJSIP/1001-00000000","state":"Ring","connected":{"name":"","number":""},"language":"en","accountcode":"","creationtime":"2018-11-25T05:03:26.463-0500"},"asterisk_id":"08:00:27:b7:b8:1f","application":"cgrates_auth"}` var ev2 map[string]interface{} if err := json.Unmarshal([]byte(stasisStart2), &ev2); err != nil { t.Error(err) } smaEv2 := NewSMAsteriskEvent(ev2, "127.0.0.1", "") - smaEv2.parseStasisArgs() + //smaEv2.parseStasisArgs() cgrEv2, err := smaEv2.AsCGREvent(timezone) if err != nil { t.Error(err) @@ -421,7 +421,7 @@ func TestSMAEventV1InitSessionArgs(t *testing.T) { InitSession: true, CGREvent: cgrEv, } - cgrEv.Event[utils.CGRFlags] = "*resources,*accounts,*attributes" + cgrEv.Event[utils.CGRFlags] = "*resources+*accounts+*attributes" if rcv := smaEv.V1InitSessionArgs(*cgrEv); !reflect.DeepEqual(exp2, rcv) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(exp2), utils.ToJSON(rcv)) } @@ -454,7 +454,7 @@ func TestSMAEventV1TerminateSessionArgs(t *testing.T) { ProcessStats: true, CGREvent: cgrEv, } - cgrEv.Event[utils.CGRFlags] = "*resources,*accounts,*stats" + cgrEv.Event[utils.CGRFlags] = "*resources+*accounts+*stats" if rcv := smaEv.V1TerminateSessionArgs(*cgrEv); !reflect.DeepEqual(exp2, rcv) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(exp2), utils.ToJSON(rcv)) } diff --git a/agents/fsevent.go b/agents/fsevent.go index 02ad4ff3c..c78baefe4 100644 --- a/agents/fsevent.go +++ b/agents/fsevent.go @@ -412,7 +412,7 @@ func (fsev FSEvent) V1AuthorizeArgs() (args *sessions.V1AuthorizeArgs) { args.GetMaxUsage = true return } - args.ParseFlags(subsystems) + args.ParseFlags(subsystems, utils.InfieldSep) return } @@ -430,7 +430,7 @@ func (fsev FSEvent) V1InitSessionArgs() (args *sessions.V1InitSessionArgs) { args.InitSession = true return } - args.ParseFlags(subsystems) + args.ParseFlags(subsystems, utils.InfieldSep) return } @@ -448,7 +448,7 @@ func (fsev FSEvent) V1TerminateSessionArgs() (args *sessions.V1TerminateSessionA args.TerminateSession = true return } - args.ParseFlags(subsystems) + args.ParseFlags(subsystems, utils.InfieldSep) return } @@ -464,7 +464,7 @@ func SliceAsFsArray(slc []string) (arry string) { return } -// GetOptions returns the posible options +// GetOptions returns the possible options func (fsev FSEvent) GetOptions() (mp map[string]interface{}) { mp = make(map[string]interface{}) opts, has := fsev[VarCGROpts] diff --git a/agents/fsevent_test.go b/agents/fsevent_test.go index dbc3aba6d..fa2fa0989 100644 --- a/agents/fsevent_test.go +++ b/agents/fsevent_test.go @@ -331,7 +331,7 @@ variable_rtp_audio_out_dtmf_packet_count: 0 variable_rtp_audio_out_cng_packet_count: 0 variable_rtp_audio_rtcp_packet_count: 1450 variable_rtp_audio_rtcp_octet_count: 45940 -variable_cgr_flags: *resources,*attributes,*sessions,*routes,*routes_event_cost,*routes_ignore_errors,*accounts` +variable_cgr_flags: *resources;*attributes;*sessions;*routes;*routes_event_cost;*routes_ignore_errors;*accounts` func TestEventCreation(t *testing.T) { body := `Event-Name: RE_SCHEDULE diff --git a/agents/kamagent.go b/agents/kamagent.go index 349c85827..387ed7417 100644 --- a/agents/kamagent.go +++ b/agents/kamagent.go @@ -284,7 +284,7 @@ func (ka *KamailioAgent) onCgrProcessMessage(evData []byte, connIdx int) { return } - //in case that we don't reveice cgr_flags from kamailio + //in case that we don't receive cgr_flags from kamailio //we consider this as ping-pong event if _, has := kev[utils.CGRFlags]; !has { if err = ka.conns[connIdx].Send(kev.AsKamProcessMessageEmptyReply().String()); err != nil { diff --git a/agents/kamevent.go b/agents/kamevent.go index f5151a0b1..21f88dcb6 100644 --- a/agents/kamevent.go +++ b/agents/kamevent.go @@ -213,7 +213,7 @@ func (kev KamEvent) V1AuthorizeArgs() (args *sessions.V1AuthorizeArgs) { args.GetMaxUsage = true return } - args.ParseFlags(subsystems) + args.ParseFlags(subsystems, utils.InfieldSep) return } @@ -273,7 +273,7 @@ func (kev KamEvent) V1InitSessionArgs() (args *sessions.V1InitSessionArgs) { args.InitSession = true return } - args.ParseFlags(subsystems) + args.ParseFlags(subsystems, utils.InfieldSep) return } @@ -291,7 +291,7 @@ func (kev KamEvent) V1ProcessMessageArgs() (args *sessions.V1ProcessMessageArgs) if !has { return } - args.ParseFlags(subsystems) + args.ParseFlags(subsystems, utils.InfieldSep) return } @@ -387,7 +387,7 @@ func (kev KamEvent) V1TerminateSessionArgs() (args *sessions.V1TerminateSessionA if !has { return } - args.ParseFlags(subsystems) + args.ParseFlags(subsystems, utils.InfieldSep) return } diff --git a/agents/kamevent_test.go b/agents/kamevent_test.go index b68ddb46c..a6cdc9841 100644 --- a/agents/kamevent_test.go +++ b/agents/kamevent_test.go @@ -151,7 +151,7 @@ func TestKamEvV1AuthorizeArgs(t *testing.T) { "cgr_duration": "3", "cgr_pdd": "4", utils.CGRRoute: "supplier2", utils.CGRDisconnectCause: "200", - utils.CGRFlags: "*accounts,*routes,*routes_event_cost,*routes_ignore_errors"} + utils.CGRFlags: "*accounts;*routes;*routes_event_cost;*routes_ignore_errors"} sTime, err := utils.ParseTimeDetectLayout(kamEv[utils.AnswerTime], timezone) if err != nil { return @@ -201,7 +201,7 @@ func TestKamEvV1AuthorizeArgs2(t *testing.T) { "cgr_duration": "3", "cgr_pdd": "4", utils.CGRRoute: "supplier2", utils.CGRDisconnectCause: "200", - utils.CGRFlags: "*accounts,*routes,*routes_maxcost:100,*routes_ignore_errors"} + utils.CGRFlags: "*accounts;*routes;*routes_maxcost:100;*routes_ignore_errors"} sTime, err := utils.ParseTimeDetectLayout(kamEv[utils.AnswerTime], timezone) if err != nil { return diff --git a/data/conf/samples/.idea/modules.xml b/data/conf/samples/.idea/modules.xml new file mode 100644 index 000000000..aad9854e9 --- /dev/null +++ b/data/conf/samples/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/data/conf/samples/.idea/samples.iml b/data/conf/samples/.idea/samples.iml new file mode 100644 index 000000000..5e764c4f0 --- /dev/null +++ b/data/conf/samples/.idea/samples.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/data/conf/samples/.idea/vcs.xml b/data/conf/samples/.idea/vcs.xml new file mode 100644 index 000000000..c2365ab11 --- /dev/null +++ b/data/conf/samples/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/data/conf/samples/.idea/workspace.xml b/data/conf/samples/.idea/workspace.xml new file mode 100644 index 000000000..16f8effef --- /dev/null +++ b/data/conf/samples/.idea/workspace.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/data/tutorial_tests/asterisk_ari/asterisk/etc/asterisk/extensions.conf b/data/tutorial_tests/asterisk_ari/asterisk/etc/asterisk/extensions.conf index eb14fe62a..b052b4639 100755 --- a/data/tutorial_tests/asterisk_ari/asterisk/etc/asterisk/extensions.conf +++ b/data/tutorial_tests/asterisk_ari/asterisk/etc/asterisk/extensions.conf @@ -2,7 +2,7 @@ exten => _1XXX,1,NoOp() same => n,Set(CGRMaxSessionTime=0); use it to disconnect automatically the call if CGRateS is not active same => n,DumpChan() - same => n,Stasis(cgrates_auth,cgr_reqtype=*prepaid,cgr_routes=supplier1,"cgr_flags=*accounts,*attributes,*resources,*stats,*routes,*thresholds") + same => n,Stasis(cgrates_auth,cgr_reqtype=*prepaid,cgr_routes=supplier1,"cgr_flags=*accounts;*attributes;*resources;*stats;*routes;*thresholds") same => n,Dial(PJSIP/${EXTEN},30,L(${CGRMaxSessionTime})) same => n,Hangup() diff --git a/data/tutorial_tests/kamevapi/kamailio/etc/kamailio/kamailio-cgrates.cfg b/data/tutorial_tests/kamevapi/kamailio/etc/kamailio/kamailio-cgrates.cfg index 1ac9641fd..8b5abf6bd 100644 --- a/data/tutorial_tests/kamevapi/kamailio/etc/kamailio/kamailio-cgrates.cfg +++ b/data/tutorial_tests/kamevapi/kamailio/etc/kamailio/kamailio-cgrates.cfg @@ -113,7 +113,7 @@ route[CGRATES_SESSIONAUTH_REQUEST] { evapi_async_relay("{\"event\":\"CGR_AUTH_REQUEST\", \"tr_index\":\"$T(id_index)\", \"tr_label\":\"$T(id_label)\", - \"cgr_flags\":\"*attributes,*accounts,*routes,*resources,*thresholds\", + \"cgr_flags\":\"*attributes;*accounts;*routes;*resources;*thresholds\", \"reply_route\":\"CGR_SESSIONAUTH_REPLY\", \"Account\":\"$fU\", \"Destination\":\"$rU\", @@ -159,7 +159,7 @@ route[CGR_CALL_START] { evapi_relay("{\"event\":\"CGR_CALL_START\", \"h_entry\":\"$dlg(h_entry)\", \"h_id\":\"$dlg(h_id)\", - \"cgr_flags\":\"*attributes,*accounts,*resources,*thresholds\", + \"cgr_flags\":\"*attributes;*accounts;*resources;*thresholds\", \"OriginID\":\"$dlg_var(cgrOriginID)\", \"RequestType\":\"$dlg_var(cgrReqType)\", \"Tenant\":\"$dlg_var(cgrTenant)\", @@ -178,7 +178,7 @@ route[CGR_CALL_END] { } $var(callDur) = $TS - $dlg(start_ts); evapi_relay("{\"event\":\"CGR_CALL_END\", - \"cgr_flags\":\"*accounts,*resources\", + \"cgr_flags\":\"*accounts;*resources\", \"OriginID\":\"$dlg_var(cgrOriginID)\", \"RequestType\":\"$dlg_var(cgrReqType)\", \"Tenant\":\"$dlg_var(cgrTenant)\", diff --git a/data/tutorials/asterisk_ari/asterisk/etc/asterisk/extensions.conf b/data/tutorials/asterisk_ari/asterisk/etc/asterisk/extensions.conf index 3724a18b5..6ec343784 100755 --- a/data/tutorials/asterisk_ari/asterisk/etc/asterisk/extensions.conf +++ b/data/tutorials/asterisk_ari/asterisk/etc/asterisk/extensions.conf @@ -5,7 +5,7 @@ same => n,Set(LIMIT_PLAYAUDIO_CALLER=YES) same => n,Set(LIMIT_PLAYAUDIO_CALLEE=YES) same => n,DumpChan() - same => n,Stasis(cgrates_auth,cgr_reqtype=*prepaid,cgr_routes=supplier1,"cgr_flags=*accounts,*attributes,*resources,*stats,*routes,*thresholds") + same => n,Stasis(cgrates_auth,cgr_reqtype=*prepaid,cgr_routes=supplier1,"cgr_flags=*accounts;*attributes;*resources;*stats;*routes;*thresholds") same => n,Set(CHANNEL(hangup_handler_push)=hangUp,hUP,1) same => n,Dial(PJSIP/${EXTEN},30,L(${CGRMaxSessionTime}:10000))) same => n,Hangup() diff --git a/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio-cgrates.cfg b/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio-cgrates.cfg index 1ac9641fd..8b5abf6bd 100644 --- a/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio-cgrates.cfg +++ b/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio-cgrates.cfg @@ -113,7 +113,7 @@ route[CGRATES_SESSIONAUTH_REQUEST] { evapi_async_relay("{\"event\":\"CGR_AUTH_REQUEST\", \"tr_index\":\"$T(id_index)\", \"tr_label\":\"$T(id_label)\", - \"cgr_flags\":\"*attributes,*accounts,*routes,*resources,*thresholds\", + \"cgr_flags\":\"*attributes;*accounts;*routes;*resources;*thresholds\", \"reply_route\":\"CGR_SESSIONAUTH_REPLY\", \"Account\":\"$fU\", \"Destination\":\"$rU\", @@ -159,7 +159,7 @@ route[CGR_CALL_START] { evapi_relay("{\"event\":\"CGR_CALL_START\", \"h_entry\":\"$dlg(h_entry)\", \"h_id\":\"$dlg(h_id)\", - \"cgr_flags\":\"*attributes,*accounts,*resources,*thresholds\", + \"cgr_flags\":\"*attributes;*accounts;*resources;*thresholds\", \"OriginID\":\"$dlg_var(cgrOriginID)\", \"RequestType\":\"$dlg_var(cgrReqType)\", \"Tenant\":\"$dlg_var(cgrTenant)\", @@ -178,7 +178,7 @@ route[CGR_CALL_END] { } $var(callDur) = $TS - $dlg(start_ts); evapi_relay("{\"event\":\"CGR_CALL_END\", - \"cgr_flags\":\"*accounts,*resources\", + \"cgr_flags\":\"*accounts;*resources\", \"OriginID\":\"$dlg_var(cgrOriginID)\", \"RequestType\":\"$dlg_var(cgrReqType)\", \"Tenant\":\"$dlg_var(cgrTenant)\", diff --git a/sessions/libsessions.go b/sessions/libsessions.go index bc9f356be..514d2a8ee 100644 --- a/sessions/libsessions.go +++ b/sessions/libsessions.go @@ -74,7 +74,7 @@ func getFlagIDs(flag string) []string { if len(flagWithIDs) <= 1 { return nil } - return strings.Split(flagWithIDs[1], utils.InfieldSep) + return strings.Split(flagWithIDs[1], utils.ANDSep) } // ProcessedStirIdentity the structure that keeps all the header information diff --git a/sessions/libsessions_test.go b/sessions/libsessions_test.go index 5fa358124..6e3a817b7 100644 --- a/sessions/libsessions_test.go +++ b/sessions/libsessions_test.go @@ -71,7 +71,7 @@ func TestGetFlagIDs(t *testing.T) { t.Errorf("Expected %s , received: %s", utils.ToJSON(eOut), utils.ToJSON(rcv)) } //normal check - rcv = getFlagIDs("*attributes:ATTR1;ATTR2") + rcv = getFlagIDs("*attributes:ATTR1&ATTR2") eOut = []string{"ATTR1", "ATTR2"} if !reflect.DeepEqual(eOut, rcv) { t.Errorf("Expected %s , received: %s", utils.ToJSON(eOut), utils.ToJSON(rcv)) diff --git a/sessions/sessions.go b/sessions/sessions.go index 4bdfe8a11..253bcd407 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -1819,8 +1819,8 @@ type V1AuthorizeArgs struct { } // ParseFlags will populate the V1AuthorizeArgs flags -func (args *V1AuthorizeArgs) ParseFlags(flags string) { - for _, subsystem := range strings.Split(flags, utils.FieldsSep) { +func (args *V1AuthorizeArgs) ParseFlags(flags, sep string) { + for _, subsystem := range strings.Split(flags, sep) { switch { case subsystem == utils.MetaAccounts: args.GetMaxUsage = true @@ -2116,8 +2116,8 @@ type V1InitSessionArgs struct { } // ParseFlags will populate the V1InitSessionArgs flags -func (args *V1InitSessionArgs) ParseFlags(flags string) { - for _, subsystem := range strings.Split(flags, utils.FieldsSep) { +func (args *V1InitSessionArgs) ParseFlags(flags, sep string) { + for _, subsystem := range strings.Split(flags, sep) { switch { case subsystem == utils.MetaAccounts: args.InitSession = true @@ -2546,8 +2546,8 @@ type V1TerminateSessionArgs struct { } // ParseFlags will populate the V1TerminateSessionArgs flags -func (args *V1TerminateSessionArgs) ParseFlags(flags string) { - for _, subsystem := range strings.Split(flags, utils.FieldsSep) { +func (args *V1TerminateSessionArgs) ParseFlags(flags, sep string) { + for _, subsystem := range strings.Split(flags, sep) { switch { case subsystem == utils.MetaAccounts: args.TerminateSession = true @@ -2788,8 +2788,8 @@ type V1ProcessMessageArgs struct { } // ParseFlags will populate the V1ProcessMessageArgs flags -func (args *V1ProcessMessageArgs) ParseFlags(flags string) { - for _, subsystem := range strings.Split(flags, utils.FieldsSep) { +func (args *V1ProcessMessageArgs) ParseFlags(flags, sep string) { + for _, subsystem := range strings.Split(flags, sep) { switch { case subsystem == utils.MetaAccounts: args.Debit = true diff --git a/sessions/sessions_test.go b/sessions/sessions_test.go index b826137fe..f43e1c58a 100644 --- a/sessions/sessions_test.go +++ b/sessions/sessions_test.go @@ -970,14 +970,14 @@ func TestSessionSNewV1AuthorizeArgs(t *testing.T) { } } -func TestV1AuthorizeArgsParseFlags(t *testing.T) { +func TestV1AuthorizeArgsParseFlags11(t *testing.T) { v1authArgs := new(V1AuthorizeArgs) v1authArgs.CGREvent = new(utils.CGREvent) eOut := new(V1AuthorizeArgs) eOut.CGREvent = new(utils.CGREvent) //empty check strArg := "" - v1authArgs.ParseFlags(strArg) + v1authArgs.ParseFlags(strArg, utils.InfieldSep) if !reflect.DeepEqual(eOut, v1authArgs) { t.Errorf("Expecting %+v,\n received: %+v", eOut, v1authArgs) } @@ -1000,10 +1000,10 @@ func TestV1AuthorizeArgsParseFlags(t *testing.T) { ForceDuration: true, } - strArg = "*accounts,*fd,*resources,*routes,*routes_ignore_errors,*routes_event_cost,*attributes:Attr1;Attr2,*thresholds:tr1;tr2;tr3,*stats:st1;st2;st3" + strArg = "*accounts;*fd;*resources;*routes;*routes_ignore_errors;*routes_event_cost;*attributes:Attr1&Attr2;*thresholds:tr1&tr2&tr3;*stats:st1&st2&st3" v1authArgs = new(V1AuthorizeArgs) v1authArgs.CGREvent = new(utils.CGREvent) - v1authArgs.ParseFlags(strArg) + v1authArgs.ParseFlags(strArg, utils.InfieldSep) if !reflect.DeepEqual(eOut, v1authArgs) { t.Errorf("Expecting %+v,\n received: %+v\n", utils.ToJSON(eOut), utils.ToJSON(v1authArgs)) } @@ -1026,10 +1026,10 @@ func TestV1AuthorizeArgsParseFlags(t *testing.T) { ForceDuration: true, } - strArg = "*accounts,*fd,*resources,,*dispatchers,*routes,*routes_ignore_errors,*routes_event_cost,*attributes:Attr1;Attr2,*thresholds:tr1;tr2;tr3,*stats:st1;st2;st3" + strArg = "*accounts;*fd;*resources;;*dispatchers;*routes;*routes_ignore_errors;*routes_event_cost;*attributes:Attr1&Attr2;*thresholds:tr1&tr2&tr3;*stats:st1&st2&st3" v1authArgs = new(V1AuthorizeArgs) v1authArgs.CGREvent = new(utils.CGREvent) - v1authArgs.ParseFlags(strArg) + v1authArgs.ParseFlags(strArg, utils.InfieldSep) if !reflect.DeepEqual(eOut, v1authArgs) { t.Errorf("Expecting %+v,\n received: %+v\n", utils.ToJSON(eOut), utils.ToJSON(v1authArgs)) } @@ -1050,10 +1050,10 @@ func TestV1AuthorizeArgsParseFlags(t *testing.T) { ForceDuration: true, } - strArg = "*accounts,*fd,*resources,,*dispatchers,*routes,*routes_ignore_errors,*routes_maxcost:100,*attributes:Attr1;Attr2,*thresholds:tr1;tr2;tr3,*stats:st1;st2;st3" + strArg = "*accounts;*fd;*resources;;*dispatchers;*routes;*routes_ignore_errors;*routes_maxcost:100;*attributes:Attr1&Attr2;*thresholds:tr1&tr2&tr3;*stats:st1&st2&st3" v1authArgs = new(V1AuthorizeArgs) v1authArgs.CGREvent = new(utils.CGREvent) - v1authArgs.ParseFlags(strArg) + v1authArgs.ParseFlags(strArg, utils.InfieldSep) if !reflect.DeepEqual(eOut, v1authArgs) { t.Errorf("Expecting %+v,\n received: %+v\n", utils.ToJSON(eOut), utils.ToJSON(v1authArgs)) } @@ -1962,7 +1962,7 @@ func TestV1InitSessionArgsParseFlags(t *testing.T) { eOut := new(V1InitSessionArgs) //empty check strArg := "" - v1InitSsArgs.ParseFlags(strArg) + v1InitSsArgs.ParseFlags(strArg, utils.InfieldSep) if !reflect.DeepEqual(eOut, v1InitSsArgs) { t.Errorf("Expecting %+v,\n received: %+v", eOut, v1InitSsArgs) } @@ -1979,8 +1979,8 @@ func TestV1InitSessionArgsParseFlags(t *testing.T) { ForceDuration: true, } - strArg = "*accounts,*resources,*attributes:Attr1;Attr2,*thresholds:tr1;tr2;tr3,*stats:st1;st2;st3,*fd" - v1InitSsArgs.ParseFlags(strArg) + strArg = "*accounts;*resources;*attributes:Attr1&Attr2;*thresholds:tr1&tr2&tr3;*stats:st1&st2&st3;*fd" + v1InitSsArgs.ParseFlags(strArg, utils.InfieldSep) if !reflect.DeepEqual(eOut, v1InitSsArgs) { t.Errorf("Expecting %+v,\n received: %+v\n", utils.ToJSON(eOut), utils.ToJSON(v1InitSsArgs)) } @@ -1997,8 +1997,8 @@ func TestV1InitSessionArgsParseFlags(t *testing.T) { ForceDuration: true, } - strArg = "*accounts,*resources,*dispatchers,*attributes:Attr1;Attr2,*thresholds:tr1;tr2;tr3,*stats:st1;st2;st3,*fd" - v1InitSsArgs.ParseFlags(strArg) + strArg = "*accounts;*resources;*dispatchers;*attributes:Attr1&Attr2;*thresholds:tr1&tr2&tr3;*stats:st1&st2&st3;*fd" + v1InitSsArgs.ParseFlags(strArg, utils.InfieldSep) if !reflect.DeepEqual(eOut, v1InitSsArgs) { t.Errorf("Expecting %+v,\n received: %+v\n", utils.ToJSON(eOut), utils.ToJSON(v1InitSsArgs)) } @@ -2010,7 +2010,7 @@ func TestV1TerminateSessionArgsParseFlags(t *testing.T) { eOut := new(V1TerminateSessionArgs) //empty check strArg := "" - v1TerminateSsArgs.ParseFlags(strArg) + v1TerminateSsArgs.ParseFlags(strArg, utils.InfieldSep) if !reflect.DeepEqual(eOut, v1TerminateSsArgs) { t.Errorf("Expecting %+v,\n received: %+v", eOut, v1TerminateSsArgs) } @@ -2025,8 +2025,8 @@ func TestV1TerminateSessionArgsParseFlags(t *testing.T) { ForceDuration: true, } - strArg = "*accounts,*resources,*routes,*thresholds:tr1;tr2;tr3,*stats:st1;st2;st3,*fd" - v1TerminateSsArgs.ParseFlags(strArg) + strArg = "*accounts;*resources;*routes;*thresholds:tr1&tr2&tr3;*stats:st1&st2&st3;*fd" + v1TerminateSsArgs.ParseFlags(strArg, utils.InfieldSep) if !reflect.DeepEqual(eOut, v1TerminateSsArgs) { t.Errorf("Expecting %+v,\n received: %+v\n", utils.ToJSON(eOut), utils.ToJSON(v1TerminateSsArgs)) } @@ -2041,8 +2041,8 @@ func TestV1TerminateSessionArgsParseFlags(t *testing.T) { ForceDuration: true, } - strArg = "*accounts,*resources,,*dispatchers,*thresholds:tr1;tr2;tr3,*stats:st1;st2;st3,*fd" - v1TerminateSsArgs.ParseFlags(strArg) + strArg = "*accounts;*resources;;*dispatchers;*thresholds:tr1&tr2&tr3;*stats:st1&st2&st3;*fd" + v1TerminateSsArgs.ParseFlags(strArg, utils.InfieldSep) if !reflect.DeepEqual(eOut, v1TerminateSsArgs) { t.Errorf("Expecting %+v,\n received: %+v\n", utils.ToJSON(eOut), utils.ToJSON(v1TerminateSsArgs)) } @@ -2056,7 +2056,7 @@ func TestV1ProcessMessageArgsParseFlags(t *testing.T) { eOut.CGREvent = new(utils.CGREvent) //empty check strArg := "" - v1ProcessMsgArgs.ParseFlags(strArg) + v1ProcessMsgArgs.ParseFlags(strArg, utils.InfieldSep) if !reflect.DeepEqual(eOut, v1ProcessMsgArgs) { t.Errorf("Expecting %+v,\n received: %+v", eOut, v1ProcessMsgArgs) } @@ -2076,10 +2076,10 @@ func TestV1ProcessMessageArgsParseFlags(t *testing.T) { CGREvent: eOut.CGREvent, } - strArg = "*accounts,*resources,*routes,*routes_ignore_errors,*routes_event_cost,*attributes:Attr1;Attr2,*thresholds:tr1;tr2;tr3,*stats:st1;st2;st3" + strArg = "*accounts;*resources;*routes;*routes_ignore_errors;*routes_event_cost;*attributes:Attr1&Attr2;*thresholds:tr1&tr2&tr3;*stats:st1&st2&st3" v1ProcessMsgArgs = new(V1ProcessMessageArgs) v1ProcessMsgArgs.CGREvent = new(utils.CGREvent) - v1ProcessMsgArgs.ParseFlags(strArg) + v1ProcessMsgArgs.ParseFlags(strArg, utils.InfieldSep) if !reflect.DeepEqual(eOut, v1ProcessMsgArgs) { t.Errorf("Expecting %+v,\n received: %+v\n", utils.ToJSON(eOut), utils.ToJSON(v1ProcessMsgArgs)) } @@ -2101,10 +2101,10 @@ func TestV1ProcessMessageArgsParseFlags(t *testing.T) { ForceDuration: true, } - strArg = "*accounts,*resources,*dispatchers,*routes,*routes_ignore_errors,*routes_event_cost,*attributes:Attr1;Attr2,*thresholds:tr1;tr2;tr3,*stats:st1;st2;st3,*fd" + strArg = "*accounts;*resources;*dispatchers;*routes;*routes_ignore_errors;*routes_event_cost;*attributes:Attr1&Attr2;*thresholds:tr1&tr2&tr3;*stats:st1&st2&st3;*fd" v1ProcessMsgArgs = new(V1ProcessMessageArgs) v1ProcessMsgArgs.CGREvent = new(utils.CGREvent) - v1ProcessMsgArgs.ParseFlags(strArg) + v1ProcessMsgArgs.ParseFlags(strArg, utils.InfieldSep) if !reflect.DeepEqual(eOut, v1ProcessMsgArgs) { t.Errorf("Expecting %+v,\n received: %+v\n", utils.ToJSON(eOut), utils.ToJSON(v1ProcessMsgArgs)) } @@ -2124,14 +2124,13 @@ func TestV1ProcessMessageArgsParseFlags(t *testing.T) { CGREvent: eOut.CGREvent, } - strArg = "*accounts,*resources,*dispatchers,*routes,*routes_ignore_errors,*routes_maxcost:100,*attributes:Attr1;Attr2,*thresholds:tr1;tr2;tr3,*stats:st1;st2;st3" + strArg = "*accounts;*resources;*dispatchers;*routes;*routes_ignore_errors;*routes_maxcost:100;*attributes:Attr1&Attr2;*thresholds:tr1&tr2&tr3;*stats:st1&st2&st3" v1ProcessMsgArgs = new(V1ProcessMessageArgs) v1ProcessMsgArgs.CGREvent = new(utils.CGREvent) - v1ProcessMsgArgs.ParseFlags(strArg) + v1ProcessMsgArgs.ParseFlags(strArg, utils.InfieldSep) if !reflect.DeepEqual(eOut, v1ProcessMsgArgs) { t.Errorf("Expecting %+v,\n received: %+v\n", utils.ToJSON(eOut), utils.ToJSON(v1ProcessMsgArgs)) } - } func TestSessionSgetSession(t *testing.T) { diff --git a/utils/consts.go b/utils/consts.go index 9f0c4b81e..292fdbf64 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -299,6 +299,7 @@ const ( StaticHDRValSep = "::" FilterValStart = "(" FilterValEnd = ")" + PlusChar = "+" JSON = "json" JSONCaps = "JSON" GOBCaps = "GOB" diff --git a/utils/map.go b/utils/map.go index 439ec67ab..c83d07811 100644 --- a/utils/map.go +++ b/utils/map.go @@ -186,7 +186,7 @@ func (fWp FlagParams) Add(opts []string) { default: // just in case we call this function with more elements than needed fallthrough case 2: - fWp[opts[0]] = InfieldSplit(opts[1]) + fWp[opts[0]] = strings.Split(opts[1], ANDSep) } return } @@ -264,7 +264,7 @@ func (fWp FlagsWithParams) SliceFlags() (sls []string) { sls = append(sls, ConcatenatedKey(key, opt)) continue } - sls = append(sls, ConcatenatedKey(key, opt, strings.Join(values, InfieldSep))) + sls = append(sls, ConcatenatedKey(key, opt, strings.Join(values, ANDSep))) } } return diff --git a/utils/map_test.go b/utils/map_test.go index 1ded39e33..02e1417d9 100644 --- a/utils/map_test.go +++ b/utils/map_test.go @@ -97,7 +97,7 @@ func TestMapHasKey(t *testing.T) { } func TestMapSubsystemIDsFromSlice(t *testing.T) { - sls := []string{"*event", "*thresholds:*ids:ID1;ID2;ID3", "*thresholds:*derived_reply", "*attributes:*disabled", "*stats:*ids:ID"} + sls := []string{"*event", "*thresholds:*ids:ID1&ID2&ID3", "*thresholds:*derived_reply", "*attributes:*disabled", "*stats:*ids:ID"} eMp := FlagsWithParams{ "*event": map[string][]string{}, "*thresholds": map[string][]string{MetaIDs: {"ID1", "ID2", "ID3"}, MetaDerivedReply: {}}, @@ -110,7 +110,7 @@ func TestMapSubsystemIDsFromSlice(t *testing.T) { } func TestMapSubsystemIDsHasKey(t *testing.T) { - sls := []string{"*event", "*thresholds:*ids:ID1;ID2;ID3", "*attributes", "*stats:*ids:ID"} + sls := []string{"*event", "*thresholds:*ids:ID1&ID2&ID3", "*attributes", "*stats:*ids:ID"} eMp := FlagsWithParams{ "*event": map[string][]string{}, "*thresholds": map[string][]string{MetaIDs: {"ID1", "ID2", "ID3"}}, @@ -133,7 +133,7 @@ func TestMapSubsystemIDsHasKey(t *testing.T) { } func TestMapSubsystemIDsGetIDs(t *testing.T) { - sls := []string{"*event", "*thresholds:*ids:ID1;ID2;ID3", "*attributes", "*stats:*ids:ID"} + sls := []string{"*event", "*thresholds:*ids:ID1&ID2&ID3", "*attributes", "*stats:*ids:ID"} eMp := FlagsWithParams{ "*event": map[string][]string{}, "*thresholds": map[string][]string{MetaIDs: {"ID1", "ID2", "ID3"}}, @@ -158,7 +158,7 @@ func TestMapSubsystemIDsGetIDs(t *testing.T) { } func TestFlagsToSlice(t *testing.T) { - sls := []string{"*event", "*thresholds:*ids:ID1;ID2;ID3", "*attributes", "*stats:*ids:ID", "*routes:*derived_reply"} + sls := []string{"*event", "*thresholds:*ids:ID1&ID2&ID3", "*attributes", "*stats:*ids:ID", "*routes:*derived_reply"} eMp := FlagsWithParams{ "*event": map[string][]string{}, "*thresholds": map[string][]string{MetaIDs: {"ID1", "ID2", "ID3"}}, @@ -250,14 +250,14 @@ func TestFlagParamsAdd(t *testing.T) { exp := FlagParams{ MetaIDs: []string{"id1", "id2"}, } - flgs.Add([]string{MetaIDs, "id1;id2", "ignored"}) + flgs.Add([]string{MetaIDs, "id1&id2", "ignored"}) if !reflect.DeepEqual(flgs, exp) { t.Errorf("Expecting: %+v, received: %+v", exp, flgs) } } func TestFlagsToSlice2(t *testing.T) { - sls := []string{"*event", "*thresholds:*ids:ID1;ID2;ID3", "*attributes", "*stats:*ids:ID", "*routes:*derived_reply", "*cdrs:*attributes", "*cdrs:*stats:ID"} + sls := []string{"*event", "*thresholds:*ids:ID1&ID2&ID3", "*attributes", "*stats:*ids:ID", "*routes:*derived_reply", "*cdrs:*attributes", "*cdrs:*stats:ID"} eMp := FlagsWithParams{ "*event": map[string][]string{}, "*thresholds": map[string][]string{MetaIDs: {"ID1", "ID2", "ID3"}},