c.footer (1226B)
1 2 3 4 const char * 5 GNUNET_ErrorCode_get_hint (enum GNUNET_ErrorCode ec) 6 { 7 unsigned int lower = 0; 8 unsigned int upper = code_hint_pairs_length - 1; 9 unsigned int mid = upper / 2; 10 while (lower <= upper) 11 { 12 mid = (upper + lower) / 2; 13 if (code_hint_pairs[mid].ec < ec) 14 { 15 lower = mid + 1; 16 } 17 else if (code_hint_pairs[mid].ec > ec) 18 { 19 upper = mid - 1; 20 } 21 else 22 { 23 return code_hint_pairs[mid].hint; 24 } 25 } 26 return "<no hint found>"; 27 } 28 29 30 unsigned int 31 GNUNET_ErrorCode_get_http_status (enum GNUNET_ErrorCode ec) 32 { 33 unsigned int lower = 0; 34 unsigned int upper = code_hint_pairs_length - 1; 35 unsigned int mid = upper / 2; 36 while (lower <= upper) 37 { 38 mid = (upper + lower) / 2; 39 if (code_hint_pairs[mid].ec < ec) 40 { 41 lower = mid + 1; 42 } 43 else if (code_hint_pairs[mid].ec > ec) 44 { 45 upper = mid - 1; 46 } 47 else 48 { 49 return code_hint_pairs[mid].http_code; 50 } 51 } 52 return UINT_MAX; 53 } 54 55 56 unsigned int 57 GNUNET_ErrorCode_get_http_status_safe (enum GNUNET_ErrorCode ec) 58 { 59 unsigned int hc; 60 61 hc = GNUNET_ErrorCode_get_http_status (ec); 62 if ( (0 == hc) || 63 (UINT_MAX == hc) ) 64 return MHD_HTTP_INTERNAL_SERVER_ERROR; 65 return hc; 66 }