Escape from character

i was trying to implement goiftime() function from database …

in my database table i input the time field as 18:00-01:00,,,* without any space and no other charecter.

but when i call this field through mysql query in func_odbc.conf value from this date-time field is getting like 18:01-01:00,,,* !! i don know why asterisk add this \ character.

log is following

-- Executing [s@macro-ivrnew:23] GotoIfTime("SIP/2000-00000004", "[b]18:01-01:00\,*\,*\,*?$time}[/b]") in new stack

[2015-03-05 04:43:31] WARNING[30225][C-0000000e]: pbx.c:9199 get_range: Invalid day of week ‘’, skipping element
[2015-03-05 04:43:31] WARNING[30225][C-0000000e]: pbx.c:9199 get_range: Invalid day '
’, skipping element

i need to get the value as 18:01-01:00,,,* so that i can pass this value to goiftime() function

let me send more detail :

IN func_odbc.conf :

[THE_TIME]
prefix=GET
dsn=asteriskcdr
readsql=SELECT time FROM tbl_time WHERE exten = '${ARG1}'

IN my Mysql Database tbl_time is :

exten time 4444 01:01-11:59,*,*,*
following dialplan is working fine in my extension.conf

[macro-testivr]

exten => s,1,NoOp()

        same => n,set(TIME=17:00-18:00,*,*,*)
        same => n,Verbose(I found ${TIME})
        same => n,GoToIfTime(${TIME}?found:goaway)
        same => n(found),PlayBack(letters/w)
        same => n,hangup()
        same => n(goaway),hangup()

exten => 4444,1,Answer()
exten => 4444,n,macro(testivr,${EXTEN})

And my log is

 == Using SIP RTP CoS mark 5
    -- Executing [4444@from-internal:1] Answer("SIP/2000-00000000", "") in new stack
       > 0xb711faa8 -- Probation passed - setting RTP source address to 103.4.65.86:8000
    -- Executing [4444@from-internal:2] Macro("SIP/2000-00000000", "testivr,4444") in new stack
    -- Executing [s@macro-testivr:1] NoOp("SIP/2000-00000000", "") in new stack
    -- [b]Executing [s@macro-testivr:2] Set("SIP/2000-00000000", "TIME=10:00-18:00,*,*,*") in new stack[/b]
    -- Executing [s@macro-testivr:3] Verbose("SIP/2000-00000000", "I found 10:00-18:00,*,*,*") in new stack
[2015-03-05 13:09:57] WARNING[9948][C-00000000]: app_verbose.c:101 verbose_exec: 'I found 10:00-18:00' is not a verboser number
*,*,*
    -[b]- Executing [s@macro-testivr:4] GotoIfTime("SIP/2000-00000000", "10:00-18:00,*,*,*?found:goaway") in new stack[/b]
    -- Goto (macro-testivr,s,5)
    -- Executing [s@macro-testivr:5] Playback("SIP/2000-00000000", "letters/w") in new stack
    -- <SIP/2000-00000000> Playing 'letters/w.gsm' (language 'en')
[2015-03-05 13:09:57] NOTICE[9948][C-00000000]: channel.c:4301 __ast_read: Dropping incompatible voice frame on SIP/2000-00000000 of format ulaw since our native format has changed to (gsm)
    -- Executing [s@macro-testivr:6] Hangup("SIP/2000-00000000", "") in new stack

But when i try with following dialplan, the value from tbl_time contains some “” characters

And the LOG IS

  == Using SIP RTP CoS mark 5
    -- Executing [4444@from-internal:1] Answer("SIP/2000-00000001", "") in new stack
       > 0xb703adc0 -- Probation passed - setting RTP source address to 103.4.65.86:8000
    -- Executing [4444@from-internal:2] Macro("SIP/2000-00000001", "testivr,4444") in new stack
    -- Executing [s@macro-testivr:1] NoOp("SIP/2000-00000001", "") in new stack
[2015-03-05 13:18:17] NOTICE[12441][C-00000005]: channel.c:4301 __ast_read: Dropping incompatible voice frame on SIP/2000-00000001 of format ulaw since our native format has changed to (gsm)
[b]    -- Executing [s@macro-testivr:2] Set("SIP/2000-00000001", "TIME=01:01-11:59\,*\,*\,*") in new stack[/b]
    -- Executing [s@macro-testivr:3] Verbose("SIP/2000-00000001", "I found 01:01-11:59\,*\,*\,*") in new stack
I found 01:01-11:59,*,*,*
    --[b] Executing [s@macro-testivr:4] GotoIfTime("SIP/2000-00000001", "01:01-11:59\,*\,*\,*?found:goaway") in new stack[/b]
[2015-03-05 13:18:17] WARNING[13247][C-00000005]: pbx.c:9199 get_range: Invalid day of week '*\', skipping element
[2015-03-05 13:18:17] WARNING[13247][C-00000005]: pbx.c:9199 get_range: Invalid day '*\', skipping element
    -- Goto (macro-testivr,s,7)
    -- Executing [s@macro-testivr:7] Hangup("SIP/2000-00000001", "") in new stack
  == Spawn extension (macro-testivr, s, 7) exited non-zero on 'SIP/2000-00000001' in macro 'testivr'
  == Spawn extension (from-internal, 4444, 2) exited non-zero on 'SIP/2000-00000001'
    -- Registered SIP '2006' at 192.168.110.49:61648

Seems a sensible thing to do as people don’t normally expect a single variable to affect multiple fields, and doing so could have security implications.

I don’t know how the string replace and similar functions handle , but I would investigate.

You can try FILTER Function.
I haven’t tested but something like ${FILTER(0-9-*:,${TIME})}

–Satish Barot

function filter() can not allow - or * … tried in several ways …

Which version of Asterisk?
I am on 11.16.0 and it works.
My sample dialplan…
[fltr]
exten => s,1,NoOp()
same => n,Answer()
same => n,Set(TIME=01:01-11:59,,,)
same => n,Set(NT=${FILTER(0-9-
:,${TIME})})

CLI Output…

-- Executing [s@fltr:1] NoOp("Local/s@fltr-00000005;2", "") in new stack
-- Executing [s@fltr:2] Answer("Local/s@fltr-00000005;2", "") in new stack
-- Launching Wait(3) on Local/s@fltr-00000005;1
-- Executing [s@fltr:3] Set("Local/s@fltr-00000005;2", "TIME=01:01-11:59\,*\,*\,*") in new stack
-- Executing [s@fltr:4] Set("Local/s@fltr-00000005;2", "NT=01:01-11:59,*,*,*") in new stack

–Satish Barot

thanks a lot satish,

your post help me to figure it out. but i got another problem regarding Multirow Functionality with func_odbc

Now My table is like

exten     time                                  file                  status
3333      09:01-11:59\,*\,*\,*        letters/a                1
3333      12:00-20:59\,*\,*\,*        letters/b                1
3333      21:00-08:59\,*\,*\,*        letters/c                1

function_odbc.conf

[THE_TIME]
prefix=GET
dsn=asteriskcdr
readsql=SELECT time,file from tbl_time WHERE exten = '${ARG1}' and status = '1'

i tried to play loop in extension.conf


exten => s,1,NoOp()

        same => n,Set(ARRAY(time,file)=${GET_THE_TIME(${ARG1})})
        same => n,set(NT=${FILTER(0-9-*:\,,${time})})
        same => n,Verbose(total Row found ${ODBCROWS})
        same => n,Set(COUNTER=1)
        same => n,While($[${COUNTER} <= ${ODBCROWS}])
        same => n,Verbose(I found ${file})
        same => n,Verbose(I found ${NT})
        same => n,Set(COUNTER=$[${COUNTER} + 1])
        same => n,EndWhile()

it returns only one row

in your another post u suggest to follow viewtopic.php?f=13&t=87348 for multirow functionality . but that link is not working.
i found u suggest to use mulirow option along with ODBC_FETCH() but cant understand where to put it through . can u plz help me out ??

i’ve figured out how to get one field from multiple rows. but how can i get multiple fields from each row ?? like both time and file field ?? the following example return time field for each row. i posted all codes if it helps someone else who is querying for one field from multiple rows. but i need multiple field from multiple rows.

database table

exten     time                                  file                  status
3333      09:01-11:59\,*\,*\,*        letters/a                1
3333      12:00-20:59\,*\,*\,*        letters/b                1
3333      21:00-08:59\,*\,*\,*        letters/c                1

func_odbc.conf

[THE_TIME]
prefix=GET
dsn=asteriskcdr
mode=multirow
readsql=SELECT time from tbl_time WHERE exten = '${ARG1}' and status = '1'

and extension.conf


[macro-looptest]

exten => s,1,Verbose(1,Looping example)
        same => n,Set(ODBC_ID=${GET_THE_TIME(${MACRO_EXTEN})})
        same => n,GotoIf($[${ODBCROWS} < 1]?no_rows,1)
        same => n,Set(COUNTER=1)
        same => n,Verbose(total rows found ${ODBCROWS})

        same => n,While($[${COUNTER} <= ${ODBCROWS}])
        same => n,Set(TIME=${ODBC_FETCH(${ODBC_ID})})
        same => n,Verbose(This is ${TIME})
        same => n,set(NT=${FILTER(0-9-*:\,,${TIME})})
        same => n,Verbose(I found NEW TIME AS ${NT})
        same => n,Set(COUNTER=$[${COUNTER} + 1])
        same => n,EndWhile()
        same => n,ODBCFinish()

