⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ncbi_server_info.c

📁 ncbi源码
💻 C
📖 第 1 页 / 共 3 页
字号:
                    break;                }            }        }        if (*str && !isspace((unsigned char)(*str)))            break;        while (*str && isspace((unsigned char)(*str)))            str++;    }    if (*str) {        free(info);        info = 0;    }    return info;}size_t SERV_SizeOfInfo(const SSERV_Info *info){    return sizeof(*info) - sizeof(USERV_Info) +        s_GetAttrByType(info->type)->vtable.SizeOf(&info->u);}int/*bool*/ SERV_EqualInfo(const SSERV_Info *i1, const SSERV_Info *i2){    if (i1->type != i2->type || i1->host != i2->host || i1->port != i2->port)        return 0;    return s_GetAttrByType(i1->type)->vtable.Equal(&i1->u, &i2->u);}/***************************************************************************** *  NCBID::   constructor and virtual functions */static char* s_Ncbid_Write(size_t reserve, const USERV_Info* u){    const SSERV_NcbidInfo* info = &u->ncbid;    char* str = (char*) malloc(reserve + strlen(SERV_NCBID_ARGS(info))+3);    if (str)        sprintf(str + reserve, "%s",                *SERV_NCBID_ARGS(info) ? SERV_NCBID_ARGS(info) : "''");    return str;}static SSERV_Info* s_Ncbid_Read(const char** str){    SSERV_Info* info;    char        *args, *c;    if (!(args = strdup(*str)))        return 0;    for (c = args; *c; c++)        if (isspace((unsigned char)(*c))) {            *c++ = '\0';            while (*c && isspace((unsigned char)(*c)))                c++;            break;        }    if ((info = SERV_CreateNcbidInfo(0, 80, args)) != 0)        *str += c - args;    free(args);    return info;}static size_t s_Ncbid_SizeOf(const USERV_Info* u){    return sizeof(u->ncbid) + strlen(SERV_NCBID_ARGS(&u->ncbid))+1;}static int/*bool*/ s_Ncbid_Equal(const USERV_Info* u1, const USERV_Info* u2){    return        strcmp(SERV_NCBID_ARGS(&u1->ncbid), SERV_NCBID_ARGS(&u2->ncbid)) == 0;}SSERV_Info* SERV_CreateNcbidInfo(unsigned int   host, unsigned short port, const char*    args){    size_t args_len = args ? strlen(args) : 0;    SSERV_Info* info = (SSERV_Info*) malloc(sizeof(SSERV_Info) + args_len + 1);    if (info) {        info->type         = fSERV_Ncbid;        info->host         = host;        info->port         = port;        info->sful         = 0;        info->locl         = s_LocalServerDefault & 0x0F;        info->time         = 0;        info->coef         = 0.0;        info->rate         = 0.0;        info->mime_t       = SERV_MIME_TYPE_UNDEFINED;        info->mime_s       = SERV_MIME_SUBTYPE_UNDEFINED;        info->mime_e       = eENCOD_None;        info->flag         = SERV_DEFAULT_FLAG;        memset(&info->reserved, 0, sizeof(info->reserved));        info->quorum       = 0;        info->u.ncbid.args = (TNCBI_Size) sizeof(info->u.ncbid);        if (strcmp(args, "''") == 0) /* special case */            args = 0;        strcpy(SERV_NCBID_ARGS(&info->u.ncbid), args ? args : "");    }    return info;}/***************************************************************************** *  STANDALONE::   constructor and virtual functions *//*ARGSUSED*/static char* s_Standalone_Write(size_t reserve, const USERV_Info* u_info){    char* str = (char*) malloc(reserve + 1);    if (str)        str[reserve] = '\0';    return str;}/*ARGSUSED*/static SSERV_Info* s_Standalone_Read(const char** str){    return SERV_CreateStandaloneInfo(0, 0);}static size_t s_Standalone_SizeOf(const USERV_Info* u){    return sizeof(u->standalone);}/*ARGSUSED*/static int/*bool*/ s_Standalone_Equal(const USERV_Info* u1,                                      const USERV_Info* u2){    return 1;}SSERV_Info* SERV_CreateStandaloneInfo(unsigned int   host, unsigned short port){    SSERV_Info *info = (SSERV_Info*) malloc(sizeof(SSERV_Info));    if (info) {        info->type   = fSERV_Standalone;        info->host   = host;        info->port   = port;        info->sful   = 0;        info->locl   = s_LocalServerDefault & 0x0F;        info->time   = 0;        info->coef   = 0.0;        info->rate   = 0.0;        info->mime_t = SERV_MIME_TYPE_UNDEFINED;        info->mime_s = SERV_MIME_SUBTYPE_UNDEFINED;        info->mime_e = eENCOD_None;        info->flag   = SERV_DEFAULT_FLAG;        memset(&info->reserved, 0, sizeof(info->reserved));        info->quorum = 0;        memset(&info->u.standalone, 0, sizeof(info->u.standalone));    }    return info;}/***************************************************************************** *  HTTP::   constructor and virtual functions */static char* s_Http_Write(size_t reserve, const USERV_Info* u){    const SSERV_HttpInfo* info = &u->http;    char* str = (char*) malloc(reserve + strlen(SERV_HTTP_PATH(info))+1 +                               strlen(SERV_HTTP_ARGS(info))+1);    if (str) {        int n = sprintf(str + reserve, "%s", SERV_HTTP_PATH(info));                if (*SERV_HTTP_ARGS(info))            sprintf(str + reserve + n, "?%s", SERV_HTTP_ARGS(info));    }    return str;}static SSERV_Info* s_HttpAny_Read(ESERV_Type type, const char** str){    SSERV_Info*    info;    char           *path, *args, *c;    if (!**str || !(path = strdup(*str)))        return 0;    for (c = path; *c; c++)        if (isspace((unsigned char)(*c))) {            *c++ = '\0';            while (*c && isspace((unsigned char)(*c)))                c++;            break;        }    if ((args = strchr(path, '?')) != 0)        *args++ = '\0';    /* Sanity check: no parameter delimiter allowed within path */    if (!strchr(path, '&') &&        (info = SERV_CreateHttpInfo(type, 0, 80, path, args)) != 0)        *str += c - path;    else        info = 0;    free(path);    return info;}static SSERV_Info *s_HttpGet_Read(const char** str){    return s_HttpAny_Read(fSERV_HttpGet, str);}static SSERV_Info *s_HttpPost_Read(const char** str){    return s_HttpAny_Read(fSERV_HttpPost, str);}static SSERV_Info *s_Http_Read(const char** str){    return s_HttpAny_Read(fSERV_Http, str);}static size_t s_Http_SizeOf(const USERV_Info* u){    return sizeof(u->http) + strlen(SERV_HTTP_PATH(&u->http))+1 +        strlen(SERV_HTTP_ARGS(&u->http))+1;}static int/*bool*/ s_Http_Equal(const USERV_Info* u1, const USERV_Info* u2){    return        strcmp(SERV_HTTP_PATH(&u1->http), SERV_HTTP_PATH(&u2->http)) == 0 &&        strcmp(SERV_HTTP_ARGS(&u1->http), SERV_HTTP_ARGS(&u2->http)) == 0;}SSERV_Info* SERV_CreateHttpInfo(ESERV_Type     type, unsigned int   host, unsigned short port, const char*    path, const char*    args){    size_t add_len = (path ? strlen(path) : 0)+1 + (args ? strlen(args) : 0);    SSERV_Info* info;    if (type & ~fSERV_Http)        return 0;    if ((info = (SSERV_Info*) malloc(sizeof(SSERV_Info) + add_len+1)) != 0) {        info->type        = type;        info->host        = host;        info->port        = port;        info->sful        = 0;        info->locl        = s_LocalServerDefault & 0x0F;        info->time        = 0;        info->coef        = 0.0;        info->rate        = 0.0;        info->mime_t      = SERV_MIME_TYPE_UNDEFINED;        info->mime_s      = SERV_MIME_SUBTYPE_UNDEFINED;        info->mime_e      = eENCOD_None;        info->flag        = SERV_DEFAULT_FLAG;        memset(&info->reserved, 0, sizeof(info->reserved));        info->quorum      = 0;        info->u.http.path = (TNCBI_Size) sizeof(info->u.http);        info->u.http.args = (TNCBI_Size) (info->u.http.path +                                          strlen(path ? path : "")+1);        strcpy(SERV_HTTP_PATH(&info->u.http), path ? path : "");        strcpy(SERV_HTTP_ARGS(&info->u.http), args ? args : "");    }    return info;}/***************************************************************************** *  FIREWALL::   constructor and virtual functions */static char* s_Firewall_Write(size_t reserve, const USERV_Info* u_info){    const char* name = SERV_TypeStr(u_info->firewall.type);    size_t namelen = strlen(name);    char* str = (char*) malloc(reserve + (namelen ? namelen + 1 : 0));    if (str)        strcpy(str + reserve, name);    return str;}static SSERV_Info* s_Firewall_Read(const char** str){    ESERV_Type type;    const char* s;    if (!(s = SERV_ReadType(*str, &type)))        type = (ESERV_Type) fSERV_Any;    else        *str = s;    return SERV_CreateFirewallInfo(0, 0, type);}static size_t s_Firewall_SizeOf(const USERV_Info* u){    return sizeof(u->firewall);}static int/*bool*/ s_Firewall_Equal(const USERV_Info* u1, const USERV_Info* u2){    return u1->firewall.type == u2->firewall.type;}SSERV_Info* SERV_CreateFirewallInfo(unsigned int host, unsigned short port,                                    ESERV_Type type){    SSERV_Info* info = (SSERV_Info*) malloc(sizeof(SSERV_Info));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -