public VxDbusSchema(string busurl) { WvUrl url = new WvUrl(busurl); if (url.host.e() || url.host == "session") bus = WvDbus.session_bus; else bus = new WvDbus(wv.fmt("tcp:host={0},port={1}", url.host, url.port)); }
public WvDbi_MSSQL(string moniker) { string real; if (!moniker.StartsWith("//")) real = moniker; else { // try to parse it as an URL WvUrl url = new WvUrl(moniker); if (url.path.StartsWith("/")) url.path = url.path.Substring(1); if ((url.user+url.password).e()) real = wv.fmt("server={0};database={1};" + "Integrated Security=SSPI;", url.host, url.path); else real = wv.fmt("server={0};database={1};" + "User ID={2};Password={3};", url.host, url.path, url.user, url.password); } log.print("MSSQL create: '{0}'\n", real); try { opendb(new SqlConnection(real)); } catch { try { Dispose(); } catch {} throw; } }
public WvDbi_Sqlite(string moniker) { WvUrl url = new WvUrl(moniker); string path = "URI=file:" + url.path; log.print("Sqlite create: '{0}'\n", path); opendb(new SqliteConnection(path)); }
public WvDbi_ODBC(string moniker) { string real; if (moniker.StartsWith("dsn=") || moniker.StartsWith("driver=")) real = moniker; else { // try to parse it as an URL WvUrl url = new WvUrl(moniker); if (url.path.StartsWith("/")) url.path = url.path.Substring(1); if (url.method == "file") // method not provided real = wv.fmt("dsn={0};database={1};" + "User ID={2};uid={2};Password={3};pwd={3}", url.host, url.path, url.user, url.password); else real = wv.fmt("driver={0};server={1};database={2};" + "User ID={3};uid={3};Password={4};pwd={4}", url.method, url.host, url.path, url.user, url.password); } log.print("ODBC create: '{0}'\n", real); opendb(new OdbcConnection(real)); }
public static int _Main(string[] args) { // command line options VxCopyOpts opts = VxCopyOpts.Verbose; int verbose = (int)WvLog.L.Info; string outfile = null; var global_syms = new Dictionary<string,string>(); var extra = new OptionSet() .Add("n|dry-run", delegate(string v) { opts |= VxCopyOpts.DryRun; } ) .Add("f|force", delegate(string v) { opts |= VxCopyOpts.Destructive; } ) .Add("v|verbose", delegate(string v) { verbose++; } ) .Add("g|global-sym=", delegate(string v) { var splitopts = StringSplitOptions.RemoveEmptyEntries; char[] splitchars = {',', ';', ':'}; if (v.ne()) foreach (var sym in v.Split(splitchars, splitopts)) global_syms.Add(sym.ToLower(), null); } ) .Add("o|output-file=", delegate(string v) { outfile = v; }) .Parse(args); WvLog.maxlevel = (WvLog.L)verbose; if (extra.Count < 1) { ShowHelp(); return 97; } string cmd = extra[0]; if (cmd == "pascalgen") return pascalgen_Main(extra, global_syms, outfile); WvIni bookmarks = new WvIni( wv.PathCombine(wv.getenv("HOME"), ".wvdbi.ini")); string moniker = extra.Count > 1 ? extra[1] : bookmarks.get("Defaults", "url", null); string dir = extra.Count > 2 ? extra[2] : "."; if (cmd == "dfix") { VxDiskSchema disk = new VxDiskSchema(dir); bool consider_rules = true; if (consider_rules) return disk.FixSchemaData(disk.GetReplaceRules(), disk.GetFieldsToSkip()); else return disk.FixSchemaData(null,null); } if (moniker.e()) { ShowHelp(); return 96; } // look up a bookmark if it exists, else use the provided name as a // moniker moniker = bookmarks.get("Bookmarks", moniker, moniker); // provide a default username/password if they weren't provided // FIXME: are there URLs that should have a blank username/password? WvUrl url = new WvUrl(moniker); if (url.user.e()) url.user = bookmarks.get("Defaults", "user"); if (url.password.e()) url.password = bookmarks.get("Defaults", "password"); using (var backend = GetBackend(url)) { bookmarks.set("Defaults", "url", url.ToString(true)); bookmarks.maybeset("Defaults", "user", url.user); bookmarks.maybeset("Defaults", "password", url.password); string p = url.path.StartsWith("/") ? url.path.Substring(1) : url.path; bookmarks.set("Bookmarks", p, url.ToString(true)); try { bookmarks.save(); } catch (IOException) { // not a big deal if we can't save our bookmarks. } if (cmd == "remote") return 0; // just saved the bookmark, so we're done else if (cmd == "pull") do_pull(backend, dir, opts); else if (cmd == "push") do_push(backend, dir, opts); else if (cmd == "dpull") do_dpull(backend, dir, opts); else if (cmd == "dpush") do_dpush(backend, dir, opts); else { Console.Error.WriteLine("\nUnknown command '{0}'\n", cmd); ShowHelp(); } } return 0; }
private static ISchemaBackend GetBackend(WvUrl url) { log.print("Connecting to '{0}'\n", url); return VxSchema.create(url.ToString(true)); }
[Test] public void urls() { WvUrl u; u = new WvUrl("/foo/blah"); WVPASSEQ(u.ToString(), "file:/foo/blah"); WVPASSEQ(u.host, null); WVPASSEQ(u.port, 0); u = new WvUrl("foo/blah"); WVPASSEQ(u.ToString(), "file:foo/blah"); WVPASSEQ(u.host, null); WVPASSEQ(u.port, 0); u = new WvUrl("file:foo/blah"); WVPASSEQ(u.ToString(), "file:foo/blah"); u = new WvUrl("whatever:anything@nothing:stuff"); WVPASSEQ(u.ToString(), "whatever:anything@nothing:stuff"); WVPASSEQ(u.host, null); WVPASSEQ(u.port, 0); WVPASSEQ(u.path, "anything@nothing:stuff"); u = new WvUrl("http:"); WVPASSEQ(u.ToString(), "http:"); u = new WvUrl("http://"); WVPASSEQ(u.ToString(), "http:"); u = new WvUrl("http://*****:*****@host:57/path/to/stuff"); WVPASSEQ(u.ToString(), "http://user@host:57/path/to/stuff"); WVPASSEQ(u.ToString(true), "http://*****:*****@host:57/path/to/stuff"); WVPASSEQ(u.method, "http"); WVPASSEQ(u.user, "user"); WVPASSEQ(u.password, "pass"); WVPASSEQ(u.host, "host"); WVPASSEQ(u.port, 57); WVPASSEQ(u.path, "/path/to/stuff"); // Microsoft UNC-style paths are actually valid URLs by our measure :) u = new WvUrl(@"\\server\path\to\stuff"); WVPASSEQ(u.ToString(), "file://server/path/to/stuff"); WVPASSEQ(u.method, "file"); WVPASSEQ(u.user, null); WVPASSEQ(u.password, null); WVPASSEQ(u.host, "server"); WVPASSEQ(u.port, 0); WVPASSEQ(u.path, "/path/to/stuff"); u = new WvUrl(@"\\ser:9@1:23\path\to\stuff"); WVPASSEQ(u.ToString(), "file://ser@1:23/path/to/stuff"); WVPASSEQ(u.ToString(true), "file://*****:*****@1:23/path/to/stuff"); WVPASSEQ(u.method, "file"); WVPASSEQ(u.user, "ser"); WVPASSEQ(u.password, "9"); WVPASSEQ(u.host, "1"); WVPASSEQ(u.port, 23); WVPASSEQ(u.path, "/path/to/stuff"); u = new WvUrl("://:@:"); WVPASSEQ(u.ToString(), ":"); WVPASSEQ(u.method, ""); WVPASSEQ(u.user, null); WVPASSEQ(u.password, null); WVPASSEQ(u.host, null); WVPASSEQ(u.port, 0); WVPASSEQ(u.path, ""); u = new WvUrl("://:47@:"); WVPASSEQ(u.ToString(), "://"); WVPASSEQ(u.ToString(true), "://:47@"); }