ARSperl

 view release on metacpan or  search on metacpan

supportrev.c  view on Meta::CPAN

	}
	if (SvTYPE((SV *) h) == SVt_PVHV) {
		if (hv_exists(h,  k, strlen(k) )) {
			val = hv_fetch(h,  k, strlen(k) , 0);
			if (val && *val) {

				/* hash value should be an hash reference */

				if (SvTYPE(SvRV(*val)) == SVt_PVHV) {
					if (rev_ARDisplayStruct(ctrl, (HV *) SvRV(*val), d) != 0)
						return -1;
					return 0;
				} else
					ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
						    "rev_ARDisplayStruct_helper: hash value is not an array reference");
			} else {
				ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
					    "rev_ARDisplayStruct_helper: hv_fetch returned null");
				return -2;
			}
		} else {
			ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
			   "rev_ARDisplayStruct_helper: key doesn't exist");
			return -2;
		}
	} else
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
		"rev_ARDisplayStruct_helper: first argument is not a hash");
	return -1;
}

/* ROUTINE
 *   rev_ARDisplayStruct(hv, displayStruct)
 *
 * DESCRIPTION
 *   given a hash that contains displaystruct keys
 *   and an empty (preallocated) displaystruct, fill
 *   in the display struct.
 */

int
rev_ARDisplayStruct(ARControlStruct * ctrl, HV * h, ARDisplayStruct * d)
{
	int             rv = 0, rv2 = 0;
	char            buf[1024];

	rv += strcpyHVal(h, "displayTag", d->displayTag, AR_MAX_NAME_SIZE);
	rv += strcpyHVal(h, "label", d->label, AR_MAX_NAME_SIZE);
	rv += intcpyHVal(h, "x", &(d->x));
	rv += intcpyHVal(h, "y", &(d->y));
	rv += uintcpyHVal(h, "length", &(d->length));
	rv += uintcpyHVal(h, "numRows", &(d->numRows));

	/* variables that need some decoding before we store them */

	/*
	 * "option" will be either "VISIBLE" or "HIDDEN" default: Visible
	 */

	if ((rv2 = strcpyHVal(h, "option", buf, sizeof(buf)-1)) == 0) {
		if (strncasecmp(buf, "HIDDEN", sizeof(buf)) == 0)
			d->option = AR_DISPLAY_OPT_HIDDEN;
		else
			d->option = AR_DISPLAY_OPT_VISIBLE;
	} else
		rv += rv2;

	/*
	 * "labelLocation" will be either "Left" or "Top" default: Left
	 */

	if ((rv2 = strcpyHVal(h, "labelLocation", buf, sizeof(buf)-1)) == 0) {
		if (strncasecmp(buf, "Top", sizeof(buf)) == 0)
			d->labelLocation = AR_DISPLAY_LABEL_TOP;
		else
			d->labelLocation = AR_DISPLAY_LABEL_LEFT;
	} else
		rv += rv2;

	/*
	 * "type" will be one of: NONE, TEXT, NUMTEXT, CHECKBOX, CHOICE,
	 * BUTTON default: NONE
	 */

	if ((rv2 = strcpyHVal(h, "type", buf, sizeof(buf)-1)) == 0) {
		if (strncasecmp(buf, "TEXT", sizeof(buf)) == 0)
			d->type = AR_DISPLAY_TYPE_TEXT;
		else if (strncasecmp(buf, "NUMTEXT", sizeof(buf)) == 0)
			d->type = AR_DISPLAY_TYPE_NUMTEXT;
		else if (strncasecmp(buf, "CHECKBOX", sizeof(buf)) == 0)
			d->type = AR_DISPLAY_TYPE_CHECKBOX;
		else if (strncasecmp(buf, "CHOICE", sizeof(buf)) == 0)
			d->type = AR_DISPLAY_TYPE_CHOICE;
		else if (strncasecmp(buf, "BUTTON", sizeof(buf)) == 0)
			d->type = AR_DISPLAY_TYPE_BUTTON;
		else
			d->type = AR_DISPLAY_TYPE_NONE;
	} else
		rv += rv2;

	return rv;
}

/* ROUTINE
 *   rev_ARInternalIdList(hv, key, idliststruct)
 *
 * DESCRIPTION
 *   given a hash, a key and an empty idliststruct,
 *   pull out the hash value and populate the structure.
 *
 * RETURNS
 *   0 on success
 *  -1 on failure
 *  -2 on warning
 */

int
rev_ARInternalIdList(ARControlStruct * ctrl, HV * h, char *k, ARInternalIdList * il)
{

	if (!il || !h || !k) {
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
			    "rev_ARInternalIdList: required param is NULL");
		return -1;
	}
	if (SvTYPE((SV *) h) == SVt_PVHV) {
		if (hv_exists(h,  k, strlen(k) )) {
			SV            **val = hv_fetch(h,  k, strlen(k) , 0);
			if (val && *val) {

				/* hash value should be an array reference */

				if (SvTYPE(SvRV(*val)) == SVt_PVAV) {
					AV             *ar = (AV *) SvRV((SV *) * val);
					int             i;

					/*
					 * allocate space for display
					 * structure list
					 */

					il->numItems = av_len(ar) + 1;
					if (il->numItems == 0)
						return 0;	/* nothing to do */
					il->internalIdList = MALLOCNN(sizeof(ARInternalId) * il->numItems);

					/*
					 * iterate over the array, grabbing
					 * each integer out of it and placing
					 * into the idlist.
					 */

					for (i = 0; i <= av_len(ar); i++) {
						SV            **aval = av_fetch(ar, i, 0);

supportrev.c  view on Meta::CPAN

			break;
		case AR_DATA_TYPE_CONTROL:
			return -1;	/* FIX: implement */
			break;
		case AR_DATA_TYPE_COORDS:
			m->u.coordListVal = (ARCoordList *) MALLOCNN(sizeof(ARCoordList));
			if (rev_ARCoordList(ctrl, h, k, m->u.coordListVal) == -1)
				return -1;
			break;
		case AR_DATA_TYPE_ULONG:
			m->u.ulongVal = (unsigned long) SvIV(*val);
			break;
#endif
#if AR_EXPORT_VERSION >= 4
		case AR_DATA_TYPE_DECIMAL:
			if (strmakHVal(h, k, &(m->u.decimalVal)) == -1)
				return -1;
			break;
#endif
#if AR_EXPORT_VERSION >= 7
		case AR_DATA_TYPE_DATE:
			m->u.dateVal = SvIV(*val);
			break;
		case AR_DATA_TYPE_TIME_OF_DAY:
			m->u.timeOfDayVal = (ARTime) SvIV(*val);
			break;
		case AR_DATA_TYPE_CURRENCY:
			m->u.currencyVal = (ARCurrencyStruct*) MALLOCNN(sizeof(ARCurrencyStruct));
			if( sv_to_ARCurrencyStruct(ctrl,*val,m->u.currencyVal) == -1 )
				return -1;
			break;
		case AR_DATA_TYPE_VIEW:
		case AR_DATA_TYPE_DISPLAY:
			if (strmakHVal(h, k, &(m->u.charVal)) == -1)
				return -1;
			break;
#endif
		default:
			ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
				    "rev_ARValueStruct: unknown data type:");
			ARError_add(AR_RETURN_WARNING, AP_ERR_CONTINUE,
				    tp);
			return -2;
		}
		return 0;
	}
	ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
		 "rev_ARValueStruct: hash value(s) were invalid for keys:");
	ARError_add(AR_RETURN_WARNING, AP_ERR_CONTINUE, k);
	ARError_add(AR_RETURN_WARNING, AP_ERR_CONTINUE, t);
	return -2;
}

