Commit 57491b3e by BoxuanXu

Initial commit

0 parents
Showing with 4976 additions and 0 deletions
#!/bin/bash
#__website__ = "www.seetatech.com"
#__author__ = "seetatech"
#__editor__ = "xuboxuan"
#__Date__ = "20170908"
s_pwd=$PWD
#begin install common
if [ ! -s "/usr/lib64/libfastcommon.so" ];then
echo "Begin install common file"
if [ ! -d "libfastcommon" ];then
echo "Begin download libfastcommon"
git clone https://github.com/happyfish100/libfastcommon.git
cd libfastcommon
else
echo "Don't need to download libfastcommon"
cd libfastcommon
fi
chmod +x make.sh
./make.sh
./make.sh install
else
echo "fastcommon has been installed"
fi
if [ -s "/usr/lib64/libfastcommon.so" ];then
echo "common file install success"
else
echo "common file install failed"
exit 1
fi
cd $s_pwd
#begin install fastdfs-pro
if [ ! -s "/usr/local/fastdfs-pro/bin/fdfs_test" ];then
echo "Begin install fastdfs"
if [ ! -d "fastdfs-pro" ];then
echo "Begin download fastdfs:"
#git clone https://github.com/happyfish100/fastdfs.git
#git clone git@47.92.110.187:shenyizhong/fastdfs-pro.git
wget -c ftp://192.168.1.244/pub/fastdfs-pro.tar.gz
tar xzvf fastdfs-pro.tar.gz
cd fastdfs-pro
git checkout dev
else
echo "Don't need to download fastdfs"
cd fastdfs-pro
fi
chmod +x make.sh
./make.sh
./make.sh install
echo \#\!/bin/sh >> /etc/profile.d/fastdfs-pro.sh
echo "export FASTDFS_PRO_HOME=/usr/local/fastdfs-pro" >> /etc/profile.d/fastdfs-pro.sh
echo "export PATH=\$PATH:\$FASTDFS_PRO_HOME/bin" >> /etc/profile.d/fastdfs-pro.sh
echo "export C_INCLUDE_PATH=\$C_INCLUDE_PATH:\$FASTDFS_PRO_HOME/include" >> /etc/profile.d/fastdfs-pro.sh
echo "export CPLUS_INCLUDE_PATH=\$CPLUS_INCLUDE_PATH:\$FASTDFS_PRO_HOME/include" >> /etc/profile.d/fastdfs-pro.sh
source /etc/profile
ln -s /usr/local/fastdfs-pro/lib64/libfdfsclient.so /usr/lib64/libfdfsclient.so
ln -s /usr/local/fastdfs-pro/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
#copy configure file to etc dir
cp conf/http.conf conf/mime.types /etc/fdfs
echo "Begin edit configure file"
echo "finish edit configure file"
else
echo "fastdfs has been installed"
fi
if [ -s "/usr/bin/fdfs_test" ];then
echo "fastdfs install success!!!"
else
echo "fastdfs install failed"
exit 1
fi
cd $s_pwd
cp change_storage_conf.sh /etc/fdfs/
#install fastdfs-nginx-model
if [ ! -d "fastdfs-nginx-module" ];then
echo "Begin download fastdfs-nginx-module:"
git clone https://github.com/happyfish100/fastdfs-nginx-module
cd fastdfs-nginx-module/src
else
echo "Don't need to download fastdfs-nginx-module"
cd fastdfs-nginx-module/src
fi
cp mod_fastdfs.conf /etc/fdfs
ln -s /data/fastdfs/storage/data/ /data/fastdfs/storage/data/M00
echo "FastDFS install success;"
cd $s_pwd
#download nginx-1.8.1
if [ ! -s "nginx-1.8.1.tar.gz" ];then
echo "Begin download nginx-1.8.1.tar.gz:"
wget -c -r http://nginx.org/download/nginx-1.8.1.tar.gz
tar -xvf nginx.org/download/nginx-1.8.1.tar.gz -C /usr/local
else
echo "Don't need to download nginx-1.8.1.tar.gz"
tar -xvf nginx-1.8.1.tar.gz -C /usr/local
fi
echo "nginx down success;"
unzip pcre-8.41.zip
cp -r pcre-8.41 /usr/local/pcre-8.41
tar zxvf openssl-1.0.2l.tar.gz
cp -r openssl-1.0.2l /usr/local/openssl-1.0.2l
tar zxvf zlib-1.2.11.tar.gz
cp -r zlib-1.2.11 /usr/local/zlib-1.2.11
cd /usr/local/pcre-8.41/
./configure
make
make install
cd /usr/local/openssl-1.0.2l/
./config
make
make install
cd /usr/local/zlib-1.2.11/
./configure
make
make install
if [ ! -d "/usr/local/nginx" ];then
cd /usr/local/nginx-1.8.1/
./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-openssl=../openssl-1.0.2l --with-pcre=../pcre-8.41 --with-zlib=../zlib-1.2.11 --add-module=$s_pwd/fastdfs-nginx-module/src
make
make install
cp $s_pwd/nginx.conf /usr/local/nginx/
else
echo "nginx has been installed"
fi
if [ -s "/usr/local/nginx" ];then
echo "nginx install success!!!"
else
echo "nginx install failed"
exit 1
fi
#!/bin/bash
#__website__ = "www.seetatech.com"
#__author__ = "seetatech"
#__editor__ = "xuboxuan"
#__Date__ = "20170908"
s_pwd=$PWD
#begin install common
if [ ! -s "/usr/lib64/libfastcommon.so" ];then
echo "Begin install common file"
if [ ! -d "libfastcommon" ];then
echo "Begin download libfastcommon"
git clone https://github.com/happyfish100/libfastcommon.git
cd libfastcommon
else
echo "Don't need to download libfastcommon"
cd libfastcommon
fi
chmod +x make.sh
./make.sh
./make.sh install
else
echo "fastcommon has been installed"
fi
if [ -s "/usr/lib64/libfastcommon.so" ];then
echo "common file install success"
else
echo "common file install failed"
exit 1
fi
cd $s_pwd
#begin install fastdfs-pro
if [ ! -s "/usr/local/fastdfs-pro/bin/fdfs_test" ];then
echo "Begin install fastdfs"
if [ ! -d "fastdfs-pro" ];then
echo "Begin download fastdfs:"
#git clone https://github.com/happyfish100/fastdfs.git
#git clone git@47.92.110.187:shenyizhong/fastdfs-pro.git
wget -c ftp://192.168.1.244/pub/fastdfs-pro.tar.gz
tar xzvf fastdfs-pro.tar.gz
cd fastdfs-pro
git checkout dev
else
echo "Don't need to download fastdfs"
cd fastdfs-pro
fi
chmod +x make.sh
./make.sh
./make.sh install
echo \#\!/bin/sh >> /etc/profile.d/fastdfs-pro.sh
echo "export FASTDFS_PRO_HOME=/usr/local/fastdfs-pro" >> /etc/profile.d/fastdfs-pro.sh
echo "export PATH=\$PATH:\$FASTDFS_PRO_HOME/bin" >> /etc/profile.d/fastdfs-pro.sh
echo "export C_INCLUDE_PATH=\$C_INCLUDE_PATH:\$FASTDFS_PRO_HOME/include" >> /etc/profile.d/fastdfs-pro.sh
echo "export CPLUS_INCLUDE_PATH=\$CPLUS_INCLUDE_PATH:\$FASTDFS_PRO_HOME/include" >> /etc/profile.d/fastdfs-pro.sh
source /etc/profile
ln -s /usr/local/fastdfs-pro/lib64/libfdfsclient.so /usr/lib64/libfdfsclient.so
ln -s /usr/local/fastdfs-pro/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
#copy configure file to etc dir
cp conf/http.conf conf/mime.types /etc/fdfs
echo "Begin edit configure file"
echo "finish edit configure file"
else
echo "fastdfs has been installed"
fi
if [ -s "/usr/bin/fdfs_test" ];then
echo "fastdfs install success!!!"
else
echo "fastdfs install failed"
exit 1
fi
#install fastdfs-nginx-model
if [ ! -d "fastdfs-nginx-module" ];then
echo "Begin download fastdfs-nginx-module:"
git clone https://github.com/happyfish100/fastdfs-nginx-module
cd fastdfs-nginx-module/src
else
echo "Don't need to download fastdfs-nginx-module"
cd fastdfs-nginx-module/src
fi
cp mod_fastdfs.conf /etc/fdfs
ln -s /data/fastdfs/storage/data/ /data/fastdfs/storage/data/M00
echo "FastDFS install success;"
cd $s_pwd
cp change_tracker_conf.sh /etc/fdfs/
#download nginx-1.8.1
if [ ! -s "nginx-1.8.1.tar.gz" ];then
echo "Begin download nginx-1.8.1.tar.gz:"
wget -c -r http://nginx.org/download/nginx-1.8.1.tar.gz
tar -xvf nginx.org/download/nginx-1.8.1.tar.gz -C /usr/local
else
echo "Don't need to download nginx-1.8.1.tar.gz"
tar -xvf nginx-1.8.1.tar.gz -C /usr/local
fi
echo "nginx down success;"
unzip pcre-8.41.zip
cp -r pcre-8.41 /usr/local/pcre-8.41
tar zxvf openssl-1.0.2l.tar.gz
cp -r openssl-1.0.2l /usr/local/openssl-1.0.2l
tar zxvf zlib-1.2.11.tar.gz
cp -r zlib-1.2.11 /usr/local/zlib-1.2.11
cd /usr/local/pcre-8.41/
./configure
make
make install
cd /usr/local/openssl-1.0.2l/
./config
make
make install
cd /usr/local/zlib-1.2.11/
./configure
make
make install
if [ ! -d "/usr/local/nginx" ];then
cd /usr/local/nginx-1.8.1/
./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-openssl=../openssl-1.0.2l --with-pcre=../pcre-8.41 --with-zlib=../zlib-1.2.11 --add-module=$s_pwd/fastdfs-nginx-module/src
make
make install
cp $s_pwd/nginx.conf /usr/local/nginx/
else
echo "nginx has been installed"
fi
if [ -s "/usr/local/nginx" ];then
echo "nginx install success!!!"
else
echo "nginx install failed"
exit 1
fi
#!/bin/bash
arr=$(echo $GROUP|tr "," "\n")
for g in $arr;do
mkdir -p /data/fastdfs/storage$g
#edit fastdfs's configure file
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage_group$g.conf
#edit storage's configure file
sed -i "s/base_path=\/home\/yuqing\/fastdfs/base_path=\/data\/fastdfs\/storage$g/g" /etc/fdfs/storage_group$g.conf
sed -i "s/store_path0=\/home\/yuqing\/fastdfs/store_path0=\/data\/fastdfs\/storage$g/g" /etc/fdfs/storage_group$g.conf
sed -i "s/tracker_server=192.168.209.121:22122/tracker_server=$TRACKER_HOST:22122/g" /etc/fdfs/storage_group$g.conf
sed -i "s/group_name=group1/group_name=group$g/g" /etc/fdfs/storage_group$g.conf
if [ ${#g} -lt 2 ];then
sed -i "s/port=23000/port=2300$g/g" /etc/fdfs/storage_group$g.conf
elif [ ${#g} -lt 3 ];then
sed -i "s/port=23000/port=230$g/g" /etc/fdfs/storage_group$g.conf
elif [ ${#g} -lt 4 ];then
sed -i "s/port=23000/port=23$g/g" /etc/fdfs/storage_group$g.conf
fi
/usr/bin/fdfs_storaged /etc/fdfs/storage_group$g.conf
done
pid=`ps -ef | grep nginx | grep -v grep | awk '{print $2}'`
if [ "${pid}" = "" ];then
/usr/local/nginx/nginx
else
kill -9 $pid
/usr/local/nginx/nginx
fi
#!/bin/bash
echo "Begin edit configure file"
#create three dir to save tracker storage and client data
mkdir -p /data/fastdfs/tracker
mkdir -p /data/fastdfs/client
mkdir -p /data/fastdfs/storage
#edit fastdfs's configure file
cd /etc/fdfs
cp client.conf.sample client.conf
cp tracker.conf.sample tracker.conf
cp storage.conf.sample storage.conf
#edit tracker's configure file
sed -i "s/base_path=\/home\/yuqing\/fastdfs/base_path=\/data\/fastdfs\/tracker/g" tracker.conf
#edit client's configure file
sed -i "s/base_path=\/home\/yuqing\/fastdfs/base_path=\/data\/fastdfs\/client/g" client.conf
sed -i "s/tracker_server=192.168.0.197:22122/tracker_server=$TRACKER_HOST:22122/g" client.conf
sed -i "s/store_path0=\/home\/yuqing\/fastdfs/store_path0=\/data\/fastdfs\/storage/g" mod_fastdfs.conf
sed -i "s/tracker_server=tracker:22122/tracker_server=$TRACKER_HOST:22122/g" mod_fastdfs.conf
sed -i "s/url_have_group_name = false/url_have_group_name = true/g" mod_fastdfs.conf
sed -i "s/base_path=\/home\/yuqing\/fastdfs/base_path=\/data\/fastdfs\/storage/g" /etc/fdfs/storage.conf
sed -i "s/store_path0=\/home\/yuqing\/fastdfs/store_path0=\/data\/fastdfs\/storage/g" /etc/fdfs/storage.conf
sed -i "s/tracker_server=192.168.209.121:22122/tracker_server=$TRACKER_HOST:22122/g" /etc/fdfs/storage.conf
sed -i "s/group_name=group1/group_name=group0/g" /etc/fdfs/storage.conf
arr=$(echo $ALL_GROUP|tr "," "\n")
group_num=0
for g in $arr;do
if [ "$group_num" -eq "0" ];then
group_name="group"$g
else
group_name=$group_name"\/group"$g
fi
echo [group$g] >> mod_fastdfs.conf
echo group_name=group$g >> mod_fastdfs.conf
if [ ${#g} -lt 2 ];then
echo storage_server_port=2300$g >> mod_fastdfs.conf
elif [ ${#g} -lt 3 ];then
echo storage_server_port=230$g >> mod_fastdfs.conf
elif [ ${#g} -lt 4 ];then
echo storage_server_port=23$g >> mod_fastdfs.conf
fi
echo store_path_count=1 >> mod_fastdfs.conf
echo store_path0=/data/fastdfs/storage$g >> mod_fastdfs.conf
sed -i "N;46a\}" /usr/local/nginx/nginx.conf;
sed -i "N;46angx_fastdfs_module;" /usr/local/nginx/nginx.conf;
sed -i "N;46alocation /group$g/M00 {" /usr/local/nginx/nginx.conf;
group_num=$(($group_num +1));
done
if [ "$group_num" -eq "1" ];then
sed -i "s/group_name=group1/group_name=$group_name/g" mod_fastdfs.conf
else
sed -i "s/group_count = 0/group_count = $group_num/g" mod_fastdfs.conf
sed -i "s/group_name=group1/group_name=$group_name/g" mod_fastdfs.conf
fi
echo "finish edit configure file"
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
pid=`ps -ef | grep nginx | grep -v grep | awk '{print $2}'`
if [ "${pid}" = "" ];then
/usr/local/nginx/nginx
else
kill -9 $pid
/usr/local/nginx/nginx
fi
Version 1.20 2017-05-26
* support multi regions for HTTP Range
Version 1.19 2017-04-14
* change INT64_PRINTF_FORMAT to PRId64
* ignore range->end >= file_size
* fix HTTP status when file id is invalid
Version 1.18 2016-02-24
* bug fixed: do NOT use header_only field of request,
use method field instead
Version 1.17 2014-11-22
* change include path of fastcommon and fastdfs
you must upgrade your FastDFS server to v5.04
or higher version
Version 1.16 2014-05-04
* mod_fastdfs.conf remove parameter: http.need_find_content_type
* bug fixed: remove flv duplicate start variable define
* flv support end parameter
* bug fixed: in function proxy_create_request, use r->unparsed_uri
when r->valid_unparsed_uri is true, otherwise use r->uri and r->args
Version 1.15 2013-01-13
* add storage server port config with multi groups
* support flv, you must upgrade your FastDFS server to v4.06
or higher version
Version 1.14 2012-12-29
* bug fixed: do not check store path index when not same group
you must upgrade your FastDFS server to v4.05 or higher version
* proxy handler deal headers more gracefully
* set last modified time correctly
* support multi groups
Version 1.13 2012-11-14
* support filename include storage server ID
must upgrade your FastDFS server to v4.03 or higher version
* call function fdfs_mod_init change from ngx_http_fastdfs_set to
ngx_http_fastdfs_process_init
Version 1.12 2012-10-20
* log detail error info when stat file fail
* mod_fastdfs.conf add parameter: load_fdfs_parameters_from_tracker,
not load parameters from the FDFS tracker server by default
Version 1.11 2012-08-27
* add more debug info
* use nginx error page when HTTP status is not ok
Version 1.10 2012-01-03
* use r->uri and r->args instead of r->unparsed_uri to support
rewrite correctly
Version 1.09 2011-11-26
* bug fixed: correct HTTP status when nginx send file with range
Version 1.08 2011-08-21
* add store path count in startup log info
* support HTTP range
Version 1.07 2011-07-31
* add more error log
* bug fixed: miss sub dir data in data path
Version 1.06 2011-06-11
* bug fixed: cross group does not proxy or redirect when the file upload
one day ago
* support trunk file (FastDFS server version >= 3.00)
Version 1.05 2011-03-16
* support request header if_modified_since
Version 1.04 2011-03-12
* support url parameter "filename" to specify attachment filename
* add Last-Modified header
Version 1.03 2011-01-31
* use FastDFS V2.08 client library
Version 1.02 2010-12-20
* fix signedness and signed assignment
* change ngx_http_fastdfs_proxy_handler return type from ngx_int_t to int
Version 1.01 2010-11-15
* use nginx proxy deal approach
Version 1.00 2010-11-08
* first version
Copy right 2010 Happy Fish / YuQing
This software may be copied only under the terms of the GNU General
Public License V3, Please visit the FastDFS Home Page for more detail.
English language: http://english.csource.org/
Chinese language: http://www.csource.org/
#step 1. first install the FastDFS storage server and client library,
the FastDFS version should >= 5.11. download address:
https://github.com/happyfish100/fastdfs
#step 2. install nginx server
FastDFS nginx module test passed with nginx 1.8.1,
my nginx installed in /usr/local/nginx
#step 3. download FastDFS nginx module source package and unpack it, such as:
tar xzf fastdfs_nginx_module_v1.20.tar.gz
#step 4. enter the nginx source dir, compile and install the module, such as:
cd nginx-1.8.1
./configure --add-module=/home/yuqing/fastdfs-nginx-module/src
make; make install
Notice: before compile, you can change FDFS_OUTPUT_CHUNK_SIZE and
FDFS_MOD_CONF_FILENAME macro in the config file as:
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
#step 5. config the nginx config file such as nginx.conf, add the following lines:
location /M00 {
root /home/yuqing/fastdfs/data;
ngx_fastdfs_module;
}
#step 6. make a symbol link ${fastdfs_base_path}/data/M00 to ${fastdfs_base_path}/data,
command line such as:
ln -s /home/yuqing/fastdfs/data /home/yuqing/fastdfs/data/M00
#step 7. change the config file /etc/fdfs/mod_fastdfs.conf, more detail please see it
#step 8. restart the nginx server, such as:
/usr/local/nginx/sbin/nginx -s stop; /usr/local/nginx/sbin/nginx
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
#ifndef FDFS_MOD_COMMON_H
#define FDFS_MOD_COMMON_H
#include <time.h>
#include "tracker_types.h"
#ifndef HTTP_OK
#define HTTP_OK 200
#endif
#ifndef HTTP_NOCONTENT
#define HTTP_NOCONTENT 204
#endif
#ifndef HTTP_PARTIAL_CONTENT
#define HTTP_PARTIAL_CONTENT 206
#endif
#ifndef HTTP_MOVEPERM
#define HTTP_MOVEPERM 301
#endif
#ifndef HTTP_MOVETEMP
#define HTTP_MOVETEMP 302
#endif
#ifndef HTTP_NOTMODIFIED
#define HTTP_NOTMODIFIED 304
#endif
#ifndef HTTP_BADREQUEST
#define HTTP_BADREQUEST 400
#endif
#ifndef HTTP_NOTFOUND
#define HTTP_NOTFOUND 404
#endif
#ifndef HTTP_RANGE_NOT_SATISFIABLE
#define HTTP_RANGE_NOT_SATISFIABLE 416
#endif
#ifndef HTTP_INTERNAL_SERVER_ERROR
#define HTTP_INTERNAL_SERVER_ERROR 500
#endif
#ifndef HTTP_SERVUNAVAIL
#define HTTP_SERVUNAVAIL 503
#endif
#ifndef FDFS_STORAGE_STORE_PATH_PREFIX_CHAR
#define FDFS_STORAGE_STORE_PATH_PREFIX_CHAR 'M'
#endif
#define FDFS_MAX_HTTP_RANGES 5
#define FDFS_MAX_HTTP_BOUNDARY 20
#ifdef __cplusplus
extern "C" {
#endif
struct fdfs_http_response;
typedef void (*FDFSOutputHeaders)(void *arg, struct fdfs_http_response *pResponse);
typedef int (*FDFSSendReplyChunk)(void *arg, const bool last_buff, \
const char *buff, const int size);
typedef int (*FDFSSendFile)(void *arg, const char *filename, \
const int filename_len, const int64_t file_offset, \
const int64_t download_bytes);
typedef int (*FDFSProxyHandler)(void *arg, const char *dest_ip_addr);
struct fdfs_http_resp_content_range {
int length;
char content[64];
};
struct fdfs_http_response {
int status; //HTTP status
time_t last_modified; //last modified time of the file
int redirect_url_len;
int range_len; //for redirect
int boundary_len;
short content_range_count;
int64_t content_length;
char *content_type;
char *attachment_filename;
char redirect_url[256];
char content_disposition[128];
char content_type_buff[128];
char range[256]; //for redirect
char range_content_type[64]; //for multi range content
struct fdfs_http_resp_content_range content_ranges[FDFS_MAX_HTTP_RANGES];
char last_modified_buff[32];
char boundary[FDFS_MAX_HTTP_BOUNDARY];
bool header_outputed; //if header output
};
struct fdfs_http_range {
int64_t start;
int64_t end;
};
struct fdfs_http_context {
int server_port;
short range_count;
bool header_only;
bool if_range;
struct fdfs_http_range ranges[FDFS_MAX_HTTP_RANGES];
char if_modified_since[32];
char *url;
void *arg; //for callback
FDFSOutputHeaders output_headers;
FDFSSendFile send_file; //nginx send file
FDFSSendReplyChunk send_reply_chunk;
FDFSProxyHandler proxy_handler; //nginx proxy handler
};
struct fdfs_download_callback_args {
struct fdfs_http_context *pContext;
struct fdfs_http_response *pResponse;
int64_t sent_bytes; //sent bytes
int range_index;
};
/**
* init function
* params:
* return: 0 success, !=0 fail, return the error code
*/
int fdfs_mod_init();
/**
* http request handler
* params:
* pContext the context
* return: http status code, HTTP_OK success, != HTTP_OK fail
*/
int fdfs_http_request_handler(struct fdfs_http_context *pContext);
/**
* format http datetime
* params:
* t the time
* buff the string buffer
* buff_size the buffer size
* return: 0 success, !=0 fail, return the error code
*/
//int fdfs_format_http_datetime(time_t t, char *buff, const int buff_size);
/**
* parse range parameter
* params:
* value the range value
* pContext the context
* return: 0 success, !=0 fail, return the error code
*/
int fdfs_parse_ranges(const char *value, struct fdfs_http_context *pContext);
#ifdef __cplusplus
}
#endif
#endif
ngx_addon_name=ngx_http_fastdfs_module
if test -n "${ngx_module_link}"; then
ngx_module_type=HTTP
ngx_module_name=$ngx_addon_name
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
ngx_module_libs="-lfastcommon -lfdfsclient"
ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c"
ngx_module_deps=
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
. auto/module
else
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
fi
# connect timeout in seconds
# default value is 30s
connect_timeout=2
# network recv and send timeout in seconds
# default value is 30s
network_timeout=30
# the base path to store log files
base_path=/tmp
# if load FastDFS parameters from tracker server
# since V1.12
# default value is false
load_fdfs_parameters_from_tracker=true
# storage sync file max delay seconds
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# since V1.12
# default value is 86400 seconds (one day)
storage_sync_file_max_delay = 86400
# if use storage ID instead of IP address
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# default value is false
# since V1.13
use_storage_id = false
# specify storage ids filename, can use relative or absolute path
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# since V1.13
storage_ids_filename = storage_ids.conf
# FastDFS tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
# valid only when load_fdfs_parameters_from_tracker is true
tracker_server=tracker:22122
# the port of the local storage server
# the default value is 23000
storage_server_port=23000
# the group name of the local storage server
group_name=group1
# if the url / uri including the group name
# set to false when uri like /M00/00/00/xxx
# set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx
# default value is false
url_have_group_name = false
# path(disk or mount point) count, default value is 1
# must same as storage.conf
store_path_count=1
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
# must same as storage.conf
store_path0=/home/yuqing/fastdfs
#store_path1=/home/yuqing/fastdfs1
# standard log level as syslog, case insensitive, value list:
### emerg for emergency
### alert
### crit for critical
### error
### warn for warning
### notice
### info
### debug
log_level=info
# set the log filename, such as /usr/local/apache2/logs/mod_fastdfs.log
# empty for output to stderr (apache and nginx error_log file)
log_filename=
# response mode when the file not exist in the local file system
## proxy: get the content from other storage server, then send to client
## redirect: redirect to the original storage server (HTTP Header is Location)
response_mode=proxy
# the NIC alias prefix, such as eth in Linux, you can see it by ifconfig -a
# multi aliases split by comma. empty value means auto set by OS type
# this paramter used to get all ip address of the local host
# default values is empty
if_alias_prefix=
# use "#include" directive to include HTTP config file
# NOTE: #include is an include directive, do NOT remove the # before include
#include http.conf
# if support flv
# default value is false
# since v1.15
flv_support = true
# flv file extension name
# default value is flv
# since v1.15
flv_extension = flv
# set the group count
# set to none zero to support multi-group on this storage server
# set to 0 for single group only
# groups settings section as [group1], [group2], ..., [groupN]
# default value is 0
# since v1.14
group_count = 0
# group settings for group #1
# since v1.14
# when support multi-group on this storage server, uncomment following section
#[group1]
#group_name=group1
#storage_server_port=23000
#store_path_count=2
#store_path0=/home/yuqing/fastdfs
#store_path1=/home/yuqing/fastdfs1
# group settings for group #2
# since v1.14
# when support multi-group, uncomment following section as neccessary
#[group2]
#group_name=group2
#storage_server_port=23000
#store_path_count=1
#store_path0=/home/yuqing/fastdfs
client/Makefile
client/fdfs_link_library.sh
client/test/Makefile
storage/Makefile
tracker/Makefile
Copy right 2009 Happy Fish / YuQing
FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page for more detail.
English language: http://english.csource.org/
Chinese language: http://www.csource.org/
#step 1. download libfastcommon source package from github and install it,
the github address:
https://github.com/happyfish100/libfastcommon.git
#step 2. download FastDFS source package and unpack it,
tar xzf FastDFS_v5.x.tar.gz
#for example:
tar xzf FastDFS_v5.08.tar.gz
#step 3. enter the FastDFS dir
cd FastDFS
#step 4. execute:
./make.sh
#step 5. make install
./make.sh install
#step 6. edit/modify the config file of tracker and storage
#step 7. run server programs
#start the tracker server:
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
#in Linux, you can start fdfs_trackerd as a service:
/sbin/service fdfs_trackerd start
#start the storage server:
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
#in Linux, you can start fdfs_storaged as a service:
/sbin/service fdfs_storaged start
#step 8. run test program
#run the client test program:
/usr/bin/fdfs_test <client_conf_filename> <operation>
/usr/bin/fdfs_test1 <client_conf_filename> <operation>
#for example, upload a file:
/usr/bin/fdfs_test conf/client.conf upload /usr/include/stdlib.h
#step 9. run monitor program
#run the monitor program:
/usr/bin/fdfs_monitor <client_conf_filename>
tracker server config file sample please see conf/tracker.conf
storage server config file sample please see conf/storage.conf
client config file sample please see conf/client.conf
Item detail
1. server common items
---------------------------------------------------
| item name | type | default | Must |
---------------------------------------------------
| base_path | string | | Y |
---------------------------------------------------
| disabled | boolean| false | N |
---------------------------------------------------
| bind_addr | string | | N |
---------------------------------------------------
| network_timeout | int | 30(s) | N |
---------------------------------------------------
| max_connections | int | 256 | N |
---------------------------------------------------
| log_level | string | info | N |
---------------------------------------------------
| run_by_group | string | | N |
---------------------------------------------------
| run_by_user | string | | N |
---------------------------------------------------
| allow_hosts | string | * | N |
---------------------------------------------------
| sync_log_buff_interval| int | 10(s) | N |
---------------------------------------------------
| thread_stack_size | string | 1M | N |
---------------------------------------------------
memo:
* base_path is the base path of sub dirs:
data and logs. base_path must exist and it's sub dirs will
be automatically created if not exist.
$base_path/data: store data files
$base_path/logs: store log files
* log_level is the standard log level as syslog, case insensitive
# emerg: for emergency
# alert
# crit: for critical
# error
# warn: for warning
# notice
# info
# debug
* allow_hosts can ocur more than once, host can be hostname or ip address,
"*" means match all ip addresses, can use range like this: 10.0.1.[1-15,20]
or host[01-08,20-25].domain.com, for example:
allow_hosts=10.0.1.[1-15,20]
allow_hosts=host[01-08,20-25].domain.com
2. tracker server items
---------------------------------------------------
| item name | type | default | Must |
---------------------------------------------------
| port | int | 22000 | N |
---------------------------------------------------
| store_lookup | int | 0 | N |
---------------------------------------------------
| store_group | string | | N |
---------------------------------------------------
| store_server | int | 0 | N |
---------------------------------------------------
| store_path | int | 0 | N |
---------------------------------------------------
| download_server | int | 0 | N |
---------------------------------------------------
| reserved_storage_space| string | 1GB | N |
---------------------------------------------------
memo:
* the value of store_lookup is:
0: round robin (default)
1: specify group
2: load balance (supported since V1.1)
* store_group is the name of group to store files.
when store_lookup set to 1(specify group),
store_group must be set to a specified group name.
* reserved_storage_space is the reserved storage space for system
or other applications. if the free(available) space of any stoarge
server in a group <= reserved_storage_space, no file can be uploaded
to this group (since V1.1)
bytes unit can be one of follows:
# G or g for gigabyte(GB)
# M or m for megabyte(MB)
# K or k for kilobyte(KB)
# no unit for byte(B)
3. storage server items
-------------------------------------------------
| item name | type | default | Must |
-------------------------------------------------
| group_name | string | | Y |
-------------------------------------------------
| tracker_server | string | | Y |
-------------------------------------------------
| port | int | 23000 | N |
-------------------------------------------------
| heart_beat_interval | int | 30(s) | N |
-------------------------------------------------
| stat_report_interval| int | 300(s) | N |
-------------------------------------------------
| sync_wait_msec | int | 100(ms) | N |
-------------------------------------------------
| sync_interval | int | 0(ms) | N |
-------------------------------------------------
| sync_start_time | string | 00:00 | N |
-------------------------------------------------
| sync_end_time | string | 23:59 | N |
-------------------------------------------------
| store_path_count | int | 1 | N |
-------------------------------------------------
| store_path0 | string |base_path| N |
-------------------------------------------------
| store_path# | string | | N |
-------------------------------------------------
|subdir_count_per_path| int | 256 | N |
-------------------------------------------------
|check_file_duplicate | boolean| 0 | N |
-------------------------------------------------
| key_namespace | string | | N |
-------------------------------------------------
| keep_alive | boolean| 0 | N |
-------------------------------------------------
| sync_binlog_buff_interval| int | 60s | N |
-------------------------------------------------
memo:
* tracker_server can ocur more than once, and tracker_server format is
"host:port", host can be hostname or ip address.
* store_path#, # for digital, based 0
* check_file_duplicate: when set to true, must work with FastDHT server,
more detail please see INSTALL of FastDHT. FastDHT download page:
http://code.google.com/p/fastdht/downloads/list
* key_namespace: FastDHT key namespace, can't be empty when
check_file_duplicate is true. the key namespace should short as possible
Copyright (C) 2008 Happy Fish / YuQing
FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page for more detail.
English language: http://english.csource.org/
Chinese language: http://www.csource.org/
FastDFS is an open source high performance distributed file system. It's major
functions include: file storing, file syncing and file accessing (file uploading
and file downloading), and it can resolve the high capacity and load balancing
problem. FastDFS should meet the requirement of the website whose service based
on files such as photo sharing site and video sharing site.
FastDFS has two roles: tracker and storage. The tracker takes charge of
scheduling and load balancing for file access. The storage store files and it's
function is file management including: file storing, file syncing, providing file
access interface. It also manage the meta data which are attributes representing
as key value pair of the file. For example: width=1024, the key is "width" and
the value is "1024".
The tracker and storage contain one or more servers. The servers in the tracker
or storage cluster can be added to or removed from the cluster by any time without
affecting the online services. The servers in the tracker cluster are peer to peer.
The storarge servers organizing by the file volume/group to obtain high capacity.
The storage system contains one or more volumes whose files are independent among
these volumes. The capacity of the whole storage system equals to the sum of all
volumes' capacity. A file volume contains one or more storage servers whose files
are same among these servers. The servers in a file volume backup each other,
and all these servers are load balancing. When adding a storage server to a
volume, files already existing in this volume are replicated to this new server
automatically, and when this replication done, system will switch this server
online to providing storage services.
When the whole storage capacity is insufficiency, you can add one or more
volumes to expand the storage capacity. To do this, you need to add one or
more storage servers.
The identification of a file is composed of two parts: the volume name and
the file name.
Client test code use client library please refer to the directory: client/test.
.SUFFIXES: .c .o .lo
COMPILE = $(CC) $(CFLAGS)
ENABLE_STATIC_LIB = $(ENABLE_STATIC_LIB)
ENABLE_SHARED_LIB = $(ENABLE_SHARED_LIB)
INC_PATH = -I../common -I../tracker -I/usr/include/fastcommon
LIB_PATH = $(LIBS) -lfastcommon
TARGET_PATH = $(TARGET_PREFIX)/bin
TARGET_LIB = $(TARGET_PREFIX)/lib64
TARGET_INC = $(TARGET_PREFIX)/include
CONFIG_PATH = $(TARGET_CONF_PATH)
FDFS_STATIC_OBJS = ../common/fdfs_global.o ../common/fdfs_http_shared.o \
../common/mime_file_parser.o ../tracker/tracker_proto.o \
../tracker/fdfs_shared_func.o \
../storage/trunk_mgr/trunk_shared.o \
tracker_client.o client_func.o \
client_global.o storage_client.o
STATIC_OBJS = $(FDFS_STATIC_OBJS)
FDFS_SHARED_OBJS = ../common/fdfs_global.lo ../common/fdfs_http_shared.lo \
../common/mime_file_parser.lo ../tracker/tracker_proto.lo \
../tracker/fdfs_shared_func.lo \
../storage/trunk_mgr/trunk_shared.lo \
tracker_client.lo client_func.lo \
client_global.lo storage_client.lo \
stbfclient.lo
FDFS_HEADER_FILES = ../common/fdfs_define.h ../common/fdfs_global.h \
../common/mime_file_parser.h ../common/fdfs_http_shared.h \
../tracker/tracker_types.h ../tracker/tracker_proto.h \
../tracker/fdfs_shared_func.h \
../storage/trunk_mgr/trunk_shared.h \
tracker_client.h storage_client.h storage_client1.h \
client_func.h client_global.h fdfs_client.h \
stbfclient.h
ALL_OBJS = $(STATIC_OBJS) $(FDFS_SHARED_OBJS)
ALL_PRGS = fdfs_monitor fdfs_test fdfs_test1 fdfs_crc32 fdfs_upload_file \
fdfs_download_file fdfs_delete_file fdfs_file_info \
fdfs_appender_test fdfs_appender_test1 fdfs_append_file \
fdfs_upload_appender
STATIC_LIBS = libfdfsclient.a
SHARED_LIBS = libfdfsclient.so
CLIENT_SHARED_LIBS = libfdfsclient.so
ALL_LIBS = $(STATIC_LIBS) $(SHARED_LIBS)
all: $(ALL_OBJS) $(ALL_PRGS) $(ALL_LIBS)
libfdfsclient.so:
$(COMPILE) -o $@ $< -shared $(FDFS_SHARED_OBJS) $(LIB_PATH)
libfdfsclient.a:
ar cru $@ $< $(FDFS_STATIC_OBJS)
.o:
$(COMPILE) -o $@ $< $(STATIC_OBJS) $(LIB_PATH) $(INC_PATH)
.c:
$(COMPILE) -o $@ $< $(STATIC_OBJS) $(LIB_PATH) $(INC_PATH)
.c.o:
$(COMPILE) -c -o $@ $< $(INC_PATH)
.c.lo:
$(COMPILE) -c -fPIC -o $@ $< $(INC_PATH)
install:
mkdir -p $(TARGET_PATH)
mkdir -p $(CONFIG_PATH)
mkdir -p $(TARGET_LIB)
mkdir -p $(TARGET_PREFIX)/lib
cp -f $(ALL_PRGS) $(TARGET_PATH)
if [ $(ENABLE_STATIC_LIB) -eq 1 ]; then cp -f $(STATIC_LIBS) $(TARGET_LIB); cp -f $(STATIC_LIBS) $(TARGET_PREFIX)/lib/;fi
if [ $(ENABLE_SHARED_LIB) -eq 1 ]; then cp -f $(CLIENT_SHARED_LIBS) $(TARGET_LIB); cp -f $(CLIENT_SHARED_LIBS) $(TARGET_PREFIX)/lib/;fi
mkdir -p $(TARGET_INC)/fastdfs
cp -f $(FDFS_HEADER_FILES) $(TARGET_INC)/fastdfs
if [ ! -f $(CONFIG_PATH)/client.conf.sample ]; then cp -f ../conf/client.conf $(CONFIG_PATH)/client.conf.sample; fi
clean:
rm -f $(ALL_OBJS) $(ALL_PRGS) $(ALL_LIBS)
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
// client_func.h
#include "tracker_types.h"
#include "client_global.h"
#include "ini_file_reader.h"
#ifndef _CLIENT_FUNC_H_
#define _CLIENT_FUNC_H_
typedef struct {
time_t create_timestamp;
int crc32;
int source_id; // source storage id
int64_t file_size;
char source_ip_addr[IP_ADDRESS_SIZE]; // source storage ip address
} FDFSFileInfo;
#ifdef __cplusplus
extern "C" {
#endif
#define fdfs_client_init(filename) \
fdfs_client_init_ex((&g_tracker_group), filename)
#define fdfs_client_init_from_buffer(buffer) \
fdfs_client_init_from_buffer_ex((&g_tracker_group), buffer)
#define fdfs_client_destroy() fdfs_client_destroy_ex((&g_tracker_group))
/**
* client initial from config file
* params:
* pTrackerGroup: tracker group
* conf_filename: client config filename
* return: 0 success, !=0 fail, return the error code
**/
int fdfs_client_init_ex(TrackerServerGroup *pTrackerGroup,
const char *conf_filename);
/**
* client initial from buffer
* params:
* pTrackerGroup: tracker group
* conf_filename: client config filename
* return: 0 success, !=0 fail, return the error code
**/
int fdfs_client_init_from_buffer_ex(TrackerServerGroup *pTrackerGroup,
const char *buffer);
/**
* load tracker server group
* params:
* pTrackerGroup: tracker group
* conf_filename: tracker server group config filename
* return: 0 success, !=0 fail, return the error code
**/
int fdfs_load_tracker_group(TrackerServerGroup *pTrackerGroup,
const char *conf_filename);
/**
* load tracker server group
* params:
* pTrackerGroup: tracker group
* conf_filename: config filename
* items: ini file items
* nItemCount: ini file item count
* return: 0 success, !=0 fail, return the error code
**/
int fdfs_load_tracker_group_ex(TrackerServerGroup *pTrackerGroup,
const char *conf_filename,
IniContext *pIniContext);
/**
* copy tracker server group
* params:
* pDestTrackerGroup: the dest tracker group
* pSrcTrackerGroup: the source tracker group
* return: 0 success, !=0 fail, return the error code
**/
int fdfs_copy_tracker_group(TrackerServerGroup *pDestTrackerGroup,
TrackerServerGroup *pSrcTrackerGroup);
/**
* client destroy function
* params:
* pTrackerGroup: tracker group
* return: none
**/
void fdfs_client_destroy_ex(TrackerServerGroup *pTrackerGroup);
/**
* tracker group equals
* params:
* pGroup1: tracker group 1
* pGroup2: tracker group 2
* return: true for equals, otherwise false
**/
bool fdfs_tracker_group_equals(TrackerServerGroup *pGroup1,
TrackerServerGroup *pGroup2);
/**
* get file ext name from filename, extension name do not include dot
* params:
* filename: the filename
* return: file ext name, NULL for no ext name
**/
#define fdfs_get_file_ext_name1(filename) \
fdfs_get_file_ext_name_ex(filename, false)
/**
* get file ext name from filename, extension name maybe include dot
* params:
* filename: the filename
* return: file ext name, NULL for no ext name
**/
#define fdfs_get_file_ext_name2(filename) \
fdfs_get_file_ext_name_ex(filename, true)
#define fdfs_get_file_ext_name(filename) \
fdfs_get_file_ext_name_ex(filename, true)
/**
* get file ext name from filename
* params:
* filename: the filename
* twoExtName: two extension name as the extension name
* return: file ext name, NULL for no ext name
**/
const char *fdfs_get_file_ext_name_ex(const char *filename,
const bool twoExtName);
#ifdef __cplusplus
}
#endif
#endif
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
#include <stdlib.h>
#include <string.h>
#include "client_global.h"
int g_tracker_server_http_port = 80;
TrackerServerGroup g_tracker_group = {0, 0, -1, NULL};
bool g_anti_steal_token = false;
BufferInfo g_anti_steal_secret_key = {0};
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
// client_global.h
#ifndef _CLIENT_GLOBAL_H
#define _CLIENT_GLOBAL_H
#include "common_define.h"
#include "tracker_types.h"
#include "fdfs_shared_func.h"
#ifdef __cplusplus
extern "C" {
#endif
extern int g_tracker_server_http_port;
extern TrackerServerGroup g_tracker_group;
extern bool g_anti_steal_token;
extern BufferInfo g_anti_steal_secret_key;
#define fdfs_get_tracker_leader_index(leaderIp, leaderPort) \
fdfs_get_tracker_leader_index_ex(&g_tracker_group, leaderIp, leaderPort)
#ifdef __cplusplus
}
#endif
#endif
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "fdfs_client.h"
#include "logger.h"
int main(int argc, char *argv[]) {
char *conf_filename;
char *local_filename;
ConnectionInfo *pTrackerServer;
int result;
char appender_file_id[128];
if (argc < 4) {
printf(
"Usage: %s <config_file> <appender_file_id> "
"<local_filename>\n",
argv[0]);
return 1;
}
log_init();
g_log_context.log_level = LOG_ERR;
conf_filename = argv[1];
if ((result = fdfs_client_init(conf_filename)) != 0) {
return result;
}
pTrackerServer = tracker_get_connection();
if (pTrackerServer == NULL) {
fdfs_client_destroy();
return errno != 0 ? errno : ECONNREFUSED;
}
snprintf(appender_file_id, sizeof(appender_file_id), "%s", argv[2]);
local_filename = argv[3];
if ((result = storage_append_by_filename1(
pTrackerServer, NULL, local_filename, appender_file_id)) != 0) {
printf(
"append file fail, "
"error no: %d, error info: %s\n",
result, STRERROR(result));
return result;
}
tracker_disconnect_server_ex(pTrackerServer, true);
fdfs_client_destroy();
return result;
}
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
#ifndef FDFS_CLIENT_H
#define FDFS_CLIENT_H
#include "shared_func.h"
#include "tracker_types.h"
#include "tracker_proto.h"
#include "tracker_client.h"
#include "storage_client.h"
#include "storage_client1.h"
#include "client_func.h"
#include "client_global.h"
#endif
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "hash.h"
int main(int argc, char *argv[]) {
int64_t file_size;
int64_t remain_bytes;
char *filename;
int fd;
int read_bytes;
int result;
int crc32;
char buff[512 * 1024];
if (argc < 2) {
printf("Usage: %s <filename>\n", argv[0]);
return 1;
}
filename = argv[1];
fd = open(filename, O_RDONLY);
if (fd < 0) {
printf(
"file: "__FILE__
", line: %d, "
"open file %s fail, "
"errno: %d, error info: %s\n",
__LINE__, filename, errno, STRERROR(errno));
return errno != 0 ? errno : EACCES;
}
if ((file_size = lseek(fd, 0, SEEK_END)) < 0) {
printf(
"file: "__FILE__
", line: %d, "
"call lseek fail, "
"errno: %d, error info: %s\n",
__LINE__, errno, STRERROR(errno));
close(fd);
return errno;
}
if (lseek(fd, 0, SEEK_SET) < 0) {
printf(
"file: "__FILE__
", line: %d, "
"call lseek fail, "
"errno: %d, error info: %s\n",
__LINE__, errno, STRERROR(errno));
close(fd);
return errno;
}
crc32 = CRC32_XINIT;
result = 0;
remain_bytes = file_size;
while (remain_bytes > 0) {
if (remain_bytes > sizeof(buff)) {
read_bytes = sizeof(buff);
} else {
read_bytes = remain_bytes;
}
if (read(fd, buff, read_bytes) != read_bytes) {
printf(
"file: "__FILE__
", line: %d, "
"call lseek fail, "
"errno: %d, error info: %s\n",
__LINE__, errno, STRERROR(errno));
result = errno != 0 ? errno : EIO;
break;
}
crc32 = CRC32_ex(buff, read_bytes, crc32);
remain_bytes -= read_bytes;
}
close(fd);
if (result == 0) {
crc32 = CRC32_FINAL(crc32);
printf("%u\n", crc32);
}
return result;
}
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "fdfs_client.h"
#include "logger.h"
int main(int argc, char *argv[]) {
char *conf_filename;
ConnectionInfo *pTrackerServer;
int result;
char file_id[128];
if (argc < 3) {
printf("Usage: %s <config_file> <file_id>\n", argv[0]);
return 1;
}
log_init();
g_log_context.log_level = LOG_ERR;
ignore_signal_pipe();
conf_filename = argv[1];
if ((result = fdfs_client_init(conf_filename)) != 0) {
return result;
}
pTrackerServer = tracker_get_connection();
if (pTrackerServer == NULL) {
fdfs_client_destroy();
return errno != 0 ? errno : ECONNREFUSED;
}
snprintf(file_id, sizeof(file_id), "%s", argv[2]);
if ((result = storage_delete_file1(pTrackerServer, NULL, file_id)) != 0) {
printf(
"delete file fail, "
"error no: %d, error info: %s\n",
result, STRERROR(result));
}
tracker_disconnect_server_ex(pTrackerServer, true);
fdfs_client_destroy();
return result;
}
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "fdfs_client.h"
#include "logger.h"
int main(int argc, char *argv[]) {
char *conf_filename;
char *local_filename;
ConnectionInfo *pTrackerServer;
int result;
char file_id[128];
int64_t file_size;
int64_t file_offset;
int64_t download_bytes;
if (argc < 3) {
printf(
"Usage: %s <config_file> <file_id> "
"[local_filename] [<download_offset> "
"<download_bytes>]\n",
argv[0]);
return 1;
}
log_init();
g_log_context.log_level = LOG_ERR;
ignore_signal_pipe();
conf_filename = argv[1];
if ((result = fdfs_client_init(conf_filename)) != 0) {
return result;
}
pTrackerServer = tracker_get_connection();
if (pTrackerServer == NULL) {
fdfs_client_destroy();
return errno != 0 ? errno : ECONNREFUSED;
}
snprintf(file_id, sizeof(file_id), "%s", argv[2]);
file_offset = 0;
download_bytes = 0;
if (argc >= 4) {
local_filename = argv[3];
if (argc >= 6) {
file_offset = strtoll(argv[4], NULL, 10);
download_bytes = strtoll(argv[5], NULL, 10);
}
} else {
local_filename = strrchr(file_id, '/');
if (local_filename != NULL) {
local_filename++; // skip /
} else {
local_filename = file_id;
}
}
result = storage_do_download_file1_ex(
pTrackerServer, NULL, FDFS_DOWNLOAD_TO_FILE, file_id, file_offset,
download_bytes, &local_filename, NULL, &file_size);
if (result != 0) {
printf(
"download file fail, "
"error no: %d, error info: %s\n",
result, STRERROR(result));
}
tracker_disconnect_server_ex(pTrackerServer, true);
fdfs_client_destroy();
return 0;
}
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "fdfs_client.h"
#include "logger.h"
int main(int argc, char *argv[]) {
char *conf_filename;
char file_id[128];
int result;
FDFSFileInfo file_info;
if (argc < 3) {
printf("Usage: %s <config_file> <file_id>\n", argv[0]);
return 1;
}
log_init();
g_log_context.log_level = LOG_ERR;
ignore_signal_pipe();
conf_filename = argv[1];
if ((result = fdfs_client_init(conf_filename)) != 0) {
return result;
}
snprintf(file_id, sizeof(file_id), "%s", argv[2]);
memset(&file_info, 0, sizeof(file_info));
result = fdfs_get_file_info_ex1(file_id, true, &file_info);
if (result != 0) {
printf(
"query file info fail, "
"error no: %d, error info: %s\n",
result, STRERROR(result));
} else {
char szDatetime[32];
printf("source storage id: %d\n", file_info.source_id);
printf("source ip address: %s\n", file_info.source_ip_addr);
printf("file create timestamp: %s\n",
formatDatetime(file_info.create_timestamp, "%Y-%m-%d %H:%M:%S",
szDatetime, sizeof(szDatetime)));
printf("file size: %" PRId64 "\n", file_info.file_size);
printf("file crc32: %u (0x%08X)\n", file_info.crc32, file_info.crc32);
}
tracker_close_all_connections();
fdfs_client_destroy();
return 0;
}
tmp_src_filename=_fdfs_check_bits_.c
cat <<EOF > $tmp_src_filename
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main()
{
printf("%d\n", (int)sizeof(long));
return 0;
}
EOF
gcc -D_FILE_OFFSET_BITS=64 -o a.out $tmp_src_filename
OS_BITS=`./a.out`
rm $tmp_src_filename a.out
TARGET_LIB="$(TARGET_PREFIX)/lib"
if [ "`id -u`" = "0" ]; then
ln -fs $TARGET_LIB/libfastcommon.so.1 /usr/lib/libfastcommon.so
ln -fs $TARGET_LIB/libfdfsclient.so.1 /usr/lib/libfdfsclient.so
if [ "$OS_BITS" = "8" ]; then
ln -fs $TARGET_LIB/libfastcommon.so.1 /usr/lib64/libfastcommon.so
ln -fs $TARGET_LIB/libfdfsclient.so.1 /usr/lib64/libfdfsclient.so
fi
fi
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "fdfs_client.h"
#include "logger.h"
int main(int argc, char *argv[]) {
char *conf_filename;
char *local_filename;
char group_name[FDFS_GROUP_NAME_MAX_LEN + 1];
ConnectionInfo *pTrackerServer;
int result;
int store_path_index;
ConnectionInfo storageServer;
char file_id[128];
if (argc < 3) {
printf("Usage: %s <config_file> <local_filename>\n", argv[0]);
return 1;
}
log_init();
g_log_context.log_level = LOG_ERR;
ignore_signal_pipe();
conf_filename = argv[1];
if ((result = fdfs_client_init(conf_filename)) != 0) {
return result;
}
pTrackerServer = tracker_get_connection();
if (pTrackerServer == NULL) {
fdfs_client_destroy();
return errno != 0 ? errno : ECONNREFUSED;
}
*group_name = '\0';
store_path_index = 0;
if ((result = tracker_query_storage_store(pTrackerServer, &storageServer,
group_name, &store_path_index)) !=
0) {
fdfs_client_destroy();
fprintf(stderr,
"tracker_query_storage fail, "
"error no: %d, error info: %s\n",
result, STRERROR(result));
return result;
}
local_filename = argv[2];
result = storage_upload_appender_by_filename1(
pTrackerServer, &storageServer, store_path_index, local_filename, NULL,
NULL, 0, group_name, file_id);
if (result != 0) {
fprintf(stderr,
"upload file fail, "
"error no: %d, error info: %s\n",
result, STRERROR(result));
tracker_disconnect_server_ex(pTrackerServer, true);
fdfs_client_destroy();
return result;
}
printf("%s\n", file_id);
tracker_disconnect_server_ex(pTrackerServer, true);
fdfs_client_destroy();
return 0;
}
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "fdfs_client.h"
#include "logger.h"
static void usage(char *argv[]) {
printf(
"Usage: %s <config_file> <local_filename> "
"[storage_ip:port] [store_path_index]\n",
argv[0]);
}
int main(int argc, char *argv[]) {
char *conf_filename;
char *local_filename;
char group_name[FDFS_GROUP_NAME_MAX_LEN + 1];
ConnectionInfo *pTrackerServer;
int result;
int store_path_index;
ConnectionInfo storageServer;
char file_id[128];
if (argc < 3) {
usage(argv);
return 1;
}
log_init();
g_log_context.log_level = LOG_ERR;
ignore_signal_pipe();
conf_filename = argv[1];
if ((result = fdfs_client_init(conf_filename)) != 0) {
return result;
}
pTrackerServer = tracker_get_connection();
if (pTrackerServer == NULL) {
fdfs_client_destroy();
return errno != 0 ? errno : ECONNREFUSED;
}
local_filename = argv[2];
*group_name = '\0';
if (argc >= 4) {
const char *pPort;
const char *pIpAndPort;
pIpAndPort = argv[3];
pPort = strchr(pIpAndPort, ':');
if (pPort == NULL) {
fdfs_client_destroy();
fprintf(stderr,
"invalid storage ip address and "
"port: %s\n",
pIpAndPort);
usage(argv);
return 1;
}
storageServer.sock = -1;
snprintf(storageServer.ip_addr, sizeof(storageServer.ip_addr), "%.*s",
(int)(pPort - pIpAndPort), pIpAndPort);
storageServer.port = atoi(pPort + 1);
if (argc >= 5) {
store_path_index = atoi(argv[4]);
} else {
store_path_index = -1;
}
} else if ((result = tracker_query_storage_store(pTrackerServer,
&storageServer, group_name,
&store_path_index)) != 0) {
fdfs_client_destroy();
fprintf(stderr,
"tracker_query_storage fail, "
"error no: %d, error info: %s\n",
result, STRERROR(result));
return result;
}
result = storage_upload_by_filename1(pTrackerServer, &storageServer,
store_path_index, local_filename, NULL,
NULL, 0, group_name, file_id);
if (result == 0) {
printf("%s\n", file_id);
} else {
fprintf(stderr,
"upload file fail, "
"error no: %d, error info: %s\n",
result, STRERROR(result));
}
tracker_disconnect_server_ex(pTrackerServer, true);
fdfs_client_destroy();
return result;
}
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <limits.h>
#include "fdfs_client.h"
#include "logger.h"
int stbf_test() { return 0; }
static char g_conf_filename[PATH_MAX] = {"/etc/fdfs/client.conf"};
int stbf_setconf(const char* conf_filename) {
if (strlen(conf_filename) != 0) {
strcpy(g_conf_filename, conf_filename);
return 0;
} else {
return 1;
}
}
int stbf_upload(const char* local_filename, char* ret_file_id) {
char group_name[FDFS_GROUP_NAME_MAX_LEN + 1] = {0};
ConnectionInfo* pTrackerServer;
int result = 0;
int store_path_index;
ConnectionInfo storageServer;
char file_id[128] = {0};
log_init();
g_log_context.log_level = LOG_ERR;
ignore_signal_pipe();
if ((result = fdfs_client_init(g_conf_filename)) != 0) {
return result;
}
pTrackerServer = tracker_get_connection();
if (pTrackerServer == NULL) {
fdfs_client_destroy();
return errno != 0 ? errno : ECONNREFUSED;
}
*group_name = '\0';
if ((result = tracker_query_storage_store(pTrackerServer, &storageServer,
group_name, &store_path_index)) !=
0) {
fdfs_client_destroy();
fprintf(stderr,
"tracker_query_storage fail, "
"error no: %d, error info: %s\n",
result, STRERROR(result));
return result;
}
result = storage_upload_by_filename1(pTrackerServer, &storageServer,
store_path_index, local_filename, NULL,
NULL, 0, group_name, file_id);
if (result == 0) {
strcpy(ret_file_id, file_id);
} else {
fprintf(stderr,
"upload file fail, "
"error no: %d, error info: %s\n",
result, STRERROR(result));
}
tracker_disconnect_server_ex(pTrackerServer, true);
fdfs_client_destroy();
return result;
}
int stbf_download(const char* fdfs_id, char* local_path) {
char* path_name = NULL;
char* local_filename = NULL;
ConnectionInfo* pTrackerServer;
int result = 0;
int64_t file_size;
int64_t file_offset;
int64_t download_bytes;
log_init();
g_log_context.log_level = LOG_ERR;
ignore_signal_pipe();
if ((result = fdfs_client_init(g_conf_filename)) != 0) {
return result;
}
pTrackerServer = tracker_get_connection();
if (pTrackerServer == NULL) {
fdfs_client_destroy();
return errno != 0 ? errno : ECONNREFUSED;
}
file_offset = 0;
download_bytes = 0;
local_filename = strrchr(fdfs_id, '/');
if (local_filename != NULL) {
local_filename++;
} else {
local_filename = (char*)(fdfs_id);
}
path_name = malloc(PATH_MAX);
sprintf(path_name, "%s/%s", local_path, local_filename);
// SYZ, 20170704, local_filename -> path_name
result = storage_do_download_file1_ex(
pTrackerServer, NULL, FDFS_DOWNLOAD_TO_FILE, fdfs_id, file_offset,
download_bytes, &path_name, NULL, &file_size);
if (result != 0) {
printf(
"download file '%s' fail, "
"error no: %d, error info: %s\n",
local_filename, result, STRERROR(result));
}
printf("%s\n", path_name);
tracker_disconnect_server_ex(pTrackerServer, true);
fdfs_client_destroy();
free(path_name);
return result;
}
int stbf_delete(const char* fdfs_id) {
ConnectionInfo* pTrackerServer;
int result = 0;
log_init();
g_log_context.log_level = LOG_ERR;
ignore_signal_pipe();
if ((result = fdfs_client_init(g_conf_filename)) != 0) {
return result;
}
pTrackerServer = tracker_get_connection();
if (pTrackerServer == NULL) {
fdfs_client_destroy();
return errno != 0 ? errno : ECONNREFUSED;
}
if ((result = storage_delete_file1(pTrackerServer, NULL, fdfs_id)) != 0) {
printf(
"delete file fail, "
"error no: %d, error info: %s\n",
result, STRERROR(result));
}
tracker_disconnect_server_ex(pTrackerServer, true);
fdfs_client_destroy();
return result;
}
void stbf_release() {}
#ifndef SEETABRAIN_UPLOAD_H_
#define SEETABRAIN_UPLOAD_H_
#ifdef __cplusplus
extern "C" {
#endif
extern int stbf_test();
extern int stbf_setconf(const char* conf_pathname);
extern int stbf_upload(const char* local_filename, char* ret_file_id);
extern int stbf_download(const char* fdfs_id, const char* local_path);
extern int stbf_delete(const char* fdfs_id);
extern int stbf_release();
#ifdef __cplusplus
}
#endif
#endif
.SUFFIXES: .c .o
COMPILE = $(CC) $(CFLAGS)
INC_PATH = -I/usr/include/fastcommon -I/usr/include/fastdfs
LIB_PATH = -L/usr/local/lib -lfastcommon -lfdfsclient $(LIBS)
TARGET_PATH = $(TARGET_PATH)
ALL_OBJS =
ALL_PRGS = fdfs_monitor fdfs_test fdfs_test1
all: $(ALL_OBJS) $(ALL_PRGS)
.o:
$(COMPILE) -o $@ $< $(SHARED_OBJS) $(LIB_PATH) $(INC_PATH)
.c:
$(COMPILE) -o $@ $< $(ALL_OBJS) $(LIB_PATH) $(INC_PATH)
.c.o:
$(COMPILE) -c -o $@ $< $(INC_PATH)
install:
cp -f $(ALL_PRGS) $(TARGET_PATH)
clean:
rm -f $(ALL_OBJS) $(ALL_PRGS)
../fdfs_monitor.c
\ No newline at end of file
../fdfs_test1.c
\ No newline at end of file
.SUFFIXES: .c .o
COMPILE = $(CC) -Wall -O2 -D_FILE_OFFSET_BITS=64 -DOS_LINUX
#COMPILE = $(CC) -Wall -g -D_FILE_OFFSET_BITS=64 -DOS_LINUX -D__DEBUG__
INC_PATH = -I/usr/local/include
LIB_PATH = -L/usr/local/lib
TARGET_PATH = /usr/local/bin
COMMON_LIB =
SHARED_OBJS = hash.o chain.o shared_func.o ini_file_reader.o \
logger.o sockopt.o fdfs_global.o base64.o sched_thread.o \
mime_file_parser.o fdfs_http_shared.o
ALL_OBJS = $(SHARED_OBJS)
ALL_PRGS =
all: $(ALL_OBJS) $(ALL_PRGS)
.o:
$(COMPILE) -o $@ $< $(SHARED_OBJS) $(COMMON_LIB) $(LIB_PATH) $(INC_PATH)
.c:
$(COMPILE) -o $@ $< $(ALL_OBJS) $(COMMON_LIB) $(LIB_PATH) $(INC_PATH)
.c.o:
$(COMPILE) -c -o $@ $< $(INC_PATH)
install:
cp -f $(ALL_PRGS) $(TARGET_PATH)
clean:
rm -f $(ALL_OBJS) $(ALL_PRGS)
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
// fdfs_define.h
#ifndef _FDFS_DEFINE_H_
#define _FDFS_DEFINE_H_
#include <pthread.h>
#include "common_define.h"
#define FDFS_TRACKER_SERVER_DEF_PORT 22000
#define FDFS_STORAGE_SERVER_DEF_PORT 23000
#define FDFS_DEF_STORAGE_RESERVED_MB 1024
#define TRACKER_ERROR_LOG_FILENAME "trackerd"
#define STORAGE_ERROR_LOG_FILENAME "storaged"
#define FDFS_RECORD_SEPERATOR '\x01'
#define FDFS_FIELD_SEPERATOR '\x02'
#define SYNC_BINLOG_BUFF_DEF_INTERVAL 60
#define CHECK_ACTIVE_DEF_INTERVAL 100
#define DEFAULT_STORAGE_SYNC_FILE_MAX_DELAY 86400
#define DEFAULT_STORAGE_SYNC_FILE_MAX_TIME 300
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <errno.h>
#include "logger.h"
#include "fdfs_global.h"
int g_fdfs_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
int g_fdfs_network_timeout = DEFAULT_NETWORK_TIMEOUT;
char g_fdfs_base_path[MAX_PATH_SIZE] = {'/', 't', 'm', 'p', '\0'};
Version g_fdfs_version = {5, 11};
bool g_use_connection_pool = false;
ConnectionPool g_connection_pool;
int g_connection_pool_max_idle_time = 3600;
/*
data filename format:
HH/HH/filename: HH for 2 uppercase hex chars
*/
int fdfs_check_data_filename(const char *filename, const int len) {
if (len < 6) {
logError(
"file: "__FILE__
", line: %d, "
"the length=%d of filename \"%s\" is too short",
__LINE__, len, filename);
return EINVAL;
}
if (!IS_UPPER_HEX(*filename) || !IS_UPPER_HEX(*(filename + 1)) ||
*(filename + 2) != '/' || !IS_UPPER_HEX(*(filename + 3)) ||
!IS_UPPER_HEX(*(filename + 4)) || *(filename + 5) != '/') {
logError(
"file: "__FILE__
", line: %d, "
"the format of filename \"%s\" is invalid",
__LINE__, filename);
return EINVAL;
}
if (strchr(filename + 6, '/') != NULL) {
logError(
"file: "__FILE__
", line: %d, "
"the format of filename \"%s\" is invalid",
__LINE__, filename);
return EINVAL;
}
return 0;
}
int fdfs_gen_slave_filename(const char *master_filename,
const char *prefix_name, const char *ext_name,
char *filename, int *filename_len) {
char true_ext_name[FDFS_FILE_EXT_NAME_MAX_LEN + 2];
char *pDot;
int master_file_len;
master_file_len = strlen(master_filename);
if (master_file_len < 28 + FDFS_FILE_EXT_NAME_MAX_LEN) {
logError(
"file: "__FILE__
", line: %d, "
"master filename \"%s\" is invalid",
__LINE__, master_filename);
return EINVAL;
}
pDot = strchr(
master_filename + (master_file_len - (FDFS_FILE_EXT_NAME_MAX_LEN + 1)),
'.');
if (ext_name != NULL) {
if (*ext_name == '\0') {
*true_ext_name = '\0';
} else if (*ext_name == '.') {
snprintf(true_ext_name, sizeof(true_ext_name), "%s", ext_name);
} else {
snprintf(true_ext_name, sizeof(true_ext_name), ".%s", ext_name);
}
} else {
if (pDot == NULL) {
*true_ext_name = '\0';
} else {
strcpy(true_ext_name, pDot);
}
}
if (*true_ext_name == '\0' && strcmp(prefix_name, "-m") == 0) {
logError(
"file: "__FILE__
", line: %d, "
"prefix_name \"%s\" is invalid",
__LINE__, prefix_name);
return EINVAL;
}
/* when prefix_name is empty, the extension name of master file and
slave file can not be same
*/
if ((*prefix_name == '\0') &&
((pDot == NULL && *true_ext_name == '\0') ||
(pDot != NULL && strcmp(pDot, true_ext_name) == 0))) {
logError(
"file: "__FILE__
", line: %d, "
"empty prefix_name is not allowed",
__LINE__);
return EINVAL;
}
if (pDot == NULL) {
*filename_len = sprintf(filename, "%s%s%s", master_filename,
prefix_name, true_ext_name);
} else {
*filename_len = pDot - master_filename;
memcpy(filename, master_filename, *filename_len);
*filename_len += sprintf(filename + *filename_len, "%s%s", prefix_name,
true_ext_name);
}
return 0;
}
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
// fdfs_global.h
#ifndef _FDFS_GLOBAL_H
#define _FDFS_GLOBAL_H
#include "common_define.h"
#include "fdfs_define.h"
#include "connection_pool.h"
#define FDFS_FILE_EXT_NAME_MAX_LEN 6
#ifdef __cplusplus
extern "C" {
#endif
extern int g_fdfs_connect_timeout;
extern int g_fdfs_network_timeout;
extern char g_fdfs_base_path[MAX_PATH_SIZE];
extern Version g_fdfs_version;
extern bool g_use_connection_pool;
extern ConnectionPool g_connection_pool;
extern int g_connection_pool_max_idle_time;
int fdfs_check_data_filename(const char *filename, const int len);
int fdfs_gen_slave_filename(const char *master_filename,
const char *prefix_name, const char *ext_name,
char *filename, int *filename_len);
#ifdef __cplusplus
}
#endif
#endif
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
#ifndef _FDFS_HTTP_SHARED_H
#define _FDFS_HTTP_SHARED_H
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "ini_file_reader.h"
#include "hash.h"
typedef struct {
bool disabled;
bool anti_steal_token;
/* if need find content type by file extension name */
bool need_find_content_type;
/* if support multi range */
bool support_multi_range;
/* the web server port */
int server_port;
/* key is file ext name, value is content type */
HashArray content_type_hash;
BufferInfo anti_steal_secret_key;
BufferInfo token_check_fail_buff;
char default_content_type[64];
char token_check_fail_content_type[64];
int token_ttl;
} FDFSHTTPParams;
#ifdef __cplusplus
extern "C" {
#endif
/**
load HTTP params from conf file
params:
pIniContext: the ini file items, return by iniLoadItems
conf_filename: config filename
pHTTPParams: the HTTP params
return: 0 for success, != 0 fail
**/
int fdfs_http_params_load(IniContext *pIniContext, const char *conf_filename,
FDFSHTTPParams *pHTTPParams);
void fdfs_http_params_destroy(FDFSHTTPParams *pParams);
/**
generate anti-steal token
params:
secret_key: secret key buffer
file_id: FastDFS file id
timestamp: current timestamp, unix timestamp (seconds), 0 for never
timeout
token: return token buffer
return: 0 for success, != 0 fail
**/
int fdfs_http_gen_token(const BufferInfo *secret_key, const char *file_id,
const int timestamp, char *token);
/**
check anti-steal token
params:
secret_key: secret key buffer
file_id: FastDFS file id
timestamp: the timestamp to generate the token, unix timestamp (seconds)
token: token buffer
ttl: token ttl, delta seconds
return: 0 for passed, != 0 fail
**/
int fdfs_http_check_token(const BufferInfo *secret_key, const char *file_id,
const int timestamp, const char *token,
const int ttl);
/**
get parameter value
params:
param_name: the parameter name to get
params: parameter array
param_count: param count
return: param value pointer, return NULL if not exist
**/
char *fdfs_http_get_parameter(const char *param_name, KeyValuePair *params,
const int param_count);
/**
get file extension name
params:
filename: the filename
filename_len: the length of filename
ext_len: return the length of extension name
return: extension name, NULL for none
**/
const char *fdfs_http_get_file_extension(const char *filename,
const int filename_len, int *ext_len);
/**
get content type by file extension name
params:
pHTTPParams: the HTTP params
ext_name: the extension name
ext_len: the length of extension name
content_type: return content type
content_type_size: content type buffer size
return: 0 for success, != 0 fail
**/
int fdfs_http_get_content_type_by_extname(FDFSHTTPParams *pParams,
const char *ext_name,
const int ext_len, char *content_type,
const int content_type_size);
#ifdef __cplusplus
}
#endif
#endif
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <fcntl.h>
#include "logger.h"
#include "http_func.h"
#include "shared_func.h"
#include "mime_file_parser.h"
int load_mime_types_from_file(HashArray *pHash, const char *mime_filename) {
#define MIME_DELIM_CHARS " \t"
int result;
char *content;
char *pLine;
char *pLastEnd;
char *content_type;
char *ext_name;
char *lasts;
int http_status;
int content_len;
int64_t file_size;
char error_info[512];
if (strncasecmp(mime_filename, "http://", 7) == 0) {
if ((result = get_url_content(mime_filename, 30, 60, &http_status,
&content, &content_len, error_info)) !=
0) {
logError(
"file: "__FILE__
", line: %d, "
"get_url_content fail, "
"url: %s, error info: %s",
__LINE__, mime_filename, error_info);
return result;
}
if (http_status != 200) {
free(content);
logError(
"file: "__FILE__
", line: %d, "
"HTTP status code: %d != 200, url: %s",
__LINE__, http_status, mime_filename);
return EINVAL;
}
} else {
if ((result = getFileContent(mime_filename, &content, &file_size)) !=
0) {
return result;
}
}
if ((result = hash_init_ex(pHash, PJWHash, 2 * 1024, 0.75, 0, true)) != 0) {
free(content);
logError(
"file: "__FILE__
", line: %d, "
"hash_init_ex fail, errno: %d, error info: %s",
__LINE__, result, STRERROR(result));
return result;
}
pLastEnd = content - 1;
while (pLastEnd != NULL) {
pLine = pLastEnd + 1;
pLastEnd = strchr(pLine, '\n');
if (pLastEnd != NULL) {
*pLastEnd = '\0';
}
if (*pLine == '\0' || *pLine == '#') {
continue;
}
lasts = NULL;
content_type = strtok_r(pLine, MIME_DELIM_CHARS, &lasts);
while (1) {
ext_name = strtok_r(NULL, MIME_DELIM_CHARS, &lasts);
if (ext_name == NULL) {
break;
}
if (*ext_name == '\0') {
continue;
}
if ((result = hash_insert_ex(pHash, ext_name, strlen(ext_name) + 1,
content_type, strlen(content_type) + 1,
true)) < 0) {
free(content);
result *= -1;
logError(
"file: "__FILE__
", line: %d, "
"hash_insert_ex fail, errno: %d, "
"error info: %s",
__LINE__, result, STRERROR(result));
return result;
}
}
}
free(content);
// hash_stat_print(pHash);
return 0;
}
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
#ifndef _MINE_FILE_PARSER_H
#define _MINE_FILE_PARSER_H
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "hash.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
load mime types from file
params:
pHash: hash array to store the mime types,
key is the file extension name, eg. jpg
value is the content type, eg. image/jpeg
the hash array will be initialized in this function,
the hash array should be destroyed when used done
mime_filename: the mime filename,
file format is same as apache's file: mime.types
return: 0 for success, !=0 for fail
**/
int load_mime_types_from_file(HashArray *pHash, const char *mime_filename);
#ifdef __cplusplus
}
#endif
#endif
# connect timeout in seconds
# default value is 30s
connect_timeout=30
# network timeout in seconds
# default value is 30s
network_timeout=60
# the base path to store log files
base_path=/home/yuqing/fastdfs
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=192.168.0.197:22122
#standard log level as syslog, case insensitive, value list:
### emerg for emergency
### alert
### crit for critical
### error
### warn for warning
### notice
### info
### debug
log_level=info
# if use connection pool
# default value is false
# since V4.05
use_connection_pool = false
# connections whose the idle time exceeds this time will be closed
# unit: second
# default value is 3600
# since V4.05
connection_pool_max_idle_time = 3600
# if load FastDFS parameters from tracker server
# since V4.05
# default value is false
load_fdfs_parameters_from_tracker=false
# if use storage ID instead of IP address
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# default value is false
# since V4.05
use_storage_id = false
# specify storage ids filename, can use relative or absolute path
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# since V4.05
storage_ids_filename = storage_ids.conf
#HTTP settings
http.tracker_server_port=80
#use "#include" directive to include HTTP other settiongs
##include http.conf
# HTTP default content type
http.default_content_type = application/octet-stream
# MIME types mapping filename
# MIME types file format: MIME_type extensions
# such as: image/jpeg jpeg jpg jpe
# you can use apache's MIME file: mime.types
http.mime_types_filename=mime.types
# if use token to anti-steal
# default value is false (0)
http.anti_steal.check_token=false
# token TTL (time to live), seconds
# default value is 600
http.anti_steal.token_ttl=900
# secret key to generate anti-steal token
# this parameter must be set when http.anti_steal.check_token set to true
# the length of the secret key should not exceed 128 bytes
http.anti_steal.secret_key=FastDFS1234567890
# return the content of the file when check token fail
# default value is empty (no file sepecified)
http.anti_steal.token_check_fail=/home/yuqing/fastdfs/conf/anti-steal.jpg
# if support multi regions for HTTP Range
# default value is true
http.multi_range.enabed = true
# is this config file disabled
# false for enabled
# true for disabled
disabled=false
# the name of the group this storage server belongs to
#
# comment or remove this item for fetching from tracker server,
# in this case, use_storage_id must set to true in tracker.conf,
# and storage_ids.conf must be configed correctly.
group_name=group1
# bind an address of this host
# empty for bind all addresses of this host
bind_addr=
# if bind an address of this host when connect to other servers
# (this storage server as a client)
# true for binding the address configed by above parameter: "bind_addr"
# false for binding any address of this host
client_bind=true
# the storage server port
port=23000
# connect timeout in seconds
# default value is 30s
connect_timeout=30
# network timeout in seconds
# default value is 30s
network_timeout=60
# heart beat interval in seconds
heart_beat_interval=30
# disk usage report interval in seconds
stat_report_interval=60
# the base path to store data and log files
base_path=/home/yuqing/fastdfs
# max concurrent connections the server supported
# default value is 256
# more max_connections means more memory will be used
max_connections=256
# the buff size to recv / send data
# this parameter must more than 8KB
# default value is 64KB
# since V2.00
buff_size = 256KB
# accept thread count
# default value is 1
# since V4.07
accept_threads=1
# work thread count, should <= max_connections
# work thread deal network io
# default value is 4
# since V2.00
work_threads=4
# if disk read / write separated
## false for mixed read and write
## true for separated read and write
# default value is true
# since V2.00
disk_rw_separated = true
# disk reader thread count per store base path
# for mixed read / write, this parameter can be 0
# default value is 1
# since V2.00
disk_reader_threads = 1
# disk writer thread count per store base path
# for mixed read / write, this parameter can be 0
# default value is 1
# since V2.00
disk_writer_threads = 1
# when no entry to sync, try read binlog again after X milliseconds
# must > 0, default value is 200ms
sync_wait_msec=50
# after sync a file, usleep milliseconds
# 0 for sync successively (never call usleep)
sync_interval=0
# storage sync start time of a day, time format: Hour:Minute
# Hour from 0 to 23, Minute from 0 to 59
sync_start_time=00:00
# storage sync end time of a day, time format: Hour:Minute
# Hour from 0 to 23, Minute from 0 to 59
sync_end_time=23:59
# write to the mark file after sync N files
# default value is 500
write_mark_file_freq=500
# path(disk or mount point) count, default value is 1
store_path_count=1
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/home/yuqing/fastdfs
#store_path1=/home/yuqing/fastdfs2
# subdir_count * subdir_count directories will be auto created under each
# store_path (disk), value can be 1 to 256, default value is 256
subdir_count_per_path=256
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=192.168.209.121:22122
#standard log level as syslog, case insensitive, value list:
### emerg for emergency
### alert
### crit for critical
### error
### warn for warning
### notice
### info
### debug
log_level=info
#unix group name to run this program,
#not set (empty) means run by the group of current user
run_by_group=
#unix username to run this program,
#not set (empty) means run by current user
run_by_user=
# allow_hosts can ocur more than once, host can be hostname or ip address,
# "*" (only one asterisk) means match all ip addresses
# we can use CIDR ips like 192.168.5.64/26
# and also use range like these: 10.0.1.[0-254] and host[01-08,20-25].domain.com
# for example:
# allow_hosts=10.0.1.[1-15,20]
# allow_hosts=host[01-08,20-25].domain.com
# allow_hosts=192.168.5.64/26
allow_hosts=*
# the mode of the files distributed to the data path
# 0: round robin(default)
# 1: random, distributted by hash code
file_distribute_path_mode=0
# valid when file_distribute_to_path is set to 0 (round robin),
# when the written file count reaches this number, then rotate to next path
# default value is 100
file_distribute_rotate_count=100
# call fsync to disk when write big file
# 0: never call fsync
# other: call fsync when written bytes >= this bytes
# default value is 0 (never call fsync)
fsync_after_written_bytes=0
# sync log buff to disk every interval seconds
# must > 0, default value is 10 seconds
sync_log_buff_interval=10
# sync binlog buff / cache to disk every interval seconds
# default value is 60 seconds
sync_binlog_buff_interval=10
# sync storage stat info to disk every interval seconds
# default value is 300 seconds
sync_stat_file_interval=300
# thread stack size, should >= 512KB
# default value is 512KB
thread_stack_size=512KB
# the priority as a source server for uploading file.
# the lower this value, the higher its uploading priority.
# default value is 10
upload_priority=10
# the NIC alias prefix, such as eth in Linux, you can see it by ifconfig -a
# multi aliases split by comma. empty value means auto set by OS type
# default values is empty
if_alias_prefix=
# if check file duplicate, when set to true, use FastDHT to store file indexes
# 1 or yes: need check
# 0 or no: do not check
# default value is 0
check_file_duplicate=0
# file signature method for check file duplicate
## hash: four 32 bits hash code
## md5: MD5 signature
# default value is hash
# since V4.01
file_signature_method=hash
# namespace for storing file indexes (key-value pairs)
# this item must be set when check_file_duplicate is true / on
key_namespace=FastDFS
# set keep_alive to 1 to enable persistent connection with FastDHT servers
# default value is 0 (short connection)
keep_alive=0
# you can use "#include filename" (not include double quotes) directive to
# load FastDHT server list, when the filename is a relative path such as
# pure filename, the base path is the base path of current/this config file.
# must set FastDHT server list when check_file_duplicate is true / on
# please see INSTALL of FastDHT for detail
##include /home/yuqing/fastdht/conf/fdht_servers.conf
# if log to access log
# default value is false
# since V4.00
use_access_log = false
# if rotate the access log every day
# default value is false
# since V4.00
rotate_access_log = false
# rotate access log time base, time format: Hour:Minute
# Hour from 0 to 23, Minute from 0 to 59
# default value is 00:00
# since V4.00
access_log_rotate_time=00:00
# if rotate the error log every day
# default value is false
# since V4.02
rotate_error_log = false
# rotate error log time base, time format: Hour:Minute
# Hour from 0 to 23, Minute from 0 to 59
# default value is 00:00
# since V4.02
error_log_rotate_time=00:00
# rotate access log when the log file exceeds this size
# 0 means never rotates log file by log file size
# default value is 0
# since V4.02
rotate_access_log_size = 0
# rotate error log when the log file exceeds this size
# 0 means never rotates log file by log file size
# default value is 0
# since V4.02
rotate_error_log_size = 0
# keep days of the log files
# 0 means do not delete old log files
# default value is 0
log_file_keep_days = 0
# if skip the invalid record when sync file
# default value is false
# since V4.02
file_sync_skip_invalid_record=false
# if use connection pool
# default value is false
# since V4.05
use_connection_pool = false
# connections whose the idle time exceeds this time will be closed
# unit: second
# default value is 3600
# since V4.05
connection_pool_max_idle_time = 3600
# use the ip address of this storage server if domain_name is empty,
# else this domain name will ocur in the url redirected by the tracker server
http.domain_name=
# the port of the web server on this storage server
http.server_port=8888
# <id> <group_name> <ip_or_hostname>
# 100001 group1 192.168.0.196
# 100002 group1 192.168.0.116
# is this config file disabled
# false for enabled
# true for disabled
disabled=false
# bind an address of this host
# empty for bind all addresses of this host
bind_addr=
# the tracker server port
port=22122
# connect timeout in seconds
# default value is 30s
connect_timeout=30
# network timeout in seconds
# default value is 30s
network_timeout=60
# the base path to store data and log files
base_path=/home/yuqing/fastdfs
# max concurrent connections this server supported
max_connections=256
# accept thread count
# default value is 1
# since V4.07
accept_threads=1
# work thread count, should <= max_connections
# default value is 4
# since V2.00
work_threads=4
# min buff size
# default value 8KB
min_buff_size = 8KB
# max buff size
# default value 128KB
max_buff_size = 128KB
# the method of selecting group to upload files
# 0: round robin
# 1: specify group
# 2: load balance, select the max free space group to upload file
store_lookup=2
# which group to upload file
# when store_lookup set to 1, must set store_group to the group name
store_group=group2
# which storage server to upload file
# 0: round robin (default)
# 1: the first server order by ip address
# 2: the first server order by priority (the minimal)
# Note: if use_trunk_file set to true, must set store_server to 1 or 2
store_server=0
# which path(means disk or mount point) of the storage server to upload file
# 0: round robin
# 2: load balance, select the max free space path to upload file
store_path=0
# which storage server to download file
# 0: round robin (default)
# 1: the source storage server which the current file uploaded to
download_server=0
# reserved storage space for system or other applications.
# if the free(available) space of any stoarge server in
# a group <= reserved_storage_space,
# no file can be uploaded to this group.
# bytes unit can be one of follows:
### G or g for gigabyte(GB)
### M or m for megabyte(MB)
### K or k for kilobyte(KB)
### no unit for byte(B)
### XX.XX% as ratio such as reserved_storage_space = 10%
reserved_storage_space = 10%
#standard log level as syslog, case insensitive, value list:
### emerg for emergency
### alert
### crit for critical
### error
### warn for warning
### notice
### info
### debug
log_level=info
#unix group name to run this program,
#not set (empty) means run by the group of current user
run_by_group=
#unix username to run this program,
#not set (empty) means run by current user
run_by_user=
# allow_hosts can ocur more than once, host can be hostname or ip address,
# "*" (only one asterisk) means match all ip addresses
# we can use CIDR ips like 192.168.5.64/26
# and also use range like these: 10.0.1.[0-254] and host[01-08,20-25].domain.com
# for example:
# allow_hosts=10.0.1.[1-15,20]
# allow_hosts=host[01-08,20-25].domain.com
# allow_hosts=192.168.5.64/26
allow_hosts=*
# sync log buff to disk every interval seconds
# default value is 10 seconds
sync_log_buff_interval = 10
# check storage server alive interval seconds
check_active_interval = 120
# thread stack size, should >= 64KB
# default value is 64KB
thread_stack_size = 64KB
# auto adjust when the ip address of the storage server changed
# default value is true
storage_ip_changed_auto_adjust = true
# storage sync file max delay seconds
# default value is 86400 seconds (one day)
# since V2.00
storage_sync_file_max_delay = 86400
# the max time of storage sync a file
# default value is 300 seconds
# since V2.00
storage_sync_file_max_time = 300
# if use a trunk file to store several small files
# default value is false
# since V3.00
use_trunk_file = false
# the min slot size, should <= 4KB
# default value is 256 bytes
# since V3.00
slot_min_size = 256
# the max slot size, should > slot_min_size
# store the upload file to trunk file when it's size <= this value
# default value is 16MB
# since V3.00
slot_max_size = 16MB
# the trunk file size, should >= 4MB
# default value is 64MB
# since V3.00
trunk_file_size = 64MB
# if create trunk file advancely
# default value is false
# since V3.06
trunk_create_file_advance = false
# the time base to create trunk file
# the time format: HH:MM
# default value is 02:00
# since V3.06
trunk_create_file_time_base = 02:00
# the interval of create trunk file, unit: second
# default value is 38400 (one day)
# since V3.06
trunk_create_file_interval = 86400
# the threshold to create trunk file
# when the free trunk file size less than the threshold, will create
# the trunk files
# default value is 0
# since V3.06
trunk_create_file_space_threshold = 20G
# if check trunk space occupying when loading trunk free spaces
# the occupied spaces will be ignored
# default value is false
# since V3.09
# NOTICE: set this parameter to true will slow the loading of trunk spaces
# when startup. you should set this parameter to true when neccessary.
trunk_init_check_occupying = false
# if ignore storage_trunk.dat, reload from trunk binlog
# default value is false
# since V3.10
# set to true once for version upgrade when your version less than V3.10
trunk_init_reload_from_binlog = false
# the min interval for compressing the trunk binlog file
# unit: second
# default value is 0, 0 means never compress
# FastDFS compress the trunk binlog when trunk init and trunk destroy
# recommand to set this parameter to 86400 (one day)
# since V5.01
trunk_compress_binlog_min_interval = 0
# if use storage ID instead of IP address
# default value is false
# since V4.00
use_storage_id = false
# specify storage ids filename, can use relative or absolute path
# since V4.00
storage_ids_filename = storage_ids.conf
# id type of the storage server in the filename, values are:
## ip: the ip address of the storage server
## id: the server id of the storage server
# this paramter is valid only when use_storage_id set to true
# default value is ip
# since V4.03
id_type_in_filename = ip
# if store slave file use symbol link
# default value is false
# since V4.01
store_slave_file_use_link = false
# if rotate the error log every day
# default value is false
# since V4.02
rotate_error_log = false
# rotate error log time base, time format: Hour:Minute
# Hour from 0 to 23, Minute from 0 to 59
# default value is 00:00
# since V4.02
error_log_rotate_time=00:00
# rotate error log when the log file exceeds this size
# 0 means never rotates log file by log file size
# default value is 0
# since V4.02
rotate_error_log_size = 0
# keep days of the log files
# 0 means do not delete old log files
# default value is 0
log_file_keep_days = 0
# if use connection pool
# default value is false
# since V4.05
use_connection_pool = false
# connections whose the idle time exceeds this time will be closed
# unit: second
# default value is 3600
# since V4.05
connection_pool_max_idle_time = 3600
# HTTP port on this tracker server
http.server_port=8080
# check storage HTTP server alive interval seconds
# <= 0 for never check
# default value is 30
http.check_alive_interval=30
# check storage HTTP server alive type, values are:
# tcp : connect to the storge server with HTTP port only,
# do not request and get response
# http: storage check alive url must return http status 200
# default value is tcp
http.check_alive_type=tcp
# check storage HTTP server alive uri/url
# NOTE: storage embed HTTP server support uri: /status.html
http.check_alive_uri=/status.html
%define FastDFS fastdfs
%define FDFSServer fastdfs-server
%define FDFSClient libfdfsclient
%define FDFSClientDevel libfdfsclient-devel
%define FDFSTool fastdfs-tool
%define FDFSVersion 5.0.11
%define CommitVersion %(echo $COMMIT_VERSION)
Name: %{FastDFS}
Version: %{FDFSVersion}
Release: 1%{?dist}
Summary: FastDFS server and client
License: GPL
Group: Arch/Tech
URL: http://perso.orange.fr/sebastien.godard/
Source: http://perso.orange.fr/sebastien.godard/%{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Requires: %__cp %__mv %__chmod %__grep %__mkdir %__install %__id
BuildRequires: libfastcommon-devel >= 1.0.36
%description
This package provides tracker & storage of fastdfs
commit version: %{CommitVersion}
%package -n %{FDFSServer}
Requires: libfastcommon >= 1.0.36
Summary: fastdfs tracker & storage
%package -n %{FDFSTool}
Requires: libfastcommon
Summary: fastdfs tools
%package -n %{FDFSClient}
Requires: libfastcommon
Summary: The client dynamic library of fastdfs
%package -n %{FDFSClient}-devel
Requires: %{FDFSClient}
Summary: The client header of fastdfs
%description -n %{FDFSServer}
This package provides tracker & storage of fastdfs
commit version: %{CommitVersion}
%description -n %{FDFSClient}
This package is client dynamic library of fastdfs
commit version: %{CommitVersion}
%description -n %{FDFSClient}-devel
This package is client header of fastdfs client
commit version: %{CommitVersion}
%description -n %{FDFSTool}
This package is tools for fastdfs
commit version: %{CommitVersion}
%prep
%setup -q
%build
# FIXME: I need to fix the upstream Makefile to use LIBDIR et al. properly and
# send the upstream maintainer a patch.
# add DOCDIR to the configure part
./make.sh
%install
rm -rf %{buildroot}
DESTDIR=$RPM_BUILD_ROOT ./make.sh install
#make install IGNORE_MAN_GROUP=y DOC_DIR=%{_docdir}/%{name}-%{version} INIT_DIR=%{_initrddir}
#install -m 0644 sysstat.crond %{buildroot}/%{_sysconfdir}/cron.d/sysstat
#%find_lang %{name}
%post -n %{FDFSServer}
/sbin/chkconfig --add fdfs_trackerd
/sbin/chkconfig --add fdfs_storaged
%preun -n %{FDFSServer}
/sbin/chkconfig --del fdfs_trackerd
/sbin/chkconfig --del fdfs_storaged
%postun
%clean
#rm -rf %{buildroot}
%files
#%defattr(-,root,root,-)
#/usr/local/bin/*
#/usr/local/include/*
%files -n %{FDFSServer}
%defattr(-,root,root,-)
/usr/bin/fdfs_trackerd
/usr/bin/fdfs_storaged
/usr/bin/restart.sh
/usr/bin/stop.sh
/etc/init.d/*
/etc/fdfs/tracker.conf.sample
/etc/fdfs/storage.conf.sample
/etc/fdfs/storage_ids.conf.sample
%files -n %{FDFSClient}
/usr/lib64/libfdfsclient*
/usr/lib/libfdfsclient*
/etc/fdfs/client.conf.sample
%files -n %{FDFSClient}-devel
%defattr(-,root,root,-)
/usr/include/fastdfs/*
%files -n %{FDFSTool}
/usr/bin/fdfs_monitor
/usr/bin/fdfs_test
/usr/bin/fdfs_test1
/usr/bin/fdfs_crc32
/usr/bin/fdfs_upload_file
/usr/bin/fdfs_download_file
/usr/bin/fdfs_delete_file
/usr/bin/fdfs_file_info
/usr/bin/fdfs_appender_test
/usr/bin/fdfs_appender_test1
/usr/bin/fdfs_append_file
/usr/bin/fdfs_upload_appender
%changelog
* Mon Jun 23 2014 Zaixue Liao <liaozaixue@yongche.com>
- first RPM release (1.0)
#!/bin/bash
#
# fdfs_storaged Starts fdfs_storaged
#
#
# chkconfig: 2345 99 01
# description: FastDFS storage server
### BEGIN INIT INFO
# Provides: $fdfs_storaged
### END INIT INFO
# Source function library.
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
fi
PRG=/usr/bin/fdfs_storaged
CONF=/etc/fdfs/storage.conf
if [ ! -f $PRG ]; then
echo "file $PRG does not exist!"
exit 2
fi
if [ ! -f $CONF ]; then
echo "file $CONF does not exist!"
exit 2
fi
CMD="$PRG $CONF"
RETVAL=0
start() {
echo -n "Starting FastDFS storage server: "
$CMD &
RETVAL=$?
echo
return $RETVAL
}
stop() {
$CMD stop
RETVAL=$?
return $RETVAL
}
rhstatus() {
status fdfs_storaged
}
restart() {
$CMD restart &
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
rhstatus
;;
restart|reload)
restart
;;
condrestart)
restart
;;
*)
echo "Usage: $0 {start|stop|status|restart|condrestart}"
exit 1
esac
exit $?
#!/bin/bash
#
# fdfs_trackerd Starts fdfs_trackerd
#
#
# chkconfig: 2345 99 01
# description: FastDFS tracker server
### BEGIN INIT INFO
# Provides: $fdfs_trackerd
### END INIT INFO
# Source function library.
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
fi
PRG=/usr/bin/fdfs_trackerd
CONF=/etc/fdfs/tracker.conf
if [ ! -f $PRG ]; then
echo "file $PRG does not exist!"
exit 2
fi
if [ ! -f $CONF ]; then
echo "file $CONF does not exist!"
exit 2
fi
CMD="$PRG $CONF"
RETVAL=0
start() {
echo -n $"Starting FastDFS tracker server: "
$CMD &
RETVAL=$?
echo
return $RETVAL
}
stop() {
$CMD stop
RETVAL=$?
return $RETVAL
}
rhstatus() {
status fdfs_trackerd
}
restart() {
$CMD restart &
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
rhstatus
;;
restart|reload)
restart
;;
condrestart)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
exit 1
esac
exit $?
tmp_src_filename=fdfs_check_bits.c
cat <<EOF > $tmp_src_filename
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main()
{
printf("%d\n", (int)sizeof(long));
printf("%d\n", (int)sizeof(off_t));
return 0;
}
EOF
gcc -D_FILE_OFFSET_BITS=64 -o a.out $tmp_src_filename
output=$(./a.out)
if [ -f /bin/expr ]; then
EXPR=/bin/expr
else
EXPR=/usr/bin/expr
fi
count=0
int_bytes=4
off_bytes=8
for col in $output; do
if [ $count -eq 0 ]; then
int_bytes=$col
else
off_bytes=$col
fi
count=$($EXPR $count + 1)
done
/bin/rm -f a.out $tmp_src_filename
if [ "$int_bytes" -eq 8 ]; then
OS_BITS=64
else
OS_BITS=32
fi
if [ "$off_bytes" -eq 8 ]; then
OFF_BITS=64
else
OFF_BITS=32
fi
ENABLE_STATIC_LIB=0
ENABLE_SHARED_LIB=1
TARGET_PREFIX=$DESTDIR/usr/local/fastdfs-pro
TARGET_CONF_PATH=$DESTDIR/etc/fdfs
TARGET_INIT_PATH=$DESTDIR/etc/init.d
WITH_LINUX_SERVICE=1
DEBUG_FLAG=1
CFLAGS='-Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE'
if [ "$DEBUG_FLAG" = "1" ]; then
CFLAGS="$CFLAGS -g -O -DDEBUG_FLAG"
else
CFLAGS="$CFLAGS -O3"
fi
LIBS=''
uname=$(uname)
if [ "$uname" = "Linux" ]; then
if [ $OS_BITS -eq 64 ]; then
LIBS="$LIBS -L/usr/lib64"
else
LIBS="$LIBS -L/usr/lib"
fi
CFLAGS="$CFLAGS"
elif [ "$uname" = "FreeBSD" ] || [ "$uname" = "Darwin" ]; then
LIBS="$LIBS -L/usr/lib"
CFLAGS="$CFLAGS"
if [ "$uname" = "Darwin" ]; then
CFLAGS="$CFLAGS -DDARWIN"
fi
elif [ "$uname" = "SunOS" ]; then
LIBS="$LIBS -L/usr/lib"
CFLAGS="$CFLAGS -D_THREAD_SAFE"
LIBS="$LIBS -lsocket -lnsl -lresolv"
export CC=gcc
elif [ "$uname" = "AIX" ]; then
LIBS="$LIBS -L/usr/lib"
CFLAGS="$CFLAGS -D_THREAD_SAFE"
export CC=gcc
elif [ "$uname" = "HP-UX" ]; then
LIBS="$LIBS -L/usr/lib"
CFLAGS="$CFLAGS"
fi
have_pthread=0
if [ -f /usr/lib/libpthread.so ] || [ -f /usr/local/lib/libpthread.so ] || [ -f /lib64/libpthread.so ] || [ -f /usr/lib64/libpthread.so ] || [ -f /usr/lib/libpthread.a ] || [ -f /usr/local/lib/libpthread.a ] || [ -f /lib64/libpthread.a ] || [ -f /usr/lib64/libpthread.a ]; then
LIBS="$LIBS -lpthread"
have_pthread=1
elif [ "$uname" = "HP-UX" ]; then
lib_path="/usr/lib/hpux$OS_BITS"
if [ -f $lib_path/libpthread.so ]; then
LIBS="-L$lib_path -lpthread"
have_pthread=1
fi
elif [ "$uname" = "FreeBSD" ]; then
if [ -f /usr/lib/libc_r.so ]; then
line=$(nm -D /usr/lib/libc_r.so | grep pthread_create | grep -w T)
if [ $? -eq 0 ]; then
LIBS="$LIBS -lc_r"
have_pthread=1
fi
elif [ -f /lib64/libc_r.so ]; then
line=$(nm -D /lib64/libc_r.so | grep pthread_create | grep -w T)
if [ $? -eq 0 ]; then
LIBS="$LIBS -lc_r"
have_pthread=1
fi
elif [ -f /usr/lib64/libc_r.so ]; then
line=$(nm -D /usr/lib64/libc_r.so | grep pthread_create | grep -w T)
if [ $? -eq 0 ]; then
LIBS="$LIBS -lc_r"
have_pthread=1
fi
fi
fi
if [ $have_pthread -eq 0 ] && [ "$uname" != "Darwin" ]; then
/sbin/ldconfig -p | fgrep libpthread.so > /dev/null
if [ $? -eq 0 ]; then
LIBS="$LIBS -lpthread"
else
echo -E 'Require pthread lib, please check!'
exit 2
fi
fi
TRACKER_EXTRA_OBJS=''
STORAGE_EXTRA_OBJS=''
if [ "$DEBUG_FLAG" = "1" ]; then
TRACKER_EXTRA_OBJS="$TRACKER_EXTRA_OBJS tracker_dump.o"
STORAGE_EXTRA_OBJS="$STORAGE_EXTRA_OBJS storage_dump.o"
fi
cd tracker
cp Makefile.in Makefile
perl -pi -e "s#\\\$\(CFLAGS\)#$CFLAGS#g" Makefile
perl -pi -e "s#\\\$\(LIBS\)#$LIBS#g" Makefile
perl -pi -e "s#\\\$\(TARGET_PREFIX\)#$TARGET_PREFIX#g" Makefile
perl -pi -e "s#\\\$\(TRACKER_EXTRA_OBJS\)#$TRACKER_EXTRA_OBJS#g" Makefile
perl -pi -e "s#\\\$\(TARGET_CONF_PATH\)#$TARGET_CONF_PATH#g" Makefile
make $1 $2
cd ../storage
cp Makefile.in Makefile
perl -pi -e "s#\\\$\(CFLAGS\)#$CFLAGS#g" Makefile
perl -pi -e "s#\\\$\(LIBS\)#$LIBS#g" Makefile
perl -pi -e "s#\\\$\(TARGET_PREFIX\)#$TARGET_PREFIX#g" Makefile
perl -pi -e "s#\\\$\(STORAGE_EXTRA_OBJS\)#$STORAGE_EXTRA_OBJS#g" Makefile
perl -pi -e "s#\\\$\(TARGET_CONF_PATH\)#$TARGET_CONF_PATH#g" Makefile
make $1 $2
cd ../client
cp Makefile.in Makefile
perl -pi -e "s#\\\$\(CFLAGS\)#$CFLAGS#g" Makefile
perl -pi -e "s#\\\$\(LIBS\)#$LIBS#g" Makefile
perl -pi -e "s#\\\$\(TARGET_PREFIX\)#$TARGET_PREFIX#g" Makefile
perl -pi -e "s#\\\$\(TARGET_CONF_PATH\)#$TARGET_CONF_PATH#g" Makefile
perl -pi -e "s#\\\$\(ENABLE_STATIC_LIB\)#$ENABLE_STATIC_LIB#g" Makefile
perl -pi -e "s#\\\$\(ENABLE_SHARED_LIB\)#$ENABLE_SHARED_LIB#g" Makefile
cp fdfs_link_library.sh.in fdfs_link_library.sh
perl -pi -e "s#\\\$\(TARGET_PREFIX\)#$TARGET_PREFIX#g" fdfs_link_library.sh
make $1 $2
cd test
cp Makefile.in Makefile
perl -pi -e "s#\\\$\(CFLAGS\)#$CFLAGS#g" Makefile
perl -pi -e "s#\\\$\(LIBS\)#$LIBS#g" Makefile
perl -pi -e "s#\\\$\(TARGET_PREFIX\)#$TARGET_PREFIX#g" Makefile
cd ..
if [ "$1" = "install" ]; then
cd ..
cp -f restart.sh $TARGET_PREFIX/bin
cp -f stop.sh $TARGET_PREFIX/bin
if [ "$uname" = "Linux" ]; then
if [ "$WITH_LINUX_SERVICE" = "1" ]; then
if [ ! -d /etc/fdfs ]; then
mkdir -p /etc/fdfs
cp -f conf/tracker.conf $TARGET_CONF_PATH/tracker.conf.sample
cp -f conf/storage.conf $TARGET_CONF_PATH/storage.conf.sample
cp -f conf/client.conf $TARGET_CONF_PATH/client.conf.sample
cp -f conf/storage_ids.conf $TARGET_CONF_PATH/storage_ids.conf.sample
fi
mkdir -p $TARGET_INIT_PATH
cp -f init.d/fdfs_trackerd $TARGET_INIT_PATH
cp -f init.d/fdfs_storaged $TARGET_INIT_PATH
# /sbin/chkconfig --add fdfs_trackerd
# /sbin/chkconfig --add fdfs_storaged
fi
fi
fi
dnl config.m4 for extension fastdfs_client
PHP_ARG_WITH(fastdfs_client, for fastdfs_client support FastDFS client,
[ --with-fastdfs_client Include fastdfs_client support FastDFS client])
if test "$PHP_FASTDFS_CLIENT" != "no"; then
PHP_SUBST(FASTDFS_CLIENT_SHARED_LIBADD)
if test -z "$ROOT"; then
ROOT=/usr
fi
PHP_ADD_INCLUDE($ROOT/include/fastcommon)
PHP_ADD_INCLUDE($ROOT/include/fastdfs)
PHP_ADD_LIBRARY_WITH_PATH(fastcommon, $ROOT/lib, FASTDFS_CLIENT_SHARED_LIBADD)
PHP_ADD_LIBRARY_WITH_PATH(fdfsclient, $ROOT/lib, FASTDFS_CLIENT_SHARED_LIBADD)
PHP_NEW_EXTENSION(fastdfs_client, fastdfs_client.c, $ext_shared)
CFLAGS="$CFLAGS -Wall"
fi
<?php
echo fastdfs_client_version() . "\n";
$file_info = fastdfs_storage_upload_appender_by_filename("/usr/include/stdio.h");
if (!$file_info)
{
echo "fastdfs_storage_upload_appender_by_filename fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
exit;
}
$group_name = $file_info['group_name'];
$remote_filename = $file_info['filename'];
var_dump($file_info);
$file_id = "$group_name/$remote_filename";
var_dump(fastdfs_get_file_info($group_name, $remote_filename));
$appender_filename = $remote_filename;
echo "file id: $group_name/$appender_filename\n";
if (!fastdfs_storage_append_by_filename("/usr/include/stdlib.h", $group_name, $appender_filename))
{
echo "fastdfs_storage_append_by_filename fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
exit;
}
var_dump(fastdfs_get_file_info($group_name, $appender_filename));
if (!fastdfs_storage_modify_by_filename("/usr/include/stdlib.h", 0, $group_name, $appender_filename))
{
echo "fastdfs_storage_modify_by_filename fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
exit;
}
var_dump(fastdfs_get_file_info($group_name, $appender_filename));
if (!fastdfs_storage_truncate_file($group_name, $appender_filename, 0))
{
echo "fastdfs_storage_truncate_file fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
exit;
}
var_dump(fastdfs_get_file_info($group_name, $appender_filename));
echo "function test done\n\n";
$fdfs = new FastDFS();
$file_info = $fdfs->storage_upload_appender_by_filename("/usr/include/stdio.h");
if (!$file_info)
{
echo "$fdfs->storage_upload_appender_by_filename fail, errno: " . $fdfs->get_last_error_no() . ", error info: " . $fdfs->get_last_error_info() . "\n";
exit;
}
$group_name = $file_info['group_name'];
$remote_filename = $file_info['filename'];
var_dump($file_info);
$file_id = "$group_name/$remote_filename";
var_dump($fdfs->get_file_info($group_name, $remote_filename));
$appender_filename = $remote_filename;
echo "file id: $group_name/$appender_filename\n";
if (!$fdfs->storage_append_by_filename("/usr/include/stdlib.h", $group_name, $appender_filename))
{
echo "$fdfs->storage_append_by_filename fail, errno: " . $fdfs->get_last_error_no() . ", error info: " . $fdfs->get_last_error_info() . "\n";
exit;
}
var_dump($fdfs->get_file_info($group_name, $appender_filename));
if (!$fdfs->storage_modify_by_filename("/usr/include/stdlib.h", 0, $group_name, $appender_filename))
{
echo "$fdfs->storage_modify_by_filename fail, errno: " . $fdfs->get_last_error_no() . ", error info: " . $fdfs->get_last_error_info() . "\n";
exit;
}
var_dump($fdfs->get_file_info($group_name, $appender_filename));
if (!$fdfs->storage_truncate_file($group_name, $appender_filename))
{
echo "$fdfs->storage_truncate_file fail, errno: " . $fdfs->get_last_error_no() . ", error info: " . $fdfs->get_last_error_info() . "\n";
exit;
}
var_dump($fdfs->get_file_info($group_name, $appender_filename));
echo 'tracker_close_all_connections result: ' . $fdfs->tracker_close_all_connections() . "\n";
?>
<?php
echo fastdfs_client_version() . "\n";
$appender_file_id = fastdfs_storage_upload_appender_by_filename1("/usr/include/stdio.h");
if (!$appender_file_id)
{
echo "fastdfs_storage_upload_appender_by_filename1 fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
exit;
}
var_dump($appender_file_id);
var_dump(fastdfs_get_file_info1($appender_file_id));
if (!fastdfs_storage_append_by_filename1("/usr/include/stdlib.h", $appender_file_id))
{
echo "fastdfs_storage_append_by_filename1 fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
exit;
}
var_dump(fastdfs_get_file_info1($appender_file_id));
if (!fastdfs_storage_modify_by_filename1("/usr/include/stdlib.h", 0, $appender_file_id))
{
echo "fastdfs_storage_modify_by_filename1 fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
exit;
}
var_dump(fastdfs_get_file_info1($appender_file_id));
if (!fastdfs_storage_truncate_file1($appender_file_id, 0))
{
echo "fastdfs_storage_truncate_file1 fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
exit;
}
var_dump(fastdfs_get_file_info1($appender_file_id));
echo "function test done\n\n";
$fdfs = new FastDFS();
$appender_file_id = $fdfs->storage_upload_appender_by_filename1("/usr/include/stdio.h");
if (!$appender_file_id)
{
echo "\$fdfs->storage_upload_appender_by_filename1 fail, errno: " . $fdfs->get_last_error_no() . ", error info: " . $fdfs->get_last_error_info() . "\n";
exit;
}
var_dump($appender_file_id);
var_dump($fdfs->get_file_info1($appender_file_id));
if (!$fdfs->storage_append_by_filename1("/usr/include/stdlib.h", $appender_file_id))
{
echo "\$fdfs->storage_append_by_filename1 fail, errno: " . $fdfs->get_last_error_no() . ", error info: " . $fdfs->get_last_error_info() . "\n";
exit;
}
var_dump($fdfs->get_file_info1($appender_file_id));
if (!$fdfs->storage_modify_by_filename1("/usr/include/stdlib.h", 0, $appender_file_id))
{
echo "\$fdfs->storage_modify_by_filename1 fail, errno: " . $fdfs->get_last_error_no() . ", error info: " . $fdfs->get_last_error_info() . "\n";
exit;
}
var_dump($fdfs->get_file_info1($appender_file_id));
if (!$fdfs->storage_truncate_file1($appender_file_id))
{
echo "\$fdfs->torage_truncate_file1 torage_modify_by_filename1 fail, errno: " . $fdfs->get_last_error_no() . ", error info: " . $fdfs->get_last_error_info() . "\n";
exit;
}
var_dump($fdfs->get_file_info1($appender_file_id));
echo 'tracker_close_all_connections result: ' . $fdfs->tracker_close_all_connections() . "\n";
?>
<?php
define('FILE_BUFF', "this is a test\n");
echo 'FastDFS Client Version: ' . fastdfs_client_version() . "\n";
$upload_callback_arg = array ( 'buff' => FILE_BUFF);
$upload_callback_array = array(
'callback' => 'my_upload_file_callback',
'file_size' => strlen(FILE_BUFF),
'args' => $upload_callback_arg);
$download_callback_arg = array (
'filename' => '/tmp/out.txt',
'write_bytes' => 0,
'fhandle' => NULL
);
$download_callback_array = array(
'callback' => 'my_download_file_callback',
'args' => &$download_callback_arg);
$file_info = fastdfs_storage_upload_by_callback($upload_callback_array);
if ($file_info)
{
$group_name = $file_info['group_name'];
$remote_filename = $file_info['filename'];
var_dump($file_info);
var_dump(fastdfs_get_file_info($group_name, $remote_filename));
fastdfs_storage_download_file_to_callback($group_name, $remote_filename, $download_callback_array);
}
else
{
echo "upload file fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
}
$file_id = fastdfs_storage_upload_by_callback1($upload_callback_array, 'txt');
if ($file_id)
{
var_dump($file_id);
$download_callback_arg['filename'] = '/tmp/out1.txt';
fastdfs_storage_download_file_to_callback1($file_id, $download_callback_array);
}
else
{
echo "upload file fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
}
$fdfs = new FastDFS();
$file_info = $fdfs->storage_upload_by_callback($upload_callback_array, 'txt');
if ($file_info)
{
$group_name = $file_info['group_name'];
$remote_filename = $file_info['filename'];
var_dump($file_info);
var_dump($fdfs->get_file_info($group_name, $remote_filename));
$download_callback_arg['filename'] = '/tmp/fdfs_out.txt';
$fdfs->storage_download_file_to_callback($group_name, $remote_filename, $download_callback_array);
}
else
{
echo "upload file fail, errno: " . $fdfs->get_last_error_no() . ", error info: " . $fdfs->get_last_error_info() . "\n";
}
$file_id = $fdfs->storage_upload_by_callback1($upload_callback_array, 'txt');
if ($file_id)
{
var_dump($file_id);
$download_callback_arg['filename'] = '/tmp/fdfs_out1.txt';
$fdfs->storage_download_file_to_callback1($file_id, $download_callback_array);
}
else
{
echo "upload file fail, errno: " . $fdfs->get_last_error_no() . ", error info: " . $fdfs->get_last_error_info() . "\n";
}
function my_upload_file_callback($sock, $args)
{
//var_dump($args);
$ret = fastdfs_send_data($sock, $args['buff']);
return $ret;
}
function my_download_file_callback($args, $file_size, $data)
{
//var_dump($args);
if ($args['fhandle'] == NULL)
{
$args['fhandle'] = fopen ($args['filename'], 'w');
if (!$args['fhandle'])
{
echo 'open file: ' . $args['filename'] . " fail!\n";
return false;
}
}
$len = strlen($data);
if (fwrite($args['fhandle'], $data, $len) === false)
{
echo 'write to file: ' . $args['filename'] . " fail!\n";
$result = false;
}
else
{
$args['write_bytes'] += $len;
$result = true;
}
if ((!$result) || $args['write_bytes'] >= $file_size)
{
fclose($args['fhandle']);
$args['fhandle'] = NULL;
$args['write_bytes'] = 0;
}
return $result;
}
?>
This diff could not be displayed because it is too large.
#ifndef FASTDFS_CLIENT_H
#define FASTDFS_CLIENT_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef PHP_WIN32
#define PHP_FASTDFS_API __declspec(dllexport)
#else
#define PHP_FASTDFS_API
#endif
PHP_MINIT_FUNCTION(fastdfs_client);
PHP_RINIT_FUNCTION(fastdfs_client);
PHP_MSHUTDOWN_FUNCTION(fastdfs_client);
PHP_RSHUTDOWN_FUNCTION(fastdfs_client);
PHP_MINFO_FUNCTION(fastdfs_client);
ZEND_FUNCTION(fastdfs_client_version);
ZEND_FUNCTION(fastdfs_active_test);
ZEND_FUNCTION(fastdfs_connect_server);
ZEND_FUNCTION(fastdfs_disconnect_server);
ZEND_FUNCTION(fastdfs_get_last_error_no);
ZEND_FUNCTION(fastdfs_get_last_error_info);
ZEND_FUNCTION(fastdfs_tracker_get_connection);
ZEND_FUNCTION(fastdfs_tracker_make_all_connections);
ZEND_FUNCTION(fastdfs_tracker_close_all_connections);
ZEND_FUNCTION(fastdfs_tracker_list_groups);
ZEND_FUNCTION(fastdfs_tracker_query_storage_store);
ZEND_FUNCTION(fastdfs_tracker_query_storage_store_list);
ZEND_FUNCTION(fastdfs_tracker_query_storage_update);
ZEND_FUNCTION(fastdfs_tracker_query_storage_fetch);
ZEND_FUNCTION(fastdfs_tracker_query_storage_list);
ZEND_FUNCTION(fastdfs_tracker_query_storage_update1);
ZEND_FUNCTION(fastdfs_tracker_query_storage_fetch1);
ZEND_FUNCTION(fastdfs_tracker_query_storage_list1);
ZEND_FUNCTION(fastdfs_tracker_delete_storage);
ZEND_FUNCTION(fastdfs_storage_upload_by_filename);
ZEND_FUNCTION(fastdfs_storage_upload_by_filename1);
ZEND_FUNCTION(fastdfs_storage_upload_by_filebuff);
ZEND_FUNCTION(fastdfs_storage_upload_by_filebuff1);
ZEND_FUNCTION(fastdfs_storage_upload_by_callback);
ZEND_FUNCTION(fastdfs_storage_upload_by_callback1);
ZEND_FUNCTION(fastdfs_storage_upload_appender_by_filename);
ZEND_FUNCTION(fastdfs_storage_upload_appender_by_filename1);
ZEND_FUNCTION(fastdfs_storage_upload_appender_by_filebuff);
ZEND_FUNCTION(fastdfs_storage_upload_appender_by_filebuff1);
ZEND_FUNCTION(fastdfs_storage_upload_appender_by_callback);
ZEND_FUNCTION(fastdfs_storage_upload_appender_by_callback1);
ZEND_FUNCTION(fastdfs_storage_delete_file);
ZEND_FUNCTION(fastdfs_storage_delete_file1);
ZEND_FUNCTION(fastdfs_storage_download_file_to_buff);
ZEND_FUNCTION(fastdfs_storage_download_file_to_buff1);
ZEND_FUNCTION(fastdfs_storage_download_file_to_file);
ZEND_FUNCTION(fastdfs_storage_download_file_to_file1);
ZEND_FUNCTION(fastdfs_storage_download_file_to_callback);
ZEND_FUNCTION(fastdfs_storage_download_file_to_callback1);
ZEND_FUNCTION(fastdfs_storage_set_metadata);
ZEND_FUNCTION(fastdfs_storage_set_metadata1);
ZEND_FUNCTION(fastdfs_storage_get_metadata);
ZEND_FUNCTION(fastdfs_storage_get_metadata1);
ZEND_FUNCTION(fastdfs_http_gen_token);
ZEND_FUNCTION(fastdfs_get_file_info);
ZEND_FUNCTION(fastdfs_get_file_info1);
ZEND_FUNCTION(fastdfs_storage_file_exist);
ZEND_FUNCTION(fastdfs_storage_file_exist1);
ZEND_FUNCTION(fastdfs_gen_slave_filename);
ZEND_FUNCTION(fastdfs_send_data);
ZEND_FUNCTION(fastdfs_storage_upload_slave_by_filename);
ZEND_FUNCTION(fastdfs_storage_upload_slave_by_filename1);
ZEND_FUNCTION(fastdfs_storage_upload_slave_by_filebuff);
ZEND_FUNCTION(fastdfs_storage_upload_slave_by_filebuff1);
ZEND_FUNCTION(fastdfs_storage_upload_slave_by_callback);
ZEND_FUNCTION(fastdfs_storage_upload_slave_by_callback1);
ZEND_FUNCTION(fastdfs_storage_append_by_filename);
ZEND_FUNCTION(fastdfs_storage_append_by_filename1);
ZEND_FUNCTION(fastdfs_storage_append_by_filebuff);
ZEND_FUNCTION(fastdfs_storage_append_by_filebuff1);
ZEND_FUNCTION(fastdfs_storage_append_by_callback);
ZEND_FUNCTION(fastdfs_storage_append_by_callback1);
ZEND_FUNCTION(fastdfs_storage_modify_by_filename);
ZEND_FUNCTION(fastdfs_storage_modify_by_filename1);
ZEND_FUNCTION(fastdfs_storage_modify_by_filebuff);
ZEND_FUNCTION(fastdfs_storage_modify_by_filebuff1);
ZEND_FUNCTION(fastdfs_storage_modify_by_callback);
ZEND_FUNCTION(fastdfs_storage_modify_by_callback1);
ZEND_FUNCTION(fastdfs_storage_truncate_file);
ZEND_FUNCTION(fastdfs_storage_truncate_file1);
PHP_FASTDFS_API zend_class_entry *php_fdfs_get_ce(void);
PHP_FASTDFS_API zend_class_entry *php_fdfs_get_exception(void);
PHP_FASTDFS_API zend_class_entry *php_fdfs_get_exception_base(int root
TSRMLS_DC);
#ifdef __cplusplus
}
#endif
#endif /* FASTDFS_CLIENT_H */
extension = fastdfs_client.so
; the base path
fastdfs_client.base_path = /tmp
; connect timeout in seconds
; default value is 30s
fastdfs_client.connect_timeout = 2
; network timeout in seconds
; default value is 30s
fastdfs_client.network_timeout = 60
; standard log level as syslog, case insensitive, value list:
;;; emerg for emergency
;;; alert
;;; crit for critical
;;; error
;;; warn for warning
;;; notice
;;; info
;;; debug
fastdfs_client.log_level = info
; set the log filename, such as /usr/local/fastdfs/logs/fastdfs_client.log
; empty for output to stderr
fastdfs_client.log_filename =
; secret key to generate anti-steal token
; this parameter must be set when http.anti_steal.check_token set to true
; the length of the secret key should not exceed 128 bytes
fastdfs_client.http.anti_steal_secret_key =
; FastDFS cluster count, default value is 1
fastdfs_client.tracker_group_count = 1
; config file of FastDFS cluster ;, based 0
; must include absolute path, such as fastdfs_client.tracker_group0
; the config file is same as conf/client.conf
fastdfs_client.tracker_group0 = /etc/fdfs/client.conf
; if use connection pool
; default value is false
; since V4.05
fastdfs_client.use_connection_pool = true
; connections whose the idle time exceeds this time will be closed
; unit: second
; default value is 3600
; since V4.05
fastdfs_client.connection_pool_max_idle_time = 3600
%define php_inidir %(php --ini | head -n 1 | awk -F ':' '{print $2;}' | sed 's/ //g')
%define php_extdir %(php-config --extension-dir 2>/dev/null)
Name: fastdfs_client
Version: 5.0.9
Release: 1%{?dist}
Summary: The php extension of fastdfs client
License: GPL
Group: Arch/Tech
URL: https://github.com/happyfish100/fastdfs
Source: https://github.com/happyfish100/fastdfs/%{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: libfdfsclient-devel
Requires: libfdfsclient
%description
This package provides the php extension for fastdfs client
%prep
%setup -q
%build
phpize
%configure
make
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}%{php_extdir}
mkdir -p %{buildroot}%{php_inidir}/php.d
cp -f .libs/fastdfs_client.so %{buildroot}%{php_extdir}/
cp -f fastdfs_client.ini %{buildroot}%{php_inidir}/php.d/
%post
%preun
%postun
%clean
#rm -rf %{buildroot}
%files
%defattr(-,root,root,-)
%{php_extdir}/*
%{php_inidir}/php.d/*
%changelog
* Mon Jun 23 2014 Zaixue Liao <liaozaixue@yongche.com>
- first RPM release (1.0)
<?php
$group_name = "group1";
$remote_filename = "M00/28/E3/U6Q-CkrMFUgAAAAAAAAIEBucRWc5452.h";
$file_id = $group_name . FDFS_FILE_ID_SEPERATOR . $remote_filename;
echo fastdfs_client_version() . "\n";
$storage = fastdfs_tracker_query_storage_store();
if (!$storage)
{
error_log("errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info());
exit(1);
}
$server = fastdfs_connect_server($storage['ip_addr'], $storage['port']);
if (!$server)
{
error_log("errno1: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info());
exit(1);
}
if (!fastdfs_active_test($server))
{
error_log("errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info());
exit(1);
}
$storage['sock'] = $server['sock'];
$file_info = fastdfs_storage_upload_by_filename("/usr/include/stdio.h", null, array('test' => 1));
if ($file_info)
{
$group_name = $file_info['group_name'];
$remote_filename = $file_info['filename'];
var_dump($file_info);
var_dump(fastdfs_get_file_info($group_name, $remote_filename));
$master_filename = $remote_filename;
$prefix_name = '.part1';
$meta_list = array('width' => 1024, 'height' => 768, 'color' => 'blue');
$slave_file_info = fastdfs_storage_upload_slave_by_filename("/usr/include/stdio.h",
$group_name, $master_filename, $prefix_name, null, $meta_list);
if ($slave_file_info !== false)
{
var_dump($slave_file_info);
$generated_filename = fastdfs_gen_slave_filename($master_filename, $prefix_name);
if ($slave_file_info['filename'] != $generated_filename)
{
echo "${slave_file_info['filename']}\n != \n${generated_filename}\n";
}
//echo "delete slave file return: " . fastdfs_storage_delete_file($slave_file_info['group_name'], $slave_file_info['filename']) . "\n";
}
else
{
echo "fastdfs_storage_upload_slave_by_filename fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
}
echo "delete file return: " . fastdfs_storage_delete_file($file_info['group_name'], $file_info['filename']) . "\n";
}
?>
#!/bin/sh
if [ -z "$1" ]; then
/bin/echo "$0 <command line>"
exit 1
fi
if [ -f /bin/awk ]; then
AWK=/bin/awk
else
AWK=/usr/bin/awk
fi
if [ -f /bin/grep ]; then
GREP=/bin/grep
else
GREP=/usr/bin/grep
fi
if [ -f /bin/expr ]; then
EXPR=/bin/expr
else
EXPR=/usr/bin/expr
fi
if [ -f /bin/sed ]; then
SED=/bin/sed
else
SED=/usr/bin/sed
fi
program=`/bin/echo $1 | $AWK -F '/' '{print $NF;}'`
param=''
grep_cmd="$GREP -w $program"
list='2 3 4 5 6 7 8 9'
for i in $list; do
eval p='$'$i
if [ -z "$p" ]; then
break
fi
param="$param $p"
#first_ch=`$EXPR substr "$p" 1 1`
first_ch=`/bin/echo "$p" | $SED -e 's/\(.\).*/\1/'`
if [ "$first_ch" = "-" ]; then
p="'\\$p'"
fi
grep_cmd="$grep_cmd | $GREP -w $p"
done
cmd="/bin/ps auxww | $grep_cmd | $GREP -v grep | $GREP -v $0 | $AWK '{print \$2;}'"
pids=`/bin/sh -c "$cmd"`
if [ ! -z "$pids" ]; then
i=0
count=0
/bin/echo "stopping $program ..."
while [ 1 -eq 1 ]; do
new_pids=''
for pid in $pids; do
if [ $i -eq 0 ]; then
/bin/kill $pid
else
/bin/kill $pid >/dev/null 2>&1
fi
if [ $? -eq 0 ]; then
new_pids="$new_pids $pid"
fi
count=`$EXPR $count + 1`
done
if [ -z "$new_pids" ]; then
break
fi
pids="$new_pids"
/usr/bin/printf .
/bin/sleep 1
i=`$EXPR $i + 1`
done
fi
/bin/echo ""
cmd="/bin/ps auxww | $grep_cmd | $GREP -v grep | $GREP -v $0 | /usr/bin/wc -l"
count=`/bin/sh -c "$cmd"`
if [ $count -eq 0 ]; then
/bin/echo "starting $program ..."
exec $1 $param
exit $?
else
cmd="/bin/ps auxww | $grep_cmd | $GREP -v grep | $GREP -v $0"
/bin/sh -c "$cmd"
/bin/echo "already running $program count: $count, restart aborted!"
exit 16
fi
#!/bin/sh
if [ -z "$1" ]; then
/bin/echo "$0 <command line>"
exit 1
fi
if [ -f /bin/awk ]; then
AWK=/bin/awk
else
AWK=/usr/bin/awk
fi
if [ -f /bin/grep ]; then
GREP=/bin/grep
else
GREP=/usr/bin/grep
fi
if [ -f /bin/expr ]; then
EXPR=/bin/expr
else
EXPR=/usr/bin/expr
fi
if [ -f /bin/sed ]; then
SED=/bin/sed
else
SED=/usr/bin/sed
fi
program=`/bin/echo $1 | $AWK -F '/' '{print $NF;}'`
grep_cmd="$GREP -w $program"
list='2 3 4 5 6 7 8 9'
for i in $list; do
eval p='$'$i
if [ -z "$p" ]; then
break
fi
#first_ch=`$EXPR substr "$p" 1 1`
first_ch=`/bin/echo "$p" | $SED -e 's/\(.\).*/\1/'`
if [ "$first_ch" = "-" ]; then
p="'\\$p'"
fi
grep_cmd="$grep_cmd | $GREP -w $p"
done
cmd="/bin/ps auxww | $grep_cmd | $GREP -v grep | $GREP -v $0 | $AWK '{print \$2;}'"
pids=`/bin/sh -c "$cmd"`
if [ ! -z "$pids" ]; then
i=0
count=0
/bin/echo "stopping $program ..."
while [ 1 -eq 1 ]; do
new_pids=''
for pid in $pids; do
if [ $i -eq 0 ]; then
/bin/kill $pid
else
/bin/kill $pid >/dev/null 2>&1
fi
if [ $? -eq 0 ]; then
new_pids="$new_pids $pid"
fi
count=`$EXPR $count + 1`
done
if [ -z "$new_pids" ]; then
break
fi
pids="$new_pids"
/usr/bin/printf .
/bin/sleep 1
i=`$EXPR $i + 1`
done
fi
/bin/echo ""
cmd="/bin/ps auxww | $grep_cmd | $GREP -v grep | $GREP -v $0 | /usr/bin/wc -l"
count=`/bin/sh -c "$cmd"`
if [ $count -eq 0 ]; then
exit 0
else
cmd="/bin/ps auxww | $grep_cmd | $GREP -v grep | $GREP -v $0"
/bin/sh -c "$cmd"
/bin/echo "already running $program count: $count, stop fail!"
exit 16
fi
.SUFFIXES: .c .o
COMPILE = $(CC) $(CFLAGS)
INC_PATH = -I. -Itrunk_mgr -I../common -I../tracker -I../client -Ifdht_client -I/usr/include/fastcommon
LIB_PATH = $(LIBS) -lfastcommon
TARGET_PATH = $(TARGET_PREFIX)/bin
CONFIG_PATH = $(TARGET_CONF_PATH)
SHARED_OBJS = ../common/fdfs_global.o \
../tracker/fdfs_shared_func.o ../tracker/tracker_proto.o \
tracker_client_thread.o storage_global.o storage_func.o \
storage_service.o storage_sync.o storage_nio.o storage_dio.o \
storage_ip_changed_dealer.o storage_param_getter.o \
storage_disk_recovery.o trunk_mgr/trunk_mem.o \
trunk_mgr/trunk_shared.o trunk_mgr/trunk_sync.o \
trunk_mgr/trunk_client.o trunk_mgr/trunk_free_block_checker.o \
../client/client_global.o ../client/tracker_client.o \
../client/storage_client.o ../client/client_func.o \
fdht_client/fdht_proto.o fdht_client/fdht_client.o \
fdht_client/fdht_func.o fdht_client/fdht_global.o \
$(STORAGE_EXTRA_OBJS)
ALL_OBJS = $(SHARED_OBJS)
ALL_PRGS = fdfs_storaged
all: $(ALL_OBJS) $(ALL_PRGS)
.o:
$(COMPILE) -o $@ $< $(SHARED_OBJS) $(LIB_PATH) $(INC_PATH)
.c:
$(COMPILE) -o $@ $< $(ALL_OBJS) $(LIB_PATH) $(INC_PATH)
.c.o:
$(COMPILE) -c -o $@ $< $(INC_PATH)
install:
mkdir -p $(TARGET_PATH)
mkdir -p $(CONFIG_PATH)
cp -f $(ALL_PRGS) $(TARGET_PATH)
if [ ! -f $(CONFIG_PATH)/storage.conf.sample ]; then cp -f ../conf/storage.conf $(CONFIG_PATH)/storage.conf.sample; fi
clean:
rm -f $(ALL_OBJS) $(ALL_PRGS)
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
// fdht_client.h
#ifndef _FDHT_CLIENT_H
#define _FDHT_CLIENT_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "fdht_define.h"
#include "fdht_types.h"
#include "fdht_proto.h"
#include "fdht_func.h"
#ifdef __cplusplus
extern "C" {
#endif
extern GroupArray g_group_array; // group info, including server list
extern bool g_keep_alive; // persistent connection flag
/*
init function
param:
filename: client config filename
return: 0 for success, != 0 for fail (errno)
*/
int fdht_client_init(const char *filename);
/*
init function
param:
filename: client config filename
pGroupArray: return server list
bKeepAlive: return keep alive flag
return: 0 for success, != 0 for fail (errno)
*/
int fdht_load_conf(const char *filename, GroupArray *pGroupArray,
bool *bKeepAlive);
int fdht_connect_all_servers(GroupArray *pGroupArray, const bool bKeepAlive,
int *success_count, int *fail_count);
void fdht_disconnect_all_servers(GroupArray *pGroupArray);
/*
destroy function, free resource
param:
return: none
*/
void fdht_client_destroy();
#define fdht_get(pKeyInfo, ppValue, value_len) \
fdht_get_ex1((&g_group_array), g_keep_alive, pKeyInfo, FDHT_EXPIRES_NONE, \
ppValue, value_len, malloc)
#define fdht_get_ex(pKeyInfo, expires, ppValue, value_len) \
fdht_get_ex1((&g_group_array), g_keep_alive, pKeyInfo, expires, ppValue, \
value_len, malloc)
#define fdht_batch_get(pObjectInfo, key_list, key_count, success_count) \
fdht_batch_get_ex1((&g_group_array), g_keep_alive, pObjectInfo, key_list, \
key_count, FDHT_EXPIRES_NONE, malloc, success_count)
#define fdht_batch_get_ex(pObjectInfo, key_list, key_count, expires, \
success_count) \
fdht_batch_get_ex1((&g_group_array), g_keep_alive, pObjectInfo, key_list, \
key_count, expires, malloc, success_count)
#define fdht_set(pKeyInfo, expires, pValue, value_len) \
fdht_set_ex((&g_group_array), g_keep_alive, pKeyInfo, expires, pValue, \
value_len)
#define fdht_batch_set(pObjectInfo, key_list, key_count, expires, \
success_count) \
fdht_batch_set_ex((&g_group_array), g_keep_alive, pObjectInfo, key_list, \
key_count, expires, success_count)
#define fdht_inc(pKeyInfo, expires, increase, pValue, value_len) \
fdht_inc_ex((&g_group_array), g_keep_alive, pKeyInfo, expires, increase, \
pValue, value_len)
#define fdht_delete(pKeyInfo) \
fdht_delete_ex((&g_group_array), g_keep_alive, pKeyInfo)
#define fdht_batch_delete(pObjectInfo, key_list, key_count, success_count) \
fdht_batch_delete_ex((&g_group_array), g_keep_alive, pObjectInfo, \
key_list, key_count, success_count)
#define fdht_stat(server_index, buff, size) \
fdht_stat_ex((&g_group_array), g_keep_alive, server_index, buff, size)
/*
get value of the key
param:
pGroupArray: group info, can use &g_group_array
bKeepAlive: persistent connection flag, true for persistent connection
pKeyInfo: the key to fetch
expires: expire time (unix timestamp)
FDHT_EXPIRES_NONE - do not change the expire time of the key
FDHT_EXPIRES_NEVER- set the expire time to forever(never
expired)
ppValue: return the value of the key
value_len: return the length of the value (bytes)
malloc_func: malloc function, can be standard function named malloc
return: 0 for success, != 0 for fail (errno)
*/
int fdht_get_ex1(GroupArray *pGroupArray, const bool bKeepAlive,
FDHTKeyInfo *pKeyInfo, const time_t expires, char **ppValue,
int *value_len, MallocFunc malloc_func);
/*
get values of the key list
param:
pGroupArray: group info, can use &g_group_array
bKeepAlive: persistent connection flag, true for persistent connection
pObjectInfo: the object to fetch, namespace and object id can't be
empty
key_list: key list, return the value of the key
key_count: key count
expires: expire time (unix timestamp)
FDHT_EXPIRES_NONE - do not change the expire time of the keys
FDHT_EXPIRES_NEVER- set the expire time to forever(never
expired)
malloc_func: malloc function, can be standard function named malloc
return: 0 for success, != 0 for fail (errno)
*/
int fdht_batch_get_ex1(GroupArray *pGroupArray, const bool bKeepAlive,
FDHTObjectInfo *pObjectInfo, FDHTKeyValuePair *key_list,
const int key_count, const time_t expires,
MallocFunc malloc_func, int *success_count);
/*
set value of the key
param:
pGroupArray: group info, can use &g_group_array
bKeepAlive: persistent connection flag, true for persistent connection
pKeyInfo: the key to set
expires: expire time (unix timestamp)
FDHT_EXPIRES_NEVER- set the expire time to forever(never
expired)
pValue: the value of the key
value_len: the length of the value (bytes)
return: 0 for success, != 0 for fail (errno)
*/
int fdht_set_ex(GroupArray *pGroupArray, const bool bKeepAlive,
FDHTKeyInfo *pKeyInfo, const time_t expires, const char *pValue,
const int value_len);
/*
set values of the key list
param:
pGroupArray: group info, can use &g_group_array
bKeepAlive: persistent connection flag, true for persistent connection
pObjectInfo: the object to fetch, namespace and object id can't be
empty
key_list: key list, return the value of the key
key_count: key count
expires: expire time (unix timestamp)
FDHT_EXPIRES_NEVER- set the expire time to forever(never
expired)
return: 0 for success, != 0 for fail (errno)
*/
int fdht_batch_set_ex(GroupArray *pGroupArray, const bool bKeepAlive,
FDHTObjectInfo *pObjectInfo, FDHTKeyValuePair *key_list,
const int key_count, const time_t expires,
int *success_count);
/*
increase value of the key, if the key does not exist,
set the value to increment value (param named "increase")
param:
pGroupArray: group info, can use &g_group_array
bKeepAlive: persistent connection flag, true for persistent connection
pKeyInfo: the key to increase
expires: expire time (unix timestamp)
FDHT_EXPIRES_NEVER- set the expire time to forever(never
expired)
increase: the increment value, can be negative, eg. 1 or -1
pValue: return the value after increment
value_len: return the length of the value (bytes)
return: 0 for success, != 0 for fail (errno)
*/
int fdht_inc_ex(GroupArray *pGroupArray, const bool bKeepAlive,
FDHTKeyInfo *pKeyInfo, const time_t expires, const int increase,
char *pValue, int *value_len);
/*
delete the key
param:
pGroupArray: group info, can use &g_group_array
bKeepAlive: persistent connection flag, true for persistent connection
pKeyInfo: the key to delete
return: 0 for success, != 0 for fail (errno)
*/
int fdht_delete_ex(GroupArray *pGroupArray, const bool bKeepAlive,
FDHTKeyInfo *pKeyInfo);
/*
delete key list
param:
pGroupArray: group info, can use &g_group_array
bKeepAlive: persistent connection flag, true for persistent connection
pObjectInfo: the object to fetch, namespace and object id can't be
empty
key_list: key list, return the value of the key
key_count: key count
return: 0 for success, != 0 for fail (errno)
*/
int fdht_batch_delete_ex(GroupArray *pGroupArray, const bool bKeepAlive,
FDHTObjectInfo *pObjectInfo,
FDHTKeyValuePair *key_list, const int key_count,
int *success_count);
/*
query stat of server
param:
pGroupArray: group info, can use &g_group_array
server_index: index of server, based 0
buff: return stat buff, key value pair as key=value, row seperated by \n
size: buff size
return: 0 for success, != 0 for fail (errno)
*/
int fdht_stat_ex(GroupArray *pGroupArray, const bool bKeepAlive,
const int server_index, char *buff, const int size);
#ifdef __cplusplus
}
#endif
#endif
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
No preview for this file type
No preview for this file type
No preview for this file type
This diff is collapsed. Click to expand it.
No preview for this file type
No preview for this file type
No preview for this file type
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!