* Compression function * 1) Only mandatory headers will be kept * 2) The rest of the headers along with the body * will form the new body which will be use for compression * 3) The Content-Encoding Header will set to gzip, probably * base64 also */
| 1032 | * base64 also |
| 1033 | */ |
| 1034 | static int mc_compress(struct sip_msg* msg, int *algo_p, int *flags_p, |
| 1035 | mc_whitelist_p wh_list) |
| 1036 | { |
| 1037 | int ret = -1; |
| 1038 | int index; |
| 1039 | int algo = (algo_p? *algo_p: 0); |
| 1040 | int flags = *flags_p; |
| 1041 | struct mc_comp_args* args; |
| 1042 | |
| 1043 | /* first check if anyone else has called mc_compact() on this msg */ |
| 1044 | if (GET_GLOBAL_CTX(compress_ctx_pos)) |
| 1045 | return -1; |
| 1046 | |
| 1047 | if (!(flags&BODY_COMP_FLG) && !(flags&HDR_COMP_FLG)) { |
| 1048 | LM_WARN("nothing requested to compress! " |
| 1049 | "please choose at least one of the 'b' or 'h' flags\n"); |
| 1050 | return -1; |
| 1051 | } |
| 1052 | |
| 1053 | if (wh_list) |
| 1054 | wh_list = mc_dup_whitelist(wh_list); |
| 1055 | |
| 1056 | /* Simulate a whitelist which will contain only the Content-Length |
| 1057 | header in case BODY_COMP_FLG is set */ |
| 1058 | if (flags&HDR_COMP_FLG && wh_list) { |
| 1059 | /* Remove mandatory headers if they have been set */ |
| 1060 | for (index=0; index < veclen(mnd_hdrs, int); index++) { |
| 1061 | if (wh_list->hdr_mask[mnd_hdrs[index]/MC_BYTE_SIZE] |
| 1062 | & (1 << mnd_hdrs[index]%MC_BYTE_SIZE)) { |
| 1063 | wh_list->hdr_mask[mnd_hdrs[index]/MC_BYTE_SIZE] ^= |
| 1064 | 1 << (mnd_hdrs[index]%MC_BYTE_SIZE); |
| 1065 | } |
| 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | |
| 1070 | /* Content Length must be encoded if asked for body to be encoded*/ |
| 1071 | if (flags&BODY_COMP_FLG) { |
| 1072 | if (!wh_list && parse_whitelist(NULL, &wh_list, NULL) < 0) { |
| 1073 | LM_ERR("could not allocate new list!\n"); |
| 1074 | goto end; |
| 1075 | } |
| 1076 | wh_list->hdr_mask[HDR_CONTENTLENGTH_T/MC_BYTE_SIZE] |= |
| 1077 | 1 << (HDR_CONTENTLENGTH_T%MC_BYTE_SIZE); |
| 1078 | } |
| 1079 | |
| 1080 | args=pkg_malloc(sizeof(struct mc_comp_args)); |
| 1081 | if (args==NULL) { |
| 1082 | LM_ERR("no more pkg mem\n"); |
| 1083 | goto end; |
| 1084 | } |
| 1085 | |
| 1086 | args->hdr2compress_list = wh_list; |
| 1087 | args->flags = flags; |
| 1088 | args->algo = algo; |
| 1089 | SET_GLOBAL_CTX(compress_ctx_pos, (void*)args); |
| 1090 | |
| 1091 | /* register stateless callbacks */ |
nothing calls this directly
no test coverage detected