static int
rev_ARValueStructStr2Type(ARControlStruct * ctrl, char *type, unsigned int *n)
{
	int             i = 0;

	if (type && *type) {
		for (i = 0; DataTypeMap[i].number != TYPEMAP_LAST; i++)
			if (strcasecmp(type,  DataTypeMap[i].name) == 0)
				break;
		if (DataTypeMap[i].number != TYPEMAP_LAST) {
			*n = DataTypeMap[i].number;
			return 0;
		}
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
		       "rev_ARValueStructStr2Type: type given is unknown:");
		ARError_add(AR_RETURN_ERROR, AP_ERR_CONTINUE,
			    type);
	} else
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
			    "rev_ARValueStructStr2Type: type param is NULL");
	return -1;
}

static int
rev_ARValueStructKW2KN(ARControlStruct * ctrl, char *keyword, unsigned int *n)
{
	int             i;

	if (keyword && (*keyword == '\0')) {
		for (i = 0; KeyWordMap[i].number != TYPEMAP_LAST; i++) {
			if (compmem(keyword, KeyWordMap[i].name, KeyWordMap[i].len) == 0)
				break;
		}
		if (KeyWordMap[i].number != TYPEMAP_LAST) {
			*n = KeyWordMap[i].number;
			return 0;
		}
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
		       "rev_ARValueStructKW2KN: keyword given is unknown:");
		ARError_add(AR_RETURN_ERROR, AP_ERR_CONTINUE,
			    keyword);
	} else
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
			    "rev_ARValueStructKW2KN: keyword param is NULL");

	return -1;
}

static int
rev_ARValueStructDiary(ARControlStruct * ctrl, HV * h, char *k, char **d)
{
	if (!h || !k || !d) {
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
			"rev_ARValueStructDiary: invalid (NULL) parameter");
		return -1;
	}
	if (hv_exists(h,  k, strlen(k) )) {
		SV            **hr = hv_fetch(h,  k, strlen(k) , 0);
		if (hr && *hr && SvROK(*hr) && (SvTYPE(*hr) == SVt_PVHV)) {
			HV             *h2 = (HV *) SvRV(*hr);
			char           *user = (char *) NULL, *value = (char *) NULL;
			ARTimestamp     timestamp = 0;
			int             rv = 0;

			/* fetch the keys: timestamp, user and value */

			rv += strmakHVal(h2, "user", &user);
			rv += strmakHVal(h2, "value", &value);

supportrev.c  view on Meta::CPAN

		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
			    "rev_ARByteList: invalid (NULL) parameter");
		return -1;
	}
	if (hv_exists(h,  k, strlen(k) )) {
		SV            **hr = hv_fetch(h,  k, strlen(k) , 0);
		if (hr && *hr && SvROK(*hr) && (SvTYPE(SvRV(*hr)) == SVt_PVHV)) {
			HV             *h2 = (HV *) SvRV(*hr);

			if ( hv_exists(h2, "type", strlen("type")) && hv_exists(h2, "value", strlen("value")) ) {
				SV            **tv = hv_fetch(h2,  "type", strlen("type") , 0);
				SV            **vv = hv_fetch(h2,  "value", strlen("value") , 0);

				/* we are expecting two PV's */

				if (SvPOK(*tv) && SvPOK(*vv)) {
					char           *typeString = SvPV(*tv, PL_na);	/* SvPV is a macro */
					char           *byteString = SvPV(*vv, PL_na);
					int             byteLen = SvCUR(*vv);

					if (rev_ARByteListStr2Type(ctrl, typeString, &(b->type)) == -1)
						return -1;
					b->numItems = byteLen;
					b->bytes = MALLOCNN(byteLen + 1);	/* don't want FreeAR..
										 * to whack us */
					copymem(b->bytes, byteString, byteLen);
					return 0;
				}
			} else {
				ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
					    "rev_ARByteList: required keys (type and value) not found in inner hash.");
			}
		} else {
			ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
				    "rev_ARByteList: hash value is not hash ref for key:");
			ARError_add(AR_RETURN_ERROR, AP_ERR_CONTINUE,
				    k ? k : "[key null]");
			printf( "SvTYPE = %d\n", SvTYPE(*hr) );
		}
	} else {
		ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
			    "rev_ARByteList: hash key doesn't exist:");
		ARError_add(AR_RETURN_WARNING, AP_ERR_CONTINUE,
			    k ? k : "[key null]");
		return -2;
	}
	return -1;
}

