Esempio n. 1
0
void
_SHOWSTRING(
	const char *string,
	const char *name,
	const char *file,
	int line)
{
	if(__debug_level >= DEBUGLEVEL_Reports)
	{
		_INDENT();

		if(debug_file == (BPTR)NULL)
		{
			if(string != NULL)
				kprintf("%s:%ld:%s = 0x%08lx \"%s\"\n",file,line,name,string,string);
			else
				kprintf("%s:%ld:%s = NULL \"\"\n",file,line,name);
		}
		else
		{
			if(string != NULL)
				FPrintf(debug_file,"%s:%ld:%s = 0x%08lx \"%s\"\n",file,line,name,string,string);
			else
				FPrintf(debug_file,"%s:%ld:%s = NULL \"\"\n",file,line,name);

			Flush(debug_file);
		}
	}
}
Esempio n. 2
0
void moveInfoApplyCriterion( MoveInfo *theMoveInfo,
                            SourceCriterionFunc theSourceCriterion,
                            CriterionFunc theCriterion )
{
    Stack *sourceStack, *destStack;
    Move *theMove;
    int i, j;

#ifdef DEBUG
    FPrintf( Output(), "0x%lx: ", theMoveInfo );
#endif
    for( i = 0; i < boardNumStacks(); i++ )
    {
        if( !theSourceCriterion( sourceStack = &theMoveInfo->mi_Stacks[i] ))
            continue;
        for( j = 0; j < boardNumStacks(); j++ )
        {
            if( i == j )
                continue;
            destStack = &theMoveInfo->mi_Stacks[j];
            if(( theCriterion( sourceStack, destStack ))&&
               ( theMove = moveAlloc( i, j )))
            {
                moveAddTail( &theMoveInfo->mi_Moves, theMove );
#ifdef DEBUG
                FPrintf( Output(), "(%ld->%ld)", i, j );
#endif
            }
        }
    }
#ifdef DEBUG
    FPrintf( Output(), "\n" );
#endif
}
Esempio n. 3
0
void
_INDENT(void)
{
	if(program_name_len > 0)
	{
		if(debug_file == (BPTR)NULL)
			kprintf("(%s) ",program_name);
		else
			FPrintf(debug_file,"(%s) ",program_name);
	}

	if(__debug_level >= DEBUGLEVEL_CallTracing)
	{
		int i;

		if(debug_file == (BPTR)NULL)
		{
			for(i = 0 ; i < indent_level ; i++)
				kprintf("   ");
		}
		else
		{
			for(i = 0 ; i < indent_level ; i++)
				FPrintf(debug_file,"   ");
		}
	}
}
Esempio n. 4
0
void ConsolePrintWarning(MSGVEC *msgvecP)
{
  TCHAR format[80];
  TCHAR *msgtextP;

  // Print the primary warning message.

  msgtextP = GetMessageText(msgvecP->code);

  StrPrintf (format, msgtextP,
    msgvecP->param[0], msgvecP->param[1], msgvecP->param[2],
    msgvecP->param[3], msgvecP->param[4], msgvecP->param[5],
    msgvecP->param[6], msgvecP->param[7]);

  FPrintf (stderr, _T("\nWarning: %s\n"), format);

  // Print the (optional) secondary warning message.

  if (msgvecP->subcode)
    {
    msgtextP = GetMessageText(msgvecP->subcode);

    StrPrintf (format, msgtextP,
      msgvecP->subparam[0], msgvecP->subparam[1], msgvecP->subparam[2],
      msgvecP->subparam[3], msgvecP->subparam[4], msgvecP->subparam[5],
      msgvecP->subparam[6], msgvecP->subparam[7]);

    FPrintf (stderr, _T("%s\n"), format);
    }
}
Esempio n. 5
0
void opponentPrintSequence( MoveInfo *theMoveInfo )
{
    FPrintf( Output(), "[" );
    while( theMoveInfo->mi_Parent )
    {
        FPrintf( Output(), "(%ld->%ld)", theMoveInfo->mi_SrcStack,
                theMoveInfo->mi_DestStack );
        theMoveInfo = theMoveInfo->mi_Parent;
    }
    FPrintf( Output(), "]\n" );
}
Esempio n. 6
0
/*
=================
Error

For abnormal program terminations
=================
*/
void Error( const char *error, ...)
{
  char out_buffer[4096];
  char tmp[4096];
	va_list argptr;

	va_start (argptr,error);
	vsprintf (tmp, error, argptr);
	va_end (argptr);

  sprintf( out_buffer, "************ ERROR ************\n%s\n", tmp );

  FPrintf( SYS_ERR, out_buffer );

#ifdef DBG_XML  
  DumpXML();
#endif

  //++timo HACK ALERT .. if we shut down too fast the xml stream won't reach the listener.
  // a clean solution is to send a sync request node in the stream and wait for an answer before exiting
  Sys_Sleep( 1000 );
  
  Broadcast_Shutdown();

	exit (1);
}
Esempio n. 7
0
void
_SHOWPOINTER(
	void *pointer,
	const char *name,
	const char *file,
	int line)
{
	if(__debug_level >= DEBUGLEVEL_Reports)
	{
		char *fmt;

		_INDENT();

		if(pointer != NULL)
			fmt = "%s:%ld:%s = 0x%08lx\n";
		else
			fmt = "%s:%ld:%s = NULL\n";

		if(debug_file == (BPTR)NULL)
		{
			kprintf(fmt,file,line,name,pointer);
		}
		else
		{
			FPrintf(debug_file,fmt,file,line,name,pointer);
			Flush(debug_file);
		}
	}
}
Esempio n. 8
0
void Sys_FPrintf( int flag, const char *format, ... )
{
	char out_buffer[4096];
	va_list argptr;

	/* filter verbose messages */
	if( (flag == SYS_VRB) && (verbose == qfalse) )
		return;

	/* catch current stage */
	if( !strncmp( format, "--- ", 4) )
	{
		strncpy( currentStage, format + 4, sizeof(currentStage) - 1 );
		char *p = strstr( currentStage, " ---" );
		if( p != NULL )
			p[ 0 ] = 0;
	}

	/* print */
	va_start( argptr, format );
	vsprintf( out_buffer, format, argptr );
	va_end( argptr );

	/* send */
	FPrintf (flag, out_buffer);
}
Esempio n. 9
0
int main (int argc, char ** argv)
{
    struct Library *base1, *base2;
    BPTR seglist;
    
    FPuts(Output(), (STRPTR)"Testing peropener.library\n");
    
    base1=OpenLibrary((STRPTR)"peropener.library",0);
    base2=OpenLibrary((STRPTR)"peropener.library",0);

    FPrintf(Output(), (STRPTR)"base1=%lx, base2=%lx\n", base1, base2);
    
    if (base1 != NULL)
        CloseLibrary(base1);
    if (base2 != NULL)
        CloseLibrary(base2);

    FPuts(Output(), (STRPTR)"\nTesting perid.library\n");

    base1=OpenLibrary((STRPTR)"perid.library",0);
    base2=OpenLibrary((STRPTR)"perid.library",0);
    
    FPrintf(Output(), (STRPTR)"base1=%lx, base2=%lx\n", base1, base2);

    seglist = LoadSeg((CONST_STRPTR)"peropenertest_child");
    if (seglist != (BPTR)NULL)
    {
        RunCommand(seglist, 10*1024, "\n", -1);
        UnLoadSeg(seglist);
    }
    else
    {
        FPrintf(Output(), (STRPTR)"Failed to load peropenertest_child\n");
    }
    
    if (base1 != NULL)
        CloseLibrary(base1);
    if (base2 != NULL)
        CloseLibrary(base2);

    Flush (Output ());
    
    return 0;
}
Esempio n. 10
0
void Sys_Printf( const char *format, ... ){
	char out_buffer[4096];
	va_list argptr;

	va_start( argptr, format );
	vsprintf( out_buffer, format, argptr );
	va_end( argptr );

	FPrintf( SYS_STD, out_buffer );
}
Esempio n. 11
0
void opponentPrintStacks( Stack *theStacks )
{
    Card loCard, hiCard;
    int i, *stackNoPtr;

    for( i = *(stackNoPtr = tempStacks); i < NUM_STACKS; i = *(++stackNoPtr))
    {
        if( theStacks[i].st_NumCards )
        {
            loCard = theStacks[i].st_Cards[0];
            hiCard = theStacks[i].st_Cards[theStacks[i].st_NumCards-1];
            FPrintf( Output(), "[%s%s,%s%s]", RankToStr[cardRank(loCard)],
                    SuitToStr[cardSuit(loCard)], RankToStr[cardRank(hiCard)],
                    SuitToStr[cardSuit(hiCard)] );
        }
        else
            FPrintf( Output(), "[EMPTY]" );
    }
}
Esempio n. 12
0
int identify(CONST_STRPTR filename, BOOL verbose)
{
    int  rc   = RETURN_OK;
    BPTR lock = Lock(filename, ACCESS_READ);
    
    if (lock != NULL)
    {
        struct DataType *dt = ObtainDataType(DTST_FILE, lock, TAG_DONE);
        if (dt != NULL)
        {
            struct DataTypeHeader *dth = dt->dtn_Header;
            
            if (!verbose)
            {
                Printf
                (
                    "%s:\t%s/%s\n", 
                    filename, gid2string(dth->dth_GroupID), dth->dth_Name
                );
            }
            else
            {   
                ULONG gid = AROS_LONG2BE(dth->dth_GroupID),
                      id  = AROS_LONG2BE(dth->dth_ID);
                
                Printf
                (
                    "File:        %s\n"
                    "Type:        %s/%s\t(GID: %.4s, ID: %.4s)\n"
                    "DT Basename: %s\n\n",
                    filename, gid2string(dth->dth_GroupID), dth->dth_Name,
                    (CONST_STRPTR) &gid, (CONST_STRPTR) &id,
                    dth->dth_BaseName
                );
            }
        }
        else
        {
            FPrintf(Error(), ERROR_HEADER": Could not obtain datatype for file.\n");
            rc = RETURN_FAIL;
        }

        UnLock(lock);
    }
    else
    {
        PrintFault(IoErr(), ERROR_HEADER);
        rc = RETURN_FAIL;
    }

    return rc;
}
Esempio n. 13
0
void Sys_FPrintf (int flag, const char *format, ...)
{
  char out_buffer[4096];
	va_list argptr;
  
  if ((flag == SYS_VRB) && (verbose == qfalse))
    return;

  va_start (argptr, format);
	vsprintf (out_buffer, format, argptr);
	va_end (argptr);

  FPrintf (flag, out_buffer);
}
Esempio n. 14
0
/* Open and initialize AmiSSL */
static BOOL Init(void)
{
	BOOL is_ok = FALSE;

	if (!(SocketBase = OpenLibrary("bsdsocket.library", 4)))
		FPrintf(GetStdErr(), "Couldn't open bsdsocket.library v4!\n");
#if defined(__amigaos4__)
	else if (!(ISocket = (struct SocketIFace *)GetInterface(SocketBase, "main", 1, NULL)))
		FPrintf(GetStdErr(), "Couldn't get Socket interface!\n");
#endif
	else if (!(AmiSSLMasterBase = OpenLibrary("amisslmaster.library",
	                                          AMISSLMASTER_MIN_VERSION)))
		FPrintf(GetStdErr(), "Couldn't open amisslmaster.library v"
		                     MKSTR(AMISSLMASTER_MIN_VERSION) "!\n");
#if defined(__amigaos4__)
	else if (!(IAmiSSLMaster = (struct AmiSSLMasterIFace *)GetInterface(AmiSSLMasterBase,
	                                                                    "main", 1, NULL)))
		FPrintf(GetStdErr(), "Couldn't get AmiSSLMaster interface!\n");
#endif
	else if (!InitAmiSSLMaster(AMISSL_CURRENT_VERSION, TRUE))
		FPrintf(GetStdErr(), "AmiSSL version is too old!\n");
	else if (!(AmiSSLBase = OpenAmiSSL()))
		FPrintf(GetStdErr(), "Couldn't open AmiSSL!\n");
#if defined(__amigaos4__)
	else if (!(IAmiSSL = (struct AmiSSLIFace *)GetInterface(AmiSSLBase,
	                                                        "main", 1, NULL)))
		FPrintf(GetStdErr(), "Couldn't get AmiSSL interface!\n");
#endif
#if defined(__amigaos4__)
	else if (InitAmiSSL(AmiSSL_ErrNoPtr, &errno,
	                    AmiSSL_ISocket, ISocket,
	                    TAG_DONE) != 0)
#else
	else if (InitAmiSSL(AmiSSL_ErrNoPtr, &errno,
	                    AmiSSL_SocketBase, SocketBase,
	                    TAG_DONE) != 0)
#endif
		FPrintf(GetStdErr(), "Couldn't initialize AmiSSL!\n");
	else
		is_ok = TRUE;

	if (!is_ok)
		Cleanup(); /* This is safe to call even if something failed above */

	return(is_ok);
}
Esempio n. 15
0
void
_DPRINTF_HEADER(
	const char *file,
	int line)
{
	if(__debug_level >= DEBUGLEVEL_Reports)
	{
		_INDENT();

		if(debug_file == (BPTR)NULL)
			kprintf("%s:%ld:",file,line);
		else
			FPrintf(debug_file,"%s:%ld:",file,line);
	}
}
Esempio n. 16
0
void
_SHOWMSG(
	const char *string,
	const char *file,
	int line)
{
	if(__debug_level >= DEBUGLEVEL_Reports)
	{
		_INDENT();

		if(debug_file == (BPTR)NULL)
		{
			kprintf("%s:%ld:%s\n",file,line,string);
		}
		else
		{
			FPrintf(debug_file,"%s:%ld:%s\n",file,line,string);
			Flush(debug_file);
		}
	}
}
Esempio n. 17
0
void opponentStoreMoveSequence( MoveInfo *theMoveInfo )
{
    MoveInfo *aMoveInfo;
    Move *aMove;

#ifdef DEBUG
    FPrintf( Output(), "Best sequence now: " );
    opponentPrintSequence( theMoveInfo );
#endif

    while( aMove = moveRemHead( MoveSequence ))
        moveFree( aMove );

    for( aMoveInfo = theMoveInfo; aMoveInfo->mi_Parent;
        aMoveInfo = aMoveInfo->mi_Parent )
    {
        if( aMove = moveAlloc( aMoveInfo->mi_SrcStack,
                              aMoveInfo->mi_DestStack ))
            moveAddHead( MoveSequence, aMove );
    }
}
Esempio n. 18
0
void Sys_Printf( const char *format, ... )
{
	char out_buffer[4096];
	va_list argptr;

	/* catch current stage */
	if( !strncmp( format, "--- ", 4) )
	{
		strncpy( currentStage, format + 4, sizeof(currentStage) - 1 );
		char *p = strstr( currentStage, " ---" );
		if( p != NULL )
			p[ 0 ] = 0;
	}

	/* print */
	va_start( argptr, format );
	vsprintf( out_buffer, format, argptr );
	va_end( argptr );

	/* send */
	FPrintf( SYS_STD, out_buffer );
}
Esempio n. 19
0
__saveds __asm ULONG GROM_Generate (a2 Object *Win, a1 SW_IDATA **idata)
{
   UBYTE fspec[FMSIZE];
   BPTR  fp = NULL;
   ULONG x, Cost1 = (ULONG)(idata[2]), Cost2 = (ULONG)(idata[3]);
   UBYTE DoneText[] = "\33c\33bDone:\33n Registration form saved to file %s\n\n"
                      "Email to " SRK_EMAIL " or send by postal mail to:\n\n"
                      "   %s Registration\n"
                      "   405 Pulsar St.\n"
                      "   Fort Collins, CO 80525 USA\n\n"
                      "See the above file for more information.\n\n"
                      "Thank you for registering %s!";
   UBYTE ErrText[]  = "\33c\33bError:\33n Unable to open registration file %s.";
   UBYTE *Prog = (UBYTE *)(idata[1]);

   AddPart(strcpy(fspec, "RAM:"), Prog, FMSIZE);
   strcat(fspec, ".Regform");

   for (x=0; RG_ParseTable[x].Keyword; x++) {
      UBYTE *Val;
      get((*idata)->Gads[x], MUIA_String_Contents, &Val);

      if (RG_ParseTable[x].Required && (!Val || !Val[0])) {
         MUI_Request(Win, (*idata)->RegWin, 0,NULL, "*_Ok",(char *)
                     "\33c\33bError:\33n No value suppled for required "
                     "field '%s'\n",
                     RG_ParseTable[x].Keyword, NULL);
         goto Done;
      }
   }


   if (!(fp = Open(fspec, MODE_NEWFILE))) {
      MUI_Request(Win, (*idata)->RegWin, 0,NULL, "*_Ok",(char *)ErrText,
                  fspec, NULL, NULL);
      goto Done;
   }

   FPrintf(fp, "E-mail this form to %s with the subject line:\n"
               "  CMD REGISTER %s\n\n"
               "Registration cost is US $%ld for E-Mail registration and\n"
               "US $%ld for postal mail registration.  E-Mail registration\n"
               "will receive a keyfile shortly.  Postal registration should\n"
               "allow 4 weeks and include a disk and self addressed stamped\n"
               "envelope.  Checks can be made payable to ShadowWorks Software.\n\n"
               "Registration request for %s\n\n",

           SRK_EMAIL, Prog, Cost1, Cost2, Prog);

   for (x=0; RG_ParseTable[x].Keyword; x++) {
      UBYTE *Val;
      
      get((*idata)->Gads[x], MUIA_String_Contents, &Val);

      if (Val && Val[0])
         FPrintf(fp, "%-10s = %s\n", RG_ParseTable[x].Keyword, Val);
   }

   Close(fp); fp = NULL;

   MUI_Request(Win, (*idata)->RegWin, 0,NULL, "*_Ok",(char *)DoneText,
               fspec, Prog, Prog);

   set(Win, MUIA_Window_Open, FALSE);

  Done:
   if (fp) Close(fp);

   return 0;
}
Esempio n. 20
0
/* Connect to the specified server, either directly or through the specified
 * proxy using HTTP CONNECT method.
 */
