[asterisk-bugs] [JIRA] (ASTERISK-24017) HASHKEYS() doesn't work with hashes set as globals

Matt Jordan (JIRA) noreply at issues.asterisk.org
Thu Jul 10 09:18:57 CDT 2014


Matt Jordan created ASTERISK-24017:
--------------------------------------

             Summary: HASHKEYS() doesn't work with hashes set as globals
                 Key: ASTERISK-24017
                 URL: https://issues.asterisk.org/jira/browse/ASTERISK-24017
             Project: Asterisk
          Issue Type: Bug
      Security Level: None
          Components: Functions/func_strings
    Affects Versions: SVN, 1.8.28.2, 11.6.0, 12.3.2
         Environment: SVN-branch-12-r417705M
            Reporter: John Bigelow


h2. Summary
Hashes can be set as global variables using the HASH() dialplan function. However it appears that the HASHKEYS() dialplan function can not retreive hashes that were set as global variables. Looking at {{funcs/func_strings.c}} in the function {{static int hashkeys_read()}}, it appears it only looks for variables on the channel and not any globals.

h2. Demonstration
h3. Dialplan
{code}
[test]
; Set hash variables on channel, print values of keys, print all keys - does work.
exten => 1,1,Answer()
exten => 1,n,NoOp(Setting hash vars on channel)
exten => 1,n,Set(HASH(HASH_ONE,hello)=world)
exten => 1,n,Set(HASH(HASH_ONE,foo)=bar)
exten => 1,n,NoOp(HASH_ONE 'hello ${HASH(HASH_ONE,hello)}')
exten => 1,n,NoOp(HASH_ONE 'foo ${HASH(HASH_ONE,foo)}')
exten => 1,n,NoOp(HASH_ONE KEYS: ${HASHKEYS(HASH_ONE)})
exten => 1,n,Wait(2)
exten => 1,n,Hangup()

; Set hash variables as globals, print values of keys, print all keys - does not work.
exten => 2,1,Answer()
exten => 2,n,NoOp(Setting hash vars as globals)
exten => 2,n,Set(GLOBAL(HASH(HASH_TWO,linus))=torvalds)
exten => 2,n,Set(GLOBAL(HASH(HASH_TWO,richard))=stallman)
exten => 2,n,NoOp(HASH_TWO 'linus ${HASH(HASH_TWO,linus)}')
exten => 2,n,NoOp(HASH_TWO 'richard ${HASH(HASH_TWO,richard)}')
exten => 2,n,NoOp(HASH_TWO KEYS: ${HASHKEYS(HASH_TWO)})
exten => 2,n,NoOp(HASH_TWO KEYS: ${GLOBAL(${HASHKEYS(HASH_TWO)})})
exten => 2,n,Wait(2)
exten => 2,n,Hangup()
{code}

h3. Output of executing dialplan
Output of executing extension {{1}} that sets the hash variables on the channel and shows the HASHKEYS() function properly returning the keys(priority 7):
{code}
*CLI> originate local/1 at test application echo
     -- Executing [1 at test:1] Answer("Local/1 at test-00000000;2", "") in new stack
     -- Launching echo() on Local/1 at test-00000000;1
     -- Executing [1 at test:2] NoOp("Local/1 at test-00000000;2", "Setting hash vars on channel") in new stack
     -- Executing [1 at test:3] Set("Local/1 at test-00000000;2", "HASH(HASH_ONE,hello)=world") in new stack
     -- Executing [1 at test:4] Set("Local/1 at test-00000000;2", "HASH(HASH_ONE,foo)=bar") in new stack
     -- Executing [1 at test:5] NoOp("Local/1 at test-00000000;2", "HASH_ONE 'hello world'") in new stack
     -- Executing [1 at test:6] NoOp("Local/1 at test-00000000;2", "HASH_ONE 'foo bar'") in new stack
     -- Executing [1 at test:7] NoOp("Local/1 at test-00000000;2", "HASH_ONE KEYS: foo,hello") in new stack
     -- Executing [1 at test:8] Wait("Local/1 at test-00000000;2", "2") in new stack
     -- Executing [1 at test:9] Hangup("Local/1 at test-00000000;2", "") in new stack
   == Spawn extension (test, 1, 9) exited non-zero on 'Local/1 at test-00000000;2'
{code}

Output of executing extension {{2}} that sets the hash variables as globals and shows the HASHKEYS() function *not* returning the keys with or without using the GLOBAL() function(priority 7 & 8). Output of 'dialplan show globals' is also provided to show they were set as globals:
{code}
*CLI> originate local/2 at test application echo
     -- Executing [2 at test:1] Answer("Local/2 at test-00000000;2", "") in new stack
     -- Launching echo() on Local/2 at test-00000000;1
     -- Executing [2 at test:2] NoOp("Local/2 at test-00000000;2", "Setting hash vars as globals") in new stack
     -- Executing [2 at test:3] Set("Local/2 at test-00000000;2", "GLOBAL(HASH(HASH_TWO,linus))=torvalds") in new stack
   == Setting global variable '~HASH~HASH_TWO~linus~' to 'torvalds'
     -- Executing [2 at test:4] Set("Local/2 at test-00000000;2", "GLOBAL(HASH(HASH_TWO,richard))=stallman") in new stack
   == Setting global variable '~HASH~HASH_TWO~richard~' to 'stallman'
     -- Executing [2 at test:5] NoOp("Local/2 at test-00000000;2", "HASH_TWO 'linus torvalds'") in new stack
     -- Executing [2 at test:6] NoOp("Local/2 at test-00000000;2", "HASH_TWO 'richard stallman'") in new stack
     -- Executing [2 at test:7] NoOp("Local/2 at test-00000000;2", "HASH_TWO KEYS: ") in new stack
     -- Executing [2 at test:8] NoOp("Local/2 at test-00000000;2", "HASH_TWO KEYS: ") in new stack
     -- Executing [2 at test:9] Wait("Local/2 at test-00000000;2", "2") in new stack
     -- Executing [2 at test:10] Hangup("Local/2 at test-00000000;2", "") in new stack
   == Spawn extension (test, 2, 10) exited non-zero on 'Local/2 at test-00000000;2'

*CLI> dialplan show globals 
   ~HASH~HASH_TWO~richard~=stallman
   ~HASH~HASH_TWO~linus~=torvalds

    -- 2 variable(s)
{code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)



More information about the asterisk-bugs mailing list