Exemplo n.º 1
0
void Init()
{
	abba_USART_Init(USART1,9600,RX_TX_Mode);
	abba_USART_Init(USART2,9600,TX_Mode);
	//abba_GPIO_Init(GPIOB,GPIO_Pin_0,GPIO_Mode_Out_PP,1);
	//abba_PIT_Init(TIM7,1);
	NVIC_Configuration(NVIC_PriorityGroup_1,USART1_IRQn,0,1);
	//NVIC_Configuration(NVIC_PriorityGroup_1,USART2_IRQn,0,0);
	//RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7 , ENABLE);
	httpInit();
	Data.countlat = 0;
	Data.countlon = 0;
	Data.countUTC = 0;
}
Exemplo n.º 2
0
/// Call just before returning to idle loop. This checks for errors and tries to recover. Returns true if no errors.
bool net_cc3000_checkError(JsNetwork *net) {
  bool hadErrors = false;
  while (jspIsInterrupted()) {
    hadErrors = true;
    jsiConsolePrint("Looks like CC3000 has died again. Power cycling...\n");
    jspSetInterrupted(false);
    // remove all existing connections
    networkState = NETWORKSTATE_OFFLINE; // ensure we don't try and send the CC3k anything
    httpKill(net);
    httpInit();
    // power cycle
    JsVar *wlan = jsvObjectGetChild(execInfo.root, CC3000_OBJ_NAME, 0);
    if (wlan) {
      jswrap_wlan_reconnect(wlan);
      jsvUnLock(wlan);
    } else jsErrorInternal("No CC3000 object!\n");
    // jswrap_wlan_reconnect could fail, which would mean we have to do this all over again
  }
  return hadErrors;
}
Exemplo n.º 3
0
static void cgiInit(){
    httpInit();
}
Exemplo n.º 4
0
Arquivo: test.c Projeto: Dany3R9/Proj
int
main(int ac, char *av[])
{
  int i;

  httpInit();

  for (i = 1; i < ac; i++) {
    if (strcmp(av[i], "--address") == 0) {
      if (++i == ac) {
        fprintf(stderr, "missing address parameter\n");
        usage();
        return 1;
      }

      if (httpSetAddress(av[i], NULL, (set_plugin_parameter_addon) {
                         0}
          ) < 0) {
        fprintf(stderr, "cannot set address\n");
        return 1;
      }
    }

    else if (strcmp(av[i], "--port") == 0) {
      if (++i == ac) {
        fprintf(stderr, "missing port parameter\n");
        usage();
        return 1;
      }

      if (httpSetPort(av[i], NULL, (set_plugin_parameter_addon) {
                      0}
          ) < 0) {
        fprintf(stderr, "cannot set port\n");
        return 1;
      }
    }

    else if (strcmp(av[i], "--work-dir") == 0) {
      if (++i == ac) {
        fprintf(stderr, "missing work directory parameter\n");
        usage();
        return 1;
      }

      if (httpSetWorkDir(av[i], NULL, (set_plugin_parameter_addon) {
                         0}
          ) < 0) {
        fprintf(stderr, "cannot set work directory\n");
        return 1;
      }
    }

    else if (strcmp(av[i], "--root-dir") == 0) {
      if (++i == ac) {
        fprintf(stderr, "missing root directory parameter\n");
        usage();
        return 1;
      }

      if (httpSetRootDir(av[i], NULL, (set_plugin_parameter_addon) {
                         0}
          ) < 0) {
        fprintf(stderr, "cannot set root directory\n");
        return 1;
      }
    }

    else if (strcmp(av[i], "--index-file") == 0) {
      if (++i == ac) {
        fprintf(stderr, "missing index file parameter\n");
        usage();
        return 1;
      }

      httpSetIndexFile(av[i], NULL, (set_plugin_parameter_addon) {
                       0}
      );
    }

    else if (strcmp(av[i], "--user") == 0) {
      if (++i == ac) {
        fprintf(stderr, "missing user parameter\n");
        usage();
        return 1;
      }

      httpSetUser(av[i], NULL, (set_plugin_parameter_addon) {
                  0}
      );
    }

    else if (strcmp(av[i], "--password") == 0) {
      if (++i == ac) {
        fprintf(stderr, "missing password parameter\n");
        usage();
        return 1;
      }

      httpSetPassword(av[i], NULL, (set_plugin_parameter_addon) {
                      0}
      );
    }

    else if (strcmp(av[i], "--sess-time") == 0) {
      if (++i == ac) {
        fprintf(stderr, "missing timeout parameter\n");
        usage();
        return 1;
      }

      if (httpSetSessTime(av[i], NULL, (set_plugin_parameter_addon) {
                          0}
          ) < 0) {
        fprintf(stderr, "cannot set session timeout\n");
        return 1;
      }
    }

    else if (strcmp(av[i], "--pub-dir") == 0) {
      if (++i == ac) {
        fprintf(stderr, "missing public directory parameter\n");
        usage();
        return 1;
      }

      httpSetPubDir(av[i], NULL, (set_plugin_parameter_addon) {
                    0}
      );
    }

    else if (strcmp(av[i], "--quantum") == 0) {
      if (++i == ac) {
        fprintf(stderr, "missing quantum parameter\n");
        usage();
        return 1;
      }

      if (httpSetQuantum(av[i], NULL, (set_plugin_parameter_addon) {
                         0}
          ) < 0) {
        fprintf(stderr, "cannot set quantum\n");
        return 1;
      }
    }

    else if (strcmp(av[i], "--mess-time") == 0) {
      if (++i == ac) {
        fprintf(stderr, "missing timeout parameter\n");
        usage();
        return 1;
      }

      if (httpSetMessTime(av[i], NULL, (set_plugin_parameter_addon) {
                          0}
          ) < 0) {
        fprintf(stderr, "cannot set message timeout\n");
        return 1;
      }
    }

    else if (strcmp(av[i], "--mess-limit") == 0) {
      if (++i == ac) {
        fprintf(stderr, "missing limit parameter\n");
        usage();
        return 1;
      }

      if (httpSetMessLimit(av[i], NULL, (set_plugin_parameter_addon) {
                           0}
          ) < 0) {
        fprintf(stderr, "cannot set message queue limit\n");
        return 1;
      }
    }

    else {
      fprintf(stderr, "invalid argument: %s\n", av[i]);
      usage();
      return 1;
    }
  }

  signal(SIGINT, sigHand);
  signal(SIGTERM, sigHand);

  if (httpSetup() < 0) {
    fprintf(stderr, "cannot set up HTTP server\n");
    return 1;
  }

  while (1) {
    if (httpService(10) < 0) {
      fprintf(stderr, "cannot run HTTP server\n");
      return 1;
    }

    usleep(100000);
  }

  return 0;
}
Exemplo n.º 5
0
/*JSON{ "type":"init", "generate" : "jswrap_http_init" }*/
void jswrap_http_init() {
  httpInit();
}
Exemplo n.º 6
0
int main(void)
{     
  u8 i,timediff = 0;  
  char lati[10],loni[11],signaldiff = 'V';
  time Realtime;
  Datapack temp;
  Sys_init();
  clear_OLED();
  setCharsOLED("Loading Now",30,3);
  keyinit();
  Ds1302_Init();
  httpInit();
  clear_OLED();
  uartbuf.countlat = 0;
  uartbuf.countlon = 0;
  uartbuf.countUTC = 0;
  Menu();
  clear_OLED();
  showTime(&timediff,&signaldiff);
  
  rim();
  while(1)
  { 
    
    if(readkey())
    {
      if(display_flag)
      {
	display_flag = 0;
	clear_OLED();
      }
      else
      {
	display_flag = 1;
	clear_OLED();
	timediff = 99;
	showTime(&timediff,&signaldiff); 
      }
    }
    if(UARTflag==1)
    {
      if(display_flag)
      {
      	showTime(&timediff,&signaldiff); 
      }
      if(uartbuf.status=='A')
      {
	temp = uartbuf;
	//Sendpack(&uartbuf);
	for(i=0;i<10;i++)
	{
	  if(((uartbuf.longitude[i]>='0' && uartbuf.longitude[i] <='9') || uartbuf.longitude[i] =='.'))
	  {
	    loni[i] = uartbuf.longitude[i];
	    lati[i] = uartbuf.latitude[i];
	  }
	  else
	  {
	    //sendChars("AB");
	    break;
	  }
	  if(i==9)
	  {
	    loni[10] = uartbuf.longitude[10];
	    temp = uartbuf;
	    Send_PostMessage(&temp,&lati,&loni);
	    if(signaldiff!='A')
	    {
	      if(display_flag==1)
	      {
	      	SendSignal('A');
	      }
	      signaldiff = 'A';
	    }
	    uartbuf.countlat = 0;
	    uartbuf.countlon = 0;
	    uartbuf.countUTC = 0;
	    uartbuf.status = 'V';
	  }
	}
	
      }
      else
      {
	if(signaldiff!='V')
	{
	  if(display_flag == 1)
	  {
	      signaldiff = 'V';
	  }
	  SendSignal('V');
	}
      }
      UARTflag=0;	
      rim();
    }
    //printf("¶¨");
    //delay_ms(1);
    //addrOLED(1,2); 
    //setCharOLED('X');
  }  
}
Exemplo n.º 7
0
static int download_file(char *url, char *file, int mode, u64 *size)
{
    int flags = 0;
    int ret = 0;
    void *http_p = NULL;
    void *uri_p = NULL;
    httpUri uri;
    s32 transID = 0;
    s32 clientID;
    int pool_size = 0;
    int recv = -1;
    u64 length = 0;
    int code = 0;
    FILE *fp = NULL;
    float parts = 0;
    float cpart;
    char buffer[16384];

    use_async_fd = 128;
    my_f_async.flags = 0;

    if(mode == 2) {
        if(size) sprintf(temp_buffer + 4096, "File Size: %u MB\n%s", (u32) (*size/0x100000ULL), strrchr(file, '/') + 1);
        else sprintf(temp_buffer + 4096, "File: %s", strrchr(file, '/') + 1);

        single_bar(temp_buffer + 4096);
    }

    http_p = malloc(0x10000);
    if(!http_p) {ret= -1; goto err;}

    ret = httpInit(http_p, 0x10000);
	if(ret < 0) goto err;
    flags|= 1;

    ret = httpCreateClient(&clientID);
    if(ret < 0) goto err;
    flags|= 2;

    httpClientSetConnTimeout(clientID, 10000000);

	ret = httpUtilParseUri(NULL, url, NULL, 0, &pool_size);
	if (ret < 0) goto err;

	uri_p = malloc(pool_size);
	if (!uri_p) goto err;

	ret = httpUtilParseUri(&uri, url, uri_p, pool_size, NULL);
	if (ret < 0) goto err;

    ret = httpCreateTransaction(&transID, clientID, HTTP_METHOD_GET, &uri);
	if (ret < 0) goto err;
    
    free(uri_p); 
    uri_p = NULL;

	ret = httpSendRequest(transID, NULL, 0, NULL);
	if (ret < 0) goto err;
		
    ret = httpResponseGetStatusCode(transID, &code);
    if (ret < 0) goto err;
		
	if (code == 404 || code == 403) {ret=-4; goto err;}

	ret = httpResponseGetContentLength(transID, &length);
	if (ret < 0) {
		if (ret == HTTP_STATUS_CODE_No_Content) {
            length = 0ULL;
            ret = 0;
		} else goto err;
	}

    if(size) *size = length;

    if(mode == 1) goto err; // get only the size

    if(mode == 2) {
        parts = (length == 0) ? 0.0f : 100.0f / ((double) length / (double) sizeof(buffer));
        cpart = 0;
    }
    
    fp = fopen(file, "wb");
	if(!fp) goto err;
	
    int acum = 0;
	while (recv != 0 && length != 0ULL) {
        memset(buffer, 0x0, sizeof(buffer));
		if (httpRecvResponse(transID, buffer, sizeof(buffer) - 1, &recv) < 0) {fclose(fp); ret = -5; goto err;}
		if (recv == 0) break;
		if (recv > 0) {
			//if(fwrite(buffer, 1, recv, fp) != recv) {fclose(fp); fp = NULL; ret = -6; goto err;}
            ///////////////////

        loop_write:
            if(use_async_fd == 128) {
                use_async_fd = 1;
                my_f_async.flags = 0;
                my_f_async.size = recv;
                my_f_async.fp = fp;
                my_f_async.mem = malloc(recv);
                if(my_f_async.mem) memcpy(my_f_async.mem, (void *) buffer, recv);        
                my_f_async.ret = -1;
                my_f_async.flags = ASYNC_ENABLE;
                event_thread_send(0x555ULL, (u64) my_func_async, (u64) &my_f_async);

            } else {
             
                if(!(my_f_async.flags & ASYNC_ENABLE)) {

                    if(my_f_async.flags & ASYNC_ERROR) {
                        fclose(fp); fp = NULL; ret = -6; goto err;
                    }
                   
                    my_f_async.flags = 0;
                    my_f_async.size = recv;
                    my_f_async.fp = fp;
                    my_f_async.mem = malloc(recv);
                    if(my_f_async.mem) memcpy(my_f_async.mem, (void *) buffer, recv);  
                    my_f_async.ret = -1;
                    my_f_async.flags = ASYNC_ENABLE;
                    event_thread_send(0x555ULL, (u64) my_func_async, (u64) &my_f_async);
                    
                } else {
                    goto loop_write;
                }
            }
            ///////////////////
            length -= recv;
            acum+= recv;
		}

        if(mode == 2 && progress_action == 2) {ret = -0x555; goto err;}

        pad_last_time = 0;
    
        if(mode == 2) {

            if(acum >= sizeof(buffer)) {
                acum-= sizeof(buffer);
                cpart += parts;
                if(cpart >= 1.0f) {
                    update_bar((u32) cpart);
                    cpart-= (float) ((u32) cpart); 
                }
            }
        }
	}

 
	ret = 0;
	
err:

    if(my_f_async.flags & ASYNC_ENABLE){
        wait_event_thread();
        if(my_f_async.flags  & ASYNC_ERROR) {
            
            if(fp) fclose(fp); fp = NULL; ret = -6;
        }
        my_f_async.flags = 0;
    }

    event_thread_send(0x555ULL, (u64) 0, 0);

    if(mode == 2) {
        msgDialogAbort();
    }

    if(fp) {
        fclose(fp);
        if(ret < 0) unlink_secure(file);
    }

    if(transID) httpDestroyTransaction(transID);
    if(flags & 2) httpDestroyClient(clientID);
    if(flags & 1) httpEnd();
    if(http_p) free(http_p);
    if(uri_p) free(uri_p); 
    return ret;
}
Exemplo n.º 8
0
int8_t sendSms(duk_context *JsContext, InputParameters_t *Parameters, char *Input[])
{
    extern const char const *ErrorMessages[];
    extern HttpHandle_t *Handle;
    extern Output_t OutputMessages;
    int8_t RetCode = EXIT_SUCCESS;
    
    char *GatewayLocation;
    
    if (Parameters->GatewayLocation)
    {
        uint8_t GatewayLocationLength = strlen(Input[Parameters->GatewayLocation] );
        
        if ( Input[Parameters->GatewayLocation][GatewayLocationLength - 1] == '/')
        {
            Input[Parameters->GatewayLocation][GatewayLocationLength - 1] = '\0';
            GatewayLocationLength--;
        }
        
        // 10 = '/' + ".gateway" + '\0'
        GatewayLocation = malloc(GatewayLocationLength + strlen(Input[Parameters->Gateway] ) + 10);
        
        if (!GatewayLocation)
        {
            setErrorMsg(ErrorMessages[MEMORY], true);
            return NO_MEMORY;
        }
        
        sprintf(GatewayLocation, "%s/%s.gateway",Input[Parameters->GatewayLocation], Input[Parameters->Gateway] );
    }
    else
    {
        // 27 = "/usr/share/esmska/" + ".gateway" + '\0'
        GatewayLocation = malloc(strlen(Input[Parameters->Gateway] ) + 27);
        
        if (!GatewayLocation)
        {
            setErrorMsg(ErrorMessages[MEMORY], true);
            return NO_MEMORY;
        }
        
        sprintf(GatewayLocation, "/usr/share/esmska/%s.gateway", Input[Parameters->Gateway] );
    }
    
    if (duk_peval_file(JsContext, GatewayLocation) )
    {
        duk_get_prop_string(JsContext, -1, "message");
        
        setErrorMsg(ErrorMessages[MODULE_PROCESSING], false);
        setErrorMsg(Input[Parameters->Gateway], false);
        setErrorMsg(duk_get_string(JsContext, -1), true);
        
        free(GatewayLocation);
        return MODULE_ERROR;
    }
    
    free(GatewayLocation);
    duk_pop(JsContext); // Zahozeni vysledku (undefined)
    
    // Zpristupneni potrebnych udaju jako username, passwd, cislo, text zpravy
    duk_push_global_object(JsContext);
    
    if (Parameters->User) duk_push_string(JsContext, Input[Parameters->User] );
    else duk_push_string(JsContext, "");
    duk_put_prop_string(JsContext, -2, "LOGIN");
    
    if (Parameters->Password) duk_push_string(JsContext, Input[Parameters->Password] );
    else duk_push_string(JsContext, "");
    duk_put_prop_string(JsContext, -2, "PASSWORD");
    
    if (Parameters->SenderNumber) duk_push_string(JsContext, Input[Parameters->SenderNumber] );
    else duk_push_string(JsContext, "");
    duk_put_prop_string(JsContext, -2, "SENDERNUMBER");
    
    duk_push_string(JsContext, Input[Parameters->Number] );
    duk_put_prop_string(JsContext, -2, "NUMBER");
    
    duk_push_string(JsContext, Input[Parameters->Text] );
    duk_put_prop_string(JsContext, -2, "MESSAGE");
    
    if (duk_peval_string(JsContext, "RECEIPT = (getFeatures().indexOf('RECEIPT') > -1 ? true : false)") )
    {
        duk_get_prop_string(JsContext, -1, "message");
        
        setErrorMsg(ErrorMessages[RECEIPT_SETTING], false);
        setErrorMsg(duk_get_string(JsContext, -1), true);
        
        return MODULE_ERROR;
    }
    
    duk_pop(JsContext);
    
    // Zpristupneni potrebnych metod, promennych a samotny objekt EXEC
    duk_push_object(JsContext);
    duk_push_c_function(JsContext, get, 2);
    duk_put_prop_string(JsContext, -2, "getURL");
    duk_push_c_function(JsContext, post, 3);
    duk_put_prop_string(JsContext, -2, "postURL");
    duk_push_c_function(JsContext, setProblem, 2);
    duk_put_prop_string(JsContext, -2, "setProblem");
    duk_push_c_function(JsContext, setSupplementalMsg, 1);
    duk_put_prop_string(JsContext, -2, "setSupplementalMessage");
    duk_push_c_function(JsContext, stall, 1);
    duk_put_prop_string(JsContext, -2, "sleep");
    duk_push_c_function(JsContext, setReferer, 1);
    duk_put_prop_string(JsContext, -2, "setReferer");
    
    duk_push_string(JsContext, "Free SMS remaining: ");
    duk_put_prop_string(JsContext, -2, "INFO_FREE_SMS_REMAINING");
    duk_push_string(JsContext, "The gateway doesn't provide any information about successful sending. The message might be and might not be delivered.");
    duk_put_prop_string(JsContext, -2, "INFO_STATUS_NOT_PROVIDED");
    duk_push_string(JsContext, "Remaining credit: ");
    duk_put_prop_string(JsContext, -2, "INFO_CREDIT_REMAINING");
    
    duk_put_prop_string(JsContext, -2, "EXEC");
    
    // Vytvoreni CURL contextu
    if ( !(Handle = httpInit() ) )
    {
        setErrorMsg(ErrorMessages[NO_CURL_CONTEXT], true);
        
        return CURL_ERROR;
    }
    
    // Volani funkce send()
    duk_get_prop_string(JsContext, -1, "send");
    if (duk_pcall(JsContext, 0) )
    {
        if (duk_is_number(JsContext, -1) )
        {
            uint8_t ErrCode = duk_get_number(JsContext, -1);
            
            if (ErrCode < 90)
            {
                setErrorMsg(ErrorMessages[GENERIC], false);
                setErrorMsg(curl_easy_strerror(ErrCode), true);
                
                RetCode = CURL_ERROR;
            }
            else
            {
                OutputMessages.MessagesArray[OutputMessages.NextFree].MsgType = ERR;
                OutputMessages.MessagesArray[OutputMessages.NextFree].IsEndOfMsg = 1;
                
                switch (ErrCode)
                {
                    case NO_MEMORY:
                        OutputMessages.MessagesArray[OutputMessages.NextFree++].Msg = ErrorMessages[MEMORY];
                        RetCode = INTERNAL_ERROR;
                    break;
                    
                    case NO_POST_DATA:
                        OutputMessages.MessagesArray[OutputMessages.NextFree++].Msg = ErrorMessages[POST_DATA];
                        RetCode = MODULE_ERROR;
                    break;
                    
                    case SET_PROBLEM_NO_MSG:
                        OutputMessages.MessagesArray[OutputMessages.NextFree++].Msg = ErrorMessages[NO_EXPLAINING];
                        RetCode = MODULE_ERROR;
                    break;
                    
                    case SLEEP_NOT_NUMBER:
                        OutputMessages.MessagesArray[OutputMessages.NextFree++].Msg = ErrorMessages[SLEEP_NUMBER];
                        RetCode = MODULE_ERROR;
                    break;
                    
                    case ODD_URL_PARAMETERS:
                        OutputMessages.MessagesArray[OutputMessages.NextFree++].Msg = ErrorMessages[URL_PARAMETERS];
                        RetCode = MODULE_ERROR;
                    break;
                    
                    case ODD_POST_PARAMETERS:
                        OutputMessages.MessagesArray[OutputMessages.NextFree++].Msg = ErrorMessages[POST_PARAMETERS];
                        RetCode = MODULE_ERROR;
                    break;
                }
            }
        }
        else
        {
            setErrorMsg(duk_safe_to_string(JsContext, -1), true);
            
            RetCode = DUKTAPE_ERROR;
        }
    }
    else
    {
        bool SendRetVal;
        
        if (duk_is_boolean(JsContext, -1) ) SendRetVal = duk_get_boolean(JsContext, -1);
        else
        {
            setErrorMsg(ErrorMessages[NOT_BOOL], true);
            
            SendRetVal = (bool) ( (int8_t) duk_to_number(JsContext, -1) );
        }
            
        if (!SendRetVal) RetCode = GATEWAY_ERROR;
    }
    
    httpCleanUp(Handle);
    
    return RetCode;
}