static int ConnectToServer(char *host, short port, char *proxy, short pport)
{
	struct sockaddr_in addr;
	char buffer[1024]; /* This should be dynamically alocated */
	BOOL is_ok = FALSE;
	char *s1, *s2;
	int sock;

	/* Create a socket and connect to the server */
	if ((sock = socket(AF_INET, SOCK_STREAM, 0)) >= 0)
	{
		memset(&addr, 0, sizeof(addr));
		addr.sin_family = AF_INET;

		if (proxy && pport)
		{
			addr.sin_addr.s_addr = inet_addr(proxy); /* This should be checked against INADDR_NONE */
			addr.sin_port = htons(pport);
		}
		else
		{
			addr.sin_addr.s_addr = inet_addr(host); /* This should be checked against INADDR_NONE */
			addr.sin_port = htons(port);
		}

		if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) >= 0)
		{
			/* For proxy connection, use SSL tunneling. First issue a HTTP CONNECT
			 * request and then proceed as with direct HTTPS connection.
			 */
			if (proxy && pport)
			{
				/* This should be done with snprintf to prevent buffer
				 * overflows, but some compilers don't have it and
				 * handling that would be an overkill for this example
				 */
				sprintf(buffer, "CONNECT %s:%ld HTTP/1.0\r\n\r\n",
				        host, (long)port);

				/* In a real application, it would be necessary to loop
				 * until everything is sent or an error occurrs, but here we
				 * hope that everything gets sent at once.
				 */
				if (send(sock, buffer, strlen(buffer), 0) >= 0)
				{
					int len;

					/* Again, some optimistic behaviour: HTTP response might not be
					 * received with only one recv
					 */
					if ((len = recv(sock, buffer, sizeof(buffer) - 1, 0)) >= 0)
					{
						/* Assuming it was received, find the end of
						 * the line and cut it off
						 */
						if ((s1 = strchr(buffer, '\r'))
						    || (s1 = strchr(buffer, '\n')))
							*s1 = '\0';
						else
							buffer[len] = '\0';

						Printf("Proxy returned: %s\n", buffer);

						/* Check if HTTP response makes sense */
						if (strncmp(buffer, "HTTP/", 4) == 0
						    && (s1 = strchr(buffer, ' '))
						    && (s2 = strchr(++s1, ' '))
						    && (s2 - s1 == 3))
						{
							/* Only accept HTTP 200 OK response */
							if (atol(s1) == 200)
								is_ok = TRUE;
							else
								FPrintf(GetStdErr(), "Proxy responce indicates error!\n");
						}
						else
							FPrintf(GetStdErr(), "Amibigous proxy responce!\n");
					}
					else
						FPrintf(GetStdErr(), "Couldn't get proxy response!\n");
				}
				else
					FPrintf(GetStdErr(), "Couldn't send request to proxy!\n");
			}
			else
				is_ok = TRUE;
		}
    else
      FPrintf(GetStdErr(), "Couldn't connect to server\n");

		if (!is_ok)
		{
			CloseSocket(sock);
			sock = -1;
		}
	}

	return(sock);
}
Esempio n. 21
0
int main(void)
{
    out = Output();

    slot1 = AllocTaskStorageSlot();
    FPrintf(out, "Got slot %ld\n", slot1);

    slot2 = AllocTaskStorageSlot();
    FPrintf(out, "Got slot %ld\n", slot2);

    FreeTaskStorageSlot(slot2);
    FPrintf(out, "Freed slot %ld\n", slot2);

    slot2 = AllocTaskStorageSlot();
    FPrintf(out, "Got slot %ld\n", slot2);

    slot3 = AllocTaskStorageSlot();
    FPrintf(out, "Got slot %ld\n", slot3);

    SetTaskStorageSlot(slot1, 69);
    FPrintf(out, "Stored value 69 in slot %ld\n", slot1);

    FPrintf(out, "Checking value in subtask\n");
    struct Process *proc = 
        CreateNewProcTags(
            NP_Entry, printslot1, NP_Name, "Check slot1",
            NP_Synchronous, TRUE, TAG_DONE
        );
    assert(proc != NULL);

    FreeTaskStorageSlot(slot1);
    FPrintf(out, "Freed slot %ld\n", slot1);

    slot1 = AllocTaskStorageSlot();
    FPrintf(out, "Got slot %ld\n", slot1);

    FreeTaskStorageSlot(slot2);
    FPrintf(out, "Freed slot %ld\n", slot2);

    FreeTaskStorageSlot(slot1);
    FPrintf(out, "Freed slot %ld\n", slot1);

    FreeTaskStorageSlot(slot3);
    FPrintf(out, "Freed slot %ld\n", slot3);

    return 0;
}
Esempio n. 22
0
static void printslot1(void)
{
    FPrintf(out, "Value slot %ld: %ld\n", slot1, GetTaskStorageSlot(slot1));
}
Esempio n. 23
0
/* The program expects at most four arguments: host in IP format, port
 * number to connect to, proxy in IP format and proxy port number.
 * If last two are specified, host can be in any format proxy will
 * understand (since this is an example for SSL programming, host name
 * resolving code is left out).
 *
 * Default values are "127.0.0.1", 443. If any proxy parameter is
 * omitted, the program will connect directly to the host.
 */
