Exemplo n.º 1
0
static int labels_numeric (char **S, int n)
{
    int t;

    for (t=0; t<n; t++) {
	if (!numeric_string(S[t])) {
	    return 0;
	}
    }  

    return 1;
}
Exemplo n.º 2
0
static int check_imported_varname (char *vname, int vnum,
				   int row, int col,
				   PRN *prn)
{
    int err = 0;

    if (*vname == '\0') {
	if (vnum > 0) {
	    fprintf(stderr, "variable name %d is missing\n", vnum);
	    sprintf(vname, "v%d", vnum);
	} else {
	    err = missing_varname();
	}
    } else if (numeric_string(vname)) {
	err = check_varname(vname);
    } else {
	char *s, tmp[VNAMELEN];

	strcpy(tmp, vname);
	s = tmp;
	*vname = '\0';
	
	while (*s && !isalpha(*s)) s++;
	if (*s == '\0') {
	    if (vnum > 0) {
		fprintf(stderr, "variable name %d is garbage\n", vnum);
		sprintf(vname, "v%d", vnum);
	    } else {
		err = missing_varname();
	    }
	} else {
	    strncat(vname, s, VNAMELEN - 1);
	}
	iso_to_ascii(vname);
	strip_vname_illegals(vname);
	err = check_varname(vname);
    }

    if (err) {
	err = E_DATA;
	if (row >= 0 && col >= 0) {
	    pprintf(prn, _("At row %d, column %d:\n"), row, col);
	}
	pputs(prn, gretl_errmsg_get());
    }

    return err;
}
Exemplo n.º 3
0
static int stray_numeric (int vtype, char *tmp, double *x)
{
    if (vtype == VALUE_STRING) {
	if (string_is_blank(tmp)) {
	    *x = NADBL;
	    return 1;
	} else if (import_na_string(tmp)) {
	    *x = NADBL;
	    return 1;
	} else if (numeric_string(tmp)) {
	    *x = atof(tmp);
	    return 1;
	}
    }

    return 0;
}
Exemplo n.º 4
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() */
Exemplo n.º 5
0
/*********************************************************************
** module_std_init()
**
** Description:	Perform basic initialization common to ALL Arbor background
**		modules. This includes verifying calling format (correct
**		number of args), $ARBORDATA directory is accessible, etc.
**		Also, logs into *SPECIFIED* database. This is done by logging
**		into Catalog database (ARBOR_CATALOG_QUERY / ARBOR_CATALOG_
**		DATABASE) and looking up the SERVER_DEFINITION entry for the
**		given server_id.  The result is that a single connection to
**		the specified server (database) will be returned as output.
**
** NOTE:	If we are EC/Arbor, we will delay setting debug mode until
**		after counting EMFs (EC/Arbor is restricted to number of
**		active EMFs). As of this writting (24-jul-97), counting of
**		EMFs is only done for BIP (hardcoded in count_equip()).
**
** Input:	argc - from main(), # parameters supplied on cmd line
**		argv = from main(), pointers to parameters supplied on cmd line
**		module_name = e.g., "CAP", "BIP",
**		debug_flag = if true, debug SQL log file will be opened. even
**			if false, if tra_switch is found to be true, debug SQL
**			log will be opened.
** Output:	server_id - server_id supplied on command line. This is
**			server_id module is to run against, regardless of default
**			server / database.
**		arbordata - value of $ARBORDATA env variable. must be an
**			accessible directory. This function returns pointer to
**			static memory. Could be overwritten on successive calls
**			but this function should only be called once!
**		ctrl_rpt_fname - full pathname for control report (pathname and
**			filename). Caller must still open file and write ctrl rpt.
**			This function returns pointer to static memory. Could be
**			overwritten on successive calls but this function should
**			only be called once!
**		tra_switch - value of module's TRA_SWITCH (SYSTEM_PARAMETERS).
**			If true, debug SQL log file will be opened.
**		tim_switch - value of module's TIM_SWITCH (SYSTEM_PARAMETERS).
**		dbp - open database connection.
**
** Returns:	SUCCESS, or EXITS on failure.
************************************************************************
*/
int module_std_init(	int	argc,		/* input: */
			char	**argv,		/* input: */
			char	*module_name,	/* input: e.g., "CAP" */
			int	debug_flag,	/* input:  true/false: if true, turn on debugging */
			int	*server_id,	/* OUTPUT: Arbor server_id number */
			char	**arbordata,	/* OUTPUT: $ARBORDATA */
			char	**ctrl_rpt_fname,/* OUTPUT: full pathname for ctrl rpt file */
			int	*tra_switch,	/* OUTPUT: module's TRA_SWITCH, turns on debugging */
			int	*tim_switch,	/* OUTPUT: module's TIM_SWITCH, turns on debugging */
			Arb_connection	**dbp)	/* OUTPUT: connection to DB */
{
   static char	static_arbordata[szPATHNAME];
   static char	static_ctrl_rpt[szPATHNAME];

   char	*p;
   Arb_connection dbpCat, *dbpCatalog;
   ARBOR_SERVER_DEFINITION asd;

   char	char_server_id[6];	/* char representation of server_id for other lib calls */

   dbpCatalog = &dbpCat;

   if(argc < 3) {
	arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		basename(argv[0]), 0,
		"Bad Parameter list, Usage: %s process_name server_id",
		basename(argv[0]));
	exit(1);
   }
   arb_set_process_id(argv[1]);

   if((! numeric_string(argv[2])) || (strlen(argv[2]) < 1) || (strlen(argv[2]) > 3)) {
	arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), 0,
		"Bad Parameter list (Invalid server_id: %s), Usage: %s process_name server_id",
		argv[2], basename(argv[0]));
	exit(1);
   }
   *server_id = atoi(argv[2]);

   if((*server_id <= 0) || (*server_id > 99)) {
	arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"Invalid server_id: %s, Usage: %s process_name server_id",
		argv[2], basename(argv[0]));
	exit(1);
   }
   sprintf(char_server_id, "%02d", *server_id);	/* char string server_id */

   if((p = getenv("ARBORDATA")) == NULL) {
	arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"%s ERROR: unable to get ARBORDATA env variable",
		basename(argv[0]));
	exit(1);
   }
   strcpy(static_arbordata, p);
   *arbordata = static_arbordata;

   if(access(*arbordata, R_OK + X_OK)) {
	arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"%s ERROR: unable to access ARBORDATA directory: %s",
		basename(argv[0]), *arbordata);
	exit(1);
   }

   if(open_activity_log(arb_get_process_id(), *server_id) == FAILURE) {
	arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"%s ERROR: Unable to open activity log file",
		basename(argv[0]));
	exit(1);
   }

   if(init_login_record(arb_get_process_id()) == FAILURE) {
	arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"%s ERROR: Database login record initialization failed!",
		basename(argv[0]));
	exit(1);
   }

   /* Register default database error handler before any database work
   ** gets done.
   */
   arb_set_db_err_fn(mod_default_db_err);

   /* Note this isn't the only chance. Once DB connection is open, we will
   ** look for a DEBUG parameter for the given module in SYSTEM_PARAMETERS.
   ** If there is one, that will also result in debug SQL log file being
   ** opened.
   **
   ** If we are *NOT* EC/Arbor, start debug now, if appropriate. If we *ARE*
   ** EC/Arbor, then delay setting debug mode until after counting EMFs.
   */
