Ejemplo n.º 1
0
void	la_getdat(uint4 kid, int4 code, date *date_ptr, uint4 lo, uint4 hi)
/* kid - virt. keyb. ID		*/
/* code - promt msg code	*/
/* date_ptr - date/time returned	*/
/* lo - min value of date	*/
/* hi - max value of date	*/
{
	int		status;
	bool		valid;
	char		pro[64], res[64];
	unsigned short	length;			/* res. string length	*/
	int4		mlen = 32;		/* max length of result */
	int		smg$read_string(), sys$getmsg();
	int		sys$asctim();
	$DESCRIPTOR(dini, res);			/* initial string	*/
	$DESCRIPTOR(dres, res);			/* resuting string	*/
	$DESCRIPTOR(dprm, pro);			/* prompt string	*/
	error_def(LA_INVAL);

	dprm.dsc$w_length = 64;
	status = sys$getmsg(code, &length, &dprm, 1, 0);
	if (SS$_NORMAL != status)
		lib$signal(status);
	dprm.dsc$w_length = length;
	dres.dsc$w_length = 12;
	if (0 == (*date_ptr)[1])
	{	/* no initial date */
		res[0] = 0;
		length = 0;
	} else
	{
		status = sys$asctim(&length, &dres, date_ptr, 0);
		if (SS$_NORMAL != status)
			lib$signal(status);
	}
	dres.dsc$w_length = 64;
	valid = FALSE;
	while ((SS$_NORMAL != status) || !valid)
	{
		res[length] = ' ';
		dini.dsc$w_length = length;
		status = smg$read_string(&kid, &dres, &dprm, &mlen, 0, 0, 0, &length, 0, 0, &dini);
		if (SS$_NORMAL != status)
			lib$signal(status);
		else  if (0 == length)
		{	/* no datstatus/time */
			(*date_ptr)[0] = (*date_ptr)[1] = lo = 0;
			hi = 1;
		} else  if (0 != length)
		{	/* date/time entered */
			status = lib$convert_date_string(&dres, date_ptr);
			if (SS$_NORMAL != status)
				la_putmsgs(status);
		}
		valid = ((*date_ptr)[1] >= lo || (*date_ptr)[1] < hi);
		if (!valid)
			la_putmsgu(LA_INVAL, 0, 0);
	}
}
Ejemplo n.º 2
0
int4 cvttime(mval *src, int4 tim[2])
{
	$DESCRIPTOR	(dsrc,src->str.addr) ;
	int4            cnx= 0, fl= 127;
	int4		status;

	dsrc.dsc$w_length= src->str.len ;
	status= lib$convert_date_string(&dsrc,tim,&cnx,&fl,0,0) ;
	return status;
}
Ejemplo n.º 3
0
/************************************************************************
** Function: ProcessUsgDetail
**
** Purpose: Read a  detail usage record from usage file.
**
** returns:	SUCCESS - no errors, or "soft" (minor) error.  SUCCESS
**		          means that the record will be saved in either
**		          CDR_DATA or CDR_DATA_WORK.
**		FAILURE - serious parsing error. return FAILURE implies
**		          "hard" error.  Such records will be written to
**		          the bad image file.
**		          Note that records with hard errors will be
**		          written to bad image file as is.  This means
**		          error codes are NOT saved.  This is why we
**		          return immediately for FAILURE case.
**
** General idea is that missing data will be considered a "soft" error
** where as non-numeric data in a numeric field will be considered a
** hard error.
*************************************************************************
*/
int ProcessUsgDetail(CDR_DATA_STRUCT *cdr_data,
        RECORD_TYPE_STRUCT *rec_type,
        int  minimize,
        int  *checksum1,
        int  *checksum2,
        int  *checksum3)
{
   char *ptr;
   char tmpstr[1024];
   char gstrScratch1[1024];
   int  pos;	/* floating pointer into cdr_data->usg_rec */

   /* for time field, we need to convert to the usage time zone if
   ** it is provided. But sometime we do not have timezone in usage
   ** file, in this case we will convert to default timezone?
   ** To convert time, we need to wait after the whole usage record
   ** has been processed, then do conversion if necessary
   */

   short trans_dt_type = -1; /* -1 means not supplied in usg file,no op */
   short second_dt_type = -1;/* -1 means not supplied in usg file,no op */
   short rate_dt_type = -1;  /* -1 means not supplied in usg file,no op */
   short new_timezone = FALSE; /* to indicate whether there is a timezone
                               ** in the usage record 
                               */
   char usage_tz[szUnixTZ+1+3];
   char unix_tz[szUnixTZ+1];
   short size;     /* size of input field */
   tiny isdst;     /* ignored */

   int  i;
   int  j;

   pos = 0;
   ptr = gstrScratch1;

   if(mpsIsLogLevelHigh())
   {
      sprintf(tmpstr, "\nProcessing Record Type \'%s\'",
         rec_type->record_type);
      emit(ERRLOC,MPS_GENERIC_INFORM,tmpstr);
      sprintf(tmpstr, "===================================");
      emit(ERRLOC,MPS_GENERIC_INFORM,tmpstr);
      sprintf(tmpstr, "%-20.20s   %-20.20s   %-12.12s %-5.5s %-15.12s",
         "Field Name From", "Field Name To","Field Type", "Size","Field Value");
      emit(ERRLOC,MPS_GENERIC_INFORM,tmpstr);
      sprintf(tmpstr,
         "===============        ===============        ============ ===== ===========");
      emit(ERRLOC,MPS_GENERIC_INFORM,tmpstr);
   }

   for(i = rec_type->from_pos; i <= rec_type->to_pos; i++)
   {
      size = gsField_Mapping[i].field_from_size;
      /* Skip over some fields if in minimize / non-debug mode */
      if ( minimize && !mpsIsLogLevelHigh() )
      {
         switch(gsField_Mapping[i].field_to_id)
         {
         case to_type_id_usg:
         case to_point_origin:
         case to_point_target:
         case to_trans_dt:
         case to_timezone:
         case to_external_id:
         case to_external_id_type:
         case to_home_carrier_sid_bid:
         case to_num_tax_details:
            break;

         default:
            pos += size;
            continue;
         }
      }

      switch(gsField_Mapping[i].field_from_type)
      {
      case binary:
         j = ParseHex((char *)cdr_data->usg_rec+pos, (int) size);
         pos += size;
         if(mpsIsLogLevelHigh())
         {
            sprintf(tmpstr, 
               "%-20.20s   %-20.20s   %-12.12s %-6d%-12d",
               gsField_Mapping[i].field_from_name,
               gsField_Mapping[i].field_to_name,
               "(binary)",
               size,
               j);
            emit(ERRLOC,MPS_GENERIC_INFORM,tmpstr);
         }
         break;
      default:
         if((gsField_Mapping[i].field_to_id == to_annotation)   ||
            (gsField_Mapping[i].field_to_id == to_customer_tag) ||
            (gsField_Mapping[i].field_to_id == to_roaming_detail))
         {
            extract_field_no_strip(&ptr, (char *)cdr_data->usg_rec, &pos, (int) size);
         } else {
            extract_field(&ptr, (char *)cdr_data->usg_rec, &pos, (int) size);
         }
         if(mpsIsLogLevelHigh())
         {
            sprintf(tmpstr, 
               "%-20.20s   %-20.20s   %-12.12s %-6d%-s",
               gsField_Mapping[i].field_from_name,
               gsField_Mapping[i].field_to_name,
               "(a/n str)",
               size,
               ptr);
            emit(ERRLOC,MPS_GENERIC_INFORM,tmpstr);
         }
         break;
      } 
      if(gsField_Mapping[i].is_ignored)
      {
         continue;
      }
      if(gsField_Mapping[i].is_required && ptr[0] == '\0' &&
         gsField_Mapping[i].field_from_type != binary)
      {
         emit(ERRLOC,CAP_FIELD_MISSING_X,gsField_Mapping[i].field_from_name);
         set_cdr_error_code(cdr_data, CAP_FIELD_MISSING); 
         sprintf(tmpstr, "%d,Field: \"%s\"",
            CAP_FIELD_MISSING,gsField_Mapping[i].field_to_name);

         emit(ERRLOC,MPS_GEN_ERROR,tmpstr );
         set_mps_error_struct(tmpstr,""); 
      }

      /* if we need to convert from string to a numeric field *
      ** we need to check no digital char and overflow        */
      if(gsField_Mapping[i].field_to_type != to_string)
      {
         if(gsField_Mapping[i].field_from_type != binary)
         {
            if(numeric_string(ptr))
            {
               if(gsField_Mapping[i].field_to_type == to_numeric)
               {
               }
               else
               {
                  if(convert_to_number(ptr,&j, 
                     (short) gsField_Mapping[i].field_to_type) == FAILURE)
                  {
                     /* conversion caused overflow */
                     j = 0;
                     set_cdr_error_code(cdr_data, CAP_VALUE_OVERFLOW);
                     sprintf(tmpstr,
                        "%d,convert \"%s\" to \"%s\" caused overflow",
                        CAP_VALUE_OVERFLOW,
                        ptr,
                        gsField_Mapping[i].field_to_name);
                     set_mps_error_struct(tmpstr,"");
                  }
               }
            }
            else
            {
               /* some non-numeric characters for numeric field */
               j = 0;
               set_cdr_error_code(cdr_data, CAP_BAD_NUM_FIELD);
               sprintf(tmpstr,
                  "%d,Field value: \"%s\"",
                  CAP_BAD_NUM_FIELD,
                  ptr);
               emit(ERRLOC,CAP_BAD_NUM_FIELD );
               sprintf(tmpstr, "%-20.20s: \"%s\"",
                  gsField_Mapping[i].field_from_name,gstrScratch1);
               emit(ERRLOC,MPS_GEN_ERROR,tmpstr );
               set_mps_error_struct(tmpstr,""); 
            }
         }
         else
         {
            /* when we get a binary field, we need to check overflow
            ** since we may get the int and try to convert to a tiny */
            if(check_overflow(j, (short) gsField_Mapping[i].field_to_type) == FAILURE)
            {
               j = 0;
               /* conversion caused overflow */
               set_cdr_error_code(cdr_data, CAP_VALUE_OVERFLOW);
               sprintf(tmpstr,
                  "%d,convert %d to \"%s\" caused overflow",
                  CAP_VALUE_OVERFLOW,
                  j,
                  gsField_Mapping[i].field_to_name);
               emit(ERRLOC,MPS_GEN_ERROR,tmpstr );
               set_mps_error_struct(tmpstr,"");
            }
         } 
      } 

      switch(gsField_Mapping[i].field_to_id)
      {
      case to_ext_tracking_id:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->ext_tracking_id, ptr, szExtTrackingId);
            cdr_data->ext_tracking_id[szExtTrackingId] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->ext_tracking_id, tmpstr,szExtTrackingId);
            cdr_data->ext_tracking_id[szExtTrackingId] = '\0';
         }
         break;
      case to_trans_id:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->trans_id, ptr, szTransID);
            cdr_data->trans_id[szTransID] = '\0';
         }
         else
         {
            sprintf(cdr_data->trans_id,"%d",j);
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->trans_id, tmpstr, szTransID);
            cdr_data->trans_id[szTransID] = '\0';
         }
         break;
      case to_element_id:
         cdr_data->element_id = j;
         break;
      case to_type_id_usg:
         cdr_data->type_id_usg = j;
         cdr_data->orig_type_id_usg = j;
         break;
      case to_rate_class:
         cdr_data->rate_class = j;
         break;
      case to_bill_class:
         cdr_data->bill_class = j;
         break;
      case to_num_tax_details:
         cdr_data->num_tax_details = j;
         break;
      case to_provider_id:
         cdr_data->provider_id = j;
         break;
      case to_provider_class:
         cdr_data->provider_class = j;
         break;
      case to_jurisdiction:
         cdr_data->jurisdiction = j;
         break;
      case to_rate_currency_code:
         cdr_data->rate_currency_code = j;
         break;
      case to_emf_create_date:
         break;
      case to_point_origin:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->point_origin, ptr, szUsagePoint);
            cdr_data->point_origin[szUsagePoint] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->point_origin, tmpstr, szUsagePoint);
            cdr_data->point_origin[szUsagePoint] = '\0';
         }
         break;
      case to_country_dial_code_origin:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->country_dial_code_origin, ptr, 
               szDialCode);
            cdr_data->country_dial_code_origin[szDialCode] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->country_dial_code_origin, tmpstr, szDialCode);
            cdr_data->country_dial_code_origin[szDialCode] = '\0';
         }
         break;
      case to_point_tax_code_origin:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->point_tax_code_origin, ptr, szTaxCode);
            cdr_data->point_tax_code_origin[szTaxCode] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->point_tax_code_origin, tmpstr, szTaxCode);
            cdr_data->point_tax_code_origin[szTaxCode] = '\0';
         }
         break;
      case to_point_tax_code_type_origin:
         cdr_data->point_tax_code_type_origin = j;
         break;
      case to_point_target:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->point_target, ptr, szUsagePoint);
            cdr_data->point_target[szUsagePoint] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->point_target, tmpstr, szUsagePoint);
            cdr_data->point_target[szUsagePoint] = '\0';
         }
         break;
      case to_point_tax_code_target:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->point_tax_code_target, ptr, szTaxCode);
            cdr_data->point_tax_code_target[szTaxCode] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->point_tax_code_target, tmpstr, szTaxCode);
            cdr_data->point_tax_code_target[szTaxCode] = '\0';
         }
         break;
      case to_point_tax_code_type_target:
         cdr_data->point_tax_code_type_target = j;
         break;
      case to_trans_dt:
         /* if time comes in as unix time save it in the trans_time field
         ** and do conversion later by using a timezone 
         */
         if(gsField_Mapping[i].field_to_type == to_int)
            cdr_data->trans_time = j;
         else
         {
            /* if time comes in as char string save the string and convert
            ** to YYYYMMDD HH:MM:SS according the input format
            */
            if(convert_date_string(cdr_data->trans_dt, gstrScratch1,
               gsField_Mapping[i].date_format_type) == FAILURE)
            {
               emit(ERRLOC, MPS_BAD_FIELD, "trans_dt", cdr_data->trans_dt);
               set_cdr_error_code(cdr_data, CAP_BAD_PRIMTIME);
               sprintf(tmpstr,
                  "%d,%s: \"%s\"",
                  CAP_BAD_PRIMTIME,gsField_Mapping[i].field_to_name,
                  cdr_data->trans_dt);
               emit(ERRLOC, MPS_GEN_ERROR, tmpstr );
               set_mps_error_struct(tmpstr,"");
               break;
            }
         }
         trans_dt_type = gsField_Mapping[i].field_to_type;
         break;
      case to_second_dt:
         /* if time comes in as unix time save it in the trans_time field
         ** and do conversion later by using a timezone 
         */
         if(gsField_Mapping[i].field_to_type == to_int)
            cdr_data->second_time = j;
         else
         {
            /* if time comes in as char string save the string and convert
            ** to YYYYMMDD HH:MM:SS according the input format later 
            */
            if(convert_date_string(cdr_data->second_dt, gstrScratch1,
               gsField_Mapping[i].date_format_type) == FAILURE)
            {
               emit(ERRLOC, MPS_BAD_FIELD,"second_dt",cdr_data->second_dt);
               set_cdr_error_code(cdr_data, CAP_BAD_SECONDTIME);
               sprintf(tmpstr,
                  "%d,%s: \"%s\"",
                  CAP_BAD_SECONDTIME,
                  gsField_Mapping[i].field_to_name,
                  cdr_data->second_dt);

               emit(ERRLOC, MPS_GEN_ERROR, tmpstr );
               set_mps_error_struct(tmpstr,"");
               break;
            }
         }
         second_dt_type = gsField_Mapping[i].field_to_type;
         break;
      case to_timezone:
         cdr_data->timezone = j;
         new_timezone = TRUE;
         break;
      case to_primary_units:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->primary_units), j);
         }
         else
         {
            arb_numeric_from_string(&(cdr_data->primary_units), ptr);
            if ( arb_numeric_to_int( &(cdr_data->primary_units), &j) == FAILURE)
            {
               j = cdr_data->primary_units.low;
            }
         }
         *checksum1 += j;
         break;
      case to_primary_type:
         cdr_data->primary_type = j;
         break;
      case to_second_units:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->second_units), j);
         }
         else
         {
            arb_numeric_from_string(&(cdr_data->second_units), ptr);
            if ( arb_numeric_to_int( &(cdr_data->second_units), &j) == FAILURE)
            {
               j = cdr_data->second_units.low;
            }
         }
         *checksum2 += j;
         break;
      case to_second_type:
         cdr_data->second_type = j;
         break;
      case to_third_units:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->third_units), j);
         }
         else
         {
            arb_numeric_from_string(&(cdr_data->third_units), ptr);
            if ( arb_numeric_to_int( &(cdr_data->third_units), &j) == FAILURE)
            {
               j = cdr_data->third_units.low;
            }
         }
         *checksum3 += j;
         break;
      case to_third_type:
         cdr_data->third_type = j;
         break;
      case to_federal_tax:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->federal_tax), j);
         }
         else
         {
            arb_numeric_from_string(&(cdr_data->federal_tax), ptr);
         }
         break;
      case to_state_tax:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->state_tax), j);
         }
         else
         {
            arb_numeric_from_string(&(cdr_data->state_tax), ptr);
         }
         break;
      case to_county_tax:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->county_tax), j);
         }
         else
         {
            arb_numeric_from_string(&(cdr_data->county_tax), ptr);
         }
         break;
      case to_city_tax:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->city_tax), j);
         }
         else
         {
            arb_numeric_from_string(&(cdr_data->city_tax), ptr);
         }
         break;
      case to_other_tax:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->other_tax), j);
         }
         else
         {
            arb_numeric_from_string(&(cdr_data->other_tax), ptr);
         }
         break;
      case to_units_currency_code:
         cdr_data->units_currency_code = j;
         break;
      case to_annotation:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->annotation, ptr, size);
            cdr_data->annotation[size] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->annotation, tmpstr, size);
            cdr_data->annotation[size] = '\0';
         }
         break;
      case to_customer_tag:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->customer_tag, ptr, szCustomerTag);
            cdr_data->customer_tag[szCustomerTag] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->customer_tag, tmpstr, szCustomerTag);
            cdr_data->customer_tag[szCustomerTag] = '\0';
         }
         break;
      case to_geocode:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->geocode, ptr, szTaxCode);
            cdr_data->geocode[szTaxCode] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->geocode, tmpstr, szTaxCode);
            cdr_data->geocode[szTaxCode] = '\0';
         }
         break;
      case to_roaming_detail:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->roaming_detail, ptr, size);
            cdr_data->roaming_detail[size] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->roaming_detail, tmpstr, size);
            cdr_data->roaming_detail[size] = '\0';
         }
         break;	    
      case to_rated_units:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->rated_units), j);
         }
         else
            arb_numeric_from_string(&(cdr_data->rated_units), ptr);
         break;
      case to_total_amt:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->total_amt), j);
         }
         else
            arb_numeric_from_string(&(cdr_data->total_amt), ptr);
         break;
      case to_base_amt:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->base_amt), j);
         }
         else
            arb_numeric_from_string(&(cdr_data->base_amt), ptr);

         break;
      case to_unrounded_amount:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->unrounded_amount), j);
         }
         else
            arb_numeric_from_string(&(cdr_data->unrounded_amount), ptr);
         break;
      case to_foreign_amount:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->foreign_amount), j);
         }
         else
            arb_numeric_from_string(&(cdr_data->foreign_amount), ptr);
         break;
      case to_rate_period:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->rate_period, ptr, szRatePeriod);
            cdr_data->rate_period[szRatePeriod] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->rate_period, tmpstr, szRatePeriod);
            cdr_data->rate_period[szRatePeriod] = '\0';
         }
         break;
      case to_rate_dt:
         /* if time comes in as unix time save it in the trans_time field
         ** and do conversion later by using a timezone 
         */
         if(gsField_Mapping[i].field_to_type == to_int)
            cdr_data->rate_time = j;
         else
         {
            if(convert_date_string(cdr_data->rate_dt, gstrScratch1,
               gsField_Mapping[i].date_format_type) == FAILURE)
            { 
               emit(ERRLOC, MPS_BAD_FIELD,"rate_dt",cdr_data->rate_dt);
               set_cdr_error_code(cdr_data, CAP_BAD_RATETIME);
               sprintf(tmpstr,
                  "%d,%s: \"%s\"",
                  CAP_BAD_RATETIME,
                  gsField_Mapping[i].field_to_name,
                  cdr_data->rate_dt);
               emit(ERRLOC, MPS_GEN_ERROR, tmpstr );
               set_mps_error_struct(tmpstr,"");
               break;
            }
         }
         rate_dt_type = gsField_Mapping[i].field_to_type;
         break;
      case to_no_bill:
         cdr_data->no_bill = j;
         break;
      case to_comp_status:
         cdr_data->comp_status = j;
         break;
      case to_cdr_status:
         cdr_data->cdr_status = j;
         break;
      case to_external_id:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->external_id, ptr, size);
            cdr_data->external_id[size] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->external_id, tmpstr, size);
            cdr_data->external_id[size] = '\0';
         }
         break;
      case to_external_id_type:
         cdr_data->external_id_type = j;
         break;
      case to_account_no:
         cdr_data->account_no = j;
         break;
      case to_kp_subscr_no:
         cdr_data->kp_subscr_no = j;
         break;
      case to_kp_subscr_no_resets:
         cdr_data->kp_subscr_no_resets = j;
         break;
      case to_kp_server_id:
         cdr_data->kp_server_id = j;
         break;
      case to_ccard_account:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->miu_ccard_account, ptr, szCCardAcct);
            cdr_data->miu_ccard_account[szCCardAcct] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->miu_ccard_account, tmpstr, szCCardAcct);
            cdr_data->miu_ccard_account[szCCardAcct] = '\0';
         }
         break;
      case to_ccard_carrier_code:
         cdr_data->miu_ccard_carrier_code = j;
         break;
      case to_ccard_ownr_fname:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->miu_ccard_ownr_fname, ptr, szCCardOwnr);
            cdr_data->miu_ccard_ownr_fname[szCCardOwnr] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->miu_ccard_ownr_fname, tmpstr, szCCardOwnr);
            cdr_data->miu_ccard_ownr_fname[szCCardOwnr] = '\0';
         }
         break;
      case to_ccard_ownr_lname:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->miu_ccard_ownr_lname, ptr, szCCardOwnr);
            cdr_data->miu_ccard_ownr_lname[szCCardOwnr] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->miu_ccard_ownr_lname, tmpstr, szCCardOwnr);
            cdr_data->miu_ccard_ownr_lname[szCCardOwnr] = '\0';
         }
         break;
      case to_ccard_expire:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->miu_ccard_expire, ptr, szCCardExpire);
            cdr_data->miu_ccard_expire[szCCardExpire] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->miu_ccard_expire, tmpstr, szCCardExpire);
            cdr_data->miu_ccard_expire[szCCardExpire] = '\0';
         }
         break;
      case to_ccard_carrier:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->miu_ccard_carrier, ptr, szCCCarrier);
            cdr_data->miu_ccard_carrier[szCCCarrier] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->miu_ccard_carrier, tmpstr, szCCCarrier);
            cdr_data->miu_ccard_carrier[szCCCarrier] = '\0';
         }
         break;
      case to_free_flag:
         cdr_data->free_flag = j;
         break;
      case to_home_carrier_sid_bid:
         cdr_data->home_carrier_sid_bid = j;
         break;
      case to_open_item_id:
         cdr_data->open_item_id = j;
         break;
      case to_cell_name_origin:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->cell_name_origin, ptr, szCellName);
            cdr_data->cell_name_origin[szCellName] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->cell_name_origin, tmpstr, szCellName);
            cdr_data->cell_name_origin[szCellName] = '\0';
         }
         break;
     }
   }

   if(new_timezone)
   {
      if(timezone_lookup(cdr_data->timezone,unix_tz,&isdst) != SUCCESS)
      {
         emit(ERRLOC, CAP_BAD_USG_TIMEZONE, cdr_data->timezone);
         set_cdr_error_code(cdr_data, CAP_BAD_TIMEZONE);
         sprintf(tmpstr,"%d,Timezone:%d",CAP_BAD_TIMEZONE,cdr_data->timezone);
         emit(ERRLOC, MPS_GEN_ERROR, tmpstr );
         set_mps_error_struct(tmpstr,"");
         return(SUCCESS);
      }
      /* if we get a unix time do conversion 
      ** from int to arbor/bp date format */

      if(trans_dt_type == to_int || second_dt_type == to_int || 
         rate_dt_type == to_int)
      {
         if(mpsGetGuideTZ() == TIMEZONE_NOT_USED) 
         {
            /* convert to input usage record's timezone
            ** (already saved in cdr_data)
            */
            strcpy(usage_tz, unix_tz);
         }
         else
         {
            /* Use guiding timezone instead.
            ** NOTE: in this case, the timezone from the usage record
            **       IS DISCARDED !!
            */
            strcpy(usage_tz, mpsGetGuideTZstr());
            cdr_data->timezone = mpsGetGuideTZ();  /* int version of mpsGetGuideTZstr() */
         }

         /* ----------------------------------------------------
         ** Convert trans_dt & second_dt to appropriate timezone
         ** since we are converting a unix time_t, the "from_tz" arg
         ** of convert_timezone (arg 3) is not used.
         */

         if(trans_dt_type == to_int)
         {
            if(convert_timezone(cdr_data->trans_time, cdr_data->trans_dt, "GMT0", usage_tz)
               == FAILURE)
            {
               emit(ERRLOC, CAP_BAD_USG_TIMEZONE, cdr_data->timezone);
               set_cdr_error_code(cdr_data, CAP_BAD_TIMEZONE);
               sprintf(tmpstr,
                  "%d,Timezone:%d",
                  CAP_BAD_TIMEZONE,cdr_data->timezone);
               emit(ERRLOC, MPS_GEN_ERROR, tmpstr );
               set_mps_error_struct(tmpstr,"");
               return(SUCCESS);
            }
         }
         if(second_dt_type == to_int)
         {
            if(convert_timezone(cdr_data->second_time, cdr_data->second_dt, "GMT0", usage_tz)
               == FAILURE)
            {
               emit(ERRLOC, CAP_BAD_USG_TIMEZONE, cdr_data->timezone);
               set_cdr_error_code(cdr_data, CAP_BAD_TIMEZONE);
               sprintf(tmpstr,
                  "%d,Timezone:%d",
                  CAP_BAD_TIMEZONE,cdr_data->timezone);
               emit(ERRLOC, MPS_GEN_ERROR, tmpstr );
               set_mps_error_struct(tmpstr,"");
               return(SUCCESS);
            }
         }
         if(rate_dt_type == to_int)
         {
            if(convert_timezone(cdr_data->rate_time, cdr_data->rate_dt, "GMT0", usage_tz)
               == FAILURE)
            {
               emit(ERRLOC, CAP_BAD_USG_TIMEZONE, cdr_data->timezone);
               set_cdr_error_code(cdr_data, CAP_BAD_TIMEZONE);
               sprintf(tmpstr,
                  "%d,Timezone:%d",
                  CAP_BAD_TIMEZONE,cdr_data->timezone);
               emit(ERRLOC, MPS_GEN_ERROR, tmpstr );
               set_mps_error_struct(tmpstr,"");
               return(SUCCESS);
            }
         }
      }
   }
   else
   {
      /* no timezone provided, get the default time zone later */
      if(trans_dt_type == to_int || second_dt_type == to_int ||
         rate_dt_type == to_int)
      {
         if(mpsGetGuideTZ() == TIMEZONE_NOT_USED)
         {
            /* no default set, do not know what to convert to, hard error */
            emit(ERRLOC,CAP_NO_TIMEZONE);
            sprintf(tmpstr,
               "%d,No timezone",
               CAP_NO_TIMEZONE);
            emit(ERRLOC,MPS_GEN_ERROR, tmpstr );
            set_mps_error_struct(tmpstr,"");
            return(SUCCESS);
         }
         else
         {
            /* Use guiding timezone */
            strcpy(usage_tz, mpsGetGuideTZstr());
            cdr_data->timezone = mpsGetGuideTZ();  /* int version of mpsGetGuideTZstr() */

            /* ----------------------------------------------------
            ** Convert trans_dt & second_dt to appropriate timezone
            */

            if(trans_dt_type == to_int)
            {
               if(convert_timezone(cdr_data->trans_time, cdr_data->trans_dt,
                  "GMT0", usage_tz) == FAILURE)
               {
                  emit(ERRLOC, CAP_BAD_USG_TIMEZONE, cdr_data->timezone);
                  set_cdr_error_code(cdr_data, CAP_BAD_TIMEZONE);
                  sprintf(tmpstr,
                     "%d,Timezone:%d",
                     CAP_BAD_TIMEZONE,cdr_data->timezone);
                  emit(ERRLOC,MPS_GEN_ERROR, tmpstr );
                  set_mps_error_struct(tmpstr,"");
                  return(SUCCESS);
               }
            }
            if(second_dt_type == to_int)
            {
               if(convert_timezone(cdr_data->second_time, cdr_data->second_dt,
                  "GMT0", usage_tz) == FAILURE)
               {
                  emit(ERRLOC, CAP_BAD_USG_TIMEZONE, cdr_data->timezone);
                  set_cdr_error_code(cdr_data, CAP_BAD_TIMEZONE);
                  sprintf(tmpstr,
                     "%d,Timezone:%d",
                     CAP_BAD_TIMEZONE,cdr_data->timezone);
                  emit(ERRLOC,MPS_GEN_ERROR, tmpstr );
                  set_mps_error_struct(tmpstr,"");
                  return(SUCCESS);
               }
            }
            if(rate_dt_type == to_int)
            {
               if(convert_timezone(cdr_data->rate_time, cdr_data->rate_dt,
                  "GMT0", usage_tz) == FAILURE)
               {
                  emit(ERRLOC, CAP_BAD_USG_TIMEZONE, cdr_data->timezone);
                  set_cdr_error_code(cdr_data, CAP_BAD_TIMEZONE);
                  sprintf(tmpstr,
                     "%d,Timezone:%d",
                     CAP_BAD_TIMEZONE,cdr_data->timezone);
                  emit(ERRLOC,MPS_GEN_ERROR, tmpstr );
                  set_mps_error_struct(tmpstr,"");
                  return(SUCCESS);
               }
            }
         }
      }
   }
   return(SUCCESS);

} /* ProcessUsgDetail() */
Ejemplo n.º 4
0
static int varg_convert_date(char *date_string, char *pattern)
{
        char date_text[30];
        int bin_time[2], flags, length, status, i, from, to;
        char year_4[5], year_2[4], month_name[4];
        char month_2[2], month_1[2], date_2[3], date_1[2];
        char hour_2[3], hour_1[2], minute[3], second[3];
        char *months[] = {"", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
                          "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
                         };
        $DESCRIPTOR(date_desc, "");
        static int context;


        /*	First convert the date string into internal VMS format
        */

        date_desc.dsc$w_length = strlen(date_string);
        date_desc.dsc$a_pointer = date_string;
        context = 0;
        flags = 0X7F;
        status = lib$convert_date_string(&date_desc, &bin_time, &context, &flags);
        if ((status & 1) != 1) return status;

        /*	Now convert it back to string form.  This ensures that delta times
        	and keywords like TODAY get translated into a consistent format.
        */

        date_desc.dsc$w_length = 30;
        /* date_desc.dsc$a_pointer = &date_text;*/
        date_desc.dsc$a_pointer = date_text;
        length = 0;
        status = sys$asctim(&length, &date_desc, &bin_time, 0);
        if ((status & 1) != 1) return status;

        date_text[length] = 0;		/* add NULL terminator */
        date_string[0] = 0;			/* start with empty string */

        /*	Break the date/time string up into the constituent fields.  Fields
        	such as date have two instances - one with leading zero and one without
        	e.g. "05" and "5".
        */

        if (date_text[0] == ' ') {
                date_2[0] = '0';
                date_2[1] = date_text[1];
                date_2[2] = 0;
                date_1[0] = date_text[1];
                date_1[1] = 0;
        } else {
                date_2[0] = date_text[0];
                date_2[1] = date_text[1];
                date_2[2] = 0;
                strcpy(date_1, date_2);
        }

        /*	Extract the month name and lowercase the 2nd and 3rd characters.
        */

        month_name[0] = date_text [3];
        month_name[1] = tolower(date_text [4]);
        month_name[2] = tolower(date_text [5]);
        month_name[3] = 0;

        /*	Calculate the month number by looking up the month name in a
        	character array.
        */

        for (i = 1; i <= 12; i++) {
                if (strcmp(month_name, months[i]) == 0) {
                        sprintf(month_2, "%02d", i);
                        sprintf(month_1, "%d", i);
                        break;
                }
        }

        /*	Extract the year field (both 4 digit and 2 digit forms).
        */

        year_2[0] = date_text[9];
        year_2[1] = date_text[10];
        year_2[3] = 0;

        for (i = 0; i <= 3; i++) {
                year_4[i] = date_text[i+7];
        }

        year_4[4] = 0;

        /*	Extract hour field.
        */

        hour_2[0] = date_text[12];
        hour_2[1] = date_text[13];
        hour_2[2] = 0;

        if (date_text[12] == '0') {
                hour_1[0] = date_text[13];
                hour_1[1] = 0;
        } else strcpy(hour_1, hour_2);

        /*	Lastly copy the minutes and seconds.
        */

        for (i = 0; i <= 1; i++) {
                minute[i] = date_text[i+15];
                second[i] = date_text[i+18];
        }

        minute[2] = 0;
        second[2] = 0;

        /*	Now start building up the output string by copying characters from
        	'pattern' to 'date_string' substituting the various fields when we
        	encounter an escape pair.
        */

        from = 0;
        to = 0;

        while (pattern[from] != 0) {
                if (pattern[from] == '$') {
                        switch (pattern[from+1]) {
                        case 'Y':
                                strcat(date_string, year_4);
                                to = to + 4;
                                break;

                        case 'y':
                                strcat(date_string, year_2);
                                to = to + 2;
                                break;

                        case 'M':
                                strcat(date_string, month_name);
                                to = to + 3;
                                break;

                        case 'N':
                                strcat(date_string, month_2);
                                to = to + 2;
                                break;

                        case 'n':
                                strcat(date_string, month_1);
                                to = to + strlen(month_1);
                                break;

                        case 'D':
                                strcat(date_string, date_2);
                                to = to + 2;
                                break;

                        case 'd':
                                strcat(date_string, date_1);
                                to = to + strlen(date_1);
                                break;

                        case 'H':
                                strcat(date_string, hour_2);
                                to = to + 2;
                                break;

                        case 'h':
                                strcat(date_string, hour_1);
                                to = to + strlen(hour_1);
                                break;

                        case 'm':
                                strcat(date_string, minute);
                                to = to + 2;
                                break;

                        case 'S':
                        case 's':
                                strcat(date_string, second);
                                to = to + 2;
                                break;

                        case '$':
                                date_string[to] = '$';
                                date_string[to+1] = 0;
                                to = to + 1;
                                break;
                        }

                        from = from + 2;
                } else {
                        date_string[to] = pattern[from];
                        date_string[to+1] = 0;
                        from = from + 1;
                        to = to + 1;
                }
        }
}