AJAX: Difference between revisions

From MidasWiki
Jump to navigation Jump to search
(The midas documentation has moved to https://midas.triumf.ca/docs/)
Tag: Replaced
 
(49 intermediate revisions by 3 users not shown)
Line 1: Line 1:
= About =
The midas documentation has moved. See [https://midas.triumf.ca/docs/develop/api/javascript/deprecated/#ajax-interface AJAX interface] on the Deprecated web features page for the new documentation about the mhttpd AJAX commands.
 
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.
 
<pre>
            urlDecode(pitem);
            if (!equal_ustring(pitem, "format"))
              urlDecode(p);
            setparam(pitem, p);
</pre>
 
* BUG: confirm that values of "format0", etc are decoded correctly.
 
= jset =
 
* JSONP: no
* parameters:
** ?pnam=<code>xxx</code> - cookie_cpwd to match value of ODB /Custon/Pwd/xxx. How is this supposed to work??? How to use it???
<pre>
      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;
        }
      }
</pre>
** ?odb=<code>ODB path</code>
** ?value=<code>data</code>
** ?type=<code>integer</code> - if ODB path does not exist, it is created, using "type" as the MIDAS TID_xxx data type
** ?len=<code>integer</code> - 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 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=<code>ODB path</code>
** ?format=<code>sprintf format</code>
** ?odb0=<code>ODB path</code> - activates the multiple jget function
** ?odb<code>N</code>=<code>ODB path</code>
** ?format<code>N</code>=<code>sprintf format</code>
* 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=<code>ODB path</code>
* returns:
<pre>
  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;
  }
</pre>
* example: TBW
 
= jmsg =
 
* JSONP: no
* parameters:
** ?n=<code>number of messages to return</code>
* returns: output of cm_msg_retrieve()
<pre>
  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;
  }
</pre>
* example: TBW
 
= jgenmsg =
 
* JSONP: no
* parameters:
** ?msg=<code>message text</code>
* returns: ???
<pre>
  if (equal_ustring(getparam("cmd"), "jalm")) {
      show_text_header();
      al_get_alarms(str, sizeof(str));
      rsputs(str);
      return;
  }
</pre>
* example: TBW
 
= jalm =
 
* JSONP: no
* parameters: no
* returns: text from al_get_alarms()
 
<pre>
  if (equal_ustring(getparam("cmd"), "jalm")) {
      show_text_header();
      al_get_alarms(str, sizeof(str));
      rsputs(str);
      return;
  }
</pre>
 
* example: TBW

Latest revision as of 22:00, 30 October 2026

The midas documentation has moved. See AJAX interface on the Deprecated web features page for the new documentation about the mhttpd AJAX commands.