#ifndef ECARBOR
   if(debug_flag) {
	arb_set_db_debug_level(MEDIUM_DEBUG);
	set_debug(module_name, *server_id, argv[0]);
   }
#endif

   /* Temporarily login to Catalog db. This connection will be used
   ** for the SERVER_DEFINITION lookup to get entry for server_id from
   ** command line. This is Arbor server for process to run against.
   */
   if(arborm_login_to_catalog(ARB_STD_CONNECT, &dbpCatalog) != SUCCESS) {
	   arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"%s ERROR: Unable to login to Catalog DB",
		basename(argv[0]));
	   exit(1);
   }

   /* Now login to proper Arbor server.
   */
   if(arborm_login_to_server_id(dbpCatalog, *server_id,
				ARB_STD_CONNECT, dbp) != SUCCESS) {
	   arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"%s ERROR logging into Arbor server_id %d",
		basename(argv[0]), *server_id);
	   exit(1);
   }

   /* EC/Arbor: max active EMF check. Number of EMF's for EC/Arbor is
   ** restricted (client should use full-license Arbor/BP if they need
   ** to exceed the HARDCODED EC/Arbor limit).
   */
   if(count_equip(*dbp, module_name) != SUCCESS) {
      exit(1);
   }

   /* If we are EC, we skipped start of debug mode above.
   /* In this case, start debug now, if appropriate.
   */