int main(int argc, char *argv[])
{
	char buffer[4096]; /* This should be dynamically allocated */
	const char *request = "GET / HTTP/1.0\r\n\r\n";
	BOOL is_ok = FALSE;
	X509 *server_cert;
	SSL_CTX *ctx;
	BIO *bio_err;
	SSL *ssl;

	if (Init())
	{
		/* Basic intialization. Next few steps (up to SSL_new()) need
		 * to be done only once per AmiSSL opener.
		 */
		SSLeay_add_ssl_algorithms();
		SSL_load_error_strings();

		/* Note: BIO writing routines are prepared for NULL BIO handle */
		if((bio_err = BIO_new(BIO_s_file())) != NULL)
			BIO_set_fp_amiga(bio_err, GetStdErr(), BIO_NOCLOSE | BIO_FP_TEXT);

		/* Get a new SSL context */
		if((ctx = SSL_CTX_new(SSLv23_client_method())) != NULL)
		{
			/* Basic certificate handling. OpenSSL documentation has more
			 * information on this.
			 */
			SSL_CTX_set_default_verify_paths(ctx);
			SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
			                   NULL);

			/* The following needs to be done once per socket */
			if((ssl = SSL_new(ctx)) != NULL)
			{
				int sock;

				/* Connect to the HTTPS server, directly or through a proxy */
				if (argc > 4)
					sock = ConnectToServer(argv[1], atol(argv[2]), argv[3],
					                       atol(argv[4]));
				else
					sock = ConnectToServer(argv[1] ? argv[1] : (char *)"127.0.0.1",
					                       argc > 2 ? atol(argv[2]) : 443,
					                       NULL, 0);

				/* Check if connection was established */
				if (sock >= 0)
				{
					int ssl_err = 0;

					/* Associate the socket with the ssl structure */
					SSL_set_fd(ssl, sock);

					/* Perform SSL handshake */
					if((ssl_err = SSL_connect(ssl)) >= 0)
					{
						Printf("SSL connection using %s\n", SSL_get_cipher(ssl));

						/* Certificate checking. This example is *very* basic */
						if((server_cert = SSL_get_peer_certificate(ssl)))
						{
							char *str;

							Printf("Server certificate:\n");

							if((str = X509_NAME_oneline(X509_get_subject_name(server_cert), 0, 0)))
							{
								Printf("\tSubject: %s\n", str);
								OPENSSL_free(str);
							}
							else
								FPrintf(GetStdErr(), "Warning: couldn't read subject name in certificate!\n");

							if((str = X509_NAME_oneline(X509_get_issuer_name(server_cert),
							                            0, 0)) != NULL)
							{
								Printf("\tIssuer: %s\n", str);
								OPENSSL_free(str);
							}
							else
								FPrintf(GetStdErr(), "Warning: couldn't read issuer name in certificate!\n");

							X509_free(server_cert);

							/* Send a HTTP request. Again, this is just
							 * a very basic example.
							 */
							if ((ssl_err = SSL_write(ssl, request, strlen(request)))
							    > 0)
							{
								/* Dump everything to output */
								while ((ssl_err = SSL_read(ssl, buffer,
								                           sizeof(buffer) - 1))
								       > 0)
									FWrite(Output(), buffer, ssl_err, 1);

								FFlush(Output());

								/* This is not entirely true, check
								 * the SSL_read documentation
								 */
								is_ok = ssl_err == 0;
							}
							else
								FPrintf(GetStdErr(), "Couldn't write request!\n");
						}
						else
							FPrintf(GetStdErr(), "Couldn't get server certificate!\n");
					}
					else
						FPrintf(GetStdErr(), "Couldn't establish SSL connection!\n");

					/* If there were errors, print them */
					if (ssl_err < 0)
						ERR_print_errors(bio_err);

					/* Send SSL close notification and close the socket */
					SSL_shutdown(ssl);
					CloseSocket(sock);
				}
				else
					FPrintf(GetStdErr(), "Couldn't connect to host!\n");

        
			  FPrintf(GetStdErr(), "before SSL_free()\n");
				SSL_free(ssl);
			}
			else
				FPrintf(GetStdErr(), "Couldn't create new SSL handle!\n");

			FPrintf(GetStdErr(), "before SSL_CTX_free()\n");
			SSL_CTX_free(ctx);
		}
		else
			FPrintf(GetStdErr(), "Couldn't create new context!\n");

	  FPrintf(GetStdErr(), "before Cleanup()\n");
		Cleanup();
	}

	FPrintf(GetStdErr(), "before end of main()\n");
	return(is_ok ? RETURN_OK : RETURN_ERROR);
}
Esempio n. 24
0
void
_SHOWVALUE(
	unsigned long value,
	int size,
	const char *name,
	const char *file,
	int line)
{
	if(__debug_level >= DEBUGLEVEL_Reports)
	{
		char *fmt;

		switch(size)
		{
			case 1:

				fmt = "%s:%ld:%s = %ld, 0x%02lx";
				break;

			case 2:

				fmt = "%s:%ld:%s = %ld, 0x%04lx";
				break;

			default:

				fmt = "%s:%ld:%s = %ld, 0x%08lx";
				break;
		}

		_INDENT();

		if(debug_file == (BPTR)NULL)
			kprintf(fmt,file,line,name,value,value);
		else
			FPrintf(debug_file,fmt,file,line,name,value,value);

		if(size == 1 && value < 256)
		{
			if(debug_file == (BPTR)NULL)
			{
				if(value < ' ' || (value >= 127 && value < 160))
					kprintf(", '\\x%02lx'",value);
				else
					kprintf(", '%lc'",value);
			}
			else
			{
				if(value < ' ' || (value >= 127 && value < 160))
					FPrintf(debug_file,", '\\x%02lx'",value);
				else
					FPrintf(debug_file,", '%lc'",value);
			}
		}

		if(debug_file == (BPTR)NULL)
		{
			kprintf("\n");
		}
		else
		{
			FPrintf(debug_file,"\n");
			Flush(debug_file);
		}
	}
}