コード例 #1
0
ファイル: nettest.cpp プロジェクト: Mateuus/devsrc
int _tmain(int argc, _TCHAR* argv[])
{
  UnittestMyNetwork();
  while( *++argv ) {
    fprintf( stderr, "%s:\n", *argv );
    I_HTTPRequest * r = NewHTTPRequest( *argv );
    if( !r ) {
      fprintf( stderr, "%s: error getting URL\n" );
    }
    else {
      time_t t;
      t = 0;
      char buf[4096];
      FILE * f = 0;
      while( true ) {
        r->step();
        size_t rd = r->read( buf, 4096 );
        if( rd > 0 ) {
          if( !f ) {
            char opath[1024];
            get_url_path( opath, 1024, *argv );
            f = fopen( opath, "wb" );
            if( !f ) {
              fprintf( stderr, "%s: cannot create %s\n", *argv, opath );
              goto next;
            }
          }
          fwrite( buf, 1, rd, f );
        }
        else {
          if( r->complete() ) {
            assert( f != 0 );
            fclose( f );
            goto next;
          }
          if( !t ) {
            time( &t );
          }
          else {
            time_t t2;
            time( &t2 );
            if( t2 > t+10 ) {
              fprintf( stderr, "%s: timeout\n", *argv );
              if( f ) {
                fclose( f );
              }
              goto next;
            }
          }
        }
      }
next:
      r->dispose();
    }
  }
	return 0;
}
コード例 #2
0
ファイル: netscape.cpp プロジェクト: pagxir/libflashcross
NPError NPN_PostURLNotify(NPP instance, const char* url, const char* target,
		uint32_t len, const char* buf, NPBool file, void* notifyData)
{
	char schema[8];
	char porttext[8];
	char hostname[256];
	char url_path[512];
	const char *partial_url;

	if (target != NULL){
		fprintf(stderr, "GetURLNotify: %s %s\n", target, url);
		return NPERR_NO_ERROR;
	}

	partial_url = get_schema(url, schema, sizeof(schema));
	partial_url = get_hostname(partial_url, hostname, sizeof(hostname));
	partial_url = get_porttext(partial_url, porttext, sizeof(porttext));
	partial_url = get_url_path(partial_url, url_path, sizeof(url_path));

	if (strncmp(schema, "http://", 7)) {
		return NPERR_GENERIC_ERROR;
	}

	char *foop;
	char headers[8192];
	NPNetStream *stream;
	proto_stream *protop;
	struct sockaddr_in name;

	name.sin_family = AF_INET;
	name.sin_port   = htons(*porttext? atoi(porttext + 1): 80);
	name.sin_addr   = inaddr_convert(hostname);

	protop = new proto_stream();
	assert(protop != NULL);

	if (protop->connect(&name, sizeof(name))) {
		protop->rel();
		return NPERR_GENERIC_ERROR;
	}

	foop = headers;
	foop += sprintf(foop, "POST %s HTTP/1.0\r\n", url_path);
	foop += sprintf(foop, "Host: %s%s\r\n", hostname, porttext);
	foop += sprintf(foop, "User-Agent: %s\r\n", NPN_UserAgent(0));
	foop += sprintf(foop, "Accept: application/xml;q=0.9,*/*,q=0.8\r\n");
	foop += sprintf(foop, "Connection: close\r\n");

	stream = new NPNetStream(instance, notifyData, url, protop);
	assert(stream != NULL);

	protop->set_request(headers, buf, len);
	stream->startup();
	protop->rel();
	return NPERR_NO_ERROR;
}
コード例 #3
0
ファイル: netscape.cpp プロジェクト: pagxir/libflashcross
proto_stream *RedirectURLNotify(const char *url, const char *refer)
{
	char schema[8];
	char porttext[8];
	char hostname[256];
	char url_path[512];
	const char *partial_url;

	partial_url = get_schema(url, schema, sizeof(schema));
	partial_url = get_hostname(partial_url, hostname, sizeof(hostname));
	partial_url = get_porttext(partial_url, porttext, sizeof(porttext));
	partial_url = get_url_path(partial_url, url_path, sizeof(url_path));

	if (strncmp(schema, "http://", 7)) {
		return NULL;
	}

	char *foop;
	char headers[8192];
	NPNetStream *stream;
	proto_stream *protop;
	struct sockaddr_in name;

	name.sin_family = AF_INET;
	name.sin_port   = htons(*porttext? atoi(porttext + 1): 80);
	name.sin_addr   = inaddr_convert(hostname);

	protop = new proto_stream();
	assert(protop != NULL);

	if (protop->connect(&name, sizeof(name))) {
		protop->rel();
		return NULL;
	}

	foop = headers;
	foop += sprintf(foop, "GET %s HTTP/1.0\r\n", url_path);
	foop += sprintf(foop, "Host: %s%s\r\n", hostname, porttext);
	foop += sprintf(foop, "User-Agent: %s\r\n", NPN_UserAgent(0));
	foop += sprintf(foop, "Accept: application/xml;q=0.9,*/*,q=0.8\r\n");
	foop += sprintf(foop, "Refer: %s\r\n", refer);
	foop += sprintf(foop, "Connection: close\r\n");
	foop += sprintf(foop, "\r\n");

	protop->set_request(headers);
	return protop;
}