Following the experiment on libcurl by adopting gccxml as the medium to generate the list of $DECLAREed functions, we investigate another two popular and useful libraries, libssh2 and MagickWand.

SSH2

Libssh2 is a client-side C library to implement the SSH2 protocol, which includes scp, sftp, ssh. The details and complete SSH2 API reference manual can be found here.

Here is a code snippet showing the scenario of completing a scp operation:

$DECLARE 'libssh2_init(INT(-))="*libssh2.libssh2_init!"
$DECLARE 'libssh2_session_init_ex(INT(),INT(),INT(),INT())="*libssh2.libssh2_session_init_ex!"
$DECLARE 'libssh2_session_startup(INT(),INT(-)) TO INT(-)="*libssh2.libssh2_session_startup!"
$DECLARE 'libssh2_hostkey_hash$(INT(),INT(-)) TO STR()="*libssh2.libssh2_hostkey_hash!"
$DECLARE 'libssh2_userauth_list$(INT(),STR(),INT()) TO STR()="*libssh2.libssh2_userauth_list!"
$DECLARE 'libssh2_userauth_password_ex(INT(),STR(),INT(),STR(),INT(),INT())="*libssh2.libssh2_userauth_password_ex!"
$DECLARE 'libssh2_scp_recv(INT(),STR(),DIM())="*libssh2.libssh2_scp_recv!"
$DECLARE 'libssh2_channel_read_ex(INT(),INT(-),RETURN STR(),INT())="*libssh2.libssh2_channel_read_ex!"
$DECLARE 'libssh2_channel_free(INT())="*libssh2.libssh2_channel_free!"
$DECLARE 'libssh2_session_disconnect_ex(INT(),INT(-),STR(),STR())="*libssh2.libssh2_session_disconnect_ex!"
$DECLARE 'libssh2_session_free(INT())="*libssh2.libssh2_session_free!"
$DECLARE 'libssh2_exit()="*libssh2.libssh2_exit!"
DIM ver$, rc, session, socket, fingerprint$, channel, mem$50, userauthlist$, Stream, username$, password$
// init libssh2
rc = 'libssh2_init(0)
// open localhost at port 22
Stream = OPEN ":22", "@"
socket = FLD($OPTIONS #Stream.OPTIONS_HASH_SocketDescriptor)
// init a session
session = 'libssh2_session_init_ex(0, 0, 0, 0)
// start a session at given socket
rc = 'libssh2_session_startup(session, socket)
fingerprint$ = 'libssh2_hostkey_hash$(session, 2)
// check what authentication methods are available
userauthlist$ = 'libssh2_userauth_list$(session, username$, password$)
PRINT userauthlist$
// authenticate via password
IF ('libssh2_userauth_password_ex(session, username$, 5, password$, 6, 0))
	PRINT "Authentication by password failed."
	ELSE
	PRINT "Authentication successful"
END IF
// request a file
channel = 'libssh2_scp_recv(session, "/user3/yangl/trunk/kcml/backup/curl/a.get", 0)
// read file
rc = 'libssh2_channel_read_ex(channel, 0, BYREF mem$, 50)
PRINT mem$
'libssh2_channel_free(channel)
channel = 0
rc = 'libssh2_session_disconnect_ex(session, 0, "Session Closed!", 0)
'libssh2_session_free(session)
CLOSE #Stream
'libssh2_exit()
where "libssh2" is the dll library name.

Download

libssh2-1.2.5.zip: the Windows version of libssh2 1.2.5 including the required dll library.

libssh2_func_generic.src: the complete ported libssh2 functions and relative enumerations.

MagickWand

ImageMagick is a software suite to create, edit, convert image, it supports a variety of formats, which include GIF, JPEG, PDF, PNG, TIFF etc. ImageMagick also offers a C API interface for developers to process images, which is so-called MagickWand. The details and complete reference manual about MagickWand can be found here.

Here is a code snippet showing the scenario of adopting MagickWand library to scale an opened image and saved as "test.jpg":

$DECLARE 'magick_WandGenesis()="*CORE_RL_wand_.MagickWandGenesis!"
$DECLARE 'magick_NewMagickWand()="*CORE_RL_wand_.NewMagickWand!"
$DECLARE 'magick_ReadImage(INT(),STR())="*CORE_RL_wand_.MagickReadImage!"
$DECLARE 'magick_WriteImage(INT(),STR())="*CORE_RL_wand_.MagickWriteImage!"
$DECLARE 'magick_DestroyMagickWand(INT())="*CORE_RL_wand_.DestroyMagickWand!"
$DECLARE 'magick_MagickWandTerminus()="*CORE_RL_wand_.MagickWandTerminus!"
$DECLARE 'magick_ScaleImage(INT(),INT(),INT())="*CORE_RL_wand_.MagickScaleImage!"
DIM handle, rc
// Init the wand environment
'magick_WandGenesis()
// Get a new magick_wand
handle = 'magick_NewMagickWand()
rc = 'magick_ReadImage(handle, "KCMLlogo.jpg")
rc = 'magick_ScaleImage(handle, 160, 90)
rc = 'magick_WriteImage(handle, "test.jpg")
// Destroy the magick_wand
handle = 'magick_DestroyMagickWand(handle)
// Close the environment
'magick_MagickWandTerminus()
To be noted that "CORE_RL_wand_" is the MagickWand dll file

Download

ImageMagick-6.7.1-0-Q16-windows-dll.exe: the stable windows DLL version of ImageMagick including required MagickWand library.

MagickWand_func_generic.src: the complete ported MagickWand functions and enumerations.

See also: