处理TAP国际漫游话单的几种类库使用方法
来源:互联网 发布:北京哪里有mac专柜 编辑:程序博客网 时间:2024/05/01 08:24
snacc
这个库比较早,最早是1997年,2002年的版本是1.4,后面没有更新。在unix环境使用没问题,在linux环境下编译不过去。下面是unix环境下的使用方法。
- 升级make->gmake
http://ftp.gnu.org/gnu/make/make-3.75.tar.gz
编译snacc
cd snacc/compiler
make./snacc
Usage: ./snacc [-h] [-P] [-t] [-v] [-e] [-d] [-p] [-f] [-c | -C | -[T|O] <table output file> | -idl ] [-u <useful types ASN.1 file>] [-mm] [-mf <max file name length>] [-l <neg number>] <ASN.1 file list>
编译c-lib
cd snacc/c-lib
make编译tap031111
cd snacc/c-examples/tap031111
make
asn1c
这个是目前使用的比较广泛的一个库
http://lionet.info/asn1c/blog/
http://lionet.info/soft/asn1c-0.9.27.tar.gz
编译asn1c
cd asn1c-0.9.27
./configure & make
asn1c-0.9.27/asn1c/asn1c即为asn1c编译器建立自己的TAP转换程序所在目录
mkdir tap031001
cd tap031001
把tap031111.asn1文件放到该目录下
asn1c-0.9.27/asn1c/asn1c -fnative-types tap031001.asn1
编译器会在当前目录下生成很多.h,.c文件
将该该目录下的convert-example.c重命名为自己的文件名,如main.c
#include <stdio.h>#include <sys/types.h>#include <DataInterChange.h> /* DataInterChange ASN.1 type *//* * This is a custom function which writes the * encoded output into some FILE stream. */static intwrite_out(const void *buffer, size_t size, void *app_key) { FILE *out_fp = app_key; size_t wrote; wrote = fwrite(buffer, 1, size, out_fp); return (wrote == size) ? 0 : -1;}static int decode(const char *filename){ char buf[10240]; /* Temporary buffer */ DataInterChange_t *data_inter_change = 0; /* Type to decode */ asn_dec_rval_t rval; /* Decoder return value */ FILE *fp; /* Input file handler */ size_t size; /* Number of bytes read */ /* Open input file as read-only binary */ fp = fopen(filename, "rb"); if(!fp) { perror(filename); exit(66); /* better, EX_NOINPUT */ } /* Read up to the buffer size */ size = fread(buf, 1, sizeof(buf), fp); fclose(fp); if(!size) { fprintf(stderr, "%s: Empty or broken\n", filename); exit(65); /* better, EX_DATAERR */ } /* Decode the input buffer as DataInterChange type */ rval = ber_decode(0, &asn_DEF_DataInterChange, (void **)&data_inter_change, buf, size); if(rval.code != RC_OK) { fprintf(stderr, "%s: Broken DataInterChange encoding at byte %ld\n", filename, (long)rval.consumed); exit(65); /* better, EX_DATAERR */ } /* Print the decoded DataInterChange type as XML */ xer_fprint(stdout, &asn_DEF_DataInterChange, data_inter_change); return 0;}int main(int ac, char **av) { const char *filename = av[1]; /* BER encode the data if filename is given */ if(ac < 2) { fprintf(stderr, "Specify filename for BER output\n"); return -1; } decode(filename); return 0; /* Encoding finished successfully */}
cc -I. -o rdecode *.c
生成执行文件rdecode会直接将tap文件打印成xml文件
后面可以再用php处理这个xml文件
tap3xml
一个perl的转换库,最新版本支持tap0312,这个库是专门转换tap3文件的
安装tap3xml的perl支持库
http://www.tap3edit.com/
wget http://tap3edit.com/download/TAP3-Tap3edit-0.33.tar.gz
wget http://tap3edit.com/download/Convert-ASN1-0.19.tar.gz
wget http://search.cpan.org/CPAN/authors/id/M/MA/MAKAMAKA/JSON-2.90.tar.gz
安装上面这三个perl库
perl Makefile.PL
make
make install写一个tap3话单转换的prl脚本文件
use JSON;use TAP3::Tap3edit;use Data::Dumper;$Data::Dumper::Indent=1;$Data::Dumper::Quotekeys=1;$Data::Dumper::Useqq=1;$filename=shift;if ( ! $filename ) { die "Usage: $0 tapname\n";}$tap3 = TAP3::Tap3edit->new();$tap3->decode($filename) or die $tap3->error;$struct=$tap3->structure;$json = JSON->new->encode($struct);print "$json\n";exit();my $key;# Will scan all the calls for Camel attachments.foreach $key ( @{$struct->{'transferBatch'}->{'callEventDetails'} } ) { foreach ( keys %{$key} ) { print "This call is: $_\n"; print Dumper( $key->{$_} ); }}
按自己的需要,也可以输出成json格式
- 同时他也提供了一个tap3xml的C的源代码
http://www.tap3edit.com/call.php?url=./download/tap3xml-0.18.zip
可以直接将tap文件转换成xml文件
- 处理TAP国际漫游话单的几种类库使用方法
- JavaScript库的事件处理的几种类型(mootool)
- 《shell脚本学习指南》----字段处理的几种类型
- js 几种类型的事件处理程序
- js 几种类型的事件处理程序
- js 几种类型的事件处理程序
- linux下tap的一种使用方法
- linux下tap的一种使用方法
- LTE 国际漫游
- 小话"外包"的几种类型?
- 学习国际机票:航程的种类
- 几种类的sizeof
- AlertDialog的种类和使用方法
- Hibernate Annotation关系映射的几种类型映射用法及使用方法
- Hibernate Annotation关系映射的几种类型映射用法及使用方法
- Hibernate Annotation关系映射的几种类型映射用法及使用方法
- 单例的实现种类
- NullPointerException 的几种类型
- 用到MNIST数据集的实验(总结中……)
- 【LeetCode】 17. Letter Combinations of a Phone Number
- 学生信息系统之优化(一)之ascii码
- Codeforces 665C Simple Strings【暴力,贪心】
- linux命令
- 处理TAP国际漫游话单的几种类库使用方法
- 关于conversation generation的论文笔记
- 1.认识Makefile文件
- 2015年终总结
- python实现简单爬虫功能
- 2.变量
- STM32_DAC输出电压
- FZU Problem 2231 平行四边形数
- LeetCode 91 Decode Ways(编码方式)(*)