* This error is also used to indicate an illegal parameter value, in server
* scripts.
*/
-jsonrpc.Constant.ErrorCode.PaameterMismatch = 5;
+jsonrpc.Constant.ErrorCode.ParameterMismatch = 5;
/**
* Error code, value 6: Permission Denied
if (strspn(jsonInput.method, nameChars) != strlen(jsonInput.method))
{
/* There's some illegal character in the service name */
- error.setError(JsonRpcError.MethodNotFound,
+ error.setError(jsonrpc.Constant.ErrorCode.MethodNotFound,
"Illegal character found in method name.");
error.Send();
return;
if (strspn(jsonInput.service, "." + nameChars) != strlen(jsonInput.service))
{
/* There's some illegal character in the service name */
- error.setError(JsonRpcError.IllegalService,
+ error.setError(jsonrpc.Constant.ErrorCode.IllegalService,
"Illegal character found in service name.");
error.Send();
return;
*/
if (typeof(strstr(jsonInput.service, "..")) != "pointer")
{
- error.setError(JsonRpcError.IllegalService,
+ error.setError(jsonrpc.Constant.ErrorCode.IllegalService,
"Illegal use of two consecutive dots in service name");
error.Send();
return;
/* We'll maintain our own count of the number of open resources */
o.resourceList.count = 0;
- /*
- * Resource types
- */
- o.Type = new Object();
- o.Type.ldb = 1; /* database handle */
- o.Type.tid = 2; /* tree id */
- o.Type.fid = 3; /* file id */
- /* etc., etc., etc. */
-
/*
* Set a new saved resource.
{
/* Yup. */
error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server);
- error.setError(JsonRpcError_ResourceError,
+ error.setError(jsonrpc.Constant.ErrorCode.ResourceError,
"Session limit on resources (" +
RESOURCE_LIMIT +
") exceeded.");
/*
* Get a previously-saved resource
*/
- function _get(resourceId, type, error)
+ function _get(resourceId, error)
{
/* Does the specified resource id exist? */
if (! this.resourceList[resourceId])
/* Retrieve the resource */
var r = this.resourceList[resourceId];
- /* Is the specified resource the correct type? */
- if (r.type != type)
- {
- /* Nope. */
- error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server);
- error.setError(jsonrpc.Constant.ErrorCode.ResourceError,
- "Incorrect type for specified resource id.");
- return error;
- }
-
/* Give 'em what they came for! */
return r.resource;
}
o.get = _get;
+ /*
+ * Find a previously-saved resource
+ */
+ function _find(type, error)
+ {
+ /* Does the specified resource id exist? */
+ for (var resourceId in this.resourceList)
+ {
+ /* Retrieve the resource */
+ var r = this.resourceList[resourceId];
+
+ /* Ignore "id" and "count" integer fields */
+ if (typeof(r) == "object")
+ {
+ /* Is the specified resource the correct type? */
+ if (r.type == type)
+ {
+ /* Yup, this is the one they want. */
+ return resourceId;
+ }
+ }
+ }
+
+ /* It wasn't found. */
+ return undefined;
+ }
+ o.find = _find;
+
/*
* Release a previously-saved resource, allowing it to be freed
*/
{
if (params.length < 1)
{
- error.setError(JsonRpcError_ParameterMismatch,
+ error.setError(jsonrpc.Constant.ErrorCode.ParameterMismatch,
"usage: <db_name> [<option> ...]");
return error;
}
+ /* First, see if this database was already opened */
+ var resourceId = session.resources.find("ldb:" + params[0], error);
+ if (resourceId != undefined)
+ {
+ /* It was. Give 'em the resource id */
+ return resourceId;
+ }
+
+ /* Database was not previously opened. Connect to it. */
ldb = ldb_init();
var ret = ldb.connect(params[0]);
if (ret && ldb.db)
{
- return session.resources.set(ldb,
- session.resources.Type.ldb,
- error);
+ return session.resources.set(ldb, "ldb:" + params[0], error);
}
else
{
{
if (params.length != 1)
{
- error.setError(JsonRpcError_ParameterMismatch,
+ error.setError(jsonrpc.Constant.ErrorCode.ParameterMismatch,
"usage: <resource_id>");
return error;
}
- ldb = session.resources.get(params[0],
- session.resources.Type.ldb,
- error);
+ ldb = session.resources.get(params[0], error);
if (ldb["__type"] == "_JsonRpcError")
{
return ldb;
{
if (params.length != 1)
{
- error.setError(JsonRpcError_ParameterMismatch,
+ error.setError(jsonrpc.Constant.ErrorCode.ParameterMismatch,
"usage: <resource_id>");
return error;
}
- ldb = session.resources.get(params[0],
- session.resources.Type.ldb,
- error);
+ ldb = session.resources.get(params[0], error);
if (ldb["__type"] == "_JsonRpcError")
{
return ldb;
{
if (params.length != 1)
{
- error.setError(JsonRpcError_ParameterMismatch,
+ error.setError(jsonrpc.Constant.ErrorCode.ParameterMismatch,
"usage: <resource_id>");
return error;
}
- ldb = session.resources.get(params[0],
- session.resources.Type.ldb,
- error);
+ ldb = session.resources.get(params[0], error);
if (ldb["__type"] == "_JsonRpcError")
{
return ldb;
{
if (params.length != 1)
{
- error.setError(JsonRpcError_ParameterMismatch,
+ error.setError(jsonrpc.Constant.ErrorCode.ParameterMismatch,
"usage: <resource_id>");
return error;
}
- ldb = session.resources.get(params[0],
- session.resources.Type.ldb,
- error);
+ ldb = session.resources.get(params[0], error);
if (ldb["__type"] == "_JsonRpcError")
{
return ldb;
{
if (params.length < 2 || params.length > 5)
{
- error.setError(JsonRpcError_ParameterMismatch,
+ error.setError(jsonrpc.Constant.ErrorCode.ParameterMismatch,
"usage: " +
"<resource_id> <expr> [<baseDN> [<scope> [<attrs>]]]");
return error;
}
- ldb = session.resources.get(params[0],
- session.resources.Type.ldb,
- error);
+ ldb = session.resources.get(params[0], error);
if (ldb["__type"] == "_JsonRpcError")
{
return ldb;
}
else
{
- error.setError(JsonRpcError_ParameterMismatch,
- "invalid scope");
+ error.setError(jsonrpc.Constant.ErrorCode.ParameterMismatch,
+ "invalid scope: " + scope);
return error;
}
- return ldb.transaction_search(expr, baseDN, scope, attrs);
+ return ldb.search(expr, baseDN, scope, attrs);
}
jsonrpc.method.search = _search;
{
if (params.length != 2)
{
- error.setError(JsonRpcError_ParameterMismatch,
+ error.setError(jsonrpc.Constant.ErrorCode.ParameterMismatch,
"usage: <resource_id> <ldif>");
return error;
}
- ldb = session.resources.get(params[0],
- session.resources.Type.ldb,
- error);
+ ldb = session.resources.get(params[0], error);
if (ldb["__type"] == "_JsonRpcError")
{
return ldb;
{
if (params.length != 2)
{
- error.setError(JsonRpcError_ParameterMismatch,
+ error.setError(jsonrpc.Constant.ErrorCode.ParameterMismatch,
"usage: <resource_id> <ldif>");
return error;
}
- ldb = session.resources.get(params[0],
- session.resources.Type.ldb,
- error);
+ ldb = session.resources.get(params[0], error);
if (ldb["__type"] == "_JsonRpcError")
{
return ldb;
{
if (params.length != 2)
{
- error.setError(JsonRpcError_ParameterMismatch,
+ error.setError(jsonrpc.Constant.ErrorCode.ParameterMismatch,
"usage: <resource_id> <dn>");
return error;
}
- ldb = session.resources.get(params[0],
- session.resources.Type.ldb,
- error);
+ ldb = session.resources.get(params[0], error);
if (ldb["__type"] == "_JsonRpcError")
{
return ldb;
{
if (params.length != 3)
{
- error.setError(JsonRpcError_ParameterMismatch,
+ error.setError(jsonrpc.Constant.ErrorCode.ParameterMismatch,
"usage: <resource_id> <old_dn> <new_dn>");
return error;
}
- ldb = session.resources.get(params[0],
- session.resources.Type.ldb,
- error);
+ ldb = session.resources.get(params[0], error);
if (ldb["__type"] == "_JsonRpcError")
{
return ldb;
{
if (params.length != 2)
{
- error.setError(JsonRpcError_ParameterMismatch,
+ error.setError(jsonrpc.Constant.ErrorCode.ParameterMismatch,
"usage: <resource_id> <string_to_be_encoded>");
return error;
}
- ldb = session.resources.get(params[0],
- session.resources.Type.ldb,
- error);
+ ldb = session.resources.get(params[0], error);
if (ldb["__type"] == "_JsonRpcError")
{
return ldb;
{
if (params.length != 2)
{
- error.setError(JsonRpcError_ParameterMismatch,
+ error.setError(jsonrpc.Constant.ErrorCode.ParameterMismatch,
"usage: <resource_id> <string_to_be_decoded>");
return error;
}
- ldb = session.resources.get(params[0],
- session.resources.Type.ldb,
- error);
+ ldb = session.resources.get(params[0], error);
if (ldb["__type"] == "_JsonRpcError")
{
return ldb;
{
if (params.length != 2)
{
- error.setError(JsonRpcError_ParameterMismatch,
+ error.setError(jsonrpc.Constant.ErrorCode.ParameterMismatch,
"usage: <resource_id> <string_to_be_decoded>");
return error;
}
- ldb = session.resources.get(params[0],
- session.resources.Type.ldb,
- error);
+ ldb = session.resources.get(params[0], error);
if (ldb["__type"] == "_JsonRpcError")
{
return ldb;
{
if (params.length != 1)
{
- error.setError(JsonRpcError_ParameterMismatch,
+ error.setError(jsonrpc.Constant.ErrorCode.ParameterMismatch,
"usage: <resource_id>");
return error;
}
- ldb = session.resources.get(params[0],
- session.resources.Type.ldb,
- error);
+ ldb = session.resources.get(params[0], error);
if (ldb["__type"] == "_JsonRpcError")
{
return ldb;
/*
Root is as found by:
- source/bin/ldbsearch -H /usr/local/samba/private/sam.ldb -b '' \
- -s base defaultNamingContext
+ source/bin/ldbsearch -H /usr/local/samba/private/sam.ldb -b '' \
+ -s base defaultNamingContext
+
+Schema page:
+ source/bin/ldbsearch -H /usr/local/samba/private/sam.ldb -b '' \
+ -s base subschemaSubentry
+ source/bin/ldbsearch -H /usr/local/samba/private/sam.ldb -b \
+ 'CN=Aggregate,CN=Schema,CN=Configuration,DC=workgroup,DC=example,DC=com' \
+ -s base objectClasses attributeTypes matchingRules ldapSyntaxes
*/
function setAppearances()
appearance.initial = function(vTheme)
{
var res = oldInitial ? oldInitial.apply(this, arguments) : {};
- res.width = "96%";
+ res.width = "90%";
return res;
}
}
new qx.ui.pageview.tabview.TabViewPage(tabView_Schema);
// Build the search page
- buildPageSearch(tabViewPage_Search);
+ var searchResultsTable = buildPageSearch(tabViewPage_Search);
+
+ // Provide access to the search results table
+ tabView_.searchResultTable = searchResultsTable;
// Build the browse page
buildPageBrowse(tabViewPage_Browse);
function buildPageSearch(page)
{
+ // We need a horizontal layout for the combox box and "Find" button
+ var layout = new qx.ui.layout.HorizontalBoxLayout();
+ layout.setWidth("100%");
+
// Create a combo box for entry of the search expression
var search = new qx.ui.form.ComboBox();
search.getField().setWidth("100%");
search.setEditable(true);
- // Add the combo box to the page
- page.add(search);
+ // Add the combo box to the horizontal layout
+ layout.add(search);
- // Create a simple table model
- var tableModel = new qx.ui.table.SimpleTableModel();
- tableModel.setColumns([ "Attribute", "Value" ]);
+ // Right-justify the 'Find' button
+ var spacer = new qx.ui.basic.HorizontalSpacer;
+ layout.add(spacer);
- // Add some garbage data to it
- var attributeNames =
- [
- [ "Nickname" ],
- [ "Hostname" ],
- [ "Port" ],
- [ "Connection caching" ],
- [ "TLS" ],
- [ "Client-side caching" ],
- [ "Connections so far" ],
- [ "LDAP protocol version" ],
- [ "Vendor Name" ],
- [ "Vendor Version" ],
- [ "Support LDAP Version" ],
- [ "Supported SASL Mechanisms" ],
- [ "Junk 1" ],
- [ "Junk 2" ],
- [ "Junk 3" ]
- ];
-
+ // Create the 'Find' button
+ var find = new qx.ui.form.Button('Find');
- var rowData = [];
- for (var row = 0; row < attributeNames.length; row++)
+ // We'll be setting url and service upon execute; no need to do it now.
+ var rpc = new qx.io.remote.Rpc();
+ rpc.setTimeout(10000);
+ var mycall = null;
+
+ find.addEventListener("execute", function()
{
- rowData.push([ attributeNames[row], "" + (Math.random() * 10000) ]);
- }
- tableModel.setData(rowData);
+ // Set the URL and Service
+ rpc.setUrl("/services/");
+ rpc.setServiceName("samba.ldb");
+ rpc.setCrossDomain(false);
+
+ find.setEnabled(false);
+// abort.setEnabled(true);
+ mycall = rpc.callAsync(function(result, ex, id)
+ {
+ mycall = null;
+ if (ex == null)
+ {
+ var rowData = [];
+ for (var i = 0; i < result.length; i++)
+ {
+ var o = result[i];
+ if (typeof(o) != "object")
+ {
+ alert("Found unexpected result, type " +
+ typeof(o) +
+ ", " +
+ o +
+ "\n");
+ continue;
+ }
+ for (var field in o)
+ {
+ // skip dn and distinguishedName fields;
+ // they're shown in each row anyway.
+ if (field == "dn" || field == "distinguishedName")
+ {
+ continue;
+ }
+ rowData.push( [
+ o["dn"],
+ field,
+ o[field]
+ ] );
+ }
+
+ // Tell the table to use the new data
+ tableModel.setData(rowData);
+ }
+ }
+ else
+ {
+ alert("Async(" + id + ") exception: " + ex);
+ }
+ find.setEnabled(true);
+// abort.setEnabled(false);
+ },
+ "search", // method
+ db_handle, // database handle
+ search.getValue(), // search expression
+ "", // baseDN
+ "default", // scope
+ [ "*" ]); // attributes
+ });
+
+ // Add the button to horizontal layout
+ layout.add(find);
+
+ // Add the horizontal box layout to the page
+ page.add(layout);
+
+ // Create a simple table model
+ var tableModel = new qx.ui.table.SimpleTableModel();
+ tableModel.setColumns([ "Distinguished Name", "Attribute", "Value" ]);
+
tableModel.setColumnEditable(0, false);
- tableModel.setColumnEditable(1, true);
+ tableModel.setColumnEditable(1, false);
+ tableModel.setColumnEditable(2, false);
// Create a table
var table = new qx.ui.table.Table(tableModel);
- with (table) {
+ with (table)
+ {
set({
top: 40,
left: 0,
statusBarVisible: false,
columnVisibilityButtonVisible: false
});
- setColumnWidth(0, 200);
- setColumnWidth(1, 440);
- setMetaColumnCounts([1, -1]);
+ setColumnWidth(0, 300);
+ setColumnWidth(1, 180);
+ setColumnWidth(2, 240);
+ setMetaColumnCounts([ 1, -1 ]); // h-scroll attribute and value together
};
page.add(table);
+
+ return table;
}
function buildPageBrowse(page)
qx.core.Init.getInstance().defineMain(
function()
{
+ // Enable JSON-RPC debugging
+ qx.Settings.setCustomOfClass("qx.io.Json", "enableDebug", true);
+
+ if (false)
+ {
+ // We'd like all table columns to do "live resize". Unfortunately,
+ // it's too slow. Maybe someone wants to work on it...
+ var constructor = qx.OO.classes["qx.ui.table.TablePaneScroller"];
+ qx.Proto = constructor.prototype;
+ qx.OO.changeProperty(
+ {
+ name : "liveResize",
+ type : qx.constant.Type.BOOLEAN,
+ defaultValue : true
+ });
+ }
+
// Set appearances for this application
setAppearances();
// Create the tabs and their windows, and attach to client document
var tabView = setupTabs(clientDocument);
+
+ // Open a database connection. Uses the dangerous sync request.
+ var rpc = new qx.io.remote.Rpc();
+ rpc.setUrl("/services/");
+ rpc.setServiceName("samba.ldb");
+ rpc.setCrossDomain(false);
+
+ try
+ {
+ // db_handle is global!!! no 'var' is intentional.
+ db_handle = rpc.callSync("connect",
+ "/usr/local/samba/private/sam.ldb");
+ }
+ catch (ex)
+ {
+ alert("Sync exception: " + ex);
+ }
});
/*
* Local Variables: