gana

GNUnet Assigned Numbers Authority
Log | Files | Refs | README | LICENSE

c.footer (1524B)


      1 
      2 
      3 
      4 const char *
      5 TALER_ErrorCode_get_hint (enum TALER_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 TALER_ErrorCode_get_http_status (enum TALER_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 TALER_ErrorCode_get_http_status_safe (enum TALER_ErrorCode ec)
     58 {
     59   unsigned int hc;
     60 
     61   hc = TALER_ErrorCode_get_http_status (ec);
     62   if ( (0 == hc) ||
     63        (UINT_MAX == hc) )
     64     return MHD_HTTP_INTERNAL_SERVER_ERROR;
     65   return hc;
     66 }
     67 
     68 
     69 void __attribute__ ((constructor))
     70 TALER_ErrorCode_check_invariants (void);
     71 
     72 void __attribute__ ((constructor))
     73 TALER_ErrorCode_check_invariants (void)
     74 {
     75   for (unsigned int i = 1; i < code_hint_pairs_length; i++)
     76     GNUNET_assert (code_hint_pairs[i-1].ec <
     77                    code_hint_pairs[i].ec);
     78 }