예제 #1
0
파일: rest.c 프로젝트: kincki/contiki
//DY : FIX_ME : can add accepted encoding here
bool rest_invoke_restful_service( ConnectionState_t* pConnectionState )
{
  bool bReturnValue = false;

  HttpMethod_t requestType = http_server_get_http_method( pConnectionState );
  char* pUrl = pConnectionState->resourceUrl;

  LOG_DBG("invokeRestfulWebService---> Url : %s\n", pUrl );

  Resource_t* pResource = NULL;

  for ( pResource=(Resource_t*)list_head(restfulServices); pResource ; pResource = pResource->next )
  {
    //if the web service handles that kind of requests and urls matches
    if ( match_addresses( pConnectionState, pResource->pUrlPattern, pUrl ) )
    {
      //found the service, break.
      bReturnValue = true;

      //if method is handled by the resource, then call the corresponding function, or else
      //then send CLIENT_ERROR_METHOD_NOT_ALLOWED status.
      if ( ( pResource->requestTypesToHandle ) & requestType )
      {
        //set to http status to success, user can change it later.
        http_server_set_http_status(pConnectionState, SUCCESS_OK);

        /*if preHandler is not set or it returns true if it is set.*/
        if ( !pResource->preHandler || pResource->preHandler(pConnectionState) )
        {
          pResource->handler(pConnectionState);

          /*call post handler if exists*/
          if (pResource->postHandler)
          {
            pResource->postHandler(pConnectionState);
          }
        }
      }
      else
      {
        http_server_set_http_status(pConnectionState, CLIENT_ERROR_METHOD_NOT_ALLOWED);
      }
      break;
    }
  }

  if ( bReturnValue == false )
  {
    http_server_set_http_status(pConnectionState, CLIENT_ERROR_NOT_FOUND);
    LOG_DBG("No Restful Service Found!!!\n");
  }

  return bReturnValue;
}
예제 #2
0
파일: ldb.c 프로젝트: ysleu/RTL8685
/*
 * Rules in finding the LES address:
 * 1. If elan_name matches exactly &&
 *    there is an entry matching this ATM address for this ELAN.
 *    If elan_name matches, but ATM address is not found, reject.
 * 2. Search for first ELAN which matches in type, max_frame and
 *    ATM address.
 * 3. Return default elan
 * 4. No match, reject.
 */
Elan_t*
find_elan(unsigned char *lec_addr, const char type, 
	  const char max_frame, const char *elan_name, 
	  const short elan_name_size, unsigned short *reason)
{
  int pos;

  *reason = LE_STATUS_SUCCESS;
  for(pos=0;pos<no_elans;pos++) {
    if (elan_name_size == elan_arr[pos]->elan_name_size &&
	!memcmp(elan_name, elan_arr[pos]->elan_name, elan_name_size)) {      
      if (match_addresses(elan_arr[pos], lec_addr)) {
	return elan_arr[pos];
      } else { 
	*reason = LE_STATUS_NO_ACCESS;
	return NULL;
      }
    }
  }
  for(pos=0;pos<no_elans;pos++) {
    if ((max_frame == LE_MAX_FRAME_UNSPECIFIED ||
	 elan_arr[pos]->max_frame == LE_MAX_FRAME_UNSPECIFIED ||
	 max_frame == elan_arr[pos]->max_frame) &&
	(type == LE_LAN_TYPE_UNSPECIFIED ||
	 elan_arr[pos]->type == LE_LAN_TYPE_UNSPECIFIED ||
	 type == elan_arr[pos]->type)) {
      if (match_addresses(elan_arr[pos], lec_addr)) {
	return elan_arr[pos];
      }
    }
  }
  if (default_elan)
    return default_elan;  
  *reason = LE_STATUS_NO_CONFIG;
  return NULL;
}
예제 #3
0
int
sieve_action_vacation (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
{
  int rc;
  char *text, *from;
  mu_sieve_value_t *val;
  mu_message_t msg;
  mu_header_t hdr;
  char *my_address = mu_sieve_get_daemon_email (mach);
  
  if (diag (mach))
    return 0;
  
  val = mu_sieve_value_get (args, 0);
  if (!val)
    {
      mu_sieve_error (mach, _("cannot get text!"));
      mu_sieve_abort (mach);
    }
  else
    text = val->v.string;

  msg = mu_sieve_get_message (mach);
  mu_message_get_header (msg, &hdr);

  if (mu_sieve_tag_lookup (tags, "sender", &val))
    {
      /* Debugging hook: :sender sets fake reply address */
      from = strdup (val->v.string);
      if (!from)
        {
          mu_sieve_error (mach, "%lu: %s",
                          (unsigned long) mu_sieve_get_message_num (mach),
                          mu_strerror (ENOMEM));
          mu_sieve_abort (mach);
        }
    }
  else if (mu_sieve_get_message_sender (msg, &from))
    {
      mu_sieve_error (mach,
		      _("%lu: cannot get sender address"),
		      (unsigned long) mu_sieve_get_message_num (mach));
      mu_sieve_abort (mach);
    }

  if (mu_sieve_tag_lookup (tags, "aliases", &val)
      && match_addresses (hdr, val, &my_address) == 0)
    return 0;

  if (noreply_address_p (mach, tags, from)
      || bulk_precedence_p (hdr)
      || check_db (mach, tags, from))
    {
      free (from);
      return 0;
    }

  rc = vacation_reply (mach, tags, msg, text, from, my_address);
  free (from);
  if (rc == -1)
    mu_sieve_abort (mach);
  return rc;
}