Exemple #1
0
void TWebPgFetchEvent::OnFetchEnd(const PHttpResp& HttpResp){
  EAssert(HttpResp->IsOk());
  EndMSecs=TTm::GetCurUniMSecs();
  int StatusCd=HttpResp->GetStatusCd();
  if (StatusCd/100==2){ // codes 2XX - ok
    ChangeLastUrlToLc(HttpResp);
    PWebPg WebPg=TWebPg::New(UrlStrV, IpNumV, HttpResp);
    WebPg->PutFetchMSecs(GetFetchMSecs());
    CloseConn(); Fetch->DisconnUrl(FId);
    Fetch->OnFetch(FId, WebPg);
  } else
  if (StatusCd/100==3){ // codes 3XX - redirection
    ChangeLastUrlToLc(HttpResp);
    if (UrlStrV.Len()<5){
      TStr RedirUrlStr=HttpResp->GetFldVal("Location");
      PUrl RedirUrl=TUrl::New(RedirUrlStr, CurUrl->GetUrlStr());
      if (RedirUrl->IsOk(usHttp)){
        TStrQuV CookieQuV; HttpResp->GetCookieKeyValDmPathQuV(CookieQuV);
        AddCookieKeyValDmPathQuV(CookieQuV);
        CurUrl=RedirUrl; Retries=0; CloseConn();
        TSockHost::GetAsyncSockHost(CurUrl->GetIpNumOrHostNm(), this);
      } else {
        TStr MsgStr=TStr("Invalid Redirection URL (")+RedirUrlStr+")";
        OnFetchError(MsgStr);
      }
    } else {
      TStr MsgStr=TStr("Cycling Redirection [")+TopUrl->GetUrlStr()+"]";
      OnFetchError(MsgStr);
    }
  } else { // all other codes - error
    TStr MsgStr=TStr("Http Error (")+
     TInt::GetStr(StatusCd)+"/"+HttpResp->GetReasonPhrase()+")";
    OnFetchError(MsgStr);
  }
}
Exemple #2
0
char * ReadSMSList(int fd)
{
  int len = 0;

  printf("Reading the SMS list (AT+CMGL)...");
  fd = InitConn(115200); 
  AT(fd);
    SendStrCmd(fd, "ATE0\r");
    ReadResp(fd);
  SendStrCmd(fd, "AT+CMGL\r");
  len = ReadResp(fd);
  if (!len || len < 9) {
    printf(" Error, empty or too short reply.\n");
    SendStrCmd(fd, "ATE1\r");
    ReadResp(fd);
    CloseConn(fd);
    return NULL;
  }

  if (strstr(readbuf + len - 9, "\r\nERROR\r\n")) {
    printf(" ERROR while executing AT+CMGL.\n");
    CloseConn(fd);
    return NULL;
  }
  if (strstr(readbuf + len - 6, "\r\nOK\r\n")) {
    printf(" OK.\n");
  } else {
    printf(" Unknown error while executing AT+CMGL.\n");
    CloseConn(fd);
    return NULL;
  }
  CloseConn(fd);
  return strdup(readbuf);
}
Exemple #3
0
int ReadPB(int fd)
{
    //get pb entry number;
    //at+cpbr=?
    //+CPBR: (1-100),40,12
    unsigned char cmd[64];
    int end;
    int len;

    fd = InitConn(115200); 
    AT(fd);  
    SendStrCmd(fd, "ATE0\r");
    ReadResp(fd);
    SendStrCmd(fd,"AT+CSCS=\"UCS2\"\r");
    ReadResp(fd); 
    SendStrCmd(fd,"at+cpbr=?\r");
    ReadResp(fd);
    sscanf(readbuf,"\r\n+CPBR: (%*d-%d),%*d,%*d",&end);
    fprintf(stderr,"%s, end=%d\n",readbuf,end);
    sprintf(cmd,"at+cpbr=1,%d\r",end);
    SendStrCmd(fd,cmd);
    len = ReadResp(fd);
    fprintf(stderr,"len = %d\n",len);
    CloseConn(fd);
    return len;
}
	void CLT_ON_DISCONNECT(HCONNECT hConn)
	{
		CAsyncIOConnection* pConnection = (CAsyncIOConnection*)KeyOf(hConn);
		if(!pConnection) return;
		pConnection->OnRawDisconnected();
		CloseConn(hConn);
	}
Exemple #5
0
int SendSMS(int fd, const char *to, const char *from,const char *text)
{
    UCHAR buf[200]; 
    UCHAR at_cmd[1024];
    LPSTR strHex;
    int len;
    int pdu_len;
    int retry = 10;
   
    fd = InitConn(115200); 
    SetPDUMode(fd);
    len = ComposeSubmitSms(buf, sizeof(buf), to,from, NULL, text);
    strHex = BinToHex(buf, len);
    pdu_len = strlen(strHex)/2-1;
    printf("%d: %s\n",strlen(strHex)/2-1, strHex);
    sprintf(at_cmd,"AT+CMGS=%d\r",pdu_len);
    fprintf(stderr,"S");
    
    //return 0;
    
    SendStrCmd(fd, at_cmd);
    do{
	len = ReadResp(fd);
    }while(!strstr(readbuf,">") && retry-- > 0);
    if(retry > 0)
    {
	fprintf(stderr,">");
	sprintf(at_cmd,"%s\032",strHex); //CTRL-Z
	SendStrCmd(fd, at_cmd);
	do{
	    fprintf(stderr,".");
	    len = ReadResp(fd);
	}while(!strstr(readbuf,"+CMGS:") && retry-- > 0);
    }
    if(retry > 0)
    {
	fprintf(stderr,"OK\n");
	CloseConn(fd);
	return 0;//success
    }
    else{
	fprintf(stderr,"%s: %s\n",at_cmd,readbuf);
	free(strHex);
    }
    CloseConn(fd);
    return -1;//failed
}
Exemple #6
0
char *ReadSMS(int fd, int idx)
{
    unsigned char cmd[64];
    int len = 0;

    fd = InitConn(115200); 
   AT(fd);
    SendStrCmd(fd, "ATE0\r");
    ReadResp(fd);
   sprintf(cmd,"AT+CMGR=%d\r",idx);
  SendStrCmd(fd,cmd);
  len = ReadResp(fd);
  /*+CMGR: 0,,22
   * 0891683108100005F0040D91683186517521F8000870015030224423026D4B
   */
  if (!len || len < 6) {
    printf(" Error, empty or too short reply.\n");
    CloseConn(fd);
    return NULL;
  }
  char *ret = strdup(readbuf);
  CloseConn(fd);
  return ret;
}
Exemple #7
0
TWebPgFetch::~TWebPgFetch(){
  TIntV ConnFIdV; ConnFIdToEventH.GetKeyV(ConnFIdV);
  for (int ConnFIdN=0; ConnFIdN<ConnFIdV.Len(); ConnFIdN++){
    CloseConn(ConnFIdV[ConnFIdN]);
  }
}
Exemple #8
0
void TWebPgFetch::DisconnUrl(const int& FId){
  CloseConn(FId);
  ConnUrl();
}
Exemple #9
0
void TWebPgFetchEvent::OnFetchError(const TStr& MsgStr){
  Fetch->OnError(FId, MsgStr+" ["+CurUrl->GetUrlStr()+"]");
  CloseConn(); Fetch->DisconnUrl(FId);
}
void TNntpSockEvent::OnError(const int&, const int&, const TStr& SockErrStr){
  CloseConn();
  TStr MailIdStr=TStr("[")+NntpCmStr+"]";
  NntpClt->OnClose();
}