static int
#if AR_CURRENT_API_VERSION >= 14
rev_ARByteListStr2Type(ARControlStruct * ctrl, char *ts, ARULong32 *tv)
#else
rev_ARByteListStr2Type(ARControlStruct * ctrl, char *ts, unsigned long *tv)
#endif
{
	int             i = 0;

	if (ts && *ts && tv) {
		for (i = 0; ByteListTypeMap[i].number != TYPEMAP_LAST; i++)
			if (strncasecmp(ts,  ByteListTypeMap[i].name, strlen(ByteListTypeMap[i].name) ) == 0)
				break;
		if (ByteListTypeMap[i].number != TYPEMAP_LAST) {
			*tv = ByteListTypeMap[i].number;
			return 0;
		}
	}
	return -1;
}

int
rev_ARCoordList(ARControlStruct * ctrl, HV * h, char *k, ARCoordList * m)
{
	SV            **val;
	int             i;

	if (!m) {
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
			  "rev_ARCoordList: FieldAssignList param is NULL");
		return -1;
	}
	if (SvTYPE((SV *) h) == SVt_PVHV) {
		if (hv_exists(h,  k, strlen(k) )) {
			val = hv_fetch(h,  k, strlen(k) , 0);
			if (val && *val) {

				/* hash value should be an array reference */

				if (SvTYPE(SvRV(*val)) == SVt_PVAV) {
					AV             *ar = (AV *) SvRV((SV *) * val);

					/*
					 * allocate space for field assign
					 * structure list
					 */

					m->numItems = av_len(ar) + 1;
					if (m->numItems == 0)
						return 0;	/* nothing to do */
					m->coords = MALLOCNN(sizeof(ARCoordStruct) * m->numItems);

					/*
					 * iterate over the array, grabbing
					 * each hash reference out of it and
					 * passing that to a helper routine
					 * to fill in the Coord structure.
					 */

					for (i = 0; i <= av_len(ar); i++) {
						SV            **av_hv = av_fetch(ar, i, 0);

						if (av_hv && *av_hv && (SvTYPE(SvRV(*av_hv)) == SVt_PVHV)) {
							if (rev_ARCoordList_helper(ctrl, (HV *) SvRV(*av_hv), m, i) != 0)
								return -1;
						} else
							ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
								    "rev_ARCoordList: inner array value is not a hash reference");
					}
					return 0;
				} else
					ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,

supportrev.c  view on Meta::CPAN

		if (rev_ARCurrencyPartStruct(ctrl, h, "currencyField", m->u.currencyField) != 0)
			return -1;
#endif
	}else{
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
				"rev_ARAssignFieldStruct_helper: invalid assign type");
		return -1;
	}

#if AR_EXPORT_VERSION >= 3
	svp = hv_fetch(h,  "noMatchOption", strlen("noMatchOption") , 0);
	if (svp && *svp) {
		char           *c = SvPV(*svp, PL_na);
		if (rev_ARAssignFieldStructStr2NMO(ctrl, c, &(m->noMatchOption)) != 0)
			m->noMatchOption = AR_NO_MATCH_ERROR;
	}
	svp = hv_fetch(h,  "multiMatchOption", strlen("multiMatchOption") , 0);
	if (svp && *svp) {
		char           *c = SvPV(*svp, PL_na);
		if (rev_ARAssignFieldStructStr2MMO(ctrl, c, &(m->multiMatchOption)) != 0)
			m->multiMatchOption = AR_MULTI_MATCH_ERROR;
	}
