// not working in mingw. test.xml file is not saved properly as text file.
void FetchXMLFile() {
#if defined(LIBXML_HTTP_ENABLED)
    int ret_val;
    char *contentType; /* if available the Content-Type information will be returned at that location */

	xmlNanoHTTPInit();
	
	ret_val = xmlNanoHTTPFetch(XML_URL, "test.xml", &contentType);
	
	printf("ContentType: %s\n",contentType);
	printf("Retval %d\n", ret_val);
	
	xmlNanoHTTPCleanup();
#endif
}
Example #2
0
/**
 * Cleans up the nano HTTP state
 *
 * @param pContext HTTP Context
 * @param pContentType Content-type container
 */
static void
cleanup(void * pContext, char * pContentType)
{
    if (pContext)
    {
        xmlNanoHTTPClose(pContext);
    }

    if (pContentType)
    {
        xmlFree(pContentType);
    }

    xmlNanoHTTPCleanup();
}
Example #3
0
int main(int argc, char **argv) {
    char *contentType = NULL;

    if (argv[1] != NULL) {
	if (argv[2] != NULL) 
	    xmlNanoHTTPFetch(argv[1], argv[2], &contentType);
        else
	    xmlNanoHTTPFetch(argv[1], "-", &contentType);
	if (contentType != NULL) xmlFree(contentType);
    } else {
        xmlGenericError(xmlGenericErrorContext,
		"%s: minimal HTTP GET implementation\n", argv[0]);
        xmlGenericError(xmlGenericErrorContext,
		"\tusage %s [ URL [ filename ] ]\n", argv[0]);
    }
    xmlNanoHTTPCleanup();
    xmlMemoryDump();
    return(0);
}
void GetXMLHttp() {
	void * Ctxt;
	char *contentType;
	
	xmlNanoHTTPInit();
	
	Ctxt = xmlNanoHTTPOpen(XML_URL, &contentType);

	if (Ctxt == 0)
		printf("ERROR: xmlNanoHTTPOpen() == 0\n");

	if (xmlNanoHTTPReturnCode(Ctxt) != 200)
		printf("ERROR: HTTP Code != OK\n");

	// open output file
	FILE *fp;
	fp=fopen("test_get.xml","w");
	

	// Write to file
	const int Size = 2048;
	char Buffer[Size];
	int Count;

	while ((Count = xmlNanoHTTPRead(Ctxt, Buffer, Size)) > 0)
		fprintf(fp,"%s",Buffer);	
		//File.write(Buffer, Count);
		
	fclose(fp);

	if (Count == 0)
		printf("STATUS: Connection closed\n");

	if (Count == -1)
		printf("ERROR: xmlNanoHTTPRead() == -1\n");
	
		
	// Free ressources
	xmlFree(contentType);
	xmlNanoHTTPClose(Ctxt);
	xmlNanoHTTPCleanup();
}
Example #5
0
static Image *ReadURLImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
#define MaxBufferExtent  8192

  char
    filename[MaxTextExtent];

  FILE
    *file;

  Image
    *image;

  ImageInfo
    *read_info;

  int
    unique_file;

  image=(Image *) NULL;
  read_info=CloneImageInfo(image_info);
  SetImageInfoBlob(read_info,(void *) NULL,0);
  file=(FILE *) NULL;
  unique_file=AcquireUniqueFileResource(read_info->filename);
  if (unique_file != -1)
    file=fdopen(unique_file,"wb");
  if ((unique_file == -1) || (file == (FILE *) NULL))
    {
      read_info=DestroyImageInfo(read_info);
      (void) CopyMagickString(image->filename,read_info->filename,
        MaxTextExtent);
      ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
        image->filename);
      image=DestroyImageList(image);
      return((Image *) NULL);
    }
  (void) CopyMagickString(filename,image_info->magick,MaxTextExtent);
  (void) ConcatenateMagickString(filename,":",MaxTextExtent);
  LocaleLower(filename);
  (void) ConcatenateMagickString(filename,image_info->filename,MaxTextExtent);
  if (LocaleCompare(read_info->magick,"file") == 0)
    {
      (void) RelinquishUniqueFileResource(read_info->filename);
      unique_file=(-1);
      (void) CopyMagickString(read_info->filename,image_info->filename+2,
        MaxTextExtent);
    }
#if defined(MAGICKCORE_XML_DELEGATE) && defined(LIBXML_FTP_ENABLED)
  if (LocaleCompare(read_info->magick,"ftp") == 0)
    {
      void
        *context;

      xmlNanoFTPInit();
      context=xmlNanoFTPNewCtxt(filename);
      if (context != (void *) NULL)
        {
          if (xmlNanoFTPConnect(context) >= 0)
            (void) xmlNanoFTPGet(context,GetFTPData,(void *) file,
              (char *) NULL);
          (void) xmlNanoFTPClose(context);
        }
    }
