Jonathan H
2016-Nov-05 16:13 UTC
[asterisk-users] Is this a reasonable way to store user prefs in ASTDB? And what's this Re: Is JSON a dialplan "thing" yet? (Asterisk 14)
Thanks. OK, this is the best I can come up with on Asterisk 14 to store an unknown number of user preferences in ASTDB. Is this acceptable? Is there a better way? And... what's this error about? [Nov 5 16:05:56] NOTICE[1936][C-0000002b]: ast_expr2.y:763 compose_func_args: argbuf allocated 17 bytes; [Nov 5 16:05:56] NOTICE[1936][C-0000002b]: ast_expr2.y:782 compose_func_args: argbuf uses 16 bytes; It seems to be triggered the following line, even though the result is correct. Set(HASH(userPrefs,volume)=$[HASH(userPrefs,volume)+1]) The result "database show" after running it twice is as expected: /userPrefs/6001 : volume:3,location:London,language:en_GB Here's my test dialplan: [dbPrefStoreTest] exten => s,1,NoOp() same => n,GotoIf($[${DB_EXISTS(userPrefs/${CALLERID(num)})}]?getprefs) same => n,Set(DB(userPrefs/${CALLERID(num)})=volume:1,location:London,language:en_GB) same => n,Verbose(1,) same => n,Verbose(1,----------Get Items from DB------------) same => n(getprefs),Set(userPrefs=${DB(userPrefs/${CALLERID(num)})}) same => n,While($["${SET(mytmpvar=${SHIFT(userPrefs)})}" != ""]) same => n,Set(HASH(userPrefs,${CUT(mytmpvar,:,1)})=${CUT(mytmpvar,:,2)}) same => n,EndWhile same => n,Verbose(1,hashKeys(userPrefs) are "${HASHKEYS(userPrefs)}" and "HASH(userPrefs)" is "${HASH(userPrefs)}") same => n,Verbose(1,) same => n,Verbose(1,----------Increase the volume by 1----) same => n,Set(HASH(userPrefs,volume)=$[HASH(userPrefs,volume)+1]) same => n,Verbose(1,NOW hashKeys(userPrefs) are "${HASHKEYS(userPrefs)}" and "HASH(userPrefs)" is "${HASH(userPrefs)}") same => n,Verbose(1,) same => n,Verbose(1,----------Bundle them back up for DB storage----) same => n,Set(hUP=${HASHKEYS(userPrefs)}) same => n,While($["${SET(hashKey=${SHIFT(hUP)})}" != ""]) same => n,Set(PUSH(prefPairs)=${hashKey}:${HASH(userPrefs,${hashKey})}) same => n,Verbose(1,Current item is ${hashKey}:${HASH(userPrefs,${hashKey})}) same => n,EndWhile same => n,Verbose(1,Setting ${prefPairs} to DB) same => n,Set(DB(userPrefs/${CALLERID(num)})=${prefPairs}) same => n,Hangup() On 1 November 2016 at 23:29, Joshua Colp <jcolp at digium.com> wrote:> > On Tue, Nov 1, 2016, at 07:55 PM, Jonathan H wrote: > > I need to store some basic caller data in ASTDB - certainly doesn't need > > full blown mySQL. > > > > There's 4 or 5 bits of info per caller, and I saw that there is a json > > entry in ASTDB for the endpoint. > > > > Does that mean that there are accessible functions to deal with json now? > > I > > couldn't find anything in the docs. > > > > If not, any other ideas for storing in DB other than just family/key? > > JSON in AstDB is how the new sorcery data layer stores data there. It > serializes internal Asterisk data structures into JSON, and then back. > There's nothing currently available that I know of for JSON in the > dialplan. > > -- > Joshua Colp > Digium, Inc. | Senior Software Developer > 445 Jan Davis Drive NW - Huntsville, AL 35806 - US > Check us out at: www.digium.com & www.asterisk.org > > -- > _____________________________________________________________________ > -- Bandwidth and Colocation Provided by http://www.api-digital.com -- > > Check out the new Asterisk community forum at: https://community.asterisk.org/ > > New to Asterisk? Start here: > https://wiki.asterisk.org/wiki/display/AST/Getting+Started > > asterisk-users mailing list > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users