#endif

	/*
	 * extract and duplicate the qualifier struct. if we don't duplicate
	 * it and simply reference it, FreeARyaddayadda() will free what the
	 * reference points to and this could lead to badness if the user
	 * tries to access the qual struct later on.
	 */

	qpsv = hv_fetch(h,  "qualifier", strlen("qualifier") , 0);
	if (qpsv && *qpsv && SvROK(*qpsv)) {
		if (sv_derived_from(*qpsv, "ARQualifierStructPtr")) {
			qp = (ARQualifierStruct *) SvIV((SV *) SvRV(*qpsv));

			if (dup_qualifier2(ctrl, qp, &(m->qualifier), 0) != (ARQualifierStruct *) NULL) {
				return 0;
			}else{
				ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
					    "rev_ARAssignFieldStruct_helper: dup_qualifier2() failed");
				return -1;
			}
		} else
			ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
				    "rev_ARAssignFieldStruct_helper: qualifier key of type ARQualifierStructPtr");

	} else
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
			    "rev_ARAssignFieldStruct_helper: qualifier key is not a reference");

	return -1;
}

static int
rev_ARAssignFieldStructStr2NMO(ARControlStruct * ctrl, char *s, unsigned int *nmo)
{
	if (s && *s) {
		int             i;
		for (i = 0; NoMatchOptionMap[i].number != TYPEMAP_LAST; i++)
			if (strcasecmp(NoMatchOptionMap[i].name, s) == 0)
				break;
		if (NoMatchOptionMap[i].number != TYPEMAP_LAST) {
			*nmo = NoMatchOptionMap[i].number;
			return 0;
		}
	}
	return -1;
}

static int
rev_ARAssignFieldStructStr2MMO(ARControlStruct * ctrl, char *s, unsigned int *mmo)
{
	if (s && *s) {
		int             i;
		for (i = 0; MultiMatchOptionMap[i].number != TYPEMAP_LAST; i++)
			if (strcasecmp(MultiMatchOptionMap[i].name, s) == 0)
				break;
		if (MultiMatchOptionMap[i].number != TYPEMAP_LAST) {
			*mmo = MultiMatchOptionMap[i].number;
			return 0;
		}
	}
	return -1;
}

/* ROUTINE
 *   rev_ARStatHistoryValue(hash, key, stathistvaluestruct)
 *
 * DESCRIPTION
 *   given a hash/key that contains a ref to a status history hash structure,
 *   extract the info from the hash ref and populate the give stathist struct.
 *
 * RETURNS
 *   0 on success
 *  -1 on failure
 *  -2 on warning
 */

int
rev_ARStatHistoryValue(ARControlStruct * ctrl, HV * h, char *k, ARStatHistoryValue * s)
{
	if (!s || !h || !k) {
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
			"rev_ARStatHistoryValue: invalid (NULL) parameter");
		return -1;
	}
	if (SvTYPE((SV *) h) == SVt_PVHV) {
		if (hv_exists(h,  k, strlen(k) )) {
			SV            **val = hv_fetch(h,  k, strlen(k) , 0);
			if (val && *val) {

				/* hash value should be a hash reference */

				if (SvTYPE(SvRV(*val)) == SVt_PVHV) {
					HV             *h2 = (HV *) SvRV((SV *) * val);
					/*
					 * extract vals from hash ref and
					 * populate structure
					 */
					return rev_ARStatHistoryValue_helper(ctrl, h2, s);
				} else
					ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
						    "rev_ARStatHistoryValue: hash value is not a hash reference");
			} else {
				ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
					    "rev_ARStatHistoryValue: hv_fetch returned null");
				return -2;
			}
		} else {
			ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
			       "rev_ARStatHistoryValue: key doesn't exist");
			return -2;
		}
	} else
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
		    "rev_ARStatHistoryValue: first argument is not a hash");

supportrev.c  view on Meta::CPAN

		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
		 "rev_ARArithOpAssignStruct: first argument is not a hash");
	return -1;
}

