1 module libssh.funcs;
2 
3 import libssh.types;
4 
5 import libssh.mix;
6 
7 version (libssh_rtload)
8 {
9     import ssll;
10     public import ssll : LoadApiSymbolsVerbose;
11 
12     version (Posix)   enum libSSHNames = ["libssh.so"];
13     version (Windows) enum libSSHNames = ["libssh.dll"];
14 
15     package __gshared LibHandler lib;
16 
17     void loadLibSSH(LoadApiSymbolsVerbose verbose = LoadApiSymbolsVerbose.none,
18                     string[] names=libSSHNames)
19     {
20         import std.exception : enforce;
21 
22         if (lib !is null) return;
23 
24         foreach (name; names)
25         {
26             lib = loadLibrary(name);
27             if (lib !is null) break;
28         }
29 
30         enforce(lib, "can't load libssh");
31 
32         loadApiSymbols(verbose);
33     }
34 
35     void unloadLibSSH() { unloadLibrary(lib); }
36 }
37 
38 mixin(pastFunctions(import("libssh/funcs.txt")));
39 
40 pragma(inline, true)
41 {
42     void SSH_KNOWNHOSTS_ENTRY_FREE(ref ssh_knownhosts_entry* e)
43     {
44         if (e !is null)
45         {
46             ssh_knownhosts_entry_free(e);
47             e = null;
48         }
49     }
50 
51     void SSH_KEY_FREE(ref ssh_key x)
52     {
53         if (x !is null)
54         {
55             ssh_key_free(x);
56             x = null;
57         }
58     }
59 
60     void SSH_STRING_FREE(ref ssh_string x) 
61     {
62         if (x !is null)
63         {
64             ssh_string_free(x);
65             x = null;
66         }
67     }
68 
69     void SSH_STRING_FREE_CHAR(ref char* x)
70     {
71         if (x !is null)
72         {
73             ssh_string_free_char(x);
74             x = null;
75         }
76     }
77 
78     void SSH_BUFFER_FREE(ref ssh_buffer x)
79     {
80         if (x !is null)
81         {
82             ssh_buffer_free(x);
83             x = null;
84         }
85     }
86 }