From: Adam Dickmeiss Date: Thu, 18 Jun 2009 12:09:21 +0000 (+0200) Subject: Introduce type for BER BOOLEAN/INTEGER . X-Git-Tag: v3.0.47~3 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=8356ea58313ee1f350226172cf99bfb0b7c5583c;p=yaz-moved-to-github.git Introduce type for BER BOOLEAN/INTEGER . The BER BOOLEAN is now the integral type Odr_bool which still happens to be an 'int'. The BER INTEGER which used to be a plain 'int' is now typedef'd to Odr_int. This is still an integral 'int', but it may be changed to 64-bit via a one-liner in nmem.h (NMEM_64=1). The documentation, ASN-1 compiler as well as programs has been updated to use the new types. --- diff --git a/client/client.c b/client/client.c index d6ec0c3..0cf0cad 100644 --- a/client/client.c +++ b/client/client.c @@ -104,7 +104,7 @@ static int smallSetUpperBound = 0; static int largeSetLowerBound = 1; static int mediumSetPresentNumber = 0; static Z_ElementSetNames *elementSetNames = 0; -static odr_int_t setno = 1; /* current set offset */ +static Odr_int setno = 1; /* current set offset */ static enum oid_proto protocol = PROTO_Z3950; /* current app protocol */ #define RECORDSYNTAX_MAX 20 static char *recordsyntax_list[RECORDSYNTAX_MAX]; @@ -1640,7 +1640,7 @@ static void print_level(int iLevel) printf(" "); } -static void print_int(int iLevel, const char *pTag, odr_int_t *pInt) +static void print_int(int iLevel, const char *pTag, Odr_int *pInt) { if (pInt != NULL) { @@ -1649,6 +1649,15 @@ static void print_int(int iLevel, const char *pTag, odr_int_t *pInt) } } +static void print_bool(int iLevel, const char *pTag, Odr_bool *pInt) +{ + if (pInt != NULL) + { + print_level(iLevel); + printf("%s: %d\n", pTag, *pInt); + } +} + static void print_string(int iLevel, const char *pTag, const char *pString) { if (pString != NULL) @@ -1793,10 +1802,10 @@ static int process_resourceControlRequest(Z_ResourceControlRequest *req) { printf("Received ResourceControlRequest.\n"); print_referenceId(1, req->referenceId); - print_int(1, "Suspended Flag", req->suspendedFlag); + print_bool(1, "Suspended Flag", req->suspendedFlag); print_int(1, "Partial Results Available", req->partialResultsAvailable); - print_int(1, "Response Required", req->responseRequired); - print_int(1, "Triggered Request Flag", req->triggeredRequestFlag); + print_bool(1, "Response Required", req->responseRequired); + print_bool(1, "Triggered Request Flag", req->triggeredRequestFlag); print_external(1, req->resourceReport); return 0; } @@ -2650,7 +2659,7 @@ static int cmd_setnames(const char *arg) /* PRESENT SERVICE ----------------------------- */ static void parse_show_args(const char *arg_c, char *setstring, - odr_int_t *start, odr_int_t *number) + Odr_int *start, Odr_int *number) { char arg[40]; char *p; @@ -2686,7 +2695,7 @@ static int send_presentRequest(const char *arg) Z_APDU *apdu = zget_APDU(out, Z_APDU_presentRequest); Z_PresentRequest *req = apdu->u.presentRequest; Z_RecordComposition compo; - odr_int_t nos = 1; + Odr_int nos = 1; char setstring[100]; req->referenceId = set_refid(out); @@ -2777,7 +2786,7 @@ static int send_presentRequest(const char *arg) static int send_SRW_presentRequest(const char *arg) { char setstring[100]; - odr_int_t nos = 1; + Odr_int nos = 1; Z_SRW_PDU *sr = srw_sr; if (!sr) @@ -2923,7 +2932,7 @@ int cmd_cancel_find(const char *arg) { } int send_scanrequest(const char *set, const char *query, - odr_int_t pp, odr_int_t num, const char *term) + Odr_int pp, Odr_int num, const char *term) { Z_APDU *apdu = zget_APDU(out, Z_APDU_scanRequest); Z_ScanRequest *req = apdu->u.scanRequest; diff --git a/doc/asn.xml b/doc/asn.xml index bb84b52..c787d4f 100644 --- a/doc/asn.xml +++ b/doc/asn.xml @@ -5,7 +5,8 @@ various PDUs of the Z39.50 protocol, as well as for the complex types appearing within the PDUs. For the primitive data types, the C representation often takes the form of an ordinary C language type, - such as int. For ASN.1 constructs that have no direct + such as Odr_int which is equivalent to an integral + C integer. For ASN.1 constructs that have no direct representation in C, such as general octet strings and bit strings, the &odr; module (see section The ODR Module) provides auxiliary definitions. @@ -308,10 +309,10 @@ typedef struct Z_ext_typeent optionsOdr_bitmaskEmpty bitmask - preferredMessageSizeint30*1024 + preferredMessageSizeOdr_int30*1024 - maximumRecordSizeint30*1024 + maximumRecordSizeOdr_int30*1024 idAuthenticationZ_IdAuthenticationNULL @@ -360,13 +361,13 @@ typedef struct Z_ext_typeent optionsOdr_bitmaskEmpty bitmask - preferredMessageSizeint30*1024 + preferredMessageSizeOdr_int30*1024 - maximumRecordSizeint30*1024 + maximumRecordSizeOdr_int30*1024 - resultbool_tTRUE + resultOdr_boolTRUE implementationIdchar*"id)" @@ -405,22 +406,22 @@ typedef struct Z_ext_typeent referenceIdZ_ReferenceIdNULL - smallSetUpperBoundint0 + smallSetUpperBoundOdr_int0 - largeSetLowerBoundint1 + largeSetLowerBoundOdr_int1 - mediumSetPresentNumberint0 + mediumSetPresentNumberOdr_int0 - replaceIndicatorbool_tTRUE + replaceIndicatorOdr_boolTRUE resultSetNamechar *"default" - num_databaseNamesint0 + num_databaseNamesOdr_int0 databaseNameschar **NULL @@ -469,22 +470,22 @@ typedef struct Z_ext_typeent referenceIdZ_ReferenceIdNULL - resultCountint0 + resultCountOdr_int0 - numberOfRecordsReturnedint0 + numberOfRecordsReturnedOdr_int0 - nextResultSetPositionint0 + nextResultSetPositionOdr_int0 - searchStatusbool_tTRUE + searchStatusOdr_boolTRUE - resultSetStatusintNULL + resultSetStatusOdr_intNULL - presentStatusintNULL + presentStatusOdr_intNULL recordsZ_RecordsNULL @@ -521,13 +522,13 @@ typedef struct Z_ext_typeent resultSetIdchar*"default" - resultSetStartPointint1 + resultSetStartPointOdr_int1 - numberOfRecordsRequestedint10 + numberOfRecordsRequestedOdr_int10 - num_rangesint0 + num_rangesOdr_int0 additionalRangesZ_RangeNULL @@ -539,13 +540,13 @@ typedef struct Z_ext_typeent preferredRecordSyntaxOdr_oidNULL - maxSegmentCountintNULL + maxSegmentCountOdr_intNULL - maxRecordSizeintNULL + maxRecordSizeOdr_intNULL - maxSegmentSizeintNULL + maxSegmentSizeOdr_intNULL otherInfoZ_OtherInformationNULL @@ -572,13 +573,13 @@ typedef struct Z_ext_typeent referenceIdZ_ReferenceIdNULL - numberOfRecordsReturnedint0 + numberOfRecordsReturnedOdr_int0 - nextResultSetPositionint0 + nextResultSetPositionOdr_int0 - presentStatusintZ_PresentStatus_success + presentStatusOdr_intZ_PresentStatus_success recordsZ_RecordsNULL @@ -609,10 +610,10 @@ typedef struct Z_ext_typeent Z_ReferenceIdNULL - deleteFunctionintZ_DeleteResultSetRequest_list + deleteFunctionOdr_intZ_DeleteResultSetRequest_list - num_idsint0 + num_idsOdr_int0 resultSetListchar**NULL @@ -643,19 +644,19 @@ typedef struct Z_ext_typeent referenceIdZ_ReferenceIdNULL - deleteOperationStatusint + deleteOperationStatusOdr_int Z_DeleteStatus_success - num_statusesint0 + num_statusesOdr_int0 deleteListStatusesZ_ListStatus**NULL - numberNotDeletedintNULL + numberNotDeletedOdr_intNULL - num_bulkStatusesint0 + num_bulkStatusesOdr_int0 bulkStatusesZ_ListStatusNUL @@ -689,7 +690,7 @@ typedef struct Z_ext_typeent referenceIdZ_ReferenceIdNULL - num_databaseNamesint0 + num_databaseNamesOdr_int0 databaseNameschar**NULL @@ -701,13 +702,13 @@ typedef struct Z_ext_typeent termListAndStartPointZ_AttributesPlus... NULL - stepSizeintNULL + stepSizeOdr_intNULL - numberOfTermsRequestedint20 + numberOfTermsRequestedOdr_int20 - preferredPositionInResponseintNULL + preferredPositionInResponseOdr_intNULL otherInfoZ_OtherInformationNULL @@ -736,16 +737,16 @@ typedef struct Z_ext_typeent referenceIdZ_ReferenceIdNULL - stepSizeintNULL + stepSizeOdr_intNULL - scanStatusintZ_Scan_success + scanStatusOdr_intZ_Scan_success - numberOfEntriesReturnedint0 + numberOfEntriesReturnedOdr_int0 - positionOfTermintNULL + positionOfTermOdr_intNULL entriesZ_ListEntrisNULL @@ -779,14 +780,14 @@ typedef struct Z_ext_typeent referenceIdZ_ReferenceIdNULL - requestedActionint + requestedActionOdr_int Z_TriggerResourceCtrl_resou.. prefResourceReportFormatOdr_oidNULL - resultSetWantedbool_tNULL + resultSetWantedOdr_boolNULL otherInfoZ_OtherInformationNULL @@ -815,19 +816,19 @@ typedef struct Z_ext_typeent referenceIdZ_ReferenceIdNULL - suspendedFlagbool_tNULL + suspendedFlagOdr_boolNULL resourceReportZ_ExternalNULL - partialResultsAvailableintNULL + partialResultsAvailableOdr_intNULL - responseRequiredbool_tFALSE + responseRequiredOdr_boolFALSE - triggeredRequestFlagbool_tNULL + triggeredRequestFlagOdr_boolNULL otherInfoZ_OtherInformationNULL @@ -951,10 +952,10 @@ typedef struct Z_ext_typeent referenceIdZ_ReferenceIdNULL - numberOfRecordsReturnedintvalue=0 + numberOfRecordsReturnedOdr_intvalue=0 - num_segmentRecordsint0 + num_segmentRecordsOdr_int0 segmentRecordsZ_NamePlusRecordNULL @@ -984,7 +985,7 @@ typedef struct Z_ext_typeent referenceIdZ_ReferenceIdNULL - closeReasonintZ_Close_finished + closeReasonOdr_intZ_Close_finished diagnosticInformationchar*NULL diff --git a/doc/odr.xml b/doc/odr.xml index 627f5c9..0f6ac6f 100644 --- a/doc/odr.xml +++ b/doc/odr.xml @@ -262,7 +262,7 @@ Encoding and decoding functions - int odr_integer(ODR o, int **p, int optional, const char *name); + int odr_integer(ODR o, Odr_int **p, int optional, const char *name); int z_APDU(ODR o, Z_APDU **p, int optional, const char *name); @@ -311,7 +311,7 @@ void do_nothing_useful(int value) { ODR encode, decode; - int *valp, *resvalp; + Odr_int *valp, *resvalp; char *bufferp; int len; @@ -337,7 +337,8 @@ void do_nothing_useful(int value) printf("decoding went bad\n"); return; } - printf("the value is %d\n", *resvalp); + /* ODR_INT_PRINTF format for printf (such as %d) */ + printf("the value is " ODR_INT_PRINTF "\n", *resvalp); /* clean up */ odr_destroy(encode); @@ -585,11 +586,11 @@ void do_nothing_useful(int value) - int odr_integer(ODR o, int **p, int optional, const char *name); + int odr_integer(ODR o, Odr_int **p, int optional, const char *name); - (we don't allow values that can't be contained in a C integer.) + The Odr_int is just a simple integer. @@ -638,7 +639,7 @@ void do_nothing_useful(int value) BOOLEAN -int odr_bool(ODR o, bool_t **p, int optional, const char *name); +int odr_bool(ODR o, Odr_bool **p, int optional, const char *name); @@ -652,7 +653,7 @@ int odr_bool(ODR o, bool_t **p, int optional, const char *name); NULL -int odr_null(ODR o, bool_t **p, int optional, const char *name); +int odr_null(ODR o, Odr_null **p, int optional, const char *name); @@ -794,7 +795,7 @@ int odr_explicit_tag(ODR o, Odr_fun fun, int class, int tag, -int myInt(ODR o, int **p, int optional, const char *name) +int myInt(ODR o, Odr_int **p, int optional, const char *name) { return odr_implicit_tag(o, odr_integer, p, ODR_CONTEXT, 210, optional, name); @@ -866,8 +867,8 @@ MySequence ::= SEQUENCE { typedef struct MySequence { - int *intval; - bool_t *boolval; + Odr_int *intval; + Odr_bool *boolval; } MySequence; int mySequence(ODR o, MySequence **p, int optional, const char *name) @@ -1070,7 +1071,7 @@ MyArray ::= SEQUENCE OF INTEGER typedef struct MyArray { int num_elements; - int **elements; + Odr_int **elements; } MyArray; @@ -1194,9 +1195,9 @@ typedef struct MyChoice } which; union { - int *untagged; - int *tagged; - bool_t *other; + Odr_int *untagged; + Odr_int *tagged; + Odr_bool *other; } u; }; diff --git a/include/yaz/backend.h b/include/yaz/backend.h index aa6a9ea..a7a4874 100644 --- a/include/yaz/backend.h +++ b/include/yaz/backend.h @@ -61,7 +61,7 @@ typedef struct { bend_request request; bend_association association; int *fd; - odr_int_t hits; /* number of hits */ + Odr_int hits; /* number of hits */ int errcode; /* 0==OK */ char *errstring; /* system error string or NULL */ Z_OtherInformation *search_info; /* additional search info */ @@ -114,7 +114,7 @@ typedef struct bend_fetch_rr { /** \brief Information for scan entry */ struct scan_entry { char *term; /* the returned scan term */ - odr_int_t occurrences;/* no of occurrences or -1 if error (see below) */ + Odr_int occurrences;/* no of occurrences or -1 if error (see below) */ int errcode; /* Bib-1 diagnostic code; only used when occur.= -1 */ char *errstring; /* Additional string */ char *display_term; @@ -135,8 +135,8 @@ typedef struct bend_scan_rr { ODR stream; /* encoding stream - memory source if required */ ODR print; /* printing stream */ - odr_int_t *step_size; /* step size */ - odr_int_t term_position; /* desired index of term in result list/returned */ + Odr_int *step_size; /* step size */ + Odr_int term_position; /* desired index of term in result list/returned */ int num_entries; /* number of entries requested/returned */ /* scan term entries. The called handler does not have @@ -178,8 +178,8 @@ typedef struct bend_delete_rr { int num_setnames; char **setnames; Z_ReferenceId *referenceId; - int delete_status; /* status for the whole operation */ - odr_int_t *statuses; /* status each set - indexed as setnames */ + int delete_status; /* status for the whole operation */ + Odr_int *statuses; /* status each set - indexed as setnames */ ODR stream; ODR print; } bend_delete_rr; diff --git a/include/yaz/nmem.h b/include/yaz/nmem.h index 4157e0f..9364323 100644 --- a/include/yaz/nmem.h +++ b/include/yaz/nmem.h @@ -43,6 +43,24 @@ YAZ_BEGIN_CDECL /** \brief NMEM handle (an opaque pointer to memory) */ typedef struct nmem_control *NMEM; +/** \brief Set to 1 if YAZ BER integer is 64-bit ; 0 otherwise */ +#define NMEM_64 0 + +#if NMEM_64 +/** \brief BER/utility integer (64-bit or more) */ +typedef long long int nmem_int_t; +/** \brief printf format for nmem_int_t type */ +#define NMEM_INT_PRINTF "%lld" +#else +/** \brief BER/utility integer (32-bit on most platforms) */ +typedef int nmem_int_t; +/** \brief printf format for nmem_int_t type */ +#define NMEM_INT_PRINTF "%d" +#endif + +/** \brief BER/utility boolean */ +typedef int nmem_bool_t; + /** \brief releases memory associaged with an NMEM handle \param n NMEM handle */ @@ -94,14 +112,19 @@ YAZ_EXPORT void nmem_strsplit(NMEM nmem, const char *delim, YAZ_EXPORT void nmem_strsplit_blank(NMEM nmem, const char *dstr, char ***darray, int *num); -/** \brief allocates integer for NMEM +/** \brief allocates and sets integer for NMEM \param nmem NMEM handle \param v integer value \returns pointer to created integer */ -YAZ_EXPORT int *nmem_intdup(NMEM nmem, int v); +YAZ_EXPORT nmem_int_t *nmem_intdup(NMEM nmem, nmem_int_t v); -YAZ_EXPORT long long int *nmem_longintdup(NMEM nmem, long long int v); +/** \brief allocates and sets boolean for NMEM + \param nmem NMEM handle + \param v value (0=false, != 0 true) + \returns pointer to created boolean +*/ +YAZ_EXPORT nmem_bool_t *nmem_booldup(NMEM nmem, nmem_bool_t v); /** \brief transfers memory from one NMEM handle to another \param src source NMEM handle diff --git a/include/yaz/odr.h b/include/yaz/odr.h index c0dc755..b6abe59 100644 --- a/include/yaz/odr.h +++ b/include/yaz/odr.h @@ -44,10 +44,9 @@ YAZ_BEGIN_CDECL -#define ODR_INT_PRINTF "%lld" - -typedef long long int odr_int_t; -typedef int odr_bool_t; +typedef nmem_int_t Odr_int; +typedef nmem_bool_t Odr_bool; +#define ODR_INT_PRINTF NMEM_INT_PRINTF #ifndef bool_t #define bool_t int @@ -189,8 +188,8 @@ YAZ_EXPORT void *odr_malloc(ODR o, int size); YAZ_EXPORT char *odr_strdup(ODR o, const char *str); YAZ_EXPORT char *odr_strdupn(ODR o, const char *str, size_t n); YAZ_EXPORT char *odr_strdup_null(ODR o, const char *str); -YAZ_EXPORT odr_int_t *odr_intdup(ODR o, odr_int_t v); -YAZ_EXPORT odr_bool_t *odr_booldup(ODR o, odr_bool_t v); +YAZ_EXPORT Odr_int *odr_intdup(ODR o, Odr_int v); +YAZ_EXPORT Odr_bool *odr_booldup(ODR o, Odr_bool v); YAZ_EXPORT Odr_oct *odr_create_Odr_oct(ODR o, const unsigned char *buf, int sz); YAZ_EXPORT NMEM odr_extract_mem(ODR o); @@ -234,16 +233,16 @@ YAZ_EXPORT int ber_tag(ODR o, void *p, int zclass, int tag, YAZ_EXPORT int ber_enctag(ODR o, int zclass, int tag, int constructed); YAZ_EXPORT int ber_dectag(const unsigned char *buf, int *zclass, int *tag, int *constructed, int max); -YAZ_EXPORT int odr_bool(ODR o, int **p, int opt, const char *name); -YAZ_EXPORT int odr_integer(ODR o, odr_int_t **p, int opt, const char *name); -YAZ_EXPORT int odr_enum(ODR o, odr_int_t **p, int opt, const char *name); +YAZ_EXPORT int odr_bool(ODR o, Odr_bool **p, int opt, const char *name); +YAZ_EXPORT int odr_integer(ODR o, Odr_int **p, int opt, const char *name); +YAZ_EXPORT int odr_enum(ODR o, Odr_int **p, int opt, const char *name); YAZ_EXPORT int odr_implicit_settag(ODR o, int zclass, int tag); YAZ_EXPORT int ber_enclen(ODR o, int len, int lenlen, int exact); YAZ_EXPORT int ber_declen(const unsigned char *buf, int *len, int max); YAZ_EXPORT void odr_prname(ODR o, const char *name); YAZ_EXPORT int ber_null(ODR o); YAZ_EXPORT int odr_null(ODR o, Odr_null **p, int opt, const char *name); -YAZ_EXPORT int ber_integer(ODR o, odr_int_t *val); +YAZ_EXPORT int ber_integer(ODR o, Odr_int *val); YAZ_EXPORT int odr_constructed_begin(ODR o, void *p, int zclass, int tag, const char *name); YAZ_EXPORT int odr_constructed_end(ODR o); @@ -304,7 +303,7 @@ YAZ_EXPORT char *odr_prepend(ODR o, const char *prefix, const char *old); typedef struct Odr_external { Odr_oid *direct_reference; /* OPTIONAL */ - odr_int_t *indirect_reference; /* OPTIONAL */ + Odr_int *indirect_reference; /* OPTIONAL */ char *descriptor; /* OPTIONAL */ int which; #define ODR_EXTERNAL_single 0 diff --git a/include/yaz/prt-ext.h b/include/yaz/prt-ext.h index aaa8c2d..e4b2f3f 100644 --- a/include/yaz/prt-ext.h +++ b/include/yaz/prt-ext.h @@ -58,7 +58,7 @@ typedef struct Z_ext_typeent struct Z_External { Odr_oid *direct_reference; - odr_int_t *indirect_reference; + Odr_int *indirect_reference; char *descriptor; int which; /* Generic types */ diff --git a/include/yaz/srw.h b/include/yaz/srw.h index f8caeab..1a07418 100644 --- a/include/yaz/srw.h +++ b/include/yaz/srw.h @@ -54,7 +54,7 @@ typedef struct { #define Z_SRW_recordPacking_URL 2 char *recordData_buf; int recordData_len; - odr_int_t *recordPosition; + Odr_int *recordPosition; } Z_SRW_record; typedef struct { @@ -84,27 +84,27 @@ typedef struct { char *sortKeys; char *xSortKeys; } sort; - odr_int_t *startRecord; - odr_int_t *maximumRecords; + Odr_int *startRecord; + Odr_int *maximumRecords; char *recordSchema; char *recordPacking; char *recordXPath; char *database; char *stylesheet; - odr_int_t *resultSetTTL; + Odr_int *resultSetTTL; } Z_SRW_searchRetrieveRequest; typedef struct { - odr_int_t *numberOfRecords; + Odr_int *numberOfRecords; char * resultSetId; - odr_int_t *resultSetIdleTime; + Odr_int *resultSetIdleTime; Z_SRW_record *records; int num_records; Z_SRW_diagnostic *diagnostics; int num_diagnostics; - odr_int_t *nextRecordPosition; + Odr_int *nextRecordPosition; Z_SRW_extra_record **extra_records; /* of size num_records */ } Z_SRW_searchRetrieveResponse; @@ -129,15 +129,15 @@ typedef struct { char *xcql; char *pqf; } scanClause; - odr_int_t *responsePosition; - odr_int_t *maximumTerms; + Odr_int *responsePosition; + Odr_int *maximumTerms; char *stylesheet; char *database; } Z_SRW_scanRequest; typedef struct { char *value; - odr_int_t *numberOfRecords; + Odr_int *numberOfRecords; char *displayTerm; char *whereInList; } Z_SRW_scanTerm; @@ -238,7 +238,7 @@ YAZ_EXPORT int yaz_srw_str_to_pack(const char *str); YAZ_EXPORT char *yaz_uri_val(const char *path, const char *name, ODR o); YAZ_EXPORT void yaz_uri_val_int(const char *path, const char *name, - ODR o, odr_int_t **intp); + ODR o, Odr_int **intp); YAZ_EXPORT int yaz_srw_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, Z_SOAP **soap_package, ODR decode, char **charset); YAZ_EXPORT int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, diff --git a/src/ber_int.c b/src/ber_int.c index a134ae2..ef185aa 100644 --- a/src/ber_int.c +++ b/src/ber_int.c @@ -30,10 +30,10 @@ #include "odr-priv.h" -static int ber_encinteger(ODR o, odr_int_t val); -static int ber_decinteger(const unsigned char *buf, odr_int_t *val, int max); +static int ber_encinteger(ODR o, Odr_int val); +static int ber_decinteger(const unsigned char *buf, Odr_int *val, int max); -int ber_integer(ODR o, odr_int_t *val) +int ber_integer(ODR o, Odr_int *val) { int res; @@ -61,7 +61,7 @@ int ber_integer(ODR o, odr_int_t *val) /* * Returns: number of bytes written or -1 for error (out of bounds). */ -int ber_encinteger(ODR o, odr_int_t val) +int ber_encinteger(ODR o, Odr_int val) { int a, len; union { int i; unsigned char c[sizeof(int)]; } tmp; @@ -82,7 +82,7 @@ int ber_encinteger(ODR o, odr_int_t val) /* * Returns: Number of bytes read or 0 if no match, -1 if error. */ -int ber_decinteger(const unsigned char *buf, odr_int_t *val, int max) +int ber_decinteger(const unsigned char *buf, Odr_int *val, int max) { const unsigned char *b = buf; unsigned char fill; diff --git a/src/cqltransform.c b/src/cqltransform.c index 3846685..4036f60 100644 --- a/src/cqltransform.c +++ b/src/cqltransform.c @@ -106,7 +106,7 @@ static int cql_transform_parse_tok_line(cql_transform_t ct, wrbuf_puts(type_str, yaz_tok_parse_string(tp)); t = yaz_tok_move(tp); } - elem->attributeType = nmem_longintdup(ct->nmem, 0); + elem->attributeType = nmem_intdup(ct->nmem, 0); if (sscanf(wrbuf_cstr(type_str), ODR_INT_PRINTF, elem->attributeType) != 1) { @@ -140,7 +140,7 @@ static int cql_transform_parse_tok_line(cql_transform_t ct, { elem->which = Z_AttributeValue_numeric; elem->value.numeric = - nmem_longintdup(ct->nmem, atoi(value_str)); + nmem_intdup(ct->nmem, atoi(value_str)); } else { diff --git a/src/ill-get.c b/src/ill-get.c index a1e31c8..a0efcfa 100644 --- a/src/ill-get.c +++ b/src/ill-get.c @@ -35,8 +35,8 @@ bool_t *ill_get_bool (struct ill_get_ctl *gc, const char *name, return r; } -odr_int_t *ill_get_int(struct ill_get_ctl *gc, const char *name, - const char *sub, odr_int_t val) +Odr_int *ill_get_int(struct ill_get_ctl *gc, const char *name, + const char *sub, Odr_int val) { ODR o = gc->odr; char element[128]; @@ -54,8 +54,8 @@ odr_int_t *ill_get_int(struct ill_get_ctl *gc, const char *name, return odr_intdup(o, val); } -odr_int_t *ill_get_enumerated (struct ill_get_ctl *gc, const char *name, - const char *sub, odr_int_t val) +Odr_int *ill_get_enumerated (struct ill_get_ctl *gc, const char *name, + const char *sub, Odr_int val) { return ill_get_int(gc, name, sub, val); } diff --git a/src/nmemsdup.c b/src/nmemsdup.c index 36dc823..1f9d415 100644 --- a/src/nmemsdup.c +++ b/src/nmemsdup.c @@ -38,16 +38,16 @@ char *nmem_strdupn (NMEM mem, const char *src, size_t n) return dst; } -long long int *nmem_longintdup(NMEM mem, long long int v) +nmem_int_t *nmem_intdup(NMEM mem, nmem_int_t v) { - long long int *dst = (long long int*) nmem_malloc (mem, sizeof(*dst)); + nmem_int_t *dst = (nmem_int_t*) nmem_malloc (mem, sizeof(*dst)); *dst = v; return dst; } -int *nmem_intdup(NMEM mem, int v) +nmem_bool_t *nmem_booldup(NMEM mem, nmem_bool_t v) { - int *dst = (int*) nmem_malloc (mem, sizeof(*dst)); + nmem_bool_t *dst = (nmem_bool_t*) nmem_malloc (mem, sizeof(*dst)); *dst = v; return dst; } diff --git a/src/odr_bool.c b/src/odr_bool.c index 114799f..0434183 100644 --- a/src/odr_bool.c +++ b/src/odr_bool.c @@ -18,7 +18,7 @@ * Top level boolean en/decoder. * Returns 1 on success, 0 on error. */ -int odr_bool(ODR o, int **p, int opt, const char *name) +int odr_bool(ODR o, Odr_int **p, int opt, const char *name) { int res, cons = 0; diff --git a/src/odr_enum.c b/src/odr_enum.c index 88b39de..d658ca8 100644 --- a/src/odr_enum.c +++ b/src/odr_enum.c @@ -16,7 +16,7 @@ * Top level enum en/decoder. * Returns 1 on success, 0 on error. */ -int odr_enum(ODR o, odr_int_t **p, int opt, const char *name) +int odr_enum(ODR o, Odr_int **p, int opt, const char *name) { int res, cons = 0; @@ -44,7 +44,7 @@ int odr_enum(ODR o, odr_int_t **p, int opt, const char *name) return 0; } if (o->direction == ODR_DECODE) - *p = (odr_int_t *)odr_malloc(o, sizeof(**p)); + *p = (Odr_int *)odr_malloc(o, sizeof(**p)); return ber_integer(o, *p); } /* diff --git a/src/odr_int.c b/src/odr_int.c index 27cc35d..606f59b 100644 --- a/src/odr_int.c +++ b/src/odr_int.c @@ -16,7 +16,7 @@ * Top level integer en/decoder. * Returns 1 on success, 0 on error. */ -int odr_integer(ODR o, odr_int_t **p, int opt, const char *name) +int odr_integer(ODR o, Odr_int **p, int opt, const char *name) { int res, cons = 0; @@ -44,7 +44,7 @@ int odr_integer(ODR o, odr_int_t **p, int opt, const char *name) return 0; } if (o->direction == ODR_DECODE) - *p = (odr_int_t *)odr_malloc(o, sizeof(**p)); + *p = (Odr_int *)odr_malloc(o, sizeof(**p)); return ber_integer(o, *p); } /* diff --git a/src/odr_mem.c b/src/odr_mem.c index 3f2b02b..028d06d 100644 --- a/src/odr_mem.c +++ b/src/odr_mem.c @@ -47,14 +47,14 @@ char *odr_strdupn(ODR o, const char *str, size_t n) return nmem_strdupn(o->mem, str, n); } -odr_int_t *odr_intdup(ODR o, odr_int_t v) +Odr_int *odr_intdup(ODR o, Odr_int v) { - return nmem_longintdup(o->mem, v); + return nmem_intdup(o->mem, v); } -odr_bool_t *odr_booldup(ODR o, odr_bool_t v) +Odr_bool *odr_booldup(ODR o, Odr_bool v) { - return nmem_intdup(o->mem, v); + return nmem_booldup(o->mem, v); } int odr_total(ODR o) diff --git a/src/pquery.c b/src/pquery.c index c25a795..9a150a4 100644 --- a/src/pquery.c +++ b/src/pquery.c @@ -31,7 +31,7 @@ struct yaz_pqf_parser { static Z_RPNStructure *rpn_structure(struct yaz_pqf_parser *li, ODR o, int num_attr, int max_attr, - odr_int_t *attr_list, char **attr_clist, + Odr_int *attr_list, char **attr_clist, Odr_oid **attr_set); static Odr_oid *query_oid_getvalbyname(struct yaz_pqf_parser *li, ODR o) @@ -183,7 +183,7 @@ static int escape_string(char *out_buf, const char *in, int len) } static int p_query_parse_attr(struct yaz_pqf_parser *li, ODR o, - int num_attr, odr_int_t *attr_list, + int num_attr, Odr_int *attr_list, char **attr_clist, Odr_oid **attr_set) { const char *cp; @@ -239,7 +239,7 @@ static int p_query_parse_attr(struct yaz_pqf_parser *li, ODR o, } static Z_AttributesPlusTerm *rpn_term(struct yaz_pqf_parser *li, ODR o, - int num_attr, odr_int_t *attr_list, + int num_attr, Odr_int *attr_list, char **attr_clist, Odr_oid **attr_set) { Z_AttributesPlusTerm *zapt; @@ -256,12 +256,12 @@ static Z_AttributesPlusTerm *rpn_term(struct yaz_pqf_parser *li, ODR o, else { int i, k = 0; - odr_int_t *attr_tmp; + Odr_int *attr_tmp; elements = (Z_AttributeElement**) odr_malloc (o, num_attr * sizeof(*elements)); - attr_tmp = (odr_int_t *)odr_malloc(o, num_attr * 2 * sizeof(*attr_tmp)); + attr_tmp = (Odr_int *)odr_malloc(o, num_attr * 2 * sizeof(*attr_tmp)); memcpy(attr_tmp, attr_list, num_attr * 2 * sizeof(*attr_tmp)); for (i = num_attr; --i >= 0; ) { @@ -348,7 +348,7 @@ static Z_AttributesPlusTerm *rpn_term(struct yaz_pqf_parser *li, ODR o, } static Z_Operand *rpn_simple(struct yaz_pqf_parser *li, ODR o, - int num_attr, odr_int_t *attr_list, + int num_attr, Odr_int *attr_list, char **attr_clist, Odr_oid **attr_set) { @@ -484,7 +484,7 @@ static Z_ProximityOperator *rpn_proximity (struct yaz_pqf_parser *li, ODR o) static Z_Complex *rpn_complex(struct yaz_pqf_parser *li, ODR o, int num_attr, int max_attr, - odr_int_t *attr_list, char **attr_clist, + Odr_int *attr_list, char **attr_clist, Odr_oid **attr_set) { Z_Complex *zc; @@ -560,7 +560,7 @@ static void rpn_term_type(struct yaz_pqf_parser *li, ODR o) static Z_RPNStructure *rpn_structure(struct yaz_pqf_parser *li, ODR o, int num_attr, int max_attr, - odr_int_t *attr_list, + Odr_int *attr_list, char **attr_clist, Odr_oid **attr_set) { @@ -623,7 +623,7 @@ static Z_RPNStructure *rpn_structure(struct yaz_pqf_parser *li, ODR o, Z_RPNQuery *p_query_rpn_mk(ODR o, struct yaz_pqf_parser *li, const char *qbuf) { Z_RPNQuery *zq; - odr_int_t attr_array[1024]; + Odr_int attr_array[1024]; char *attr_clist[512]; Odr_oid *attr_set[512]; Odr_oid *top_set = 0; @@ -685,7 +685,7 @@ Z_AttributesPlusTerm *p_query_scan_mk(struct yaz_pqf_parser *li, Odr_oid **attributeSetP, const char *qbuf) { - odr_int_t attr_list[1024]; + Odr_int attr_list[1024]; char *attr_clist[512]; Odr_oid *attr_set[512]; int num_attr = 0; diff --git a/src/seshigh.c b/src/seshigh.c index aebcdc0..19c771d 100644 --- a/src/seshigh.c +++ b/src/seshigh.c @@ -2458,9 +2458,9 @@ static Z_NamePlusRecord *surrogatediagrec(association *assoc, return zget_surrogateDiagRec(assoc->encode, dbname, error, addinfo); } -static Z_Records *pack_records(association *a, char *setname, odr_int_t start, - odr_int_t *num, Z_RecordComposition *comp, - odr_int_t *next, odr_int_t *pres, +static Z_Records *pack_records(association *a, char *setname, Odr_int start, + Odr_int *num, Z_RecordComposition *comp, + Odr_int *next, Odr_int *pres, Z_ReferenceId *referenceId, Odr_oid *oid, int *errcode) { @@ -2704,9 +2704,9 @@ static Z_APDU *response_searchRequest(association *assoc, request *reqb, Z_APDU *apdu = (Z_APDU *)odr_malloc(assoc->encode, sizeof(*apdu)); Z_SearchResponse *resp = (Z_SearchResponse *) odr_malloc(assoc->encode, sizeof(*resp)); - odr_int_t *nulint = odr_intdup(assoc->encode, 0); - odr_int_t *next = odr_intdup(assoc->encode, 0); - odr_int_t *none = odr_intdup(assoc->encode, Z_SearchResponse_none); + Odr_int *nulint = odr_intdup(assoc->encode, 0); + Odr_int *next = odr_intdup(assoc->encode, 0); + Odr_int *none = odr_intdup(assoc->encode, Z_SearchResponse_none); int returnedrecs = 0; apdu->which = Z_APDU_searchResponse; @@ -2733,7 +2733,7 @@ static Z_APDU *response_searchRequest(association *assoc, request *reqb, else { bool_t *sr = odr_booldup(assoc->encode, 1); - odr_int_t *toget = odr_intdup(assoc->encode, 0); + Odr_int *toget = odr_intdup(assoc->encode, 0); Z_RecordComposition comp, *compp = 0; yaz_log(log_requestdetail, "resultCount: " ODR_INT_PRINTF, bsrt->hits); @@ -2762,7 +2762,7 @@ static Z_APDU *response_searchRequest(association *assoc, request *reqb, if (*toget && !resp->records) { - odr_int_t *presst = odr_intdup(assoc->encode, 0); + Odr_int *presst = odr_intdup(assoc->encode, 0); /* Call bend_present if defined */ if (assoc->init->bend_present) { @@ -2872,8 +2872,8 @@ static Z_APDU *process_presentRequest(association *assoc, request *reqb, Z_PresentRequest *req = reqb->apdu_request->u.presentRequest; Z_APDU *apdu; Z_PresentResponse *resp; - odr_int_t *next; - odr_int_t *num; + Odr_int *next; + Odr_int *num; int errcode = 0; const char *errstring = 0; @@ -2966,8 +2966,8 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd) Z_APDU *apdu = (Z_APDU *)odr_malloc(assoc->encode, sizeof(*apdu)); Z_ScanResponse *res = (Z_ScanResponse *) odr_malloc(assoc->encode, sizeof(*res)); - odr_int_t *scanStatus = odr_intdup(assoc->encode, Z_Scan_failure); - odr_int_t *numberOfEntriesReturned = odr_intdup(assoc->encode, 0); + Odr_int *scanStatus = odr_intdup(assoc->encode, Z_Scan_failure); + Odr_int *numberOfEntriesReturned = odr_intdup(assoc->encode, 0); Z_ListEntries *ents = (Z_ListEntries *) odr_malloc(assoc->encode, sizeof(*ents)); Z_DiagRecs *diagrecs_p = NULL; @@ -3268,7 +3268,7 @@ static Z_APDU *process_deleteRequest(association *assoc, request *reqb, bdrr->statuses = 0; if (bdrr->num_setnames > 0) { - bdrr->statuses = (odr_int_t*) + bdrr->statuses = (Odr_int*) odr_malloc(assoc->encode, sizeof(*bdrr->statuses) * bdrr->num_setnames); for (i = 0; i < bdrr->num_setnames; i++) diff --git a/src/session.h b/src/session.h index 13e06db..f7c81ce 100644 --- a/src/session.h +++ b/src/session.h @@ -122,8 +122,8 @@ typedef struct association association_state state; /* session parameters */ - odr_int_t preferredMessageSize; - odr_int_t maximumRecordSize; + Odr_int preferredMessageSize; + Odr_int maximumRecordSize; int version; /* highest version-bit set (2 or 3) */ unsigned cs_get_mask; diff --git a/src/srw.c b/src/srw.c index a8a9f3e..869f4d5 100644 --- a/src/srw.c +++ b/src/srw.c @@ -61,7 +61,7 @@ xmlNodePtr add_xsd_string(xmlNodePtr ptr, const char *elem, const char *val) } static void add_xsd_integer(xmlNodePtr ptr, const char *elem, - const odr_int_t *val) + const Odr_int *val) { if (val) { @@ -166,7 +166,7 @@ static int match_xsd_XML_n(xmlNodePtr ptr, const char *elem, ODR o, } static int match_xsd_integer(xmlNodePtr ptr, const char *elem, ODR o, - odr_int_t **val) + Odr_int **val) { #if CHECK_TYPE struct _xmlAttr *attr; diff --git a/src/srwutil.c b/src/srwutil.c index 99e417c..6284831 100644 --- a/src/srwutil.c +++ b/src/srwutil.c @@ -279,7 +279,7 @@ static void yaz_srw_decodeauth(Z_SRW_PDU *sr, Z_HTTP_Request *hreq, } #endif -void yaz_uri_val_int(const char *path, const char *name, ODR o, odr_int_t **intp) +void yaz_uri_val_int(const char *path, const char *name, ODR o, Odr_int **intp) { const char *v = yaz_uri_val(path, name, o); if (v) @@ -463,7 +463,7 @@ int yaz_srw_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, #if YAZ_HAVE_XML2 static int yaz_sru_decode_integer(ODR odr, const char *pname, - const char *valstr, odr_int_t **valp, + const char *valstr, Odr_int **valp, Z_SRW_diagnostic **diag, int *num_diag, int min_value) { @@ -1197,7 +1197,7 @@ int yaz_diag_srw_to_bib1(int code) } static void add_val_int(ODR o, char **name, char **value, int *i, - char *a_name, odr_int_t *val) + char *a_name, Odr_int *val) { if (val) { diff --git a/src/xmlquery.c b/src/xmlquery.c index 21849c6..cb433ad 100644 --- a/src/xmlquery.c +++ b/src/xmlquery.c @@ -313,7 +313,7 @@ bool_t *boolVal(ODR odr, const char *str) return odr_booldup(odr, 1); } -odr_int_t *intVal(ODR odr, const char *str) +Odr_int *intVal(ODR odr, const char *str) { return odr_intdup(odr, atoi(str)); } diff --git a/test/tstodr.c b/test/tstodr.c index 4c2ae05..f2b8b3a 100644 --- a/test/tstodr.c +++ b/test/tstodr.c @@ -136,6 +136,44 @@ static void tst(void) odr_destroy(odr_decode); } +/* example from documentation.. 'Using Odr' */ +void do_nothing_useful(int value) +{ + ODR encode, decode; + Odr_int *valp, *resvalp; + char *bufferp; + int len; + + /* allocate streams */ + if (!(encode = odr_createmem(ODR_ENCODE))) + return; + if (!(decode = odr_createmem(ODR_DECODE))) + return; + + valp = &value; + if (odr_integer(encode, &valp, 0, 0) == 0) + { + printf("encoding went bad\n"); + return; + } + bufferp = odr_getbuf(encode, &len, 0); + printf("length of encoded data is %d\n", len); + + /* now let's decode the thing again */ + odr_setbuf(decode, bufferp, len, 0); + if (odr_integer(decode, &resvalp, 0, 0) == 0) + { + printf("decoding went bad\n"); + return; + } + /* ODR_INT_PRINTF format for printf (such as %d) */ + printf("the value is " ODR_INT_PRINTF "\n", *resvalp); + + /* clean up */ + odr_destroy(encode); + odr_destroy(decode); +} + int main(int argc, char **argv) { YAZ_CHECK_INIT(argc, argv); diff --git a/util/yaz-asncomp b/util/yaz-asncomp index bd757fb..fb454a6 100755 --- a/util/yaz-asncomp +++ b/util/yaz-asncomp @@ -1217,11 +1217,11 @@ proc asnBasicEXTERNAL {} { } proc asnBasicINTEGER {} { - return {odr_integer {odr_int_t}} + return {odr_integer {Odr_int}} } proc asnBasicENUMERATED {} { - return {odr_enum {odr_int_t}} + return {odr_enum {Odr_int}} } proc asnBasicNULL {} { @@ -1229,7 +1229,7 @@ proc asnBasicNULL {} { } proc asnBasicBOOLEAN {} { - return {odr_bool {bool_t}} + return {odr_bool {Odr_bool}} } proc asnBasicOCTET {} {