| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
#ifdef HAVE_CONFIG_H |
|---|
| 20 |
# include <config.h> |
|---|
| 21 |
#endif |
|---|
| 22 |
|
|---|
| 23 |
#include "vserver.h" |
|---|
| 24 |
#include "pathconfig.h" |
|---|
| 25 |
|
|---|
| 26 |
#include <sys/stat.h> |
|---|
| 27 |
#include <string.h> |
|---|
| 28 |
|
|---|
| 29 |
static char const * |
|---|
| 30 |
completePath(char const *id, size_t len, vcCfgStyle style, char *buf) |
|---|
| 31 |
{ |
|---|
| 32 |
switch (style) { |
|---|
| 33 |
case vcCFG_RECENT_FULL : return id; |
|---|
| 34 |
case vcCFG_RECENT_SHORT : |
|---|
| 35 |
memcpy(buf, CONFDIR "/", sizeof(CONFDIR "/")-1); |
|---|
| 36 |
memcpy(buf+sizeof(CONFDIR "/")-1, id, len+1); |
|---|
| 37 |
return buf; |
|---|
| 38 |
default : return 0; |
|---|
| 39 |
} |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
int |
|---|
| 43 |
vc_compareVserverById(char const *lhs, vcCfgStyle lhs_style, |
|---|
| 44 |
char const *rhs, vcCfgStyle rhs_style) |
|---|
| 45 |
{ |
|---|
| 46 |
if (lhs_style==vcCFG_NONE || lhs_style==vcCFG_AUTO) |
|---|
| 47 |
lhs_style = vc_getVserverCfgStyle(lhs); |
|---|
| 48 |
|
|---|
| 49 |
if (rhs_style==vcCFG_NONE || rhs_style==vcCFG_AUTO) |
|---|
| 50 |
rhs_style = vc_getVserverCfgStyle(rhs); |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
if (lhs_style==vcCFG_LEGACY || rhs_style==vcCFG_LEGACY) { |
|---|
| 55 |
if (lhs_style!=rhs_style) return lhs_style - rhs_style; |
|---|
| 56 |
else return strcmp(lhs, rhs); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
{ |
|---|
| 60 |
size_t len_lhs = strlen(lhs); |
|---|
| 61 |
size_t len_rhs = strlen(rhs); |
|---|
| 62 |
char buf_lhs[sizeof(CONFDIR "//") + len_lhs]; |
|---|
| 63 |
char buf_rhs[sizeof(CONFDIR "//") + len_rhs]; |
|---|
| 64 |
|
|---|
| 65 |
char const * path_lhs = completePath(lhs, len_lhs, lhs_style, buf_lhs); |
|---|
| 66 |
char const * path_rhs = (path_lhs==0 |
|---|
| 67 |
? 0 |
|---|
| 68 |
: completePath(rhs, len_rhs, rhs_style, buf_rhs)); |
|---|
| 69 |
|
|---|
| 70 |
struct stat st_lhs; |
|---|
| 71 |
struct stat st_rhs; |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
if (path_lhs==path_rhs) return strcmp(lhs, rhs); |
|---|
| 75 |
if (path_lhs==0) return -1; |
|---|
| 76 |
if (path_rhs==0) return +1; |
|---|
| 77 |
|
|---|
| 78 |
if (stat(path_lhs, &st_lhs)==-1 || |
|---|
| 79 |
stat(path_rhs, &st_rhs)==-1) return strcmp(lhs,rhs); |
|---|
| 80 |
|
|---|
| 81 |
return (st_lhs.st_dev - st_rhs.st_dev) + (st_lhs.st_ino - st_rhs.st_ino); |
|---|
| 82 |
} |
|---|
| 83 |
} |
|---|