app/modules/enduser_setup.c
/**
 * Handle HTTP Credentials
 *
 * @return - return 0 iff credentials are found and handled successfully
 *           return 1 iff credentials aren't found
 *           return 2 iff an error occured
 */
Handle HTTP Credentials
@return - return 0 iff credentials are found and handled successfully
return 1 iff credentials aren't found
return 2 iff an error occured
Handle HTTP Credentials @return - return 0 iff credentials are found and handled successfully return 1 iff credentials aren ' t found return 2 iff an error occured
static int enduser_setup_http_handle_credentials(char *data, unsigned short data_len)
{
  ENDUSER_SETUP_DEBUG("enduser_setup_http_handle_credentials");
  state->success = 0;
  state->lastStationStatus = 0;
  char *name_str = (char *) ((uint32_t)strstr(&(data[6]), "wifi_ssid="));
  char *pwd_str = (char *) ((uint32_t)strstr(&(data[6]), "wifi_password="));
  if (name_str == NULL || pwd_str == NULL)
  {
    ENDUSER_SETUP_DEBUG("Password or SSID string not found");
    return 1;
  }
  int name_field_len = LITLEN("wifi_ssid=");
  int pwd_field_len = LITLEN("wifi_password=");
  char *name_str_start = name_str + name_field_len;
  char *pwd_str_start = pwd_str + pwd_field_len;
  int name_str_len = enduser_setup_srch_str(name_str_start, "& ");
  int pwd_str_len = enduser_setup_srch_str(pwd_str_start, "& ");
  if (name_str_len == -1 || pwd_str_len == -1)
  {
    ENDUSER_SETUP_DEBUG("Password or SSID HTTP paramter divider not found");
    return 1;
  }
  struct station_config *cnf = luaM_malloc(lua_getstate(), sizeof(struct station_config));
  c_memset(cnf, 0, sizeof(struct station_config));
  int err;
  err  = enduser_setup_http_urldecode(cnf->ssid, name_str_start, name_str_len, sizeof(cnf->ssid));
  err |= enduser_setup_http_urldecode(cnf->password, pwd_str_start, pwd_str_len, sizeof(cnf->password));
  if (err != 0 || c_strlen(cnf->ssid) == 0)
  {
    ENDUSER_SETUP_DEBUG("Unable to decode HTTP parameter to valid password or SSID");
    return 1;
  }
  ENDUSER_SETUP_DEBUG("");
  ENDUSER_SETUP_DEBUG("WiFi Credentials Stored");
  ENDUSER_SETUP_DEBUG("-----------------------");
  ENDUSER_SETUP_DEBUG("name: ");
  ENDUSER_SETUP_DEBUG(cnf->ssid);
  ENDUSER_SETUP_DEBUG("pass: ");
  ENDUSER_SETUP_DEBUG(cnf->password);
  ENDUSER_SETUP_DEBUG("-----------------------");
  ENDUSER_SETUP_DEBUG("");
  task_post_medium(do_station_cfg_handle, (task_param_t) cnf);
  return 0;
}
static int enduser_setup_http_handle_credentials ( char * data , unsigned short data_len ) { ENDUSER_SETUP_DEBUG ( " " ) ; state -> success = 0 ; state -> lastStationStatus = 0 ; char * name_str = ( char * ) ( ( uint32_t ) strstr ( & ( data [ 6 ] ) , " " ) ) ; char * pwd_str = ( char * ) ( ( uint32_t ) strstr ( & ( data [ 6 ] ) , " " ) ) ; if ( name_str == NULL || pwd_str == NULL ) { ENDUSER_SETUP_DEBUG ( " " ) ; return 1 ; } int name_field_len = LITLEN ( " " ) ; int pwd_field_len = LITLEN ( " " ) ; char * name_str_start = name_str + name_field_len ; char * pwd_str_start = pwd_str + pwd_field_len ; int name_str_len = enduser_setup_srch_str ( name_str_start , " " ) ; int pwd_str_len = enduser_setup_srch_str ( pwd_str_start , " " ) ; if ( name_str_len == -1 || pwd_str_len == -1 ) { ENDUSER_SETUP_DEBUG ( " " ) ; return 1 ; } struct station_config * cnf = luaM_malloc ( lua_getstate ( ) , sizeof ( struct station_config ) ) ; c_memset ( cnf , 0 , sizeof ( struct station_config ) ) ; int err ; err = enduser_setup_http_urldecode ( cnf -> ssid , name_str_start , name_str_len , sizeof ( cnf -> ssid ) ) ; err |= enduser_setup_http_urldecode ( cnf -> password , pwd_str_start , pwd_str_len , sizeof ( cnf -> password ) ) ; if ( err != 0 || c_strlen ( cnf -> ssid ) == 0 ) { ENDUSER_SETUP_DEBUG ( " " ) ; return 1 ; } ENDUSER_SETUP_DEBUG ( " " ) ; ENDUSER_SETUP_DEBUG ( " " ) ; ENDUSER_SETUP_DEBUG ( " " ) ; ENDUSER_SETUP_DEBUG ( " " ) ; ENDUSER_SETUP_DEBUG ( cnf -> ssid ) ; ENDUSER_SETUP_DEBUG ( " " ) ; ENDUSER_SETUP_DEBUG ( cnf -> password ) ; ENDUSER_SETUP_DEBUG ( " " ) ; ENDUSER_SETUP_DEBUG ( " " ) ; task_post_medium ( do_station_cfg_handle , ( task_param_t ) cnf ) ; return 0 ; }
Handle HTTP Credentials
 @return - return 0 iff credentials are found and handled successfully
           return 1 iff credentials aren't found
           return 2 iff an error occured
Handle HTTP Credentials @return - return 0 iff credentials are found and handled successfully return 1 iff credentials aren ' t found return 2 iff an error occured