#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <errno.h>
#include <signal.h>
#include <utime.h>
#include <stdio.h>
#include <ctype.h>
#include <stdarg.h>
#include <pi-source.h>
#include <pi-socket.h>
#include <pi-dlp.h>
#include <pi-file.h>
#include <pi-memo.h>
#include "libjpisock.h"
Include dependency graph for libjpisock.c:

Go to the source code of this file.
Defines | |
| #define | MAX_RESOURCE_SIZE 65536 |
Functions | |
| int | pilot_connect (JNIEnv *env, const char *port) |
| static void | postPilotLinkException (JNIEnv *, const char *, int, int) |
| static void | postJavaException (JNIEnv *, const char *, const char *) |
| static int | getBasicTypeField (JNIEnv *env, jclass pClass, jobject pObject, const char *sFieldType, const char *sFieldName, void *pLocation) |
| static int | assignBasicTypeField (JNIEnv *env, jclass pClass, jobject pObject, const char *sFieldType, const char *sFieldName,...) |
| JNIEXPORT jint JNICALL | Java_org_gnu_pilotlink_PilotLink_connect (JNIEnv *env, jobject obj, jstring jprt) |
| JNIEXPORT jobject JNICALL | Java_org_gnu_pilotlink_PilotLink_readAppInfo (JNIEnv *env, jobject obj, jint handle, jint db) |
| JNIEXPORT jobject JNICALL | Java_org_gnu_pilotlink_PilotLink_readSysInfo (JNIEnv *env, jobject obj, jint handle) |
| JNIEXPORT jobject JNICALL | Java_org_gnu_pilotlink_PilotLink_readUserInfo (JNIEnv *env, jobject obj, jint handler) |
| JNIEXPORT void JNICALL | Java_org_gnu_pilotlink_PilotLink_writeUserInfo (JNIEnv *env, jobject obj, jint so, jobject user) |
| JNIEXPORT int JNICALL | Java_org_gnu_pilotlink_PilotLink_writeAppBlock (JNIEnv *env, jobject obj, jint handle, jint dbhandle, jbyteArray data, jint length) |
| JNIEXPORT void JNICALL | Java_org_gnu_pilotlink_PilotLink_openConduit (JNIEnv *env, jobject obj, jint handle) |
| JNIEXPORT jint JNICALL | Java_org_gnu_pilotlink_PilotLink_createDB (JNIEnv *env, jobject obj, jint handle, jlong creator, jstring jdbname, jlong type, jint flags, jint version) |
| JNIEXPORT jint JNICALL | Java_org_gnu_pilotlink_PilotLink_deleteDB (JNIEnv *env, jobject obj, jint handle, jstring jdbname) |
| JNIEXPORT jobject JNICALL | Java_org_gnu_pilotlink_PilotLink_getAppInfoBlock (JNIEnv *env, jobject obj, jint handle, jstring jdbname) |
| JNIEXPORT jint JNICALL | Java_org_gnu_pilotlink_PilotLink_openDB (JNIEnv *env, jobject obj, jint handle, jstring jdbname) |
| JNIEXPORT jint JNICALL | Java_org_gnu_pilotlink_PilotLink_getRecordCount (JNIEnv *env, jobject obj, jint handle, jint dbh) |
| JNIEXPORT jobject JNICALL | Java_org_gnu_pilotlink_PilotLink_getRecordByIndex (JNIEnv *env, jobject obj, jint handle, jint db, jint idx) |
| JNIEXPORT jint JNICALL | Java_org_gnu_pilotlink_PilotLink_deleteRecordById (JNIEnv *env, jobject obj, jint handle, jint db, jlong id) |
| JNIEXPORT jint JNICALL | Java_org_gnu_pilotlink_PilotLink_writeRecord (JNIEnv *env, jobject obj, jint handle, jint db, jobject record) |
| JNIEXPORT void JNICALL | Java_org_gnu_pilotlink_PilotLink_closeDB (JNIEnv *env, jobject obj, jint han, jint db) |
| JNIEXPORT void JNICALL | Java_org_gnu_pilotlink_PilotLink_endSync (JNIEnv *env, jobject obj, jint sd) |
| JNIEXPORT void JNICALL | Java_org_gnu_pilotlink_PilotLink_close (JNIEnv *env, jobject obj, jint sd) |
| JNIEXPORT jobject JNICALL | Java_org_gnu_pilotlink_PilotLink_getResourceByIndex (JNIEnv *env, jobject obj, jint iSockHandle, jint iDBHandle, jint iRsrcIndex) |
| JNIEXPORT void JNICALL | Java_org_gnu_pilotlink_PilotLink_writeResource (JNIEnv *env, jobject obj, jint iSockHandle, jint iDBHandle, jobject pRecord) |
| JNIEXPORT void JNICALL | Java_org_gnu_pilotlink_PilotLink_resetSystem (JNIEnv *env, jobject, jint iSockHandle) |
| JNIEXPORT jobject JNICALL | Java_org_gnu_pilotlink_PilotLink_readDBList (JNIEnv *env, jobject, jint iSockHandle, jint cardno, jint flags, jint start) |
| #define MAX_RESOURCE_SIZE 65536 |
Definition at line 22 of file libjpisock.c.
Referenced by Java_org_gnu_pilotlink_PilotLink_getRecordByIndex(), Java_org_gnu_pilotlink_PilotLink_getResourceByIndex(), Java_org_gnu_pilotlink_PilotLink_readAppInfo(), and Java_org_gnu_pilotlink_PilotLink_writeRecord().
| static int assignBasicTypeField | ( | JNIEnv * | env, | |
| jclass | pClass, | |||
| jobject | pObject, | |||
| const char * | sFieldType, | |||
| const char * | sFieldName, | |||
| ... | ||||
| ) | [static] |
Definition at line 1297 of file libjpisock.c.
01299 { 01300 int bProceed = 1; 01301 jfieldID pFieldID = NULL; 01302 jthrowable pException = NULL; 01303 01304 pFieldID = env->GetFieldID(pClass, sFieldName, sFieldType); 01305 if (pFieldID != NULL && (pException = env->ExceptionOccurred()) == NULL) { 01306 01307 va_list ap; 01308 01309 va_start(ap, sFieldName); 01310 if (strcmp(sFieldType, "I") == 0) { 01311 jint iValue = va_arg(ap, jint); 01312 env->SetIntField(pObject, pFieldID, iValue); 01313 } else if (strcmp(sFieldType, "S") == 0) { 01314 jshort iValue = va_arg(ap, int); 01315 env->SetShortField(pObject, pFieldID, iValue); 01316 } else if (strcmp(sFieldType, "B") == 0) { 01317 jbyte iValue = va_arg(ap, int); 01318 env->SetByteField(pObject, pFieldID, iValue); 01319 } else if (strcmp(sFieldType, "Z") == 0) { 01320 jboolean iValue = va_arg(ap, int); 01321 env->SetBooleanField(pObject, pFieldID, iValue); 01322 } else if (strcmp(sFieldType, "C") == 0) { 01323 jchar iValue = va_arg(ap, int); 01324 env->SetCharField(pObject, pFieldID, iValue); 01325 } else if (strcmp(sFieldType, "J") == 0) { 01326 jlong iValue = va_arg(ap, jlong); 01327 env->SetLongField(pObject, pFieldID, iValue); 01328 } else if (strcmp(sFieldType, "F") == 0) { 01329 jfloat iValue = va_arg(ap, double); 01330 env->SetFloatField(pObject, pFieldID, iValue); 01331 } else if (strcmp(sFieldType, "D") == 0) { 01332 jdouble iValue = va_arg(ap, jdouble); 01333 env->SetDoubleField(pObject, pFieldID, iValue); 01334 } else if (strcmp(sFieldType, "Ljava/lang/String;") == 0) { 01335 const char * s = va_arg(ap, const char *); 01336 jstring jNameString = env->NewStringUTF(s); 01337 env->SetObjectField(pObject, pFieldID, jNameString); 01338 } else if (sFieldType[0] == 'L') { 01339 jobject pAssignedObject = va_arg(ap, jobject); 01340 env->SetObjectField(pObject, pFieldID, pAssignedObject); 01341 } 01342 va_end(ap); 01343 } else { 01344 bProceed = 0; 01345 } 01346 return bProceed; 01347 }
| static int getBasicTypeField | ( | JNIEnv * | env, | |
| jclass | pClass, | |||
| jobject | pObject, | |||
| const char * | sFieldType, | |||
| const char * | sFieldName, | |||
| void * | pLocation | |||
| ) | [static] |
Definition at line 1262 of file libjpisock.c.
Referenced by Java_org_gnu_pilotlink_PilotLink_writeUserInfo().
01264 { 01265 int bProceed = 1; 01266 jfieldID pFieldID = NULL; 01267 jthrowable pException = NULL; 01268 01269 pFieldID = env->GetFieldID(pClass, sFieldName, sFieldType); 01270 if (pFieldID != NULL && (pException = env->ExceptionOccurred()) == NULL) { 01271 if (strcmp(sFieldType, "I") == 0) { 01272 *((jint *)pLocation) = env->GetIntField(pObject, pFieldID); 01273 } else if (strcmp(sFieldType, "S") == 0) { 01274 *((jshort *)pLocation) = env->GetShortField(pObject, pFieldID); 01275 } else if (strcmp(sFieldType, "B") == 0) { 01276 *((jbyte *)pLocation) = env->GetByteField(pObject, pFieldID); 01277 } else if (strcmp(sFieldType, "Z") == 0) { 01278 *((jboolean *)pLocation) = env->GetBooleanField(pObject, pFieldID); 01279 } else if (strcmp(sFieldType, "C") == 0) { 01280 *((jchar *)pLocation) = env->GetCharField(pObject, pFieldID); 01281 } else if (strcmp(sFieldType, "J") == 0) { 01282 *((jlong *)pLocation) = env->GetLongField(pObject, pFieldID); 01283 } else if (strcmp(sFieldType, "F") == 0) { 01284 *((jfloat *)pLocation) = env->GetFloatField(pObject, pFieldID); 01285 } else if (strcmp(sFieldType, "D") == 0) { 01286 *((jdouble *)pLocation) = env->GetDoubleField(pObject, pFieldID); 01287 } else if (sFieldType[0] == 'L') { 01288 *((jobject *)pLocation) = env->GetObjectField(pObject, pFieldID); 01289 } 01290 } else { 01291 bProceed = 0; 01292 } 01293 return bProceed; 01294 }
| JNIEXPORT void JNICALL Java_org_gnu_pilotlink_PilotLink_close | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | sd | |||
| ) |
Definition at line 803 of file libjpisock.c.
References pi_close().
Here is the call graph for this function:

| JNIEXPORT void JNICALL Java_org_gnu_pilotlink_PilotLink_closeDB | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | han, | |||
| jint | db | |||
| ) |
Definition at line 778 of file libjpisock.c.
References dlp_CleanUpDatabase(), dlp_CloseDB(), and postPilotLinkException().
00778 { 00779 int bException = 0; 00780 int ret=dlp_CleanUpDatabase(han, db); 00781 if (ret<0) { 00782 // printf("Error cleaning up! %d\n",ret); 00783 postPilotLinkException(env, "Unable to clean up before database close", 00784 ret, errno); 00785 bException = 1; 00786 } 00787 ret=dlp_CloseDB(han, db); 00788 if (ret < 0 && !bException) { 00789 // printf("Error closing DB: %d\n",ret); 00790 postPilotLinkException(env, "Unable to close database", 00791 ret, errno); 00792 } 00793 }
Here is the call graph for this function:

| JNIEXPORT jint JNICALL Java_org_gnu_pilotlink_PilotLink_connect | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jstring | jprt | |||
| ) |
Definition at line 36 of file libjpisock.c.
References pilot_connect(), and port.
00036 { 00037 00038 jint iResult = 0; 00039 const char * port = NULL; 00040 char * prt = NULL; 00041 00042 /* Get working copy of port name */ 00043 port = env->GetStringUTFChars(jprt, NULL); 00044 prt = (char *)malloc(strlen(port) + 1); 00045 if (prt != NULL) strcpy(prt, port); 00046 env->ReleaseStringUTFChars(jprt, port); 00047 00048 iResult = pilot_connect(env, prt); 00049 if (prt != NULL) free(prt); 00050 return iResult; 00051 }
Here is the call graph for this function:

| JNIEXPORT jint JNICALL Java_org_gnu_pilotlink_PilotLink_createDB | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | handle, | |||
| jlong | creator, | |||
| jstring | jdbname, | |||
| jlong | type, | |||
| jint | flags, | |||
| jint | version | |||
| ) |
Definition at line 489 of file libjpisock.c.
References dlp_CreateDB(), postJavaException(), and postPilotLinkException().
00490 { 00491 jint db = -1; 00492 00493 /* Get working copy of database name */ 00494 const char * dbname = env->GetStringUTFChars(jdbname, NULL); 00495 char * dbn = (char *)malloc(strlen(dbname) + 1); 00496 if (dbn != NULL) strcpy(dbn, dbname); 00497 env->ReleaseStringUTFChars(jdbname, dbname); 00498 00499 if (dbn != NULL) { 00500 int ret = dlp_CreateDB(handle,creator,type,0,flags,version,dbn, &db); 00501 00502 if (ret < 0) { 00503 /* debug message replaced by Java exception */ 00504 /* 00505 printf("Error creating db %s: %d\n",dbn, ret); 00506 */ 00507 postPilotLinkException(env, "Could not create database", 00508 ret, errno); 00509 } 00510 free(dbn); 00511 } else { 00512 /* Unable to create copy - memory heap may be corrupted */ 00513 postJavaException(env, 00514 "org/gnu/pilotlink/PilotLinkException", 00515 "Unable to create working copy of database name"); 00516 } 00517 return db; 00518 }
Here is the call graph for this function:

| JNIEXPORT jint JNICALL Java_org_gnu_pilotlink_PilotLink_deleteDB | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | handle, | |||
| jstring | jdbname | |||
| ) |
Definition at line 525 of file libjpisock.c.
References dlp_DeleteDB(), postJavaException(), and postPilotLinkException().
00525 { 00526 00527 int ret = 0; 00528 00529 /* Get working copy of database name */ 00530 const char * dbname = env->GetStringUTFChars(jdbname,NULL); 00531 char * dbn = (char*)malloc(strlen(dbname)+1); 00532 if (dbn != NULL) strcpy(dbn,dbname); 00533 env->ReleaseStringUTFChars(jdbname, dbname); 00534 00535 if (dbn != NULL) { 00536 ret = dlp_DeleteDB(handle,0,dbn); 00537 if (ret < 0) { 00538 /* debug message replaced by Java exception */ 00539 /* 00540 printf("Error deleting db %s %d:\n",dbn,ret); 00541 */ 00542 postPilotLinkException(env, "Could not delete database", 00543 ret, errno); 00544 } 00545 free(dbn); 00546 } else { 00547 /* Unable to create copy - memory heap may be corrupted */ 00548 postJavaException(env, 00549 "org/gnu/pilotlink/PilotLinkException", 00550 "Unable to create working copy of database name"); 00551 } 00552 return ret; 00553 }
Here is the call graph for this function:

| JNIEXPORT jint JNICALL Java_org_gnu_pilotlink_PilotLink_deleteRecordById | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | handle, | |||
| jint | db, | |||
| jlong | id | |||
| ) |
Definition at line 727 of file libjpisock.c.
References dlp_DeleteRecord(), and postPilotLinkException().
00727 { 00728 int ret=dlp_DeleteRecord(handle,db,0,id); 00729 if (ret<0) { 00730 postPilotLinkException(env,"Deletition not possible!",ret,errno); 00731 } 00732 return ret; 00733 }
Here is the call graph for this function:

| JNIEXPORT void JNICALL Java_org_gnu_pilotlink_PilotLink_endSync | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | sd | |||
| ) |
Definition at line 796 of file libjpisock.c.
References dlp_EndOfSync(), dlpEndCodeNormal, and postPilotLinkException().
00796 { 00797 int iResult = dlp_EndOfSync(sd, dlpEndCodeNormal); 00798 if (iResult < 0) postPilotLinkException(env, "Unable to signal endSync", 00799 iResult, errno); 00800 }
Here is the call graph for this function:

| JNIEXPORT jobject JNICALL Java_org_gnu_pilotlink_PilotLink_getAppInfoBlock | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | handle, | |||
| jstring | jdbname | |||
| ) |
Definition at line 556 of file libjpisock.c.
References dlp_CloseDB(), dlp_OpenDB(), and dlp_ReadAppBlock().
00556 { 00557 int db; 00558 const char * dbname = env->GetStringUTFChars(jdbname, NULL); 00559 char * dbn = (char *)malloc(strlen(dbname) + 1); 00560 if (dbn != NULL) strcpy(dbn, dbname); 00561 env->ReleaseStringUTFChars(jdbname, dbname); 00562 if (dlp_OpenDB(handle,0,0x80|0x40,dbn,&db)<0) { 00563 00564 printf("Fehler!"); 00565 return NULL; 00566 } 00567 jbyte buff[0xffff]; 00568 int l=dlp_ReadAppBlock(handle,db,0,0xffff,(pi_buffer_t*)&buff); 00569 printf("read app-Block of size %d\n",l); 00570 fflush(stdout); 00571 00572 jclass jClass_appInfo = NULL; 00573 jobject jObject_appInfo = NULL; 00574 jmethodID jMethod_appInfo = NULL; 00575 int bProceed = 1; 00576 int iNumBytesRead = 0; 00577 00578 if (bProceed) { 00579 /* Look up RawAppInfo class */ 00580 jClass_appInfo = env->FindClass("org/gnu/pilotlink/RawAppInfo"); 00581 if (jClass_appInfo == NULL) { 00582 /* pending ClassNotFoundException in env */ 00583 bProceed = 0; 00584 } 00585 } 00586 if (bProceed) { 00587 /* Look up constructor method with byte array argument */ 00588 jMethod_appInfo = env->GetMethodID(jClass_appInfo, "<init>","([B)V"); 00589 if (jMethod_appInfo == NULL) { 00590 /* pending NoSuchMethodException in env */ 00591 bProceed = 0; 00592 } 00593 } 00594 if (bProceed) { 00595 jbyteArray jArray_buffer = env->NewByteArray(l); 00596 env->SetByteArrayRegion(jArray_buffer, 0, (jint)l, buff); 00597 jObject_appInfo = env->NewObject(jClass_appInfo, jMethod_appInfo, jArray_buffer); 00598 } 00599 00600 dlp_CloseDB(handle,db); 00601 return jObject_appInfo; 00602 00603 00604 00605 }
Here is the call graph for this function:

| JNIEXPORT jobject JNICALL Java_org_gnu_pilotlink_PilotLink_getRecordByIndex | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | handle, | |||
| jint | db, | |||
| jint | idx | |||
| ) |
Definition at line 659 of file libjpisock.c.
References buffer, dlp_ReadRecordByIndex(), MAX_RESOURCE_SIZE, postPilotLinkException(), and size.
00659 { 00660 00661 jbyte buffer[MAX_RESOURCE_SIZE]; 00662 recordid_t id; 00663 jint size, attr, category; 00664 //printf("Getting record..\n"); 00665 int ret = dlp_ReadRecordByIndex(handle, db, idx, (pi_buffer_t*)buffer, 00666 &id, &attr, &category); 00667 if (ret<0) { 00668 postPilotLinkException(env,"Error reading database by index",ret,errno); 00669 return NULL; 00670 } 00671 //printf("getting class!\n"); 00672 jclass rcls=env->FindClass("org/gnu/pilotlink/RawRecord"); 00673 if (rcls==NULL) { 00674 return NULL; 00675 } 00676 jmethodID rid=env->GetMethodID(rcls,"<init>","([BJIII)V"); 00677 if (rid==NULL) { 00678 printf("jmethodID is null!\n"); 00679 return NULL; 00680 } 00681 jbyteArray array=env->NewByteArray(size); 00682 env->SetByteArrayRegion(array,0,size,buffer); 00683 jobject record=env->NewObject(rcls, rid, array, (jlong)id,size,attr,category ); 00684 return record; 00685 00686 00687 /*jbyte * buffer; 00688 jobject jObject_RawRecord = NULL; 00689 00690 if ((buffer = (jbyte *)malloc(MAX_RESOURCE_SIZE)) != NULL) { 00691 00692 recordid_t id; 00693 jint iRecSize, iRecAttr, iRecCategory; 00694 jclass jClass_RawRecord; 00695 jmethodID jMethod_RawRecord; 00696 00697 int iResult = dlp_ReadRecordByIndex(handle, db, idx, buffer, 00698 &id, &iRecSize, &iRecAttr, &iRecCategory); 00699 if (iResult < 0) { 00700 postPilotLinkException(env, "Could not read database record by index", 00701 iResult, errno); 00702 } else if ((jClass_RawRecord = env->FindClass( 00703 "org/gnu/pilotlink/RawRecord")) == NULL) { 00704 00705 } else if ((jMethod_RawRecord = env->GetMethodID(jClass_RawRecord, 00706 "<init>", "([BJIII)V")) == NULL) { 00707 00708 } else { 00709 jbyteArray jArray_buffer = env->NewByteArray(iRecSize); 00710 env->SetByteArrayRegion(jArray_buffer, 0, iRecSize, buffer); 00711 jObject_RawRecord = env->NewObject(jClass_RawRecord, jMethod_RawRecord, 00712 jArray_buffer, (jlong)id, (jint)iRecSize, (jint)iRecAttr, (jint)iRecCategory); 00713 } 00714 free(buffer); 00715 } else { 00716 postJavaException(env, 00717 "org/gnu/pilotlink/PilotLinkException", 00718 "Unable to allocate buffer for record data"); 00719 } 00720 return jObject_RawRecord;*/ 00721 }
Here is the call graph for this function:

| JNIEXPORT jint JNICALL Java_org_gnu_pilotlink_PilotLink_getRecordCount | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | handle, | |||
| jint | dbh | |||
| ) |
Definition at line 644 of file libjpisock.c.
References dlp_ReadOpenDBInfo(), and postPilotLinkException().
00644 { 00645 jint num; 00646 int iResult; 00647 iResult = dlp_ReadOpenDBInfo(handle,dbh,&num); 00648 if (iResult < 0) { 00649 postPilotLinkException(env, "Could not get record count for database", 00650 iResult, errno); 00651 } 00652 return num; 00653 }
Here is the call graph for this function:

| JNIEXPORT jobject JNICALL Java_org_gnu_pilotlink_PilotLink_getResourceByIndex | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | iSockHandle, | |||
| jint | iDBHandle, | |||
| jint | iRsrcIndex | |||
| ) |
Definition at line 1042 of file libjpisock.c.
References dlp_ReadResourceByIndex(), MAX_RESOURCE_SIZE, postJavaException(), and postPilotLinkException().
01042 { 01043 01044 unsigned long iRsrcType; /* Resource type */ 01045 int iRsrcID; /* Resource ID */ 01046 int iRsrcSize; /* Actual resource size */ 01047 jbyte * pRsrcData; /* Buffer for resource data */ 01048 int iResult; /* Result of library call */ 01049 jobject pRecordObject = NULL; 01050 01051 /* Get "enough" memory for incoming resource data */ 01052 if ((pRsrcData = (jbyte *)malloc(MAX_RESOURCE_SIZE * sizeof(jbyte))) != NULL) { 01053 01054 /* Invoke C library function */ 01055 iResult = dlp_ReadResourceByIndex(iSockHandle, iDBHandle, iRsrcIndex, 01056 (pi_buffer_t*)pRsrcData, &iRsrcType, &iRsrcID); 01057 if (iResult >= 0) { 01058 jclass pRecordClass; 01059 jmethodID pRecordConstructor; 01060 01061 /* Look up class and constructor method */ 01062 if ((pRecordClass = env->FindClass("org/gnu/pilotlink/RawRecord")) != NULL && 01063 (pRecordConstructor = env->GetMethodID(pRecordClass, "<init>", 01064 "([BJIII)V")) != NULL ) { 01065 01066 /* Fill a Java array with resource data && invoke constructor */ 01067 jbyteArray pJavaArray = env->NewByteArray(iRsrcSize); 01068 env->SetByteArrayRegion(pJavaArray, 0, iRsrcSize, pRsrcData); 01069 pRecordObject = env->NewObject(pRecordClass, pRecordConstructor, 01070 pJavaArray, (jlong)iRsrcID, (jint)iRsrcSize, (jint)0, (jint)iRsrcType); 01071 } 01072 } else { 01073 postPilotLinkException(env, "Unable to read resource by index", iResult, errno); 01074 } 01075 free(pRsrcData); 01076 } else { 01077 postJavaException(env, 01078 "org/gnu/pilotlink/PilotLinkException", 01079 "Unable to allocate buffer for copy of resource"); 01080 } 01081 01082 return pRecordObject; 01083 }
Here is the call graph for this function:

| JNIEXPORT void JNICALL Java_org_gnu_pilotlink_PilotLink_openConduit | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | handle | |||
| ) |
Definition at line 479 of file libjpisock.c.
References dlp_OpenConduit(), and postPilotLinkException().
00479 { 00480 int iResult = dlp_OpenConduit(handle); 00481 if (iResult < 0) postPilotLinkException(env, "Unable to open conduit", iResult, errno); 00482 }
Here is the call graph for this function:

| JNIEXPORT jint JNICALL Java_org_gnu_pilotlink_PilotLink_openDB | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | handle, | |||
| jstring | jdbname | |||
| ) |
Definition at line 611 of file libjpisock.c.
References dlp_OpenDB(), dlpOpenReadWrite, postJavaException(), and postPilotLinkException().
00611 { 00612 00613 jint db = 0; 00614 00615 /* Get working copy of database name */ 00616 const char* dbname = env->GetStringUTFChars(jdbname,NULL); 00617 char* dbn = (char*)malloc(strlen(dbname)+1); 00618 if (dbn != NULL) strcpy(dbn,dbname); 00619 env->ReleaseStringUTFChars(jdbname, dbname); 00620 00621 if (dbn != NULL) { 00622 int ret=dlp_OpenDB(handle,0,dlpOpenReadWrite,dbn,&db); 00623 if (ret < 0) { 00624 /* 00625 printf("Error opening db %s: %d\n",dbn, ret); 00626 */ 00627 postPilotLinkException(env, "Could not open database", 00628 ret, errno); 00629 return (jint)ret; 00630 } 00631 } else { 00632 /* Unable to create copy - memory heap may be corrupted */ 00633 postJavaException(env, 00634 "org/gnu/pilotlink/PilotLinkException", 00635 "Unable to create working copy of database name"); 00636 } 00637 return db; 00638 }
Here is the call graph for this function:

| JNIEXPORT jobject JNICALL Java_org_gnu_pilotlink_PilotLink_readAppInfo | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | handle, | |||
| jint | db | |||
| ) |
Definition at line 57 of file libjpisock.c.
References dlp_ReadAppBlock(), MAX_RESOURCE_SIZE, postJavaException(), and postPilotLinkException().
00058 { 00059 /* 00060 unsigned char buffer[MAX_RESOURCE_SIZE]; 00061 00062 int size=dlp_ReadAppBlock(handle,db, 0,buffer,MAX_RESOURCE_SIZE); 00063 00064 //printf("STill alive...\n"); 00065 //fflush(stdout); 00066 jclass appinfo_cls=env->FindClass("org/gnu/pilotlink/RawAppInfo"); 00067 if (appinfo_cls==NULL) { 00068 printf("Class not found! Sysinfo!\n"); 00069 return NULL; 00070 } 00071 //printf("STill alive...\n"); 00072 fflush(stdout); 00073 jmethodID appinfo_mid=env->GetMethodID(appinfo_cls, "<init>","([B)V"); 00074 if (appinfo_mid==NULL) { 00075 printf("Problem mid!\n"); 00076 fflush(stdout); 00077 return NULL; 00078 } 00079 //printf("STill alive...\n"); 00080 //fflush(stdout); 00081 jbyteArray array=env->NewByteArray(size); 00082 env->SetByteArrayRegion(array,0,(jint)size,(jbyte*)buffer); 00083 jobject appinfo=env->NewObject(appinfo_cls, appinfo_mid, array); 00084 00085 return appinfo; 00086 */ 00087 00088 jclass jClass_appInfo = NULL; 00089 jobject jObject_appInfo = NULL; 00090 jmethodID jMethod_appInfo = NULL; 00091 jbyte * pBuffer = NULL; 00092 int bProceed = 1; 00093 int iNumBytesRead = 0; 00094 00095 if (bProceed) { 00096 /* Allocate memory for maximum data size */ 00097 pBuffer = (jbyte *)malloc(MAX_RESOURCE_SIZE); 00098 if (pBuffer == NULL) { 00099 postJavaException(env, 00100 "org/gnu/pilotlink/PilotLinkException", 00101 "Unable to allocate buffer for app-info block"); 00102 bProceed = 0; 00103 } 00104 } 00105 if (bProceed) { 00106 /* Read app-info block && verify successful read */ 00107 iNumBytesRead = dlp_ReadAppBlock(handle, db, 0, MAX_RESOURCE_SIZE, (pi_buffer_t*)pBuffer); 00108 if (iNumBytesRead < 0) { 00109 /* Throw Java exception, iNumBytesRead is actually an error code */ 00110 postPilotLinkException(env, "Unable to read app-block", iNumBytesRead, errno); 00111 bProceed = 0; 00112 } 00113 } 00114 if (bProceed) { 00115 /* Look up RawAppInfo class */ 00116 jClass_appInfo = env->FindClass("org/gnu/pilotlink/RawAppInfo"); 00117 if (jClass_appInfo == NULL) { 00118 /* pending ClassNotFoundException in env */ 00119 bProceed = 0; 00120 } 00121 } 00122 if (bProceed) { 00123 /* Look up constructor method with byte array argument */ 00124 jMethod_appInfo = env->GetMethodID(jClass_appInfo, "<init>","([B)V"); 00125 if (jMethod_appInfo == NULL) { 00126 /* pending NoSuchMethodException in env */ 00127 bProceed = 0; 00128 } 00129 } 00130 if (bProceed) { 00131 jbyteArray jArray_buffer = env->NewByteArray(iNumBytesRead); 00132 env->SetByteArrayRegion(jArray_buffer, 0, (jint)iNumBytesRead, pBuffer); 00133 jObject_appInfo = env->NewObject(jClass_appInfo, jMethod_appInfo, jArray_buffer); 00134 } 00135 00136 if (pBuffer != NULL) free(pBuffer); 00137 return jObject_appInfo; 00138 }
Here is the call graph for this function:

| JNIEXPORT jobject JNICALL Java_org_gnu_pilotlink_PilotLink_readDBList | ( | JNIEnv * | env, | |
| jobject | , | |||
| jint | iSockHandle, | |||
| jint | cardno, | |||
| jint | flags, | |||
| jint | start | |||
| ) |
Definition at line 1172 of file libjpisock.c.
References dlp_ReadDBList(), and postPilotLinkException().
01173 { 01174 int iResult = 0; 01175 struct DBInfo rInfoDB; 01176 jobject pDBInfoObject = NULL; 01177 01178 /* Execute low-level library call... */ 01179 iResult = dlp_ReadDBList(iSockHandle, cardno, flags, start, (pi_buffer_t*)&rInfoDB); 01180 if (iResult >= 0) { 01181 jclass pDBInfoClass = NULL; 01182 jmethodID pDBInfoMethod = NULL; 01183 int bProceed = 1; 01184 01185 /* Find class for DBInfo - throws ClassNotFoundException if not found */ 01186 if (bProceed) { 01187 pDBInfoClass = env->FindClass("org/gnu/pilotlink/DBInfo"); 01188 if (pDBInfoClass == NULL) bProceed = 0; 01189 } 01190 01191 /* Find constructor method for class DBInfo */ 01192 if (bProceed) { 01193 pDBInfoMethod = env->GetMethodID(pDBInfoClass, "<init>", 01194 "(Ljava/lang/String;IIIIIISSSBB)V"); 01195 if (pDBInfoMethod != NULL && env->ExceptionOccurred() == NULL) { 01196 /* Build new object, propagate any exception into Java caller */ 01197 jstring jString_nombre = env->NewStringUTF(rInfoDB.name); 01198 pDBInfoObject = env->NewObject(pDBInfoClass, pDBInfoMethod, 01199 jString_nombre, (jint)rInfoDB.createDate, (jint)rInfoDB.modifyDate, 01200 (jint)rInfoDB.backupDate, (jint)rInfoDB.type, (jint)rInfoDB.creator, 01201 (jint)rInfoDB.modnum, (jshort)rInfoDB.flags, (jshort)rInfoDB.version, 01202 (jshort)rInfoDB.index, (jbyte)rInfoDB.miscFlags, (jbyte)rInfoDB.more); 01203 if (env->ExceptionOccurred() != NULL) bProceed = 0; 01204 } else { 01205 /* pending NoSuchMethodException in env */ 01206 bProceed = 0; 01207 } 01208 } 01209 01210 /* "Not Found" error returns null, else throw Java exception to inform problem with listing */ 01211 } else if (iResult != -5) { 01212 postPilotLinkException(env, "Unable to read DB list entry", iResult, errno); 01213 } 01214 return pDBInfoObject; 01215 }
Here is the call graph for this function:

| JNIEXPORT jobject JNICALL Java_org_gnu_pilotlink_PilotLink_readSysInfo | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | handle | |||
| ) |
Definition at line 143 of file libjpisock.c.
References SysInfo::compatMajorVersion, SysInfo::compatMinorVersion, dlp_ReadSysInfo(), SysInfo::dlpMajorVersion, SysInfo::dlpMinorVersion, SysInfo::locale, SysInfo::maxRecSize, postPilotLinkException(), SysInfo::prodID, and SysInfo::romVersion.
00143 { 00144 /* 00145 struct SysInfo s; 00146 s.prodID[s.prodIDLength]=0; 00147 int r=dlp_ReadSysInfo(handle,&s); 00148 00149 jstring prod=env->NewStringUTF(s.prodID); 00150 00151 //printf("STill alive...\n"); 00152 fflush(stdout); 00153 jclass sysinfo_cls=env->FindClass("org/gnu/pilotlink/SysInfo"); 00154 if (sysinfo_cls==NULL) { 00155 printf("Class not found! Sysinfo!\n"); 00156 return NULL; 00157 } 00158 //printf("STill alive...\n"); 00159 fflush(stdout); 00160 jmethodID sysinfo_mid=env->GetMethodID(sysinfo_cls, "<init>","(Ljava/lang/String;JJSSSSJ)V"); 00161 if (sysinfo_mid==NULL) { 00162 printf("Problem mid!\n"); 00163 fflush(stdout); 00164 return NULL; 00165 } 00166 //printf("STill alive...\n"); 00167 fflush(stdout); 00168 jobject sysinfo=env->NewObject(sysinfo_cls, sysinfo_mid, prod, s.romVersion, s.locale, s.dlpMajorVersion, s.dlpMinorVersion,s.compatMajorVersion,s.compatMinorVersion,s.maxRecSize); 00169 printf("Returning from getsysinfo...\n"); 00170 fflush(stdout); 00171 return sysinfo; 00172 */ 00173 jclass jClass_sysInfo = NULL; 00174 jobject jObject_sysInfo = NULL; 00175 jmethodID jMethod_sysInfo = NULL; 00176 struct SysInfo rSysInfo; 00177 int bProceed = 1; 00178 00179 if (bProceed) { 00180 int iResult; 00181 00182 /* Check that dlp_ReadSysInfo call actually succeeded */ 00183 memset(&rSysInfo, 0, sizeof(struct SysInfo)); 00184 iResult = dlp_ReadSysInfo(handle, &rSysInfo); 00185 if (iResult < 0) { 00186 /* Throw Java exception in case of failure */ 00187 postPilotLinkException(env, "Unable to read SysInfo", iResult, errno); 00188 bProceed = 0; 00189 } 00190 } 00191 if (bProceed) { 00192 /* Look up SysInfo class */ 00193 jClass_sysInfo = env->FindClass("org/gnu/pilotlink/SysInfo"); 00194 if (jClass_sysInfo == NULL) { 00195 /* pending ClassNotFoundException in env */ 00196 bProceed = 0; 00197 } 00198 } 00199 if (bProceed) { 00200 /* Look up constructor method with complete-specification argument */ 00201 jMethod_sysInfo = env->GetMethodID(jClass_sysInfo, "<init>", 00202 "(Ljava/lang/String;JJSSSSJ)V"); 00203 if (jMethod_sysInfo == NULL) { 00204 /* pending NoSuchMethodException in env */ 00205 bProceed = 0; 00206 } 00207 } 00208 if (bProceed) { 00209 /* Explicit casts to jlong are required because env->NewObject() works 00210 very similar to (and probably identical) to printf() and related 00211 procedures which use stdarg.h routines for variable arguments. 00212 The constructor requires a jlong (64 bits) for some fields, but the 00213 corresponding fields in the C struct are of a system-dependent size 00214 (32 bits for an unsigned long in i386). Failure to cast to an appropriate 00215 size results in a stack misalignment which, at the very least, causes 00216 incorrect values to be received at the Java side. For the sake of 00217 completeness, jshort values are explicitly casted too. 00218 */ 00219 jstring jString_prodID = env->NewStringUTF(rSysInfo.prodID); 00220 jObject_sysInfo = env->NewObject(jClass_sysInfo, jMethod_sysInfo, 00221 jString_prodID, (jlong)rSysInfo.romVersion, (jlong)rSysInfo.locale, 00222 (jshort)rSysInfo.dlpMajorVersion, (jshort)rSysInfo.dlpMinorVersion, 00223 (jshort)rSysInfo.compatMajorVersion, 00224 (jshort)rSysInfo.compatMinorVersion, (jlong)rSysInfo.maxRecSize); 00225 } 00226 00227 return jObject_sysInfo; 00228 }
Here is the call graph for this function:

| JNIEXPORT jobject JNICALL Java_org_gnu_pilotlink_PilotLink_readUserInfo | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | handler | |||
| ) |
Definition at line 234 of file libjpisock.c.
References dlp_ReadUserInfo(), PilotUser::lastSyncDate, PilotUser::lastSyncPC, PilotUser::password, PilotUser::passwordLength, postPilotLinkException(), PilotUser::successfulSyncDate, PilotUser::userID, PilotUser::username, and PilotUser::viewerID.
00234 { 00235 /* 00236 struct PilotUser U; 00237 dlp_ReadUserInfo(handler, &U); 00238 U.username[127]=0; 00239 U.password[U.passwordLength]=0; 00240 00241 printf("Last sync-->%ld\n",U.lastSyncDate); 00242 printf("Last ssync->%ld\n",U.successfulSyncDate); 00243 jstring str_name=env->NewStringUTF(U.username); 00244 if (str_name==NULL) { 00245 return NULL; 00246 } 00247 jstring str_pw=env->NewStringUTF(U.password); 00248 if (str_pw==NULL) { 00249 return NULL; 00250 } 00251 jlong vid=U.viewerID; 00252 jlong uid=U.userID; 00253 jlong lspc=U.lastSyncPC; 00254 00255 jclass calclass=env->FindClass("java/util/Date"); 00256 if (calclass==NULL) { 00257 return NULL; 00258 } 00259 00260 jmethodID cal_mid=env->GetMethodID(calclass,"<init>","(J)V"); 00261 if (cal_mid==NULL){ 00262 return NULL; 00263 } 00264 00265 jobject lsd_date=env->NewObject(calclass,cal_mid,U.lastSyncDate*1000); 00266 jobject sucd_date=env->NewObject(calclass,cal_mid,U.successfulSyncDate*1000); 00267 00268 jclass usercls=env->FindClass("org/gnu/pilotlink/User"); 00269 if (usercls==NULL) { 00270 printf("USERCLASS not found!\n"); 00271 return NULL; 00272 } else { 00273 printf("ok...\n"); 00274 } 00275 jmethodID umid=env->GetMethodID(usercls,"<init>","(Ljava/lang/String;Ljava/lang/String;JJJLjava/util/Date;Ljava/util/Date;)V"); 00276 if (umid==NULL) { 00277 printf("MethodID not found!\n"); 00278 return NULL; 00279 } else { 00280 printf("ok...\n"); 00281 } 00282 //printf("Returning from getuserinfo...\n"); 00283 jobject u=env->NewObject(usercls,umid,str_name,str_pw,uid,vid,lspc,lsd_date, sucd_date); 00284 return u; 00285 */ 00286 00287 jclass jClass_user = NULL; 00288 jobject jObject_user = NULL; 00289 jmethodID jMethod_user = NULL; 00290 struct PilotUser rUserInfo; 00291 int bProceed = 1; 00292 00293 if (bProceed) { 00294 int iResult; 00295 00296 /* Check that dlp_ReadUserInfo call actually succeeded */ 00297 memset(&rUserInfo, 0, sizeof(struct PilotUser)); 00298 iResult = dlp_ReadUserInfo(handler, &rUserInfo); 00299 if (iResult < 0) { 00300 /* Throw Java exception in case of failure */ 00301 postPilotLinkException(env, "Unable to read UserInfo", iResult, errno); 00302 bProceed = 0; 00303 } else { 00304 /* This was taken from previous code... */ 00305 rUserInfo.username[sizeof(rUserInfo.username) - 1] = '\0'; 00306 rUserInfo.password[rUserInfo.passwordLength] = '\0'; 00307 } 00308 } 00309 if (bProceed) { 00310 /* Look up User class */ 00311 jClass_user = env->FindClass("org/gnu/pilotlink/User"); 00312 if (jClass_user == NULL) { 00313 /* pending ClassNotFoundException in env */ 00314 bProceed = 0; 00315 } 00316 } 00317 if (bProceed) { 00318 /* Look up constructor method with complete-specification argument. 00319 NOTE: a new constructor was provided in User.java in order to 00320 avoid having to create Date objects in C code, AND to fix a subtle 00321 bug in which the multiplication of time_t * int (miliseconds since 00322 Epoch) silently overflows because both time_t and int are 32-bit, 00323 and the result is NOT promoted to at least 64 bits, required for 00324 the constructor Date(long). 00325 */ 00326 jMethod_user = env->GetMethodID(jClass_user, "<init>", 00327 "(Ljava/lang/String;Ljava/lang/String;JJJJJ)V"); 00328 if (jMethod_user == NULL) { 00329 /* pending NoSuchMethodException in env */ 00330 bProceed = 0; 00331 } 00332 } 00333 if (bProceed) { 00334 /* Explicit casts added - see object creation at 00335 Java_org_gnu_pilotlink_PilotLink_readSysInfo() for explanation. */ 00336 jstring jString_username = env->NewStringUTF(rUserInfo.username); 00337 jstring jString_password = env->NewStringUTF(rUserInfo.password); 00338 jObject_user = env->NewObject(jClass_user, jMethod_user, jString_username, 00339 jString_password, (jlong)rUserInfo.userID, (jlong)rUserInfo.viewerID, 00340 (jlong)rUserInfo.lastSyncPC, (jlong)rUserInfo.lastSyncDate, 00341 (jlong)rUserInfo.successfulSyncDate); 00342 } 00343 return jObject_user; 00344 }
Here is the call graph for this function:

| JNIEXPORT void JNICALL Java_org_gnu_pilotlink_PilotLink_resetSystem | ( | JNIEnv * | env, | |
| jobject | , | |||
| jint | iSockHandle | |||
| ) |
Definition at line 1160 of file libjpisock.c.
References dlp_ResetSystem(), and postPilotLinkException().
01161 { 01162 int iResult = dlp_ResetSystem(iSockHandle); 01163 if (iResult < 0) { 01164 postPilotLinkException(env, "Unable to reset system", iResult, errno); 01165 } 01166 }
Here is the call graph for this function:

| JNIEXPORT int JNICALL Java_org_gnu_pilotlink_PilotLink_writeAppBlock | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | handle, | |||
| jint | dbhandle, | |||
| jbyteArray | data, | |||
| jint | length | |||
| ) |
Definition at line 449 of file libjpisock.c.
References buffer, dlp_WriteAppBlock(), postJavaException(), and postPilotLinkException().
00449 { 00450 /* 00451 char buffer[MAX_RESOURCE_SIZE]; 00452 env->GetByteArrayRegion(data,0,length,(jbyte*)buffer); 00453 return dlp_WriteAppBlock(handle,dbhandle,buffer,length); 00454 */ 00455 jbyte * buffer; 00456 int iResult = 0; 00457 00458 /* Allocate memory for copy of app block */ 00459 if ((buffer = (jbyte *)malloc(length * sizeof(jbyte))) != NULL) { 00460 env->GetByteArrayRegion(data, 0, length, buffer); 00461 iResult = dlp_WriteAppBlock(handle, dbhandle, buffer, length); 00462 if (iResult < 0) { 00463 /* Throw Java exception to signal error */ 00464 postPilotLinkException(env, "Unable to write app-block", iResult, errno); 00465 } 00466 free(buffer); 00467 } else { 00468 postJavaException(env, 00469 "org/gnu/pilotlink/PilotLinkException", 00470 "Unable to allocate memory for app block"); 00471 } 00472 return iResult; 00473 }
Here is the call graph for this function:

| JNIEXPORT jint JNICALL Java_org_gnu_pilotlink_PilotLink_writeRecord | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | handle, | |||
| jint | db, | |||
| jobject | record | |||
| ) |
Definition at line 738 of file libjpisock.c.
References buffer, dlp_WriteRecord(), MAX_RESOURCE_SIZE, and size.
00738 { 00739 00740 jlong id=0; 00741 jclass cls=env->GetObjectClass(record); 00742 jmethodID mid=env->GetMethodID(cls,"getCategory","()I"); 00743 00744 if (mid==NULL) { printf("Error getting mid!"); return -1; } 00745 jint cat=env->CallIntMethod(record,mid); 00746 00747 jmethodID mid2=env->GetMethodID(cls,"getId","()J"); 00748 00749 id=env->CallLongMethod(record,mid2, NULL); 00750 if (id==0) { 00751 printf("Creating new entry!\n"); 00752 } 00753 00754 mid=env->GetMethodID(cls,"getAttribs","()I"); 00755 jint attr=env->CallIntMethod(record,mid); 00756 00757 mid=env->GetMethodID(cls,"getSize","()I"); 00758 jint size=env->CallIntMethod(record,mid); 00759 printf("Got size: %d\n",size); 00760 char buffer[MAX_RESOURCE_SIZE]; 00761 mid=env->GetMethodID(cls,"getBuffer","()[B"); 00762 jbyteArray arr=(jbyteArray)env->CallObjectMethod(record,mid); 00763 env->GetByteArrayRegion(arr,0,size,(jbyte*)buffer); 00764 recordid_t i=0; 00765 int ret=dlp_WriteRecord(handle,db,attr, id, cat, buffer,size,&i); 00766 if (id==0 && ret>0) { 00767 mid=env->GetMethodID(cls,"setId","(J)V"); 00768 env->CallVoidMethod(record,mid,(jlong)i); 00769 } 00770 return ret; 00771 00772 00773 00774 }
Here is the call graph for this function:

| JNIEXPORT void JNICALL Java_org_gnu_pilotlink_PilotLink_writeResource | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | iSockHandle, | |||
| jint | iDBHandle, | |||
| jobject | pRecord | |||
| ) |
Definition at line 1089 of file libjpisock.c.
References dlp_WriteResource(), postJavaException(), and postPilotLinkException().
01090 { 01091 jlong iRsrcID; /* Resource ID for record */ 01092 jint iRsrcType; /* Resource type for record */ 01093 jint iRsrcSize; /* Actual resource size */ 01094 jbyte * pRsrcData = NULL; /* Buffer for resource data */ 01095 01096 jclass pRecordClass; /* Java class for record */ 01097 jmethodID pRecordMethod; /* Java instance method for record */ 01098 jbyteArray pDataArray; /* Java array for resource data */ 01099 jint iResult = -1; /* Result of library call */ 01100 int bProceed = 1; 01101 01102 /* Get reference to record class */ 01103 pRecordClass = env->GetObjectClass(pRecord); 01104 01105 /* Find out required attributes for resource write */ 01106 if (bProceed) { 01107 /* Find out category (resource type) */ 01108 if ((pRecordMethod = env->GetMethodID(pRecordClass, "getCategory", "()I")) != NULL) { 01109 iRsrcType = env->CallIntMethod(pRecord, pRecordMethod); 01110 } else { 01111 /* Method lookup failed */ 01112 bProceed = 0; 01113 } 01114 } 01115 if (bProceed) { 01116 /* Find out resource ID */ 01117 if ((pRecordMethod = env->GetMethodID(pRecordClass, "getId", "()J")) != NULL) { 01118 iRsrcID = env->CallLongMethod(pRecord, pRecordMethod); 01119 } else { 01120 /* Method lookup failed */ 01121 bProceed = 0; 01122 } 01123 } 01124 if (bProceed) { 01125 /* Find out resource size && allocate memory */ 01126 if ((pRecordMethod = env->GetMethodID(pRecordClass, "getSize", "()I")) != NULL) { 01127 iRsrcSize = env->CallIntMethod(pRecord, pRecordMethod); 01128 if (iRsrcSize > 0) pRsrcData = (jbyte *)malloc(iRsrcSize * sizeof(char)); 01129 if (pRsrcData == NULL) { 01130 postJavaException(env, 01131 "org/gnu/pilotlink/PilotLinkException", 01132 "Unable to allocate buffer for copy of resource"); 01133 bProceed = 0; 01134 } 01135 } else { 01136 /* Method lookup failed */ 01137 bProceed = 0; 01138 } 01139 } 01140 if (bProceed) { 01141 /* Get copy of resource data in allocated memory */ 01142 if ((pRecordMethod = env->GetMethodID(pRecordClass, "getBuffer", "()[B")) != NULL) { 01143 pDataArray = (jbyteArray)env->CallObjectMethod(pRecord, pRecordMethod); 01144 env->GetByteArrayRegion(pDataArray, 0, iRsrcSize, pRsrcData); 01145 iResult = dlp_WriteResource(iSockHandle, iDBHandle, iRsrcType, iRsrcID, 01146 pRsrcData, iRsrcSize); 01147 if (iResult < 0) { 01148 postPilotLinkException(env, "Unable to write resource", iResult, errno); 01149 } 01150 } else { 01151 /* Method lookup failed */ 01152 bProceed = 0; 01153 } 01154 } 01155 01156 if (pRsrcData != NULL) free(pRsrcData); 01157 }
Here is the call graph for this function:

| JNIEXPORT void JNICALL Java_org_gnu_pilotlink_PilotLink_writeUserInfo | ( | JNIEnv * | env, | |
| jobject | obj, | |||
| jint | so, | |||
| jobject | user | |||
| ) |
Definition at line 351 of file libjpisock.c.
References dlp_WriteUserInfo(), getBasicTypeField(), PilotUser::lastSyncDate, PilotUser::lastSyncPC, PilotUser::password, PilotUser::passwordLength, postPilotLinkException(), PilotUser::successfulSyncDate, PilotUser::userID, PilotUser::username, and PilotUser::viewerID.
00351 { 00352 /* 00353 printf("Not implemented yet...sorry\n"); 00354 */ 00355 /* Now it IS implemented... ;-) */ 00356 jclass jClass_user = NULL; 00357 jmethodID jMethod_user = NULL; 00358 struct PilotUser rUserInfo; 00359 jlong jTempValue; 00360 jstring jTempString; 00361 int bProceed = 1; 00362 00363 /* Set everything not explicitly assigned to blanks */ 00364 memset(&rUserInfo, 0, sizeof(struct PilotUser)); 00365 00366 /* Get object class for user... this should not fail */ 00367 jClass_user = env->GetObjectClass(user); 00368 00369 /* Assign all of the basic fields */ 00370 if (bProceed) { 00371 bProceed = getBasicTypeField(env, jClass_user, user, 00372 "J", "userid", &jTempValue); 00373 rUserInfo.userID = jTempValue; 00374 } 00375 if (bProceed) { 00376 bProceed = getBasicTypeField(env, jClass_user, user, 00377 "J", "viewerid", &jTempValue); 00378 rUserInfo.viewerID = jTempValue; 00379 } 00380 if (bProceed) { 00381 bProceed = getBasicTypeField(env, jClass_user, user, 00382 "J", "lastSyncPC", &jTempValue); 00383 rUserInfo.lastSyncPC = jTempValue; 00384 } 00385 if (bProceed) { 00386 jTempString = NULL; 00387 bProceed = getBasicTypeField(env, jClass_user, user, 00388 "Ljava/lang/String;", "name", &jTempString); 00389 if (bProceed && jTempString != NULL) { 00390 const char * sTempString = env->GetStringUTFChars(jTempString, 0); 00391 strncpy(rUserInfo.username, sTempString, sizeof(rUserInfo.username) - 1); 00392 rUserInfo.username[sizeof(rUserInfo.username) - 1] = '\0'; 00393 env->ReleaseStringUTFChars(jTempString, sTempString); 00394 } 00395 } 00396 if (bProceed) { 00397 jTempString = NULL; 00398 bProceed = getBasicTypeField(env, jClass_user, user, 00399 "Ljava/lang/String;", "password", &jTempString); 00400 if (bProceed && jTempString != NULL) { 00401 const char * sTempString = env->GetStringUTFChars(jTempString, 0); 00402 strncpy(rUserInfo.password, sTempString, sizeof(rUserInfo.password) - 1); 00403 rUserInfo.password[sizeof(rUserInfo.password) - 1] = '\0'; 00404 rUserInfo.passwordLength = strlen(rUserInfo.password); 00405 env->ReleaseStringUTFChars(jTempString, sTempString); 00406 } 00407 } 00408 00409 /* In order to get the correct time_t, a function call is needed. The methods 00410 User.getLastSyncDate_time_t() and User.getLastSuccessfulSyncDate_time_t() 00411 were created for this purpose. 00412 */ 00413 if (bProceed) { 00414 jMethod_user = env->GetMethodID(jClass_user, "getLastSyncDate_time_t", 00415 "()J"); 00416 if (jMethod_user == NULL) { 00417 /* pending NoSuchMethodException in env */ 00418 bProceed = 0; 00419 } else { 00420 /* Use Date.getTime() in Java side and divide by 1000 */ 00421 rUserInfo.lastSyncDate = env->CallLongMethod(user, jMethod_user); 00422 } 00423 } 00424 if (bProceed) { 00425 jMethod_user = env->GetMethodID(jClass_user, "getLastSuccessfulSyncDate_time_t", 00426 "()J"); 00427 if (jMethod_user == NULL) { 00428 /* pending NoSuchMethodException in env */ 00429 bProceed = 0; 00430 } else { 00431 /* Use Date.getTime() in Java side and divide by 1000 */ 00432 rUserInfo.successfulSyncDate = env->CallLongMethod(user, jMethod_user); 00433 } 00434 } 00435 00436 /* Write user info if all assignments were successful */ 00437 if (bProceed) { 00438 int iResult = dlp_WriteUserInfo(so, &rUserInfo); 00439 if (iResult < 0) { 00440 postPilotLinkException(env, "Unable to write UserInfo", iResult, errno); 00441 } 00442 } 00443 }
Here is the call graph for this function:

| int pilot_connect | ( | JNIEnv * | env, | |
| const char * | port | |||
| ) |
Definition at line 808 of file libjpisock.c.
References dlp_OpenConduit(), dlp_ReadSysInfo(), pi_accept_to(), PI_AF_PILOT, pi_bind(), pi_close(), PI_DEV_TIMEOUT, PI_LEVEL_DEV, pi_listen(), PI_PF_DLP, pi_setsockopt(), PI_SOCK_STREAM, pi_socket(), postJavaException(), and strerror().
Referenced by Java_org_gnu_pilotlink_PilotLink_connect(), and main().
00809 { 00810 int parent_sd = -1, /* Client socket, formerly sd */ 00811 client_sd = -1, /* Parent socket, formerly sd2 */ 00812 result; 00813 struct pi_sockaddr addr; 00814 struct stat attr; 00815 struct SysInfo sys_info; 00816 const char *defport = "/dev/pilot"; 00817 int bProceed = 1; 00818 00819 if (port == NULL && (port = getenv("PILOTPORT")) == NULL) { 00820 00821 /* err seems to be used for stat() only */ 00822 int err = 0; 00823 00824 /* Commented out debug code */ 00825 /* 00826 fprintf(stderr, " No $PILOTPORT specified and no -p " 00827 "<port> given.\n" 00828 " Defaulting to '%s'\n", defport); 00829 */ 00830 port = defport; 00831 err = stat(port, &attr); 00832 00833 /* Moved err check inside if() block - err only meaningful here */ 00834 if (err) { 00835 /* *BAD* practice - cannot recover from within Java if exit() here. 00836 Should create && throw exception instead. 00837 */ 00838 /* 00839 fprintf(stderr, " ERROR: %s (%d)\n\n", strerror(errno), errno); 00840 fprintf(stderr, " Error accessing: '%s'. Does '%s' exist?\n", 00841 port, port); 00842 //fprintf(stderr, " Please use --help for more information\n\n"); 00843 exit(1); 00844 */ 00845 00846 /* Throw an exception - FileNotFoundException seems appropriate here */ 00847 postJavaException(env, "java/io/FileNotFoundException", strerror(errno)); 00848 bProceed = 0; 00849 } 00850 } 00851 00852 /* At this point, either bProceed is 0, or port != NULL, further checks are unnecesary */ 00853 00854 /* Check bProceed to account for previous exceptions */ 00855 if (bProceed && !(parent_sd = pi_socket(PI_AF_PILOT, PI_SOCK_STREAM, PI_PF_DLP))) { 00856 /* 00857 fprintf(stderr, "\n Unable to create socket '%s'\n", 00858 port ? port : getenv("PILOTPORT")); 00859 return -1; 00860 */ 00861 /* Throw exception here to inform nature of connection failure. */ 00862 const char * sTemplate = "Unable to create socket '%s'"; 00863 char * sMessage = (char *)malloc(strlen(sTemplate) + strlen(port) + 1); 00864 if (sMessage != NULL) sprintf(sMessage, sTemplate, port); 00865 postJavaException(env, "org/gnu/pilotlink/PilotLinkException", 00866 (sMessage != NULL) ? sMessage : port); 00867 if (sMessage != NULL) free(sMessage); 00868 00869 bProceed = 0; 00870 } 00871 00872 /* Check bProceed to account for previous exceptions */ 00873 if (bProceed) { 00874 /* Removed check for port != NULL, since port was validated before */ 00875 /* 00876 if (port != NULL) { 00877 */ 00878 result = 00879 pi_bind(parent_sd, port); 00880 /* 00881 } else { 00882 result = pi_bind(parent_sd, NULL, 0); 00883 } 00884 */ 00885 } 00886 00887 if (bProceed && result < 0) { 00888 int save_errno = errno; 00889 /* 00890 const char *portname; 00891 00892 portname = (port != NULL) ? port : getenv("PILOTPORT"); 00893 if (portname) { 00894 fprintf(stderr, "\n"); 00895 errno = save_errno; 00896 fprintf(stderr, " ERROR: %s (%d)\n\n", strerror(errno), 00897 errno); 00898 00899 if (errno == 2) { 00900 fprintf(stderr, " The device %s does not exist..\n", 00901 portname); 00902 fprintf(stderr, " Possible solution:\n\n\tmknod %s c " 00903 "<major> <minor>\n\n", portname ); 00904 00905 } else if (errno == 13) { 00906 fprintf(stderr, " Please check the " 00907 "permissions on %s..\n", portname ); 00908 fprintf(stderr, " Possible solution:\n\n\tchmod 0666 " 00909 "%s\n\n", portname ); 00910 00911 } else if (errno == 19) { 00912 fprintf(stderr, " Press the HotSync button first and " 00913 "relaunch this conduit..\n\n"); 00914 } else if (errno == 21) { 00915 fprintf(stderr, " The port specified must contain a " 00916 "device name, and %s was a directory.\n" 00917 " Please change that to reference a real " 00918 "device, and try again\n\n", portname ); 00919 } 00920 00921 fprintf(stderr, " Unable to bind to port: %s\n", 00922 portname) ; 00923 fprintf(stderr, " Please use --help for more " 00924 "information\n\n"); 00925 } else 00926 fprintf(stderr, "\n No port specified\n"); 00927 */ 00928 const char * sTemplate = "Unable to bind to port %s - (%d) %s%s"; 00929 const char * sFailureReason; 00930 char * sMessage; 00931 00932 switch (save_errno) { 00933 case 2: 00934 sFailureReason = "; Device does not exist (use mknod to fix)"; 00935 break; 00936 case 13: 00937 sFailureReason = "; Access denied on device (use chmod to fix)"; 00938 break; 00939 case 19: 00940 sFailureReason = "; HotSync button must be pressed first"; 00941 break; 00942 case 21: 00943 sFailureReason = "; Device name appears to be a directory"; 00944 break; 00945 default: 00946 sFailureReason = ""; 00947 break; 00948 } 00949 sMessage = (char *)malloc(strlen(sTemplate) + strlen(port) + 16 + 00950 strlen(strerror(save_errno)) + strlen(sFailureReason)); 00951 if (sMessage != NULL) { 00952 sprintf(sMessage, sTemplate, port, save_errno, strerror(save_errno), sFailureReason); 00953 postJavaException(env, "org/gnu/pilotlink/PilotLinkException", sMessage); 00954 free(sMessage); 00955 } else { 00956 /* Unable to malloc(), inform of errno string */ 00957 postJavaException(env, "org/gnu/pilotlink/PilotLinkException", strerror(save_errno)); 00958 } 00959 00960 pi_close(parent_sd); 00961 pi_close(client_sd); 00962 // return -1; 00963 bProceed = 0; 00964 } 00965 00966 /* Removed debug message, maybe add notification framework to invoke here 00967 fprintf(stderr, 00968 "\n Listening to port: %s\n\n Please press the HotSync " 00969 "button now... ", 00970 port ? port : getenv("PILOTPORT")); 00971 */ 00972 /* Check bProceed to account for previous exceptions */ 00973 if (bProceed && pi_listen(parent_sd, 1) == -1) { 00974 /* debug message replaced with Java exception */ 00975 /* fprintf(stderr, "\n Error listening on %s\n", port); */ 00976 postJavaException(env, 00977 "org/gnu/pilotlink/PilotLinkException", 00978 "Unable to listen on port"); 00979 pi_close(parent_sd); 00980 pi_close(client_sd); 00981 /* return -1; */ 00982 bProceed = 0; 00983 } 00984 00985 /* Check bProceed to account for previous exceptions */ 00986 if (bProceed) { 00987 client_sd = pi_accept_to(parent_sd, 0, 0, 5); 00988 if (client_sd == -1) { 00989 /* debug message replaced with Java exception */ 00990 /* fprintf(stderr, "\n Error accepting data on %s\n", port); */ 00991 postJavaException(env, 00992 "org/gnu/pilotlink/PilotLinkException", 00993 "Unable to accept data on port"); 00994 pi_close(parent_sd); 00995 pi_close(client_sd); 00996 /* return -1;*/ 00997 bProceed = 0; 00998 } else { 00999 int so_timeout = 16; 01000 size_t sizeof_so_timeout = sizeof(so_timeout); 01001 01002 pi_setsockopt(client_sd, PI_LEVEL_DEV, PI_DEV_TIMEOUT, 01003 &so_timeout, &sizeof_so_timeout); 01004 } 01005 } 01006 01007 /* Removed debug message, maybe add notification framework to invoke here */ 01008 /* fprintf(stderr, "Connected\n\n"); */ 01009 01010 /* Check bProceed to account for previous exceptions */ 01011 if (bProceed) { 01012 01013 int iResult; 01014 int iNumRetries = 5; 01015 01016 while (iNumRetries > 0 && (iResult = dlp_ReadSysInfo(client_sd, &sys_info)) < 0) 01017 iNumRetries--; 01018 if (iResult < 0) { 01019 /* debug message replaced with Java exception */ 01020 /* fprintf(stderr, "\n Error read system info on %s\n", port); */ 01021 postJavaException(env, 01022 "org/gnu/pilotlink/PilotLinkException", 01023 "Unable to read system info on port"); 01024 pi_close(parent_sd); 01025 pi_close(client_sd); 01026 /* return -1; */ 01027 bProceed = 0; 01028 } 01029 } 01030 /* Removed debug message, maybe add notification framework to invoke here */ 01031 /* printf("Opening counduit...\n"); */ 01032 dlp_OpenConduit(client_sd); 01033 /* Why should parent_sd remain open after connect? Nobody receives it. */ 01034 pi_close(parent_sd); 01035 return client_sd; 01036 }
Here is the call graph for this function:

| static void postJavaException | ( | JNIEnv * | , | |
| const char * | , | |||
| const char * | ||||
| ) | [static] |
Definition at line 1255 of file libjpisock.c.
Referenced by Java_org_gnu_pilotlink_PilotLink_createDB(), Java_org_gnu_pilotlink_PilotLink_deleteDB(), Java_org_gnu_pilotlink_PilotLink_getResourceByIndex(), Java_org_gnu_pilotlink_PilotLink_openDB(), Java_org_gnu_pilotlink_PilotLink_readAppInfo(), Java_org_gnu_pilotlink_PilotLink_writeAppBlock(), Java_org_gnu_pilotlink_PilotLink_writeResource(), pilot_connect(), and postPilotLinkException().
01256 { 01257 jclass pExceptionClass = env->FindClass(sExceptionClass); 01258 if (pExceptionClass != NULL) env->ThrowNew(pExceptionClass, sMessage); 01259 }
| static void postPilotLinkException | ( | JNIEnv * | , | |
| const char * | , | |||
| int | , | |||
| int | ||||
| ) | [static] |
Definition at line 1217 of file libjpisock.c.
References dlp_strerror(), postJavaException(), and strerror().
Referenced by Java_org_gnu_pilotlink_PilotLink_closeDB(), Java_org_gnu_pilotlink_PilotLink_createDB(), Java_org_gnu_pilotlink_PilotLink_deleteDB(), Java_org_gnu_pilotlink_PilotLink_deleteRecordById(), Java_org_gnu_pilotlink_PilotLink_endSync(), Java_org_gnu_pilotlink_PilotLink_getRecordByIndex(), Java_org_gnu_pilotlink_PilotLink_getRecordCount(), Java_org_gnu_pilotlink_PilotLink_getResourceByIndex(), Java_org_gnu_pilotlink_PilotLink_openConduit(), Java_org_gnu_pilotlink_PilotLink_openDB(), Java_org_gnu_pilotlink_PilotLink_readAppInfo(), Java_org_gnu_pilotlink_PilotLink_readDBList(), Java_org_gnu_pilotlink_PilotLink_readSysInfo(), Java_org_gnu_pilotlink_PilotLink_readUserInfo(), Java_org_gnu_pilotlink_PilotLink_resetSystem(), Java_org_gnu_pilotlink_PilotLink_writeAppBlock(), Java_org_gnu_pilotlink_PilotLink_writeResource(), and Java_org_gnu_pilotlink_PilotLink_writeUserInfo().
01218 { 01219 const char * sTemplate = "%s: %s - %s"; 01220 const char * sGenericException = "org/gnu/pilotlink/PilotLinkException"; 01221 const char * sDBExistsException = "org/gnu/pilotlink/DatabaseExistsException"; 01222 const char * sDBNotFoundException = "org/gnu/pilotlink/DatabaseNotFoundException"; 01223 const char * sExceptionClass; 01224 char * sMessage = NULL; 01225 01226 // Make save_errno positive in all cases 01227 if (save_errno < 0) save_errno = -save_errno; 01228 01229 // Choose which exception to report 01230 switch (abs(iResult)) { 01231 case 5: 01232 sExceptionClass = sDBNotFoundException; 01233 break; 01234 case 9: 01235 sExceptionClass = sDBExistsException; 01236 break; 01237 default: 01238 sExceptionClass = sGenericException; 01239 break; 01240 } 01241 01242 // Attempt to describe underlying errno for exception 01243 sMessage = (char *)malloc(strlen(sTemplate) + strlen(sTexto) + 01244 strlen(dlp_strerror(iResult)) + strlen(strerror(save_errno)) + 1); 01245 if (sMessage != NULL) { 01246 sprintf(sMessage, sTemplate, sTexto, dlp_strerror(iResult), strerror(save_errno)); 01247 postJavaException(env, sExceptionClass, sMessage); 01248 free(sMessage); 01249 } else { 01250 postJavaException(env, sExceptionClass, dlp_strerror(iResult)); 01251 } 01252 }
Here is the call graph for this function:
