static int crlf_load_attributes(struct crlf_attrs *ca, git_repository *repo, const char *path) { #define NUM_CONV_ATTRS 3 static const char *attr_names[NUM_CONV_ATTRS] = { "crlf", "eol", "text", }; const char *attr_vals[NUM_CONV_ATTRS]; int error; error = git_attr_get_many(attr_vals, repo, 0, path, NUM_CONV_ATTRS, attr_names); if (error == GIT_ENOTFOUND) { ca->crlf_action = GIT_CRLF_GUESS; ca->eol = GIT_EOL_UNSET; return 0; } if (error == 0) { ca->crlf_action = check_crlf(attr_vals[2]); /* text */ if (ca->crlf_action == GIT_CRLF_GUESS) ca->crlf_action = check_crlf(attr_vals[0]); /* clrf */ ca->eol = check_eol(attr_vals[1]); /* eol */ return 0; } return -1; }
bool parse_message(t_parser *parser, char *message) { if (message == NULL) return (false); if (check_prefixe(parser, message) == true && check_command(parser, message) == true && check_params(parser, message) == true && check_crlf(parser, message) == true) return (true); return (false); }
static int crlf_check( git_filter *self, void **payload, /* points to NULL ptr on entry, may be set */ const git_filter_source *src, const char **attr_values) { int error; struct crlf_attrs ca; GIT_UNUSED(self); if (!attr_values) { ca.crlf_action = GIT_CRLF_GUESS; ca.eol = GIT_EOL_UNSET; } else { ca.crlf_action = check_crlf(attr_values[2]); /* text */ if (ca.crlf_action == GIT_CRLF_GUESS) ca.crlf_action = check_crlf(attr_values[0]); /* clrf */ ca.eol = check_eol(attr_values[1]); /* eol */ } ca.auto_crlf = GIT_AUTO_CRLF_DEFAULT; /* * Use the core Git logic to see if we should perform CRLF for this file * based on its attributes & the value of `core.autocrlf` */ ca.crlf_action = crlf_input_action(&ca); if (ca.crlf_action == GIT_CRLF_BINARY) return GIT_PASSTHROUGH; if (ca.crlf_action == GIT_CRLF_GUESS || (ca.crlf_action == GIT_CRLF_AUTO && git_filter_source_mode(src) == GIT_FILTER_SMUDGE)) { error = git_repository__cvar( &ca.auto_crlf, git_filter_source_repo(src), GIT_CVAR_AUTO_CRLF); if (error < 0) return error; if (ca.auto_crlf == GIT_AUTO_CRLF_FALSE) return GIT_PASSTHROUGH; if (ca.auto_crlf == GIT_AUTO_CRLF_INPUT && git_filter_source_mode(src) == GIT_FILTER_SMUDGE) return GIT_PASSTHROUGH; } if (git_filter_source_mode(src) == GIT_FILTER_CLEAN) { error = git_repository__cvar( &ca.safe_crlf, git_filter_source_repo(src), GIT_CVAR_SAFE_CRLF); if (error < 0) return error; /* downgrade FAIL to WARN if ALLOW_UNSAFE option is used */ if ((git_filter_source_options(src) & GIT_FILTER_OPT_ALLOW_UNSAFE) && ca.safe_crlf == GIT_SAFE_CRLF_FAIL) ca.safe_crlf = GIT_SAFE_CRLF_WARN; } *payload = git__malloc(sizeof(ca)); GITERR_CHECK_ALLOC(*payload); memcpy(*payload, &ca, sizeof(ca)); return 0; }
int http_parse_get(struct http_request_s *r, unsigned char* data) { /* rollback */ r->host_len = 0; r->uri_len = 0; r->url_len = 0; r->referer_len = 0; r->cookie_len = 0; r->user_agent_len = 0; /* 非必须头域初始化为空 */ r->cookie[0] = '\0'; r->referer[0] = '\0'; char* buf = (char *)data; char *sep = NULL; int len = 0, flag = 0; unsigned int cnt = 0; //buf += 4; //detect URI sep = strchr(buf, ' '); if (sep == 0) return IPTRAFFIC_FUNC_ERROR; len = sep - buf; if (len <= MAX_URI_LEN) { r->uri_len = len; *(r->uri + len) = '\0'; memcpy(r->uri, buf, len); } //start parse header buf = strstr(buf, "\r\n"); while(buf != 0 && cnt < 6) { buf = buf + 2; if ( (*buf != '\0' && *(buf + 1) != '\0' && check_crlf(buf, 2))) break; sep = strstr(buf, "\r\n"); if (sep == 0) { flag = 1; sep = buf + strlen(buf); } switch(buf[0]) { case 'h': case 'H': if ((sep - buf > 7) && (0 == strncasecmp("Host:", buf, 5))) //Host: man.chinaunix.net { len = (buf[5] == ' ') ? 6 : 5; buf = buf + len; len = sep - buf; if (len <= MAX_HOST_LEN) { r->host_len = len; *(r->host + len) = '\0'; memcpy(r->host, buf, len); } cnt++; } break; case 'u': case 'U': if ((sep - buf > 12) && (0 == strncasecmp("User-Agent:", buf, 11))) //User-Agent: Mozilla/5.0 Firefox/21.0 { len = (buf[11] == ' ') ? 12 : 11; buf = buf + len; len = sep - buf; if (len <= MAX_AGENT_LEN) { r->user_agent_len = len; *(r->user_agent + len) = '\0'; memcpy(r->user_agent, buf, len); } cnt++; } break; case 'r': case 'R': if ((sep - buf > 10) && (0 == strncasecmp("Referer:", buf, 8))) //Referer: http://man.chinaunix.net/develop/c&c++/linux_c/default.htm { len = (buf[8] == ' ') ? 9 : 8; buf = buf + len; len = sep - buf; if (len < MAX_REF_LEN) { r->referer_len = len; *(r->referer + len) = '\0'; memcpy(r->referer, buf, len); } cnt++; } break; case 'c': case 'C': if ((sep - buf > 9) && (0 == strncasecmp("Cookie:", buf, 7))) //Cookie: __utma=225341893.1493557647; { len = (buf[7] == ' ') ? 8 : 7; buf = buf + len; len = sep - buf; if (len < MAX_COOKIE_LEN) { r->cookie_len = len; *(r->cookie + len) = '\0'; memcpy(r->cookie, buf, len); } cnt++; } break; default: break; } if (flag == 1) break; buf = sep; } strcpy(r->url, r->host); if (strcmp(r->uri, "/") != 0) { strcat(r->url, r->uri); } r->url_len = strlen(r->url); return IPTRAFFIC_FUNC_SUCCESS; }
int http_parse_get(http_request_t *r, u_char *data) { /* rollback */ r->host_len = 0; r->uri_len = 0; r->x_requested_with_len = 0; r->referer_len = 0; r->cookie_len = 0; r->proxy = FALSE; r->user_agent_len = 0; char* buf = (char *)data; char *sep = NULL; int len = 0, flag = 0; unsigned int cnt = 0; buf += 4; //detect URI sep = strchr(buf, ' '); if (sep == 0) return -1; len = sep - buf; if (len < MAX_URI_LEN) { bzero(r->uri, MAX_URI_LEN); r->uri_len = len; *(r->uri + len) = '\0'; memcpy(r->uri, buf, len); } //start parse header buf = strstr(buf, "\r\n"); while(buf != 0 && cnt < 6) { buf = buf + 2; if ( (*buf != '\0' && *(buf + 1) != '\0' && check_crlf(buf, 2)) || *buf == NULL) break; sep = strstr(buf, "\r\n"); if (sep == 0) { flag = 1; sep = buf + strlen(buf); } switch(buf[0]) { case 'h': case 'H': if ((sep - buf > 7) && buf[3] == 't' && buf[4] == ':') //Host: man.chinaunix.net { len = (buf[5] == ' ') ? 6 : 5; buf = buf + len; len = sep - buf; if (len < MAX_HOST_LEN) { bzero(r->host, MAX_HOST_LEN); r->host_len = len; *(r->host + len) = '\0'; memcpy(r->host, buf, len); } cnt++; } break; case 'u': case 'U': if ((sep - buf > 12) && buf[5] == 'A' && buf[9] == 't' && buf[10] == ':') //User-Agent: Mozilla/5.0 Firefox/21.0 { len = (buf[11] == ' ') ? 12 : 11; buf = buf + len; len = sep - buf; if (len < MAX_AGENT_LEN) { bzero(r->user_agent, MAX_AGENT_LEN); r->user_agent_len = len; *(r->user_agent + len) = '\0'; memcpy(r->user_agent, buf, len); } cnt++; } break; case 'r': case 'R': if ((sep - buf > 10) && buf[6] == 'r' && buf[7] == ':') //Referer: http://man.chinaunix.net/develop/c&c++/linux_c/default.htm { len = (buf[8] == ' ') ? 9 : 8; buf = buf + len; len = sep - buf; if (len < MAX_REF_LEN) { bzero(r->referer, MAX_REF_LEN); r->referer_len = len; *(r->referer + len) = '\0'; memcpy(r->referer, buf, len); } cnt++; } break; case 'c': case 'C': if ((sep - buf > 9) && buf[5] == 'e' && buf[6] == ':') //Cookie: __utma=225341893.1493557647; { buf = buf + 7; len = sep - buf; if (len < MAX_COOKIE_LEN) { bzero(r->cookie, MAX_COOKIE_LEN); r->cookie_len = len; *(r->cookie + len) = '\0'; memcpy(r->cookie, buf, len); } cnt++; } break; #if 0 case 'X': case 'x': if ((sep - buf > 30) && (buf[2] == 'r' || buf[2] == 'R') && buf[16] == ':') //X-Requested-With: XMLHttpRequest\r\n { len = (buf[17] == ' ') ? 18 : 17; buf = buf + len; len = sep - buf; if (len < MAX_REQ_WITH_LEN) { bzero(r->x_requested_with, MAX_REQ_WITH_LEN); r->x_requested_with_len = len; *(r->x_requested_with + len) = '\0'; memcpy(r->x_requested_with, buf, len); } cnt++; } else if ((sep - buf > 20) && (buf[2] == 'f' || buf[2] == 'F') && buf[15] == ':') //X-Forwarded-For: client1, proxy1, proxy2。 { r->proxy = TRUE; cnt++; } break; case 'V': case 'v': if ((sep - buf > 6) && (buf[2] == 'i' || buf[2] == 'I') && buf[3] == ':') //Via: 1.1 BJNT3\r\n { r->proxy = TRUE; cnt++; } break; #endif } if (flag == 1) break; buf = sep; } strcpy(r->url, r->host); strcat(r->url, r->uri); // if (strcmp(r->uri, "/") != 0) // { // strcat(r->url, r->uri); // } r->url_len = strlen(r->url); return 1; }