Пример #1
0
void JumpropesCommon::HttpClient::get( const URI *uri, bool bBlocking, BaseSocket *anAlternateSocket ) {
   reset();

   this->host.setValue( &uri->host );
   if ( this->host.size() == 0 ) {
      if ( pLookupBase != NULL ) {
         pLookupBase->lookupHost( &this->host );
      } else {
         JRresolveAll( &this->host );
      }
   }

   this->path.setValue( &uri->path );
   this->port = uri->port.get();

   if ( !this->path.startsWith( "/", 1 ) ) {
      this->path.prepend( "/", 1 );
   }

   if ( uri->query.getLength() > 0 ) {
      this->path.append( "?", 1 );
      this->path.append( &uri->query );
   }

   IPAddress *aDefaultIp = this->host.getAddress();
   if ( aDefaultIp != NULL ) {
      if ( anAlternateSocket != NULL ) {
         socket = anAlternateSocket;
         bAlternateSocketUsed = true;
      } else {
         socket = new ClientSocket();
      }
      socket->getRemoteAddress()->setValue( aDefaultIp );
      socket->remotePort.set( this->port );
      if ( socket->connect() ) {
         connection = new HttpConnection( socket );

         connection->start();
         start();

         onStatusUpdate.execute( JRHTTPSTATUS_CONNECTED );

         sendGet();

         if ( bBlocking ) {
            while ( isRunning() ) {
               GFMillisleep( 50 );
            }
         }
      } else {
         reset();

         onStatusUpdate.execute( JRHTTPSTATUS_ERROR );
      }
   } else {
      reset();

      onStatusUpdate.execute( JRHTTPSTATUS_ERROR );
   }
}
Пример #2
0
/* Sends the query string, *query, to the database represented by *service_url.
 * *query must be a properly formatted InfluxDB query.
 * Returns a CURLcode that is globally stored in influxConn->result_code 
 */
CURLcode influxQuery(influxConn *conn, char *query){
    char *url = build_query_url(conn); //freed in sendGet()
   
    if(influx_debug){printf("[q: %s]\n", url);}
    
    update_ssl_opts(conn);
    conn->result_code = sendGet(conn, url, query);
    return conn->result_code;
}
Пример #3
0
void NetWork::getSongsUrl()
{
	m_musicCount = 0;
	QHash<int, int>::const_iterator it = m_songIds.begin();
	while (it != m_songIds.end())
	{
		QUrl url = GETMP3URL + QString("[%1]").arg(it.key());
		sendGet(url);
		it++;
	}
}
Пример #4
0
void* recvData(void *argc)
{
	recvThreadRunning = 1;

	int recvLen = 0;
	int recv_size = 0;
	int err = 0;
	socklen_t optlen = 0;
	char *retryData;
	u_int32_t lastIndex = 0;
	int pauseSign = 0;
	int recordLostNum = 0;
	int getLostNum = 0;

	pthread_detach(pthread_self());

	recvBufP = 0;
	recvProcessBufP = 0;

	optlen = sizeof(recv_size); 
	err = getsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &recv_size, &optlen); 
	if(err < 0)
	{ 
		printf("Fail to get recbuf size\n"); 
	} 

	set_rec_timeout(1, 0);//(usec, sec)
	while(recvSign)
	{
		recvLen = 0;
		if(connectionStatus == P2P)
		{
			recvLen = recvfrom(sockfd, recvProcessBuf + recvProcessBufP, MAX_RECEIVE, 0, (struct sockaddr *)&recv_sin, &recv_sin_len);
		}
		else if(connectionStatus == TURN)
		{
			recvLen = recvfrom(sockfd, recvProcessBuf + recvProcessBufP, MAX_RECEIVE, 0, (struct sockaddr *)&recv_sin, &recv_sin_len);
		}
		else 
			break;

		if(recvLen <= 0)
		{
//			usleep(100);
			continue;
		}

	    getNum += recvLen;
		recvProcessBufP += recvLen;

		if(recvProcessBufP > MAX_RECV_BUF - recv_size)
		{
			printf("recvBuf overflow!!\n");
			recvProcessBufP = 0;
		}

		if(pauseSign == 0)
		{
			recordLostNum = 0;
			getLostNum = 0;
		}

		if(getLostNum >= recordLostNum - 1)
			pauseSign = 0;

//		printf("buf back point at %d, pauseSign = %d\n", recvProcessBackBufP, pauseSign);
		if(pauseSign == 0 && recvProcessBackBufP >= 0)
		{
#if PRINT
			printf("pause status out!\n");
#endif
			memcpy(recvProcessBuf + recvProcessBufP, recvProcessBackBuf, recvProcessBackBufP);
			recvProcessBackBufP = 0;
		}

	    if(recvProcessBufP >= sizeof(struct load_head))
		{
			int scanP = 0;
			struct load_head head;
			struct get_head get;
//			struct retry_head retry;

			while(scanP + sizeof(struct load_head) < recvProcessBufP)
			{
				if(recvProcessBuf[scanP] == 'J' && recvProcessBuf[scanP + 1] == 'E' && recvProcessBuf[scanP + 2] == 'A' && recvProcessBuf[scanP + 3] == 'N')
				{
					int lostNum = 0;
					memcpy(&head, recvProcessBuf + scanP, sizeof(struct load_head));
					lostNum = head.index - lastIndex;
					//printf("lastindex %d index %d \n", lastIndex, head.index);

					if(pauseSign == 1 && lostNum == 1)
						getLostNum++;

					if(lostNum <= 0 && head.index != 0)
					{
						scanP += (head.length + sizeof(struct load_head));
						continue;
					}

					if(head.index != 0 && lostNum > 1)
					{
						if(recvProcessBackBufP != 0)
						{
						    int start, end;
						    int pri;
                            pri = findIndexInBuf(recvProcessBackBuf, &start, &end, &recvProcessBackBufP, lastIndex + 1);
					//		printf("found pack in back %d\n", pri);
						    if(pri >= 0)
						    {
								if(pri > 0)
								    sendGet(lastIndex + 1);
								lastIndex = lastIndex + 1;
								memcpy(recvBuf+recvBufP, recvProcessBackBuf + start, end - start);
								break;
						    }
						}
#if PRINT
						printf("lost pack happen, reget!!\n");
#endif
                        int i = 0;
						pauseSign = 1;
						for(i = 1;i < lostNum; i++)
						{
						}

						if(recvProcessBackBufP + recvProcessBufP - scanP < MAX_RECV_BUF)
						{
						    memcpy(recvProcessBackBuf + recvProcessBackBufP, recvProcessBuf + scanP, recvProcessBufP - scanP);
						    recvProcessBackBufP = recvProcessBackBufP + (recvProcessBufP - scanP);
						    recvProcessBufP = 0;
						}
						else
						{
							printf("back buf overflow!!\n");
							recvProcessBackBufP = 0;
						}
	
						if(lostNum > recordLostNum)
							recordLostNum = lostNum;

						break;
					}

					lastIndex = head.index;
#if PRINT
					printf("load head: %c %d %d %d %d\n", head.logo[0], head.index, head.get_number, head.priority, (unsigned int)head.length);
#endif
					if(recvProcessBufP - scanP - sizeof(struct load_head) >= head.length)
					{
						if(head.priority > 0)
							sendGet(head.index);
				
					    if(head.length == 0)
						{
#if PRINT
							printf("Empty load!Actually lost.\n");
#endif
						}

						if(recvBufP + head.length > MAX_RECV_BUF)
						{
							printf("recv processed buf overflow!!\n");
							recvBufP = 0;
						}
						pthread_mutex_lock(&recvBuf_lock);
						memcpy(recvBuf + recvBufP, recvProcessBuf + scanP + sizeof(struct load_head), head.length);
						recvBufP += head.length;
						pthread_mutex_unlock(&recvBuf_lock);
						scanP = scanP + sizeof(struct load_head) + head.length;
					}
					else
						break;
				}
				else if(recvProcessBuf[scanP] == 'G' && recvProcessBuf[scanP + 1] == 'E' && recvProcessBuf[scanP + 2] == 'T')
				{
					memcpy(&get, recvProcessBuf + scanP, sizeof(struct get_head));
#if PRINT
//					printf("get index: %d\n", get.index);
#endif
//					unreg_buff(get.index);
					scanP = scanP + sizeof(struct get_head);
				}
				else
					scanP++;
			}

			if(scanP == recvProcessBufP)
			{
				recvProcessBufP = 0;
				continue;
			}
			else if(scanP < recvProcessBufP)
			{
				recvProcessBufP -= scanP;
				memcpy(recvProcessBuf, recvProcessBuf + scanP, recvProcessBufP);
			}
		}
		else if(recvProcessBufP >= sizeof(struct get_head))
		{
			int scanP = 0;
			struct get_head get;

			while(scanP + sizeof(struct get_head) <= recvProcessBufP)
			{
				if(recvProcessBuf[scanP] == 'G' && recvProcessBuf[scanP + 1] == 'E' && recvProcessBuf[scanP + 2] == 'T')
				{
					memcpy(&get, recvProcessBuf + scanP, sizeof(struct get_head));
//					unreg_buff(get.index);
					scanP = scanP + sizeof(struct get_head);
				}
				else
					scanP++;
			}

			if(scanP == recvProcessBufP)
			{
				recvProcessBufP = 0;
				continue;
			}
			else if(scanP < recvProcessBufP)
			{
				recvProcessBufP -= scanP;
				memcpy(recvProcessBuf, recvProcessBuf + scanP, recvProcessBufP);
			}

		}

//		usleep(100);
	}

	recvThreadRunning = 0;
}
Пример #5
0
int tryLogin(int hSocket, _MODULE_DATA* _psSessionData, sLogin** login, int nPort, char* szLogin, char* szPassword)
{
  char* pReceiveBuffer = NULL;
  int nReceiveBufferSize, nRet;
  char* pTemp = NULL;

  switch(_psSessionData->nFormType)
  {
    case FORM_GET:
      writeError(ERR_DEBUG_MODULE, "[%s] Sending Web Form Authentication (GET).", MODULE_NAME);
      nRet = sendGet(hSocket, _psSessionData, szLogin, szPassword);
      break;
    case FORM_POST:
      writeError(ERR_DEBUG_MODULE, "[%s] Sending Web Form Authentication (POST).", MODULE_NAME);
      nRet = sendPost(hSocket, _psSessionData, szLogin, szPassword);
      break;
    default:
      break;
  }

  if (nRet == FAILURE)
  {
    writeError(ERR_ERROR, "[%s] Failed during sending of authentication data.", MODULE_NAME);
    (*login)->iResult = LOGIN_RESULT_UNKNOWN;
    setPassResult(*login, szPassword);
    return MSTATE_EXITING;  
  }

  writeError(ERR_DEBUG_MODULE, "[%s] Retrieving server response.", MODULE_NAME);
  pReceiveBuffer = medusaReceiveLine(hSocket, &nReceiveBufferSize);

  if ((pReceiveBuffer == NULL) || (pReceiveBuffer[0] == '\0'))
  {
    writeError(ERR_ERROR, "[%s] No data received", MODULE_NAME);
    (*login)->iResult = LOGIN_RESULT_UNKNOWN;
    setPassResult(*login, szPassword);
    return MSTATE_EXITING;  
  }

  pTemp = (char*)index(pReceiveBuffer, ' ');
  if ( !pTemp || strncmp(pTemp + 1, "200 OK", 6) != 0 )
  {
    writeError(ERR_ERROR, "The answer was NOT successfully received, understood, and accepted: error code %.4s", pTemp);
    (*login)->iResult = LOGIN_RESULT_UNKNOWN;
    setPassResult(*login, szPassword);
    return MSTATE_EXITING;
  }

  while ((strcasestr(pReceiveBuffer, _psSessionData->szDenySignal) == NULL) && (pReceiveBuffer[0] != '\0'))
  {
    free(pReceiveBuffer);
    pReceiveBuffer = medusaReceiveLine(hSocket, &nReceiveBufferSize);
  }

  if (strcasestr(pReceiveBuffer, _psSessionData->szDenySignal) != NULL)
  {
    (*login)->iResult = LOGIN_RESULT_FAIL;
    setPassResult(*login, szPassword);
    return MSTATE_NEW;
  }
   
  writeError(ERR_DEBUG_MODULE, "Login Successful");
  (*login)->iResult = LOGIN_RESULT_SUCCESS;
  setPassResult(*login, szPassword);
  return MSTATE_NEW;   
}
Пример #6
0
/* Tests an influxDB connection with a GET request.
 * 
 */
bool influxCheck(influxConn *conn)
{
    update_ssl_opts(conn);
    conn->result_code = sendGet(conn, conn->host_url, NULL);
    return conn->result_code;
}
Пример #7
0
void OpenDCCCtrlDlg::evaluateGet( int so, int value ) {
  m_soValue[so] = value;

  if( so == so_version ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "version = %d.%d", value/100, value%100 );
    m_Version->SetValue( wxString::Format(_T("%d.%d"), value/100, value%100) );
    sendGet( so_bps );
  }
  else if( so == so_bps ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "baudrate = %d", value );
    /*
     * Attention:
     * OpenDCC provides the baudrate values for read
     * depending on the selected protocol for communication.
     * The Dialog is using p50x values, so if XpressNet (Lenz)
     * protocol is selected the baudrate values must be
     * converted to Intellibox p50x values.
     */
    if( m_bLenz ) {
      /*
      lenz
        0:   9600 Baud
        1:   19200 Baud (default)
        2:   38400 Baud
        3:   57600 Baud
        4:   115200 Baud
        5:   2400 Baud
        6:   4800 Baud
      p50x
        0:   2400 Baud
        1:   4800 Baud
        2:   9600 Baud
        3:   19200 Baud
        4:   38400 Baud
        5:   57600 Baud
        6:   115200 Baud
      */
      /* The dialog is using p50x values, so convert lenz to p50x */
      switch( value ) {
        case 0: value = 2; break;
        case 1: value = 3; break;
        case 2: value = 4; break;
        case 3: value = 5; break;
        case 4: value = 6; break;
        case 5: value = 0; break;
        case 6: value = 1; break;
      }

    }
    m_Baudrate->SetSelection(value);
    sendGet( so_mode );
  }
  else if( so == so_mode ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "opendcc mode = %d", value );
    m_Mode->SetValue( value & 0x01 ? _T("Xpressnet"):_T("Standard") );
    m_Clock->SetValue(value & 0x10 ? true:false);

    iONode opendccini = wDigInt.getopendcc(m_Props);
    wOpenDCC.setfastclock(opendccini, value & 0x10 ? True:False);

    m_OpenDCCmode = value;
    sendGet( so_dcc_format );
  }
  else if( so == so_dcc_format ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "dcc format = %d", value );
    /*
    0:   DCC mit 14 Fahrstufen
    1:   reserviert (DCC mit 27 Fahrstufen, nicht implementiert)
    2:   DCC mit 28 Fahrstufen (Voreinstellung)
    3:   DCC mit 128 Fahrstufen (bzw. 126, um genau zu sein)
    */
    m_DecSpeedSteps->SetSelection(value);
    sendGet( so_bidi );
  }
  else if( so == so_bidi ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "bidi = %d", value );
    m_BiDiCutOut->SetValue(value&0x01?true:false);
    m_BiDiIdNotify->SetValue(value&0x02?true:false);
    m_BiDiAccQuery->SetValue(value&0x04?true:false);
    sendGet( so_s88_timing );
  }
  else if( so == so_s88_timing ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "s88 timing = %d", value );
    m_S88Timing->SetValue(value);
    sendGet( so_s88_bus1 );
  }
  else if( so == so_s88_bus1 ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "s88 bus1 = %d", value );
    m_S88Bus1->SetValue(value);
    sendGet( so_s88_bus2 );
  }
  else if( so == so_s88_bus2 ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "s88 bus2 = %d", value );
    m_S88Bus2->SetValue(value);
    sendGet( so_s88_bus3 );
  }
  else if( so == so_s88_bus3 ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "s88 bus3 = %d", value );
    m_S88Bus3->SetValue(value);
    sendGet( so_s88_mode );
  }
  else if( so == so_s88_mode ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "s88 mode = %d", value );
    m_S88Active->SetValue( (value&0x01) ? true:false );
    m_S88TurnoutSensors->SetValue( (value&0x02) ? true:false );
    sendGet( so_pt_resets );
  }
  else if( so == so_pt_resets ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "pt resets = %d", value );
    m_PTResets->SetValue( value );
    sendGet( so_pt_commands );
  }
  else if( so == so_pt_commands ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "pt commands = %d", value );
    m_PTCommands->SetValue( value );
    sendGet( so_pt_pom );
  }
  else if( so == so_pt_pom ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "pt pom = %d", value );
    m_PTPOMrepeat->SetValue( value );
    sendGet( so_scd_main );
  }
  else if( so == so_scd_main ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "scd main = %d", value );
    m_SCTimeMain->SetValue( value );
    sendGet( so_scd_pt );
  }
  else if( so == so_scd_pt ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "scd pt = %d", value );
    m_SCTimePT->SetValue( value );
    sendGet( so_sw_invert );
  }
  else if( so == so_sw_invert ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "sw invert = %d", value );
    m_SwitchInvert->SetValue( (value&0x01) ? true:false );
    sendGet( so_sw_commands );
  }
  else if( so == so_sw_commands ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "sw commands = %d", value );
    m_SwitchCommands->SetValue( value );
    sendGet( so_sw_time );
  }
  else if( so == so_sw_time ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "sw time = %d", value );
    m_SwitchTime->SetValue( value );
    sendGet( so_sw_sensor_offset );
  }
  else if( so == so_sw_sensor_offset ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "sw sensor offset = %d", value );
    m_SwitchSensorOffset->SetValue( value );
    sendGet( so_sw_sensor_mode );
  }
  else if( so == so_sw_sensor_mode ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "sw sensor mode = %d", value );
    m_SwitchSensorMode->SetSelection( value );
    sendGet( so_serial_number );
  }
  else if( so == so_serial_number ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "serial number = %d", value );
    m_SerialNumber->SetValue( value );
    sendGet( so_xpn_feedback_mapping );
  }
  else if( so == so_xpn_feedback_mapping ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "xpn feedback mapping = %d", value );
    m_XpnFeedbackMapping->SetSelection( value );
    sendGet( so_xpn_sensors );
  }
  else if( so == so_xpn_sensors ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "xpn sensors = %d", value );
    m_XpressNetSensors->SetValue( value );
    sendGet( so_loco_format_low );
  }
  // TODO: get list of loco decoder exceptions
  // 64 pairs starting with: so_loco_format_low, so_loco_format_high
  else if( so >= so_loco_format_low && so <= so_loco_format_high + 64*2 ) {
    TraceOp.trc( "opendcc", TRCLEVEL_INFO, __LINE__, 9999, "loco format %d = %d", so, value );

    if( m_OpenDCCmode & mode_type_xpr ) {
      /* TODO: handle mode_type_xpr database */
      stopProgress();
    }
    else {
      if( so % 2 == 1) {
        int index = ( so - so_loco_format_low ) / 2;
        int locoFormatLow  = m_soValue[so-1];
        int locoFormatHigh = m_soValue[so];
        int address = locoFormatLow + ((locoFormatHigh & 0x3F) << 8);
        int format  = (locoFormatHigh & 0xC0) >> 6;

        if( address > 0 ) {
          m_DecExceptions->InsertItem( index, wxString::Format(_T("%d"), address));
          if( format == 0 )
            m_DecExceptions->SetItem( index, 1, _T("DCC 14"));
          else if( format == 1 )
            m_DecExceptions->SetItem( index, 1, _T("DCC 27"));
          else if( format == 2 )
            m_DecExceptions->SetItem( index, 1, _T("DCC 28"));
          else if( format == 3 )
            m_DecExceptions->SetItem( index, 1, _T("DCC 128"));
          else
            m_DecExceptions->SetItem( index, 1, _T("DCC ???"));

          if( index < 64 )
            sendGet( so + 1 );
          else
            stopProgress();
        }
        else {
          stopProgress();
        }
      }
      else
Пример #8
0
void NetWork::getListInfo(int listId)
{
	QUrl url = GETLISTINFO + QString::number(listId, 10);
	sendGet(url);
}
Пример #9
0
void NetWork::getLyric(int songId)
{
	QUrl url(LYRIC + QString::number(songId) +"&lv=-1&tv=-1");
	sendGet(url, true);
}
Пример #10
0
void NetWork::getMusicList(int offset, int limit)
{
	QString u = GETMUSICLIST + QString("%1&limit=%2&uid=%3").arg(offset).arg(limit).arg(m_userId);
	QUrl url(u);
	sendGet(url, true);
}