static int
rev_ARArithOpAssignStruct_helper(ARControlStruct * ctrl,
				 HV * h, ARArithOpAssignStruct * s)
{
	SV            **svp;

	if (!hv_exists(h, "oper", 4)) {
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
			    "rev_ARArithOpAssignStruct_helper: hash does not contain required key 'oper'.");
		return -1;
	}
	/* decode the operation type */

	svp = hv_fetch(h,  "oper", strlen("oper") , 0);
	if (svp && *svp) {
		char           *c = SvPV(*svp, PL_na);
		if (rev_ARArithOpAssignStructStr2OP(ctrl, c, &(s->operation)) != 0)
			return -1;
	}
	/*
	 * if oper is 'negate' then we only are interested in the 'left'
	 * side. else we expect to get both side. call rev_ARAssignStruct()
	 * to fill it the structure.
	 */

	if( s->operation == AR_ARITH_OP_SUBTRACT && ! hv_exists(h,"left",4) ){
		s->operation = AR_ARITH_OP_NEGATE;
	}

	if (s->operation == AR_ARITH_OP_NEGATE) {
		if (hv_exists(h, "right", 5))
			return rev_ARAssignStruct(ctrl, h, "right", &(s->operandRight));
		else {
			ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
				    "rev_ARArithOpAssignStructStr2OP: operation 'negate' ('-') requires 'left' key.");
			return -1;
		}
	}
	/* other operations require both left and right */

	if (!(hv_exists(h, "left", 4) && hv_exists(h, "right", 5))) {
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
			    "rev_ARArithOpAssignStruct_helper: 'left' AND 'right' keys are required.");
		return -1;
	}
	if (rev_ARAssignStruct(ctrl, h, "left", &(s->operandLeft)) == -1)
		return -1;
	return rev_ARAssignStruct(ctrl, h, "right", &(s->operandRight));
}

static int
rev_ARArithOpAssignStructStr2OP(ARControlStruct * ctrl, char *c, unsigned int *o)
{
	int             i;
	for (i = 0; ArithOpMap[i].number != TYPEMAP_LAST; i++)
		if (strcasecmp(ArithOpMap[i].name, c) == 0)
			break;
	if (ArithOpMap[i].number == TYPEMAP_LAST) {
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
		"rev_ARArithOpAssignStructStr2OP: unknown operation word:");
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL, c);
		return -1;
	}
	*o = ArithOpMap[i].number;
	return 0;
}

/* ROUTINE
 *   rev_ARFunctionAssignStruct(hash, key, functionassignstruct)
 *
 * DESCRIPTION
 *   unpack the function assign perl structure from the hash/key pair
 *   (it will be a hash ref) and populate the functionassignstruct
 *
 * RETURNS
 *   0 on success
 *  -1 on failure
 *  -2 on warning
 */