#ifdef ECARBOR
      if(debug_flag) {
	arb_set_db_debug_level(MEDIUM_DEBUG);
	set_debug(module_name, *server_id, argv[0]);
      }
#endif	/* ECARBOR */

   /* Get SERVER_DEFINITION info for server process is running
   ** against (i.e., one just logged into above). This is just
   ** used to reset the login record so that future login's to
   ** "default" log into the proper server.
   */
   memset(&asd, 0, sizeof(asd));
   asd.server_id = *server_id;	/* info for this server */
   if(retrieve_server_info(dbpCatalog, &asd) != SUCCESS) {
	   arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"%s ERROR: Unable to get server info for server %d from Catalog DB",
		basename(argv[0]), *server_id);
	   exit(1);
   }

   /* Resetting login record, incase application uses it again,
   ** i.e., for future calls to arborm_login_to_default().
   ** Note that NULL args means not to change corresponding login
   ** record field.
   */
   set_login_record(asd.dsquery, asd.ds_database, NULL, NULL, NULL);

   /* We no longer need temporary Catalog DB connection, so close it.
   */
   if(arb_close(dbpCatalog, TRUE) != SUCCESS) {
	   arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"%s ERROR logging out of default database",
		basename(argv[0]));
	   exit(1);
   }

   initialize_message_system(module_name, *dbp);
   emit(module_name, __FILE__, __LINE__, STARTUP_MSG_MSA,
	module_name, arb_get_process_id(), char_server_id);

   /* Check msg_q & BEM status, unless we are BEM */

   /* The "ARBOR_SKIP_BEM_CHECK" unix environment variable can be
   ** used to cause module to skip the BEM alive check.  This is
   ** purposely undocumented and should only be used for unit
   ** testing and the like. Clients should NEVER become aware of
   ** this "feature".
   */
   if((p = getenv("ARBOR_SKIP_BEM_CHECK")) == NULL) {

     if(strcmp(module_name, "BEM") != 0) {

       if(msg_q_init() == FAILURE) {
	  emit(module_name, __FILE__, __LINE__, MSG_Q_INIT_ERR,
		module_name, arb_get_process_id(), errno);
	  exit(1);
       }

       if(check_bem_status(*dbp) == FAILURE) {
	  emit(module_name, __FILE__, __LINE__, BEM_NOT_RUNNING,
		module_name, arb_get_process_id());
	  exit(1);
       }
     }
   }

   /* If we get this far, dbp is connected to the proper Arbor server.
   ** Get module's TRA_SWITCH (trace / debug) and TIM_SWITCH (timing).
   ** If debug_flag not already set, and module's TRA_SWITCH is TRUE,
   ** then turn on debug SQL log. If debug_flag already set, then we've
   ** already opened debug SQL log.
   **
   ** If TIM_SWITCH was set, we will initialize the perf timer, i.e.,
   ** initialize the timing structures. We will not actually start any
   ** timers, that is up to the individual calling application.  Note
   ** that the init_perf_timer() can be safely called multiple times
   ** Thus it's okay for the calling application to also call it.
   */
   if(get_system_parameter_int(*dbp, module_name, "TRA_SWITCH", tra_switch) == FAILURE)
	*tra_switch = FALSE;

   if(get_system_parameter_int(*dbp, module_name, "TIM_SWITCH", tim_switch) == FAILURE)
	*tim_switch = FALSE;

   if(!debug_flag && *tra_switch) {
	arb_set_db_debug_level(MEDIUM_DEBUG);
	set_debug(module_name, *server_id, argv[0]);
   }

   if(*tim_switch)
   {
      if(init_perf_timer() != SUCCESS)
      {
	printf("\n\nCAP ERROR: Cannot initialize timing structures\n\n");
	exit(-1);
      }
   }

   strcpy(static_ctrl_rpt, ctrl_rpt_path(arb_get_process_id()));
   if(static_ctrl_rpt[0] == '\0') {
	arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"%s ERROR: unable to determine ctrl report pathname",
		basename(argv[0]));
	exit(1);
   }
   *ctrl_rpt_fname = static_ctrl_rpt;

   return SUCCESS;
}