int AB_ImExporterYN_CheckFile(AB_IMEXPORTER *ie, const char *fname) { AB_IMEXPORTER_YELLOWNET *ieh; GWEN_SYNCIO *sio; int rv; uint8_t tbuf[256]; assert(ie); assert(fname); assert(ie); ieh=GWEN_INHERIT_GETDATA(AB_IMEXPORTER, AB_IMEXPORTER_YELLOWNET, ie); assert(ieh); sio=GWEN_SyncIo_File_new(fname, GWEN_SyncIo_File_CreationMode_OpenExisting); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FILE_FLAGS_READ); rv=GWEN_SyncIo_Connect(sio); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_SyncIo_free(sio); return rv; } rv=GWEN_SyncIo_Read(sio, tbuf, sizeof(tbuf)-1); if (rv<1) { DBG_INFO(GWEN_LOGDOMAIN, "File \"%s\" is not supported by this plugin", fname); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return GWEN_ERROR_BAD_DATA; } tbuf[rv-1]=0; if (-1!=GWEN_Text_ComparePattern((const char *)tbuf, "*<?xml*", 0) && -1!=GWEN_Text_ComparePattern((const char *)tbuf, "*<KONAUS>*", 0)) { /* match */ DBG_INFO(GWEN_LOGDOMAIN, "File \"%s\" is supported by this plugin", fname); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return 0; } GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return GWEN_ERROR_BAD_DATA; }
GWEN_DBIO_CHECKFILE_RESULT GWEN_DBIO_XmlDb_CheckFile(GWEN_DBIO *dbio, const char *fname){ GWEN_SYNCIO *sio; int rv; uint8_t tbuf[256]; assert(dbio); assert(fname); sio=GWEN_SyncIo_File_new(fname, GWEN_SyncIo_File_CreationMode_OpenExisting); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FILE_FLAGS_READ); rv=GWEN_SyncIo_Connect(sio); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_SyncIo_free(sio); return GWEN_DBIO_CheckFileResultNotOk; } rv=GWEN_SyncIo_Read(sio, tbuf, sizeof(tbuf)-1); if (rv<1) { DBG_INFO(GWEN_LOGDOMAIN, "File \"%s\" is not supported by this plugin", fname); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return GWEN_DBIO_CheckFileResultNotOk; } tbuf[rv-1]=0; if (-1!=GWEN_Text_ComparePattern((const char*) tbuf, "*<?xml*", 0)) { /* match */ DBG_INFO(GWEN_LOGDOMAIN, "File \"%s\" is supported by this plugin", fname); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); /* don't be too sure about this, we *may* support the file, * so we dont say we don't support this file */ return GWEN_DBIO_CheckFileResultUnknown; } GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return GWEN_DBIO_CheckFileResultNotOk; }
static int check_syncio_tls1() { GWEN_SYNCIO *sio; GWEN_SYNCIO *baseLayer; int rv; char buffer[2048]; /* create socket layer */ sio=GWEN_SyncIo_Socket_new(GWEN_SocketTypeTCP, GWEN_AddressFamilyIP); if (sio==NULL) { fprintf(stderr, "ERROR in check_io_tls1: Could not create socket io layer.\n"); return 2; } GWEN_SyncIo_Socket_SetAddress(sio, "sourceforge.net"); GWEN_SyncIo_Socket_SetPort(sio, 443); baseLayer=sio; sio=GWEN_SyncIo_Tls_new(baseLayer); if (sio==NULL) { fprintf(stderr, "ERROR in check_io_tls1: Could not create TLS io layer.\n"); return 2; } GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_TLS_FLAGS_FORCE_SSL_V3); //GWEN_SyncIo_Tls_SetLocalTrustFile(sio, "test.crt"); rv=GWEN_SyncIo_Connect(sio); if (rv) { fprintf(stderr, "ERROR in check_io_tls1: Could not connect (%d)\n", rv); return 2; } rv=GWEN_SyncIo_WriteForced(sio, (const uint8_t*)TEST_PATTERN1, strlen(TEST_PATTERN1)); if (rv<1) { fprintf(stderr, "ERROR in check_io_tls1: Could not write (%d)\n", rv); return 2; } for (;;) { rv=GWEN_SyncIo_Read(sio, (uint8_t*)buffer, sizeof(buffer)-1); if (rv==0) break; else if (rv<1) { if (rv==GWEN_ERROR_TIMEOUT || rv==GWEN_ERROR_EOF) break; fprintf(stderr, "ERROR in check_io_tls1: Could not read (%d)\n", rv); return 2; } else { buffer[rv]=0; fprintf(stderr, "Data received: %s\n", buffer); } } rv=GWEN_SyncIo_Disconnect(sio); if (rv) { fprintf(stderr, "WARNING in check_io_tls1: Could not disconnect (%d)\n", rv); } return 0; }