exten => no_rows,1,Verbose(1,No rows returned)
same => n,Playback(silence/1&invalid)
same => n,Hangup()

The following will work:

[THE_TIME] prefix=GET dsn=asteriskcdr mode=multirow readsql=SELECT time,file from tbl_time WHERE exten = '${ARG1}' and status = '1'

[code][macro-looptest]

exten => s,1,Verbose(1,Looping example)
same => n,Set(ODBC_ID=${GET_THE_TIME(${MACRO_EXTEN})})
same => n,GotoIf($[${ODBCROWS} < 1]?no_rows,1)
same => n,Set(COUNTER=1)
same => n,Verbose(total rows found ${ODBCROWS})
same => n,While($[${COUNTER} <= ${ODBCROWS}])
same => n,Set(HASH(times)=${ODBC_FETCH(${ODBC_ID})})
same => n,Verbose(This is =${HASH(times,time)})
same => n,set(NT=${FILTER(0-9-*:,${HASH(times,time)})})
same => n,Verbose(I found NEW TIME AS ${NT})
same => n,Set(Soundfile=${HASH(times,file)})
same => n,Verbose(I found NEW File AS ${Soundfile})
same => n,ClearHash(times)
same => n,Set(COUNTER=$[${COUNTER} + 1])
same => n,EndWhile()
same => n,ODBCFinish()
same => n,ClearHash(times)

exten => no_rows,1,Verbose(1,No rows returned)
same => n,ClearHash(times);
same => n,ODBCFinish()
same => n,Playback(silence/1&invalid)
same => n,Hangup()[/code]

asteriskdocs.org/en/3rd_Edit … funky.html
Check ‘Using the ARRAY() Function’ section in it.

–Satish Barot

thanks a lot abw for giving the whole code. it helped me a lot. still i m stuck with a simple prob. my intention is to play several files as ivr in users chosen time .

exten     time                                  file                  status                value
3333      09:01-15:59\,SAT\,*\,*         letters/a                1                       1
3333      00:01-23:59\,*\,*\,*             letters/b                1                       2
3333      21:00-08:59\,*\,*\,*             letters/c                1                       3

as per table on satarday from 9 to 15 “a” will be played before “b” others day “b” will be played alone.

[THE_TIME]
prefix=GET
dsn=asteriskcdr
mode=multirow
readsql=SELECT time,file from tbl_time WHERE exten = '${ARG1}' and status = '1' order by value
[macro-ivr]

exten => s,1,NoOp()

        same => n,set(BLACKLIST=${SEARCH_BLACKLIST(${CALLERID(num)},${ARG1})}) ;Check DB if callerid is blocked for exten
        same => n,Verbose(Total BlackList is ${BLACKLIST})
        same => n,GotoIf($[${BLACKLIST} = 0]?proceed:goaway)            ;;; If not found proceed otherwise goaway
        same => n(proceed),Answer()
        same => n,Verbose(Looping start)
        same => n,Set(ODBC_ID=${GET_THE_TIME(${MACRO_EXTEN})})
        same => n,GotoIf($[${ODBCROWS} < 1]?no_rows,1)
        same => n,Set(COUNTER=1)
        same => n,Verbose(total rows found ${ODBCROWS})
        same => n,While($[${COUNTER} <= ${ODBCROWS}])
        same => n,Set(HASH(times)=${ODBC_FETCH(${ODBC_ID})})
        same => n,Verbose(This is =${HASH(times,time)})
        same => n,set(NT=${FILTER(a-zA-Z0-9-*:\,,${HASH(times,time)})})
        same => n,Verbose(I found NEW TIME AS ${NT})
        same => n,Set(Soundfile=${HASH(times,file)})
        same => n,Verbose(I found NEW File AS ${Soundfile})
        same => n,GOToIfTime(${NT}?playsound:no_rows,1)
        same => n(playsound),Background(${Soundfile})
        same => n,wait(1)
        same => n,ClearHash(times)
        same => n,Set(COUNTER=$[${COUNTER} + 1])
        same => n,EndWhile()
        same => n,ODBCFinish()
        same => n,ClearHash(times)
exten => no_rows,1,Verbose(1,No rows returned)
same => n,ClearHash(times)
same => n,ODBCFinish()
same => n,wait(5)
same => n,Hangup()

Problem is when its not meeting the first row validation its going directly to no_rows extension. the loop breaks down and its not checking the second row. so sound “b” is not being played if i use

same => n,GOToIfTime(${NT}?playsound:no_rows,1)

always sound file “a” is being played before “b” . means both sound is being played even its not satarday

i’ve figured it out

as i m very new in programming , cant be confident if the code is ok … i’ll appreciate any suggestion . thanks a lot again