AJAX
Jump to navigation
Jump to search
About
This page will document the MIDAS AJAX functions accessible through special mhttpd URLs.
These AJAX functions are typically accessed from browser javascript using the MIDAS mhttpd.js library.
URL percent-encoding
All parameter names and parameter values (?name=value) are passed through urlDecode.
Encoding used by urlDecode:
- %HH - decoded as char value 0xHH (hex encoding)
- "+" - decoded as " " ("plus" decoded as "space")
- other chars decoded as themselves
This is consistent with URL encoding rules specified by http://tools.ietf.org/html/rfc3986
On the client side (mhttpd.js), parameter values should be encoded using the JavaScript encodeURIComponent() function.
- BUG: value of parameter "format" is not passed through urlDecode (git commit db4602dc2ed63674413f92cc92f49f183bd14225, 21 Aug 2013), this is consistent with mhttpd.js which does not urlEncode the values. Values of "format0", etc used by ODBMGet() are decoded as expected.
urlDecode(pitem); if (!equal_ustring(pitem, "format")) urlDecode(p); setparam(pitem, p);
jset
- JSONP: no
- parameters:
- ?pnam=
xxx
- cookie_cpwd to match value of ODB /Custon/Pwd/xxx. How is this supposed to work??? How to use it???
- ?pnam=
if (*getparam("pnam")) { sprintf(ppath, "/Custom/Pwd/%s", getparam("pnam")); str[0] = 0; db_get_value(hDB, 0, ppath, str, &size, TID_STRING, TRUE); if (!equal_ustring(cookie_cpwd, str)) { show_text_header(); rsprintf("Invalid password!"); return; } }
- ?odb=
ODB path
- ?value=
data
- ?type=
integer
- if ODB path does not exist, it is created, using "type" as the MIDAS TID_xxx data type - ?len=
integer
- when ODB path is created, if "len" is not zero, it is made an array of "len" size, with all values set to "value". Except if "type" is TID_STRING, there is no array created, but "len" is used as the ODB string length.
- ?odb=
- ODB path encoding for arrays:
- /path/array[i] - write array element [i]
- /path/array - write array element [0]
- /path/array[*] - write as many array elements as there are comma-separated entries in "value". There is no check against existing array length - db_set_data_index() will grow the array as neeed.
- example: TBW
jget
- JSONP: no
- parameters:
- ?odb=
ODB path
- ?format=
sprintf format
- ?odb0=
ODB path
- activates the multiple jget function - ?odb
N
=ODB path
- ?format
N
=sprintf format
- ?odb=
- returns:
- single jget returns the text from output_key()
- multiple jget returns the values of all given ODB paths (?odb0=path?format0=format?odb1=path?format1=format?...) separated by the string "$#----#$\n".
- <DB_NO_KEY> for non-existant ODB paths (db_find_key() != DB_SUCCESS)
- BUG: some versions of mhttpd do not percent-encode the value of the "format" parameter (see section about URL encoding). Values of "format0", etc are decoded as expected.
- ODB array path encoding:
- /path/array[i] -> index=i
- /path/array[*] -> index=-1
- /path/array -> index=0
- then it is passed to output_key()
jcopy
TBW
jkey
- JSONP: no
- parameters:
- ?odb=
ODB path
- ?odb=
- returns:
if (equal_ustring(getparam("cmd"), "jkey")) { show_text_header(); if (isparam("odb") && db_find_key(hDB, 0, getparam("odb"), &hkey) == DB_SUCCESS) { db_get_key(hDB, hkey, &key); rsprintf("%s\n", key.name); rsprintf("TID_%s\n", rpc_tid_name(key.type)); rsprintf("%d\n", key.num_values); rsprintf("%d\n", key.item_size); rsprintf("%d", key.last_written); } else rsputs("<DB_NO_KEY>"); return; }
- example: TBW
jmsg
- JSONP: no
- parameters:
- ?n=
number of messages to return
- ?n=
- returns: output of cm_msg_retrieve()
if (equal_ustring(getparam("cmd"), "jmsg")) { i = 1; if (*getparam("n")) i = atoi(getparam("n")); show_text_header(); cm_msg_retrieve(i, str, sizeof(str)); rsputs(str); return; }
- example: TBW
jgenmsg
- JSONP: no
- parameters:
- ?msg=
message text
- ?msg=
- returns: ???
if (equal_ustring(getparam("cmd"), "jalm")) { show_text_header(); al_get_alarms(str, sizeof(str)); rsputs(str); return; }
- example: TBW
jalm
- JSONP: no
- parameters: no
- returns: text from al_get_alarms()
if (equal_ustring(getparam("cmd"), "jalm")) { show_text_header(); al_get_alarms(str, sizeof(str)); rsputs(str); return; }
- example: TBW