#endif
#if defined(MAGICKCORE_XML_DELEGATE) && defined(LIBXML_HTTP_ENABLED)
  if (LocaleCompare(read_info->magick,"http") == 0)
    {
      char
        buffer[MaxBufferExtent],
        *type;

      int
        bytes;

      void
        *context;

      type=(char *) NULL;
      context=xmlNanoHTTPMethod(filename,(const char *) NULL,
        (const char *) NULL,&type,(const char *) NULL,0);
      if (context != (void *) NULL)
        {
          ssize_t
            count;

          while ((bytes=xmlNanoHTTPRead(context,buffer,MaxBufferExtent)) > 0)
            count=(ssize_t) fwrite(buffer,bytes,1,file);
          xmlNanoHTTPClose(context);
          xmlFree(type);
          xmlNanoHTTPCleanup();
        }
    }
#endif
  (void) fclose(file);
  *read_info->magick='\0';
  image=ReadImage(read_info,exception);
  if (unique_file != -1)
    (void) RelinquishUniqueFileResource(read_info->filename);
  read_info=DestroyImageInfo(read_info);
  if (image == (Image *) NULL)
    (void) ThrowMagickException(exception,GetMagickModule(),CoderError,
      "NoDataReturned","`%s'",filename);
  return(GetFirstImageInList(image));
}
Example #6
0
void CheckVersionNumber()
{
	//==== Init Nano HTTP ====//
	xmlNanoHTTPInit();
	xmlNanoHTTPScanProxy(NULL);

	//==== Compute Version Number ====//
	int ver_no = 10000*VSP_VERSION_MAJOR + 100*VSP_VERSION_MINOR + VSP_VERSION_CHANGE;

	char cCurrentPath[FILENAME_MAX];
	GetCurrentDir(cCurrentPath, sizeof(cCurrentPath));

	int user_id = 0;
	int path_len = strlen(cCurrentPath);

	for ( int i = 0 ; i < path_len ; i++ )
	{
		srand ( (unsigned int)cCurrentPath[i] );
		user_id += rand() % 100000 + 1;
	}

	//==== Post User Info To Server ====//
	char poststr[256];
	sprintf( poststr, "postvar1=%d&postvar2=%d\r\n", user_id, ver_no);
	int poststrlen = strlen(poststr);
	char*  headers = "Content-Type: application/x-www-form-urlencoded \n";

	void * ctx = 0;
	ctx = xmlNanoHTTPMethod("http://www.openvsp.org/vspuse_post.php", "POST", poststr, NULL, headers, poststrlen );

	if ( ctx )
		xmlNanoHTTPClose(ctx);

	ctx = 0;

	//==== Open Settings File ====//
	bool check_version_flag = true;
	FILE* vsptime_fp = fopen( ".vsptime", "r" );
	if ( vsptime_fp )
	{
		char str[256];
		fgets( str, 256, vsptime_fp );
		int vsp_time = atoi( str );
		int del_time =  (int)time(NULL) - vsp_time;
		if ( del_time < 60*60*24*7 )				// Check Every Week
			check_version_flag = false;

		fclose( vsptime_fp );
	}

	//==== Enough Time Has Passed - Check For New Version ====//
	if ( check_version_flag )
	{
		//==== Webpage with Version Info ====//
		char * pContentType = 0;
		ctx = xmlNanoHTTPOpen("http://www.openvsp.org/latest_version.html", &pContentType);

		int retCode = xmlNanoHTTPReturnCode(ctx);

		//==== Http Return Code 200 -> OK  ====//
		string contentStr;
		if ( retCode == 200 )
		{
			char buf[2048];
			int len = 1;
			while (len > 0 && contentStr.size() < 10000 )
			{
				len = xmlNanoHTTPRead(ctx, buf, sizeof(buf));
				contentStr.append( buf, len );
			}
		}

		//==== Pulled A String From Server =====//
		if ( contentStr.size() > 0 )
		{
			int major_ver, minor_ver, change_ver;
			bool valid = ExtractVersionNumber( contentStr, &major_ver, &minor_ver, &change_ver );

			if ( valid )
			{
				if ( major_ver != VSP_VERSION_MAJOR ||minor_ver != VSP_VERSION_MINOR || change_ver != VSP_VERSION_CHANGE )
				{
					if ( screenMgrPtr )
						screenMgrPtr->MessageBox("A new version of OpenVSP is available at http://www.openvsp.org/");
				}
			}
		}
		//===== Write Time =====//
		FILE* vsptime_fp = fopen( ".vsptime", "w" );
		if ( vsptime_fp )
		{
			fprintf( vsptime_fp, "%d", time(NULL) );
			fclose( vsptime_fp );
		}
	}

	if ( ctx )
		xmlNanoHTTPClose(ctx);

	xmlNanoHTTPCleanup();
}