版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kongshuai19900505/article/details/83014774
目录
源码来自libghttp页面可以参考链接,libghttp的安装步骤如下:
1.1下载源码
Download (HTTP): http://ftp.gnome.org/pub/gnome/sources/libghttp/1.0/libghttp-1.0.9.tar.gz
Download (FTP): ftp://ftp.gnome.org/pub/gnome/sources/libghttp/1.0/libghttp-1.0.9.tar.gz
Download MD5 sum: 0690e7456f9a15c635f240f3d6d5dab2
Download size: 147 KB
Estimated disk space required: 1.5 MB
Estimated build time: less than 0.1 SBU
下载完毕解压之后查看文件:
[root@localhost code]# tar -zxvf libghttp-1.0.9.tar.gz
[root@localhost code]# tree libghttp-1.0.9
libghttp-1.0.9
├── aclocal.m4
├── AUTHORS
├── ChangeLog
├── config.guess
├── config.sub
├── configure
├── configure.in
├── COPYING
├── COPYING.LIB
├── doc
│ └── ghttp.html
├── ghttp.c
├── ghttpConf.sh.in
├── ghttp_constants.h
├── ghttp.h
├── http_base64.c
├── http_base64.h
├── http_date.c
├── http_date.h
├── http_global.h
├── http_hdrs.c
├── http_hdrs.h
├── http_req.c
├── http_req.h
├── http_resp.c
├── http_resp.h
├── http_trans.c
├── http_trans.h
├── http_uri.c
├── http_uri.h
├── INSTALL
├── install-sh
├── libghttp.spec
├── libghttp.spec.in
├── ltconfig
├── ltmain.sh
├── Makefile.am
├── Makefile.in
├── missing
├── mkinstalldirs
├── NEWS
├── README
└── TODO
1 directory, 42 files
1.2 编译安装
./configure --prefix=/opt/gnome-1.4 && make
make install &&
install -v -m644 -D doc/ghttp.html \
/opt/gnome-1.4/share/doc/libghttp-1.0.9/ghttp.html
按照上述步骤安装受质疑系统auto工具的版本,有的可能会出错比如报如下错误
configure: error: libtool configure failed
并且代码看起来有些乱,反正是不舒服,因此修改了一下代码结构
1.3 整理文件目录结构
[root@localhost libghttp]# tree
.
├── autogen.sh
├── configure.ac
├── Makefile.am
└── src
├── ghttp.c
├── ghttp_constants.h
├── ghttp.h
├── http_base64.c
├── http_base64.h
├── http_date.c
├── http_date.h
├── http_global.h
├── http_hdrs.c
├── http_hdrs.h
├── http_req.c
├── http_req.h
├── http_resp.c
├── http_resp.h
├── http_trans.c
├── http_trans.h
├── http_uri.c
├── http_uri.h
└── Makefile.am
1 directory, 232 files
这里面只是把源文件提取出来了,将所有的源文件都集中到了src下面,外文增加了autogen.sh configure.ac Makefile.am三个文件,以及src下面也增加了Makefile.am这样就不会出现automake工具版本不一致的时候报出的上述错误了,可以随时随地的进行编译, autogen.sh文件就不需要解释了,就是讲automake流程集中到了脚本中,文件可以参考https://blog.csdn.net/kongshuai19900505/article/details/79104442
configure.ac文件内容如下:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([libghttp],[1.0],[[email protected]])
AC_SUBST([PACKAGE_RELEASE],[1.0],[[email protected]])
AM_INIT_AUTOMAKE(libghttp,1.0)
AC_CONFIG_SRCDIR([src/ghttp.c])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile
src/Makefile])
# Checks for programs.
AC_PROG_CC
AC_PROG_LIBTOOL
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([stddef.h string.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_TYPE_SIZE_T
# Checks for library functions.
AC_FUNC_REALLOC
AC_CHECK_FUNCS([memset socket])
AC_OUTPUT
Makefile.am文件内容:
SUBDIRS = src
.PHONY: auto_clean
auto_clean: distclean
find . -name Makefile.in -exec rm -f {} \;
rm -rf autom4te.cache
rm -f missing aclocal.m4 config.h.in config.guess config.sub ltmain.sh install-sh configure depcomp compile
src/Makefile.am文件内容:
lib_LTLIBRARIES=libghttp.la
libghttp_la_SOURCES=ghttp.c http_base64.c http_date.c http_hdrs.c http_req.c http_resp.c http_trans.c http_uri.c ghttp_constants.h ghttp.h http_base64.h http_date.h http_global.h http_hdrs.h http_req.h http_resp.h http_trans.h http_uri.h
libghttp_la_LIBADD=
include_HEADERS=
1.4 编译
[root@localhost libghttp-1.0.9]# ./autogen.sh
[root@localhost libghttp-1.0.9]# ./configure
[root@localhost libghttp-1.0.9]# make
1.5 查看库
编译完毕后就可以查看编译出来的库在src/.lib目录中
[root@localhost libghttp-1.0.9]# ll src/.libs/
总用量 492
-rw-r--r--. 1 root root 43128 10月 11 17:21 ghttp.o
-rw-r--r--. 1 root root 8600 10月 11 17:21 http_base64.o
-rw-r--r--. 1 root root 11296 10月 11 17:21 http_date.o
-rw-r--r--. 1 root root 26296 10月 11 17:21 http_hdrs.o
-rw-r--r--. 1 root root 20592 10月 11 17:21 http_req.o
-rw-r--r--. 1 root root 38792 10月 11 17:21 http_resp.o
-rw-r--r--. 1 root root 18360 10月 11 17:21 http_trans.o
-rw-r--r--. 1 root root 12360 10月 11 17:21 http_uri.o
-rw-r--r--. 1 root root 180626 10月 11 17:21 libghttp.a
lrwxrwxrwx. 1 root root 14 10月 11 17:21 libghttp.la -> ../libghttp.la
-rw-r--r--. 1 root root 924 10月 11 17:21 libghttp.lai
lrwxrwxrwx. 1 root root 17 10月 11 17:21 libghttp.so -> libghttp.so.0.0.0
lrwxrwxrwx. 1 root root 17 10月 11 17:21 libghttp.so.0 -> libghttp.so.0.0.0
-rwxr-xr-x. 1 root root 111736 10月 11 17:21 libghttp.so.0.0.0
这样就编译完毕了,但是没有写安装的代码,用户可以自己补充。
2 文件说明
ghttp源码中文件不多算上头文件也就是十几个,代码量更少也就几千行,各个文件如下:
文件 | 说明 |
ghttp.c ghttp.h |
ghttplib对外接口文件 |
http_base64.c http_base64.h |
请求数据加密文件 |
http_date.c http_date.h |
http中的时间操作代码 |
http_hdrs.c http_hdrs.h |
http报文头处理文件 |
http_req.c http_req.h |
http请求文件 |
http_resp.c http_resp.h |
http应答代码文件 |
http_trans.c http_trans.h |
网络层代码文件 |
http_uri.c http_uri.h |
url处理文件 |
ghttp_constants.h | http报文头定义文件 |
http_global.h | 全局文件 |
3 文件依赖关系
ghttp.h文件中是所有对外 的接口和结构体,各个文件之间的依赖也非常的简单,如图所示