AJAX: Difference between revisions

From MidasWiki
Jump to navigation Jump to search
Line 54: Line 54:
** ?odb=<code>ODB path</code>
** ?odb=<code>ODB path</code>
** ?format=<code>sprintf format</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)
* BUG: some versions of mhttpd do not percent-encode the value of the "format" parameter (see section about URL encoding)

Revision as of 08:50, 21 August 2013

About

This page will document the MIDAS AJAX functions accessible through special mhttpd URLs.

URL percent-encoding

All parameter names and parameter values (?name=value) are passed through urlDecode.

  • 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.

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.

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???
      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 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
    • ?odbN=ODB path
    • ?formatN=sprintf format
  • 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)
  • 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
  • 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
  • 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
  • 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