#include "fourd.h"
#include <stdio.h>
int main(int argc, const char * argv[]) {
char *host="<host>";
char *user="<username>";
char *pass="<password>";
char *base="<base>";
FOURD*connptr=fourd_init();
int result=fourd_connect(connptr,host,user,pass,base,19812);
printf("The result is: %i\n",result);
return 0;
}
[israel@follow lib4d_sql]$ ./a.out
About to log in with user: <username> password: <password>
Running login function
Login function ran with result: 0
The result is: 0
from cffi import FFI
from dateutil import parser
from datetime import datetime, timedelta
ffi = FFI()
ffi.cdef("""<bunch of stuff from the fourd.h header here>""")
C = ffi.dlopen("./lib4d_sql.so")
connptr = C.fourd_init()
host = ffi.new("char[]", "<host>")
user = ffi.new("char[]", "<user>")
password = ffi.new("char[]", "<password>")
base = ffi.new("char[]", "<base>")
result = C.fourd_connect(connptr, host, user, password, base, 19812)
if result != 0:
error=C.fourd_error(connptr)
print ffi.string(error)
print "Unable to connect! error:", result
exit(0)
[israel@follow lib4d_sql]$ python python4d.py
About to log in with user:<username> password:<password>
Login function ran with result: -1
Error during login
Unable to connect! error: 1
from cffi import FFI
from dateutil import parser
from datetime import datetime, timedelta
ffi = FFI()
ffi.cdef("""<bunch of stuff from the fourd.h header here>""")
C=ffi.verify("""
#include "/home/israel/lib4d_sql/fourd.h"
#define BUFFER_LENGTH 131072
#define ERROR_STRING_LENGTH 2048
#define MAX_HEADER_SIZE 2048
#define DEFAULT_IMAGE_TYPE "jpg"
#define MAX_LENGTH_COLUMN_NAME 255
#define FOURD_OK 0
#define FOURD_ERROR 1
""",libraries=["4d_sql"],library_dirs=["/home/israel/lib4d_sql"])
connptr = C.fourd_init()
host = ffi.new("char[]", "<host>")
user = ffi.new("char[]", "<user>")
password = ffi.new("char[]", "<password>")
base = ffi.new("char[]", "<base>")
result = C.fourd_connect(connptr, host, user, password, base, 19812)
if result != 0:
error=C.fourd_error(connptr)
print ffi.string(error)
print "Unable to connect! error:", result
exit(0)
int fourd_connect(<args>){
//bunch of code that runs as expected
printf("About to log in with user:%s password:%s",user,password);
int loginsuccess=login(cnx,1,user,password,cnx->preferred_image_types);
printf("Login function ran with result: %i",loginsuccess);
//other code that responds to the non-zero loginsuccess as expected
}
//login is defined in a separate c file, with a header included here.
int login(FOURD *cnx,unsigned short int id_cnx,const char *user,const char*pwd,const char*image_type)
{
printf("Entering login function\n"); //this is never printed when run through python CFFI
//other code to actually login, which never runs
if(<check for error on login>)
return 1;
return 0;
}