int
rev_ARFunctionAssignStruct(ARControlStruct * ctrl,
			   HV * h, char *k, ARFunctionAssignStruct * s)
{
	if (!s || !h || !k) {
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
		    "rev_ARFunctionAssignStruct: invalid (NULL) parameter");
		return -1;
	}
	if (SvTYPE((SV *) h) == SVt_PVHV) {
		if (hv_exists(h,  k, strlen(k) )) {
			SV            **val = hv_fetch(h,  k, strlen(k) , 0);
			if (val && *val) {

				/* hash value should be an array reference */

				if (SvTYPE(SvRV(*val)) == SVt_PVAV) {
					AV             *a = (AV *) SvRV((SV *) * val);
					SV            **aval;
					int             i;

					if (av_len(a) < 0) {
						ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
							    "rev_ARFunctionAssignStruct: array must have at least 1 element.");
						return -1;
					}
					aval = av_fetch(a, 0, 0);	/* fetch function name */
					if (aval && *aval && SvPOK(*aval)) {	/* must be a string */
						char           *fn = SvPV(*aval, PL_na);
						if (rev_ARFunctionAssignStructStr2FCODE(ctrl, fn, &(s->functionCode)) == -1)
							return -1;
					} else {
						ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
							    "rev_ARFunctionAssignStruct: first element of array must be a string function name.");
						return -1;
					}

					/*
					 * loop over remaining array elements
					 * and populate the parameterList
					 */

					s->numItems = av_len(a);	/* no +1 in this case */
					if (s->numItems == 0)
						return 0;	/* nothing to do */
					s->parameterList = (ARAssignStruct *) MALLOCNN(sizeof(ARAssignStruct) * s->numItems);

					for (i = 1; i <= av_len(a); i++) {
						SV            **hvr = av_fetch(a, i, 0);
						if (hvr && *hvr && (SvTYPE(SvRV(*hvr)) == SVt_PVHV))
							if (rev_ARAssignStruct_helper(ctrl, (HV *) SvRV(*hvr),
										      &(s->parameterList[i-1])) == -1)
								return -1;
					}

					return 0;

				} else
					ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
						    "rev_ARFunctionAssignStruct: hash value is not an array reference");
			} else {
				ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
					    "rev_ARFunctionAssignStruct: hv_fetch returned null");
				return -2;
			}
		} else {
			ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
			   "rev_ARFunctionAssignStruct: key doesn't exist");
			return -2;
		}
	} else
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
		"rev_ARFunctionAssignStruct: first argument is not a hash");
	return -1;
}

static int
rev_ARFunctionAssignStructStr2FCODE(ARControlStruct * ctrl, char *c, unsigned int *o)
{
	int             i;
	for (i = 0; FunctionMap[i].number != TYPEMAP_LAST; i++)
		if (strcasecmp(FunctionMap[i].name, c) == 0)
			break;
	if (FunctionMap[i].number == TYPEMAP_LAST) {
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
			    "rev_ARFunctionAssignStructStr2FCODE: unknown function name:");
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL, c);
		return -1;
	}
	*o = FunctionMap[i].number;
	return 0;
}

#ifdef ARS452
/* ROUTINE
 *   rev_ARFilterStatusStruct(hash, key, filterstatusstruct)
 *
 * DESCRIPTION
 *   take hash ref from hash/key and extract filter status struct fields
 *   from that. populate filter status struct.
 *
 * RETURNS
 *   0 on success
 *  -1 on failure
 *  -2 on warning
 */

int
rev_ARFilterStatusStruct(ARControlStruct * ctrl, HV * h, char *k, 
			 ARFilterStatusStruct * m)
{
	if (!m || !h || !k) {
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
			    "rev_ARFilterStatusStruct: invalid (NULL) parameter");
		return -1;
	}
	if (SvTYPE((SV *) h) == SVt_PVHV) {
		if (hv_exists(h,  k, strlen(k) )) {
			SV            **val = hv_fetch(h,  k, strlen(k) , 0);
			if (val && *val) {

				/* hash value should be a hash reference */

				if (SvTYPE(SvRV(*val)) == SVt_PVHV) {
					HV             *a = (HV *) SvRV((SV *) * val);
					int             rv = 0;

					rv += strmakHVal(a, "messageText", &(m->messageText));
					rv += uintcpyHVal(a, "messageType", &(m->messageType));
					rv += longcpyHVal(a, "messageNum", &(m->messageNum));
					return rv;
				} else
					ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
						    "rev_ARFilterStatusStruct: hash value is not a hash reference");
			} else {
				ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
					    "rev_ARFilterStatusStruct: hv_fetch returned null");
				return -2;
			}
		} else {
			ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
				    "rev_ARFilterStatusStruct: key doesn't exist");

supportrev.c  view on Meta::CPAN

					I32             klen;

					/*
					 * the hash's keys are the names of
					 * the macroparm and the values are
					 * the value of the macroparm. both
					 * are pv's. so iterate over every
					 * key in the hash and populate the
					 * parms list with them.
					 */

					(void) hv_iterinit(a);
					for (i = 0; hv_iternext(a) != (HE *) NULL; i++);
					m->numItems = i;
					m->parms = (ARMacroParmStruct *) MALLOCNN(sizeof(ARMacroParmStruct)
							     * m->numItems);
					(void) hv_iterinit(a);
					i2 = 0;
					while ((hval = hv_iternextsv(a, &hkey, &klen))) {
						if (hval && SvPOK(hval)) {
							char           *vv = SvPV(hval, PL_na);
							int             vl = SvCUR(hval);

							if (i2 <= i) {
								(void) strncpy(m->parms[i2].name, hkey, sizeof(ARNameType));
								/* (void) copymem(m->parms[i2].value, vv, vl); */
								m->parms[i2].value = strdup( vv );
								i2++;
							} else {
								ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
									    "rev_ARMacroParmList: oops! more parms than i thought!");
								return -1;
							}
						} else {
							ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL, "rev_ARMacroParmList: value for macro param is not a string. macro param name:");
							ARError_add(AR_RETURN_ERROR, AP_ERR_CONTINUE, hkey);
							rv = -1;
						}
					}
					return rv;
				} else
					ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
						    "rev_ARMacroParmList: hash value is not a hash reference");
			} else {
				ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
					    "rev_ARMacroParmList: hv_fetch returned null");
				return -2;
			}
		} else {
			ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
				  "rev_ARMacroParmList: key doesn't exist");
			return -2;
		}
	} else
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
		       "rev_ARMacroParmList: first argument is not a hash");
	return -1;
}

#if defined(_WIN32) && !defined(__GNUC__)
/* roll our own strcasecmp and strncasecmp for Win */

int 
strcasecmp(char *s1, char *s2)
{
	char           *p1, *p2;
	char            c1, c2;
	p1 = s1;
	p2 = s2;
	while ((*p1 != '\0') && (*p2 != '\0')) {
		c1 = tolower(*p1);
		c2 = tolower(*p2);
		if ((c1 - c2) == 0) {
			p2++;
			p1++;
		} else {
			return (c1 - c2);
		}
	}
	return *p1 - *p2;
}

int 
strncasecmp(char *s1, char *s2, size_t n)
{

	char           *p1, *p2;
	char            c1, c2;
	size_t          i = 0;
	p1 = s1;
	p2 = s2;

	while ((*p1 != '\0') && (*p2 != '\0') && (i <= n)) {
		c1 = tolower(*p1);
		c2 = tolower(*p2);
		if ((c1 - c2) == 0) {
			p2++;
			p1++;
		} else {
			return (c1 - c2);
		}
		i++;
	}
	return (i == n)? 0 : *p1 - *p2;
}

char*
arsperl_strdup( char *s1 ){
	char *p1;
	int len = strlen( s1 );
	p1 = MALLOCNN( len + 1 );
	strncpy( p1, s1, len );
	/* p1[len] = '\0'; */
	return p1;
}

#endif



int
rev_ARDisplayInstanceList(ARControlStruct * ctrl, HV * h, char *k, ARDisplayInstanceList * d)
{
	SV            **val;
	int             i;

	if (!d) {
		ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
			    "rev_ARDisplayInstanceList: DisplayInstanceList param is NULL");
		return -1;
	}
	if (SvTYPE((SV *) h) == SVt_PVHV) {
		if (hv_exists(h,  k, strlen(k) )) {
			val = hv_fetch(h,  k, strlen(k) , 0);
			if (val && *val) {
				if (SvTYPE(SvRV(*val)) == SVt_PVHV) {
					val = hv_fetch( (HV*) SvRV(*val), "dInstanceList", strlen("dInstanceList"), 0 );

					if (val && *val) {
						/* hash value should be an array reference */
						if (SvTYPE(SvRV(*val)) == SVt_PVAV) {
							AV *ar = (AV *) SvRV((SV *) * val);

							/*



( run in 1.299 second using v1.01-cache-2.11-cpan-39bf76dae61 )