summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmpeg3/libmpeg3.c2
-rw-r--r--libopie2/opieui/oimageeffect.cpp5
-rw-r--r--library/global.cpp6
-rw-r--r--noncore/apps/opie-reader/Bkmks.cpp1
-rw-r--r--noncore/apps/opie-sheet/Excel.cpp4
-rw-r--r--noncore/apps/zsafe/zsafe.cpp45
-rw-r--r--noncore/comm/keypebble/vncauth.c6
-rw-r--r--noncore/net/ftplib/ftplib.c4
-rw-r--r--noncore/todayplugins/stockticker/libstocks/csv.c106
-rw-r--r--noncore/todayplugins/stockticker/libstocks/currency.c1
-rw-r--r--noncore/todayplugins/stockticker/libstocks/lists.h1
-rw-r--r--noncore/todayplugins/stockticker/libstocks/stocks.c23
-rw-r--r--rsync/delta.c2
13 files changed, 152 insertions, 54 deletions
diff --git a/core/multimedia/opieplayer/libmpeg3/libmpeg3.c b/core/multimedia/opieplayer/libmpeg3/libmpeg3.c
index acaecf7..c8cd3e2 100644
--- a/core/multimedia/opieplayer/libmpeg3/libmpeg3.c
+++ b/core/multimedia/opieplayer/libmpeg3/libmpeg3.c
@@ -1,142 +1,142 @@
#include "libmpeg3.h"
#include "mpeg3protos.h"
#include <stdlib.h>
#include <string.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))
mpeg3_t* mpeg3_new(char *path)
{
int i;
mpeg3_t *file = (mpeg3_t*)calloc(1, sizeof(mpeg3_t));
file->cpus = 1;
file->fs = mpeg3_new_fs(path);
file->have_mmx = mpeg3_mmx_test();
file->demuxer = mpeg3_new_demuxer(file, 0, 0, -1);
return file;
}
int mpeg3_delete(mpeg3_t *file)
{
int i;
for(i = 0; i < file->total_vstreams; i++)
mpeg3_delete_vtrack(file, file->vtrack[i]);
for(i = 0; i < file->total_astreams; i++)
mpeg3_delete_atrack(file, file->atrack[i]);
mpeg3_delete_fs(file->fs);
mpeg3_delete_demuxer(file->demuxer);
free(file);
}
int mpeg3_check_sig(char *path)
{
mpeg3_fs_t *fs;
unsigned int bits;
char *ext;
int result = 0;
fs = mpeg3_new_fs(path);
if(mpeg3io_open_file(fs))
{
/* File not found */
- return 0;
+ return mpeg3_delete_fs(fs);
}
bits = mpeg3io_read_int32(fs);
/* Test header */
if(bits == MPEG3_TOC_PREFIX || bits == MPEG3_TOC_PREFIXLOWER)
{
result = 1;
}
else
if((((bits >> 24) & 0xff) == MPEG3_SYNC_BYTE) ||
(bits == MPEG3_PACK_START_CODE) ||
((bits & 0xfff00000) == 0xfff00000) ||
(bits == MPEG3_SEQUENCE_START_CODE) ||
(bits == MPEG3_PICTURE_START_CODE) ||
(((bits & 0xffff0000) >> 16) == MPEG3_AC3_START_CODE) ||
((bits >> 8) == MPEG3_ID3_PREFIX) ||
(bits == MPEG3_RIFF_CODE))
{
result = 1;
ext = strrchr(path, '.');
if(ext)
{
/* Test file extension. */
if(strncasecmp(ext, ".mp2", 4) &&
// strncasecmp(ext, ".mp3", 4) &&
strncasecmp(ext, ".m1v", 4) &&
strncasecmp(ext, ".m2v", 4) &&
strncasecmp(ext, ".m2s", 4) &&
strncasecmp(ext, ".mpg", 4) &&
strncasecmp(ext, ".vob", 4) &&
strncasecmp(ext, ".mpeg", 4) &&
strncasecmp(ext, ".ac3", 4))
result = 0;
}
}
mpeg3io_close_file(fs);
mpeg3_delete_fs(fs);
return result;
}
mpeg3_t* mpeg3_open_copy(char *path, mpeg3_t *old_file)
{
mpeg3_t *file = 0;
unsigned int bits;
int i, done;
/* Initialize the file structure */
file = mpeg3_new(path);
/* Need to perform authentication before reading a single byte. */
if(mpeg3io_open_file(file->fs))
{
mpeg3_delete(file);
return 0;
}
/* =============================== Create the title objects ========================= */
bits = mpeg3io_read_int32(file->fs);
if(bits == MPEG3_TOC_PREFIX || bits == MPEG3_TOC_PREFIXLOWER) /* TOCV */
{
/* Table of contents for another file */
if(mpeg3_read_toc(file))
{
mpeg3_delete(file);
return 0;
}
mpeg3io_close_file(file->fs);
}
else
if(((bits >> 24) & 0xff) == MPEG3_SYNC_BYTE)
{
/* Transport stream */
file->packet_size = MPEG3_TS_PACKET_SIZE;
file->is_transport_stream = 1;
}
else
if(bits == MPEG3_PACK_START_CODE)
{
/* Program stream */
file->packet_size = MPEG3_DVD_PACKET_SIZE;
file->is_program_stream = 1;
}
else
if((bits & 0xfff00000) == 0xfff00000 ||
((bits >> 8) == MPEG3_ID3_PREFIX) ||
(bits == MPEG3_RIFF_CODE))
{
/* MPEG Audio only */
file->packet_size = MPEG3_DVD_PACKET_SIZE;
file->has_audio = 1;
file->is_audio_stream = 1;
}
else
diff --git a/libopie2/opieui/oimageeffect.cpp b/libopie2/opieui/oimageeffect.cpp
index be47eb2..93719bc 100644
--- a/libopie2/opieui/oimageeffect.cpp
+++ b/libopie2/opieui/oimageeffect.cpp
@@ -1958,195 +1958,198 @@ bool OImageEffect::blendOnLower(
--i; --b;
*b += ( ((*i - *b) * a) >> 8 );
i -= 2; b -= 2;
#endif
} while (k--);
}
return true;
}
// For selected icons
QImage& OImageEffect::selectedImage( QImage &img, const QColor &col )
{
return blend( col, img, 0.5);
}
//
// ===================================================================
// Effects originally ported from ImageMagick for PixiePlus, plus a few
// new ones. (mosfet 12/29/01)
// ===================================================================
//
void OImageEffect::normalize(QImage &img)
{
int *histogram, threshold_intensity, intense;
int x, y, i;
unsigned int gray_value;
unsigned int *normalize_map;
unsigned int high, low;
// allocate histogram and normalize map
histogram = (int *)calloc(MaxRGB+1, sizeof(int));
normalize_map = (unsigned int *)malloc((MaxRGB+1)*sizeof(unsigned int));
if(!normalize_map || !histogram){
owarn << "Unable to allocate normalize histogram and map" << oendl;
free(normalize_map);
free(histogram);
return;
}
// form histogram
if(img.depth() > 8){ // DirectClass
unsigned int *data;
for(y=0; y < img.height(); ++y){
data = (unsigned int *)img.scanLine(y);
for(x=0; x < img.width(); ++x){
gray_value = intensityValue(data[x]);
histogram[gray_value]++;
}
}
}
else{ // PsudeoClass
unsigned char *data;
unsigned int *cTable = img.colorTable();
for(y=0; y < img.height(); ++y){
data = (unsigned char *)img.scanLine(y);
for(x=0; x < img.width(); ++x){
gray_value = intensityValue(*(cTable+data[x]));
histogram[gray_value]++;
}
}
}
// find histogram boundaries by locating the 1 percent levels
threshold_intensity = (img.width()*img.height())/100;
intense = 0;
for(low=0; low < MaxRGB; ++low){
intense+=histogram[low];
if(intense > threshold_intensity)
break;
}
intense=0;
for(high=MaxRGB; high != 0; --high){
intense+=histogram[high];
if(intense > threshold_intensity)
break;
}
if (low == high){
// Unreasonable contrast; use zero threshold to determine boundaries.
threshold_intensity=0;
intense=0;
for(low=0; low < MaxRGB; ++low){
intense+=histogram[low];
if(intense > threshold_intensity)
break;
}
intense=0;
for(high=MaxRGB; high != 0; --high)
{
intense+=histogram[high];
if(intense > threshold_intensity)
break;
}
- if(low == high)
+ if(low == high) {
+ free(histogram);
+ free(normalize_map);
return; // zero span bound
}
+ }
// Stretch the histogram to create the normalized image mapping.
for(i=0; i <= MaxRGB; i++){
if (i < (int) low)
normalize_map[i]=0;
else{
if(i > (int) high)
normalize_map[i]=MaxRGB;
else
normalize_map[i]=(MaxRGB-1)*(i-low)/(high-low);
}
}
// Normalize
if(img.depth() > 8){ // DirectClass
unsigned int *data;
for(y=0; y < img.height(); ++y){
data = (unsigned int *)img.scanLine(y);
for(x=0; x < img.width(); ++x){
data[x] = qRgba(normalize_map[qRed(data[x])],
normalize_map[qGreen(data[x])],
normalize_map[qBlue(data[x])],
qAlpha(data[x]));
}
}
}
else{ // PsudeoClass
int colors = img.numColors();
unsigned int *cTable = img.colorTable();
for(i=0; i < colors; ++i){
cTable[i] = qRgba(normalize_map[qRed(cTable[i])],
normalize_map[qGreen(cTable[i])],
normalize_map[qBlue(cTable[i])],
qAlpha(cTable[i]));
}
}
free(histogram);
free(normalize_map);
}
void OImageEffect::equalize(QImage &img)
{
int *histogram, *map, *equalize_map;
int x, y, i, j;
unsigned int high, low;
// allocate histogram and maps
histogram = (int *)calloc(MaxRGB+1, sizeof(int));
map = (int *)malloc((MaxRGB+1)*sizeof(unsigned int));
equalize_map = (int *)malloc((MaxRGB+1)*sizeof(unsigned int));
if(!histogram || !map || !equalize_map){
owarn << "Unable to allocate equalize histogram and maps" << oendl;
free(histogram);
free(map);
free(equalize_map);
return;
}
// form histogram
if(img.depth() > 8){ // DirectClass
unsigned int *data;
for(y=0; y < img.height(); ++y){
data = (unsigned int *)img.scanLine(y);
for(x=0; x < img.width(); ++x){
histogram[intensityValue(data[x])]++;
}
}
}
else{ // PsudeoClass
unsigned char *data;
unsigned int *cTable = img.colorTable();
for(y=0; y < img.height(); ++y){
data = (unsigned char *)img.scanLine(y);
for(x=0; x < img.width(); ++x){
histogram[intensityValue(*(cTable+data[x]))]++;
}
}
}
// integrate the histogram to get the equalization map.
j=0;
for(i=0; i <= MaxRGB; i++){
j+=histogram[i];
map[i]=j;
}
free(histogram);
if(map[MaxRGB] == 0){
free(equalize_map);
free(map);
return;
}
// equalize
low=map[0];
high=map[MaxRGB];
for(i=0; i <= MaxRGB; i++)
diff --git a/library/global.cpp b/library/global.cpp
index 7bdd0b1..1895006 100644
--- a/library/global.cpp
+++ b/library/global.cpp
@@ -447,299 +447,303 @@ void Global::hideInputMethod()
bool Global::isBuiltinCommand( const QString &name )
{
if(!builtin)
return FALSE; // yes, it can happen
for (int i = 0; builtin[i].file; i++) {
if ( builtin[i].file == name ) {
return TRUE;
}
}
return FALSE;
}
Global::Command* Global::builtin=0;
QGuardedPtr<QWidget> *Global::running=0;
/*!
\class Global::Command
\brief The Global::Command class is internal.
\internal
*/
/*!
\internal
*/
void Global::setBuiltinCommands( Command* list )
{
if ( running )
delete [] running;
builtin = list;
int count = 0;
if (!builtin)
return;
while ( builtin[count].file )
count++;
running = new QGuardedPtr<QWidget> [ count ];
}
/*!
\internal
*/
void Global::setDocument( QWidget* receiver, const QString& document )
{
Emitter emitter(receiver,document);
}
/*!
\internal
*/
bool Global::terminateBuiltin( const QString& n )
{
if (!builtin)
return FALSE;
for (int i = 0; builtin[i].file; i++) {
if ( builtin[i].file == n ) {
delete running[i];
return TRUE;
}
}
return FALSE;
}
/*!
\internal
*/
void Global::terminate( const AppLnk* app )
{
//if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this
#ifndef QT_NO_COP
QCString channel = "QPE/Application/" + app->exec().utf8();
if ( QCopChannel::isRegistered(channel) ) {
QCopEnvelope e(channel, "quit()");
}
#endif
}
/*!
Low-level function to run command \a c.
\warning Do not use this function. Use execute instead.
\sa execute()
*/
void Global::invoke(const QString &c)
{
// Convert the command line in to a list of arguments
QStringList list = QStringList::split(QRegExp(" *"),c);
#if !defined(QT_NO_COP)
QString ap=list[0];
// see if the application is already running
// XXX should lock file /tmp/qcop-msg-ap
if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) {
// If the channel is already register, the app is already running, so show it.
- { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); }
+ {
+ QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" );
+ }
//QCopEnvelope e("QPE/System", "notBusy(QString)" );
//e << ap;
return;
}
// XXX should unlock file /tmp/qcop-msg-ap
//see if it is being started
if ( StartingAppList::isStarting( ap ) ) {
// FIXME take it out for now, since it leads to a much to short showing of wait if
// some entry is clicked.
// Real cause is that ::execute is called twice for document tab. But it would need some larger changes
// to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there
// had the idea that an apploader belongs to the launcher ...
//QCopEnvelope e("QPE/System", "notBusy(QString)" );
//e << ap;
return;
}
#endif
#ifdef QT_NO_QWS_MULTIPROCESS
QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 );
#else
QStrList slist;
unsigned int j;
for ( j = 0; j < list.count(); j++ )
slist.append( list[j].utf8() );
const char **args = new const char *[slist.count() + 1];
for ( j = 0; j < slist.count(); j++ )
args[j] = slist.at(j);
+
args[j] = NULL;
#if !defined(QT_NO_COP)
// an attempt to show a wait...
// more logic should be used, but this will be fine for the moment...
QCopEnvelope ( "QPE/System", "busy()" );
#endif
#ifdef HAVE_QUICKEXEC
#ifdef Q_OS_MACX
QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".dylib";
#else
QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so";
#endif
qDebug("libfile = %s", libexe.latin1() );
if ( QFile::exists( libexe ) ) {
qDebug("calling quickexec %s", libexe.latin1() );
quickexecv( libexe.utf8().data(), (const char **)args );
} else
#endif
{
bool success = false;
int pfd [2];
if ( ::pipe ( pfd ) < 0 )
pfd [0] = pfd [1] = -1;
pid_t pid = ::fork ( );
if ( pid == 0 ) { // child
for ( int fd = 3; fd < 100; fd++ ) {
if ( fd != pfd [1] )
::close ( fd );
}
::setpgid ( ::getpid ( ), ::getppid ( ));
// Closing of fd[1] indicates that the execvp succeeded!
if ( pfd [1] >= 0 )
::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC );
// Try bindir first, so that foo/bar works too
::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args );
::execvp ( args [0], (char * const *) args );
char resultByte = 1;
if ( pfd [1] >= 0 )
::write ( pfd [1], &resultByte, 1 );
::_exit ( -1 );
}
else if ( pid > 0 ) {
success = true;
if ( pfd [1] >= 0 )
::close ( pfd [1] );
if ( pfd [0] >= 0 ) {
while ( true ) {
char resultByte;
int n = ::read ( pfd [0], &resultByte, 1 );
if ( n == 1 ) {
success = false;
break;
}
if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR )))
continue;
break; // success
}
::close ( pfd [0] );
}
}
if ( success )
StartingAppList::add( list[0] );
else
QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 );
}
+ delete [] args;
#endif //QT_NO_QWS_MULTIPROCESS
}
/*!
Executes the application identfied by \a c, passing \a
document if it isn't null.
Note that a better approach might be to send a QCop message to the
application's QPE/Application/\e{appname} channel.
*/
void Global::execute( const QString &c, const QString& document )
{
// ask the server to do the work
#if !defined(QT_NO_COP)
if ( document.isNull() ) {
QCopEnvelope e( "QPE/System", "execute(QString)" );
e << c;
} else {
QCopEnvelope e( "QPE/System", "execute(QString,QString)" );
e << c << document;
}
#endif
return;
}
/*!
Returns the string \a s with the characters '\', '"', and '$' quoted
by a preceeding '\'.
\sa stringQuote()
*/
QString Global::shellQuote(const QString& s)
{
QString r="\"";
for (int i=0; i<(int)s.length(); i++) {
char c = s[i].latin1();
switch (c) {
case '\\': case '"': case '$':
r+="\\";
}
r += s[i];
}
r += "\"";
return r;
}
/*!
Returns the string \a s with the characters '\' and '"' quoted by a
preceeding '\'.
\sa shellQuote()
*/
QString Global::stringQuote(const QString& s)
{
QString r="\"";
for (int i=0; i<(int)s.length(); i++) {
char c = s[i].latin1();
switch (c) {
case '\\': case '"':
r+="\\";
}
r += s[i];
}
r += "\"";
return r;
}
/*!
Finds all documents on the system's document directories which
match the filter \a mimefilter, and appends the resulting DocLnk
objects to \a folder.
*/
void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter)
{
QString homedocs = QString(getenv("HOME")) + "/Documents";
DocLnkSet d(homedocs,mimefilter);
folder->appendFrom(d);
/** let's do intellegint way of searching these files
* a) the user don't want to check mediums global
* b) the user wants to check but use the global options for it
* c) the user wants to check it but not this medium
* d) the user wants to check and this medium as well
*
* In all cases we need to apply a different mimefilter to
* the medium.
* a) mimefilter.isEmpty() we need to apply the responding filter
* either the global or the one on the medium
*
* b) mimefilter is set to an application we need to find out if the
* mimetypes are included in the mime mask of the medium
*/
StorageInfo storage;
const QList<FileSystem> &fs = storage.fileSystems();
QListIterator<FileSystem> it ( fs );
for ( ; it.current(); ++it ) {
diff --git a/noncore/apps/opie-reader/Bkmks.cpp b/noncore/apps/opie-reader/Bkmks.cpp
index 00141a3..45aa045 100644
--- a/noncore/apps/opie-reader/Bkmks.cpp
+++ b/noncore/apps/opie-reader/Bkmks.cpp
@@ -250,167 +250,168 @@ CList<Bkmk>* BkmkFile::readall()
{
fseek(f,0,SEEK_SET);
bl = readall00(&read05);
}
else
{
fseek(f,0,SEEK_SET);
bl = readall00(&read03);
}
isUpgraded = true;
}
else
{
switch(newmagic & 0xff)
{
case 7:
isUpgraded = false;
bl = readall00(read07);
// qDebug("Correct version!");
break;
case 6:
isUpgraded = true;
bl = readall00(read06);
// qDebug("Correct version!");
break;
case 5:
isUpgraded = true;
bl = readall00(read05);
// qDebug("Known version!");
break;
default:
// qDebug("Unknown version!");
isUpgraded = true;
bl = readall00(read05);
}
}
}
return bl;
}
CList<Bkmk>* BkmkFile::readall00(Bkmk* (*readfn)(BkmkFile*, FILE*))
{
CList<Bkmk>* bl = new CList<Bkmk>;
while (1)
{
Bkmk* b = (*readfn)(this, f);
if (b == NULL) break;
bl->push_back(*b);
delete b;
}
return bl;
}
Bkmk* BkmkFile::read03(BkmkFile* /*_this*/, FILE* f)
{
Bkmk* b = NULL;
if (f != NULL)
{
unsigned short ln;
if (fread(&ln,sizeof(ln),1,f) == 1)
{
tchar* name = new tchar[ln+1];
fread(name,sizeof(tchar),ln,f);
name[ln] = 0;
ln = 0;
tchar* anno = new tchar[ln+1];
anno[ln] = 0;
unsigned int pos;
fread(&pos,sizeof(pos),1,f);
b = new Bkmk(name,anno,pos);
delete [] anno;
}
}
return b;
}
Bkmk* BkmkFile::read05(BkmkFile* /*_this*/, FILE* f)
{
Bkmk* b = NULL;
if (f != NULL)
{
unsigned short ln;
if (fread(&ln,sizeof(ln),1,f) == 1)
{
tchar* nm = new tchar[ln+1];
fread(nm,sizeof(tchar),ln,f);
nm[ln] = 0;
fread(&ln,sizeof(ln),1,f);
tchar* anno = new tchar[ln+1];
if (ln > 0) fread(anno,sizeof(tchar),ln,f);
anno[ln] = 0;
unsigned int pos;
fread(&pos,sizeof(pos),1,f);
b = new Bkmk(nm,anno,pos);
+ delete [] anno;
}
}
return b;
}
Bkmk* BkmkFile::read06(BkmkFile* /*_this*/, FILE* f)
{
Bkmk* b = NULL;
if (f != NULL)
{
unsigned short ln;
if (fread(&ln,sizeof(ln),1,f) == 1)
{
b = new Bkmk;
b->m_namelen = ln;
b->m_name = new unsigned char[b->m_namelen];
fread(b->m_name,1,b->m_namelen,f);
fread(&(b->m_annolen),sizeof(b->m_annolen),1,f);
if (b->m_annolen > 0)
{
b->m_anno = new unsigned char[b->m_annolen];
fread(b->m_anno,1,b->m_annolen,f);
}
fread(&(b->m_position),sizeof(b->m_position),1,f);
b->m_position2 = b->m_position+b->m_namelen-1;
b->m_red = b->m_green = b->m_blue = 127;
b->m_level = 0;
}
}
return b;
}
Bkmk* BkmkFile::read07(BkmkFile* _this, FILE* f)
{
Bkmk* b = NULL;
if (f != NULL)
{
unsigned short ln;
if (fread(&ln,sizeof(ln),1,f) == 1)
{
b = new Bkmk;
b->m_namelen = ln;
b->m_name = new unsigned char[b->m_namelen];
fread(b->m_name,1,b->m_namelen,f);
fread(&(b->m_annolen),sizeof(b->m_annolen),1,f);
if (b->m_annolen > 0)
{
b->m_anno = new unsigned char[b->m_annolen];
fread(b->m_anno,1,b->m_annolen,f);
}
fread(&(b->m_position),sizeof(b->m_position),1,f);
if (_this->m_extras)
{
fread(&(b->m_position2),sizeof(b->m_position2),1,f);
fread(&(b->m_red),sizeof(b->m_red),1,f);
fread(&(b->m_green),sizeof(b->m_green),1,f);
fread(&(b->m_blue),sizeof(b->m_blue),1,f);
fread(&(b->m_level),sizeof(b->m_level),1,f);
}
else
{
b->m_position2 = b->m_position;
b->m_red = b->m_green = b->m_blue = 255;
b->m_level = 0;
}
}
}
return b;
}
diff --git a/noncore/apps/opie-sheet/Excel.cpp b/noncore/apps/opie-sheet/Excel.cpp
index 51fe707..27080e9 100644
--- a/noncore/apps/opie-sheet/Excel.cpp
+++ b/noncore/apps/opie-sheet/Excel.cpp
@@ -284,193 +284,195 @@ int ExcelBook::Get2Bytes(void)
return Integer2Byte(i1,i2);
};
char* ExcelBook::Read(int pos, int length)
{
int i;
char *data;
data= new char[length];
SeekPosition(pos);
for(i=0; i<length; i++)
{
if(!feof(File)) data[i]=fgetc(File);
};
Position= Position+length;
return data;
};
QString ExcelBook::ReadUnicodeChar(int pos, int length)
{
int i;
QString data;
int i1=' ',i2=' ',ii;
SeekPosition(pos);
for(i=0; i<length; i++)
{
if(!feof(File)) i1=fgetc(File);
if(!feof(File)) i2=fgetc(File);
ii=Integer2Byte(i1,i2);
data.append(ii);
Position+=2;
};
return data;
};
QString* ExcelBook::GetString(int num)
{
if(num>=0 && num<(int)SharedStrings.count())
{
return SharedStrings[num];
};
return new QString("");
};
int ExcelBook::SeekBOF(void)
{
int opcode,version,streamtype,length,ret=0;
char *data;
while(!feof(File))
{
opcode=Get2Bytes();
if(opcode==XL_BOF)
{
length=Get2Bytes();
data=Read(Position,length);
version=Integer2Byte(data[0], data[1]);
streamtype=Integer2Byte(data[2], data[3]);
printf("SEEKBOF:opcode=XLBOF, %d ,version %d\r\n",Position,version);
delete [] data; data=NULL;
if (version==BIFF8) ret=8;
else if(version==BIFF7) ret=7;
printf("SEEKBOF:versionBIFF%d\r\n",ret);
if(streamtype==WBKGLOBAL) return ret *2;
else if(streamtype==WRKSHEET) return ret *1;
return 1;
};
};
return 0;
};
ExcelBREC* ExcelBook::GetBREC(void)
{
ExcelBREC* rec;
rec= new ExcelBREC;
if(FileEOF()) return NULL;
rec->data=NULL;
rec->code=Get2Bytes();
rec->length=Get2Bytes();
rec->position=Position;
SeekSkip(rec->length);
return rec;
};
ExcelBREC* ExcelBook::PeekBREC(void)
{
int oldpos;
ExcelBREC* NextRec;
oldpos=Position;
NextRec=GetBREC();
SeekPosition(oldpos);
return NextRec;
};
char* ExcelBook::GetDataOfBREC(ExcelBREC* record)
{
if(record->data==NULL)
{
- ConvertCharToArray(record,Read(record->position,record->length),record->length);
+ char* readData = Read(record->position,record->length);
+ ConvertCharToArray(record,readData,record->length);
+ delete [] readData;
};
return record->data;//new?
};
void ExcelBook::ConvertCharToArray(ExcelBREC* record, char* chars, int length)
{
record->data=new char[length];
for(int w1=0;w1<=length-1;w1++)
record->data[w1]=chars[w1];
};
bool ExcelSheet::InitCells()
{
int r;
Cells.resize(rows * cols + cols+1);
if(Cells.count()==0) return false;
for(r=0;r < Cells.count();r++)
{
Cells[r]=NULL;
};
return true;
};
void ExcelSheet::Set(int row, int col, ExcelCell* cell)
{
if(cell!=NULL&&(row*cols+col)<Cells.count())
{
Cells[row*cols+col]=cell;
};
};
ExcelCell* ExcelSheet::Get(int row, int col)
{
ExcelCell* cell;
cell=Cells[row*cols+col];
if(cell==NULL) return NULL;
return cell;
};
int ExcelBook::SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record)
{
char* data=NULL;
switch (record->code)
{
case XL_DIMENSION:
data = GetDataOfBREC(record);
if (record->length == 10)
{
sheet->rows = Integer2Byte(data[2], data[3]);
sheet->cols = Integer2Byte(data[6], data[7]);
}
else
{
sheet->rows = Integer4Byte(data[4], data[5], data[6], data[7]);
sheet->cols = Integer2Byte(data[10], data[11]);
}
sheet->InitCells();
break;
case XL_LABELSST:
HandleLabelSST(sheet, record);
break;
case XL_RK:
case XL_RK2:
HandleRK(sheet, record);
break;
case XL_MULRK:
HandleMulrk(sheet, record);
break;
case XL_ROW:
break;
case XL_NUMBER:
HandleNumber(sheet, record);
break;
case XL_BOOLERR:
break;
case XL_CONTINUE:
break;
case XL_FORMULA:
case XL_FORMULA2:
HandleFormula(sheet, record);
break;
case XL_LABEL:
break;
case XL_NAME:
HandleName(sheet, record);
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp
index f70f863..9c0c6ce 100644
--- a/noncore/apps/zsafe/zsafe.cpp
+++ b/noncore/apps/zsafe/zsafe.cpp
@@ -1679,249 +1679,255 @@ bool ZSafe::openDocument(const char* _filename, const char* )
QListViewItem *catI = new ShadedListItem( 1, ListView );
// create and insert a new item
QListViewItem * item = new ShadedListItem( 0, catI );
item->setText( 0, tr( name ) );
item->setText( 1, tr( user ) );
item->setText( 2, tr( password ) );
item->setText( 3, tr( comment ) );
item->setText( 4, tr( field5 ) );
item->setText( 5, tr( field6 ) );
if (expandTree)
catI->setOpen( TRUE );
Category *c1 = new Category();
c1->setCategoryName(category);
QString icon;
QString fullIconPath;
QPixmap *pix;
// #ifndef Q_WS_WIN
icon = conf->readEntry(APP_KEY+category);
// #endif
bool isIconAv = false;
if (!icon.isEmpty() && !icon.isNull())
{
// build the full path
fullIconPath = iconPath + icon;
pix = new QPixmap (fullIconPath);
if (!pix->isNull())
{
QImage img = pix->convertToImage();
pix->convertFromImage(img.smoothScale(14,14));
c1->setIconName (icon);
c1->setIcon (*pix);
isIconAv = true;
}
}
if (!isIconAv)
{
c1->setIcon (*getPredefinedIcon(category));
}
c1->setListItem (catI);
c1->initListItem();
categories.insert (c1->getCategoryName(), c1);
numberOfEntries++;
}
for (int count = 0; count < FIELD_SIZE; count++) {
free(entry[count]);
}
retval = loadEntry(entry);
if (retval == 2) {
// m_parent->slotStatusHelpMsg("Last entry loaded");
}
} // end while
if (numberOfEntries == 0)
{
switch( QMessageBox::warning( this, tr("ZSafe"),
tr("Empty document or\nwrong password.\nContinue?"),
tr("&No"), tr("&Yes."),
0
) ) {
case 0: // No
retval = loadFinalize();
exitZs (1);
break;
case 1: // Yes
break;
}
}
retval = loadFinalize();
return true;
}
int ZSafe::loadInit(const char* _filename, const char *password)
{
unsigned int j = 0;
unsigned int keylength=0;
int count=0, count2=0, count3=0;
unsigned char charbuf[8];
unsigned short ciphertext[4];
char key[128];
Krc2* krc2 = new Krc2();
fd = fopen (_filename, "rb");
QFileInfo f (_filename);
load_buffer_length = f.size();
load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2;
- if (fd == NULL)
+ if (fd == NULL) {
+ delete krc2;
return PWERR_OPEN;
+ }
buffer = (char *)malloc(load_buffer_length);
for (j = 0; password[j] != '\0'; j++) {
key[j] = password[j];
}
keylength = j;
krc2->rc2_expandkey (key, keylength, 128);
#ifndef Q_WS_WIN
size = read(fileno (fd), (unsigned char *) (charbuf + count), 8);
#else
size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
#endif
- if (size < 8)
+ if (size < 8) {
+ delete krc2;
return PWERR_DATA;
+ }
for (count = 0; count < 4; count++) {
count2 = count << 1;
iv[count] = charbuf[count2] << 8;
iv[count] += charbuf[count2 + 1];
}
size = 0;
bufferIndex = 0;
#ifndef Q_WS_WIN
while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) {
while (count < 8) {
count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8);
#else
while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) {
while (count < 8) {
count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
#endif
if (count2 == 0) {
+ delete krc2;
return PWERR_DATA;
}
count += count2;
} /* while (count < 8) */
size += 8;
for (count2 = 0; count2 < 8; count2 += 2) {
count3 = count2 >> 1;
ciphertext[count3] = charbuf[count2] << 8;
ciphertext[count3] += charbuf[count2 + 1];
plaintext[count3] = ciphertext[count3] ^ iv[count3];
iv[count3] = plaintext[count3];
} /* for (count2) */
krc2->rc2_decrypt (plaintext);
memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8);
bufferIndex += 8;
buffer[bufferIndex + 1] = '\0';
} /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */
+ delete krc2;
size -= buffer[size - 1];
lastcount = 0;
/* This will point to the starting index */
bufferIndex = 0;
return PWERR_GOOD;
}
int ZSafe::loadEntry(char *entry[FIELD_SIZE])
{
/* Strip off PKCS 5 padding
* Should check to make sure it's good here
*/
int count, count1=0;
for (count = lastcount; count < size; count++) {
if ((unsigned char) (buffer[count]) == 255) {
if (buffer[bufferIndex] == '\0') {
bufferIndex++;
}
entry[count1] = (char *) malloc (count - bufferIndex + 1);
memcpy (entry[count1], (unsigned char *) (buffer + bufferIndex), count - bufferIndex);
entry[count1][count - bufferIndex] = '\0';
count++;
bufferIndex = count;
count1++;
if (count1 == FIELD_SIZE) {
lastcount = count;
return 1;
}
} /* if ((unsigned char) (buffer[count]) == 255) */
} /* for (count = 0; count < size; count++) */
return 2;
}
int ZSafe::loadFinalize(void)
{
fclose (fd);
if (buffer) free(buffer);
return PWERR_GOOD;
}
bool ZSafe::saveDocument(const char* _filename,
bool withPwd,
const char* )
{
if (filename.isEmpty())
{
QMessageBox::critical( 0, tr("ZSafe"),
tr("No document defined.\nYou have to create a new document"));
return false;
}
// if (m_password.isEmpty())
// withPwd = true; // the document must be saved with a valid password
if (withPwd)
{
bool pwdOk = FALSE;
while (!pwdOk)
{
getDocPassword(tr("Enter Password"));
if (m_password.isEmpty())
{
QMessageBox::critical( 0, tr("ZSafe"),
tr("Password is empty.\nPlease enter again."));
continue;
}
QString firstPasswd = m_password;
getDocPassword(tr("Reenter Password"));
if (m_password.isEmpty())
{
QMessageBox::critical( 0, tr("ZSafe"),
tr("Password is empty.\nPlease enter again."));
continue;
}
if (firstPasswd != m_password)
{
QMessageBox::critical( 0, tr("ZSafe"),
tr("Passwords must be identical.\nPlease enter again."));
continue;
}
pwdOk = TRUE;
modified = false;
}
}
else if (modified)
{
QString fns(_filename);
fns = fns.right (fns.length() - fns.findRev ('/') - 1);
switch( QMessageBox::information( this, tr("ZSafe"),
tr("Do you want to save ") + fns + tr("\nbefore continuing?"),
@@ -2006,321 +2012,316 @@ bool ZSafe::saveDocument(const char* _filename,
strcpy(entry[j++], si->text(0).utf8());
entry[j] = (char*)malloc(strlen(si->text(1).utf8())+1);
strcpy(entry[j++], si->text(1).utf8());
entry[j] = (char*)malloc(strlen(si->text(2).utf8())+1);
strcpy(entry[j++], si->text(2).utf8());
entry[j] = (char*)malloc(strlen(si->text(3).utf8())+1);
strcpy(entry[j++], si->text(3).utf8());
entry[j] = (char*)malloc(strlen(si->text(4).utf8())+1);
strcpy(entry[j++], si->text(4).utf8());
entry[j] = (char*)malloc(strlen(si->text(5).utf8())+1);
strcpy(entry[j++], si->text(5).utf8());
retval = saveEntry(entry);
for (int z=0; z<j; z++)
{
free(entry[z]);
}
if (retval == PWERR_DATA) {
#ifndef NO_OPIE
owarn << "1: Error writing file, contents not saved" << oendl;
#else
qWarning("1: Error writing file, contents not saved");
#endif
saveFinalize();
return false;
}
}
}
if (saveFinalize() == PWERR_DATA) {
#ifndef NO_OPIE
owarn << "2: Error writing file, contents not saved" << oendl;
#else
qWarning("2: Error writing file, contents not saved");
#endif
return false;
} else {
#ifndef DESKTOP
Global::statusMessage (tr("Password file saved."));
#endif
modified = false;
return true;
}
}
PasswordForm *newPwdDialog;
bool newPwdDialogResult = false;
void ZSafe::setPasswordDialogDone()
{
newPwdDialogResult = true;
newPwdDialog->close();
}
void ZSafe::getDocPassword(QString title)
{
// open the 'Password' dialog
PasswordForm *dialog = new PasswordForm(this, title, TRUE);
newPwdDialog = dialog;
newPwdDialogResult = false;
// QPixmap image0 = Opie::Core::OResource::loadPixmap( "zsafe/zsafe", Opie::Core::OResource::SmallIcon );
// dialog->setIcon( image0);
connect( dialog->PasswordField, SIGNAL( returnPressed() ),
this, SLOT( setPasswordDialogDone() ) );
// CS: !!!
// int pos = filename.findRev ('/');
QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
dialog->setCaption(ti);
// dialog->setCaption(title);
dialog->PasswordField->setFocus();
QDialog::DialogCode result = (QDialog::DialogCode) dialog->exec();
QString password;
if (result == QDialog::Accepted || newPwdDialogResult)
{
m_password = dialog->PasswordField->text();
}
else
{
exitZs (1);
}
}
int ZSafe::saveInit(const char *_filename, const char *password)
{
char key[128];
unsigned int j = 0;
unsigned int keylength;
// int val;
int count2;
Krc2* krc2 = new Krc2();
- /* first we should check the permissions of the filename */
-/*
- if (QFile::exists(_filename)) {
- val = checkFile(_filename);
- if (val != PWERR_GOOD)
- return val;
- } else
- {
- val = creat (_filename, (S_IRUSR | S_IWUSR));
- if (val == -1)
- return PWERR_OPEN;
- else
- close(val);
- }
-*/
QFileInfo f (_filename);
save_buffer_length = f.size();
save_buffer_length = ((save_buffer_length / 1024)+1) * 1024;
fd = fopen (_filename, "wb");
- if (fd == NULL)
+ if (fd == NULL) {
+ delete krc2;
return PWERR_OPEN;
+ }
buffer = (char*)malloc(save_buffer_length);
/* make the key ready */
for (j = 0; password[j] != '\0'; j++) {
key[j] = password[j];
}
keylength = j;
krc2->rc2_expandkey (key, keylength, 128);
+ delete krc2;
/* First, we make the IV */
for (count2 = 0; count2 < 4; count2++) {
iv[count2] = rand ();
putc ((unsigned char) (iv[count2] >> 8), fd);
putc ((unsigned char) (iv[count2] & 0xff), fd);
}
bufferIndex = 0;
return PWERR_GOOD;
}
int ZSafe::saveEntry(char *entry[FIELD_SIZE])
{
char *text1;
int count2, count3;
unsigned short ciphertext[4];
Krc2* krc2 = new Krc2();
buffer = (char*)memset(buffer, '\0', save_buffer_length);
for (count2 = 0; count2 < FIELD_SIZE; count2++) {
text1 = entry[count2];
if (strlen (text1) == 0) {
strncat(buffer, " ", strlen(" "));
} else {
strncat(buffer, text1, strlen(text1));
}
/* Use 255 as the marker. \n is too tough to test for */
buffer[strlen (buffer)] = 255;
} /*for (count2 = 0; count2 < 5; count2++)*/
count2 = 0;
/* I'm using CBC mode and encrypting the data straight from top down.
* At the bottom, encrypted, I will append an MD5 hash of the file, eventually.
* PKCS 5 padding (explained at the code section
*/
while (count2 < (int)strlen (buffer)) {
#ifndef WORDS_BIGENDIAN
plaintext[bufferIndex] = buffer[count2 + 1] << 8;
plaintext[bufferIndex] += buffer[count2] & 0xff;
#endif
#ifdef WORDS_BIGENDIAN
plaintext[bufferIndex] = buffer[count2] << 8;
plaintext[bufferIndex] += buffer[count2 + 1] & 0xff;
#endif
bufferIndex++;
if (bufferIndex == 4) {
krc2->rc2_encrypt (plaintext);
for (count3 = 0; count3 < 4; count3++) {
ciphertext[count3] = iv[count3] ^ plaintext[count3];
/* Now store the ciphertext as the iv */
iv[count3] = plaintext[count3];
/* reset the buffer index */
bufferIndex = 0;
- if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA;
- if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA;
+ if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) {
+ delete krc2;
+ return PWERR_DATA;
+ }
+ if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) {
+ delete krc2;
+ return PWERR_DATA;
+ }
} /*for (count3 = 0; count3 < 5; count3++)*/
} /*if (bufferIndex == 5)*/
/* increment a short, not a byte */
count2 += 2;
} /*while (count2 < strlen (buffer))*/
- int ret = PWERR_GOOD;
- return ret;
+ delete krc2;
+ return PWERR_GOOD;
}
int ZSafe::saveFinalize(void)
{
int count1, retval = PWERR_GOOD;
unsigned short ciphertext[4];
Krc2* krc2 = new Krc2();
/* Tack on the PKCS 5 padding
* How it works is we fill up the last n bytes with the value n
*
* So, if we have, say, 13 bytes, 8 of which are used, we have 5 left
* over, leaving us 3 short, so we fill it in with 3's.
*
* If we come out even, we fill it with 8 8s
*
* um, except that in this instance we are using 4 shorts instead of 8 bytes.
* so, half everything
*/
for (count1 = bufferIndex; count1 < 4; count1++) {
plaintext[count1] = (4 - bufferIndex);
}
krc2->rc2_encrypt (plaintext);
for (count1 = 0; count1 < 4; count1++) {
ciphertext[count1] = iv[count1] ^ plaintext[count1];
if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA;
if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA;
}
fclose (fd);
free(buffer);
+ delete krc2;
return retval;
}
void ZSafe::quitMe ()
{
if (modified)
{
switch( QMessageBox::information( this, tr("ZSafe"),
tr("Do you want to save\nbefore exiting?"),
tr("&Save"),
tr("S&ave with\nnew\npassword"),
tr("&Don't Save"),
0 // Enter == button 0
) )
{ // Escape == button 2
case 0: // Save clicked, Alt-S or Enter pressed.
// save
modified = false;
saveDocument(filename, FALSE);
exitZs (1);
break;
case 1: //
// Save with new password
modified = false;
saveDocument(filename, TRUE);
exitZs (1);
break;
case 2: // Don't Save clicked or Alt-D pressed
// don't save but exitZs
exitZs (1);
break;
}
}
exitZs (1);
}
void ZSafe::categoryFieldActivated( const QString& category)
{
if (categoryDialog)
setCategoryDialogFields(categoryDialog, category);
}
void ZSafe::addCategory()
{
if (filename.isEmpty())
{
QMessageBox::critical( 0, tr("ZSafe"),
tr("No document defined.\nYou have to create a new document"));
return;
}
else
{
// open the 'Category' dialog
bool initIcons = false;
// open the 'Category' dialog
CategoryDialog *dialog;
if (categoryDialog)
{
dialog = categoryDialog;
}
else
{
categoryDialog = new CategoryDialog(this, tr("Category"), TRUE);
dialog = categoryDialog;
connect( dialog->CategoryField,
SIGNAL( activated(const QString&)),
this, SLOT( categoryFieldActivated(const QString&) ) );
initIcons = true;
}
// read all categories from the config file and store
// into a list
QFile f (cfgFile);
QStringList list;
if ( f.open(IO_ReadOnly) ) { // file opened successfully
QTextStream t( &f ); // use a text stream
QString s;
while ( !t.eof() ) { // until end of file...
s = t.readLine(); // line of text excluding '\n'
list.append(s);
}
f.close();
}
QStringList::Iterator it = list.begin();
QString categ;
QString firstCategory;
dialog->CategoryField->clear(); // remove all items
while( it != list.end() )
{
QString *cat = new QString (*it);
if (cat->contains("-field1", FALSE))
{
int pos = cat->find ("-field1");
cat->truncate(pos);
categ = *cat;
diff --git a/noncore/comm/keypebble/vncauth.c b/noncore/comm/keypebble/vncauth.c
index 277d145..7de837a 100644
--- a/noncore/comm/keypebble/vncauth.c
+++ b/noncore/comm/keypebble/vncauth.c
@@ -1,160 +1,164 @@
/*
* Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
/*
* vncauth.c - Functions for VNC password management and authentication.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include "vncauth.h"
#include "d3des.h"
/*
* We use a fixed key to store passwords, since we assume that our local
* file system is secure but nonetheless don't want to store passwords
* as plaintext.
*/
unsigned char fixedkey[8] = {23,82,107,6,35,78,88,7};
/*
* Encrypt a password and store it in a file. Returns 0 if successful,
* 1 if the file could not be written.
*/
int
vncEncryptAndStorePasswd(char *passwd, char *fname)
{
FILE *fp;
uint i;
unsigned char encryptedPasswd[8];
if ((fp = fopen(fname,"w")) == NULL) return 1;
chmod(fname, S_IRUSR|S_IWUSR);
/* pad password with nulls */
for (i = 0; i < 8; i++) {
if (i < strlen(passwd)) {
encryptedPasswd[i] = passwd[i];
} else {
encryptedPasswd[i] = 0;
}
}
/* Do encryption in-place - this way we overwrite our copy of the plaintext
password */
deskey(fixedkey, EN0);
des(encryptedPasswd, encryptedPasswd);
for (i = 0; i < 8; i++) {
putc(encryptedPasswd[i], fp);
}
fclose(fp);
return 0;
}
/*
* Decrypt a password from a file. Returns a pointer to a newly allocated
* string containing the password or a null pointer if the password could
* not be retrieved for some reason.
*/
char *
vncDecryptPasswdFromFile(char *fname)
{
FILE *fp;
int i, ch;
unsigned char *passwd = (unsigned char *)malloc(9);
- if ((fp = fopen(fname,"r")) == NULL) return NULL;
+ if ((fp = fopen(fname,"r")) == NULL) {
+ free(passwd);
+ return NULL;
+ }
for (i = 0; i < 8; i++) {
ch = getc(fp);
if (ch == EOF) {
fclose(fp);
+ free(passwd);
return NULL;
}
passwd[i] = ch;
}
deskey(fixedkey, DE1);
des(passwd, passwd);
passwd[8] = 0;
return (char *)passwd;
}
/*
* Generate CHALLENGESIZE random bytes for use in challenge-response
* authentication.
*/
void
vncRandomBytes(unsigned char *bytes)
{
int i;
unsigned int seed = (unsigned int) time(0);
srandom(seed);
for (i = 0; i < CHALLENGESIZE; i++) {
bytes[i] = (unsigned char)(random() & 255);
}
}
/*
* Encrypt CHALLENGESIZE bytes in memory using a password.
*/
void
vncEncryptBytes(unsigned char *bytes, char *passwd)
{
unsigned char key[8];
int i;
/* key is simply password padded with nulls */
for (i = 0; i < 8; i++) {
if (i < strlen(passwd)) {
key[i] = passwd[i];
} else {
key[i] = 0;
}
}
deskey(key, EN0);
for (i = 0; i < CHALLENGESIZE; i += 8) {
des(bytes+i, bytes+i);
}
}
diff --git a/noncore/net/ftplib/ftplib.c b/noncore/net/ftplib/ftplib.c
index efcd6f0..addf9d2 100644
--- a/noncore/net/ftplib/ftplib.c
+++ b/noncore/net/ftplib/ftplib.c
@@ -1079,193 +1079,197 @@ GLOBALDEF int FtpMkdir(const char *path, netbuf *nControl)
*/
GLOBALDEF int FtpChdir(const char *path, netbuf *nControl)
{
char buf[256];
if ((strlen(path) + 6) > sizeof(buf))
return 0;
sprintf(buf,"CWD %s",path);
if (!FtpSendCmd(buf,'2',nControl))
return 0;
return 1;
}
/*
* FtpCDUp - move to parent directory at remote
*
* return 1 if successful, 0 otherwise
*/
GLOBALDEF int FtpCDUp(netbuf *nControl)
{
if (!FtpSendCmd("CDUP",'2',nControl))
return 0;
return 1;
}
/*
* FtpRmdir - remove directory at remote
*
* return 1 if successful, 0 otherwise
*/
GLOBALDEF int FtpRmdir(const char *path, netbuf *nControl)
{
char buf[256];
if ((strlen(path) + 6) > sizeof(buf))
return 0;
sprintf(buf,"RMD %s",path);
if (!FtpSendCmd(buf,'2',nControl))
return 0;
return 1;
}
/*
* FtpPwd - get working directory at remote
*
* return 1 if successful, 0 otherwise
*/
GLOBALDEF int FtpPwd(char *path, int max, netbuf *nControl)
{
int l = max;
char *b = path;
char *s;
if (!FtpSendCmd("PWD",'2',nControl))
return 0;
s = strchr(nControl->response, '"');
if (s == NULL)
return 0;
s++;
while ((--l) && (*s) && (*s != '"'))
*b++ = *s++;
*b++ = '\0';
return 1;
}
/*
* FtpXfer - issue a command and transfer data
*
* return 1 if successful, 0 otherwise
*/
static int FtpXfer(const char *localfile, const char *path,
netbuf *nControl, int typ, int mode)
{
int l,c;
char *dbuf;
FILE *local = NULL;
netbuf *nData;
int rv=1;
if (localfile != NULL)
{
char ac[4] = "w";
if (typ == FTPLIB_FILE_WRITE)
ac[0] = 'r';
if (mode == FTPLIB_IMAGE)
ac[1] = 'b';
local = fopen(localfile, ac);
if (local == NULL)
{
strncpy(nControl->response, strerror(errno),
sizeof(nControl->response));
return 0;
}
}
if (local == NULL)
local = (typ == FTPLIB_FILE_WRITE) ? stdin : stdout;
if (!FtpAccess(path, typ, mode, nControl, &nData))
+ {
+ if (localfile != NULL)
+ fclose(local);
return 0;
+ }
dbuf = malloc(FTPLIB_BUFSIZ);
if (typ == FTPLIB_FILE_WRITE)
{
while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0)
if ((c = FtpWrite(dbuf, l, nData)) < l)
{
printf("short write: passed %d, wrote %d\n", l, c);
rv = 0;
break;
}
}
else
{
while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0)
if (fwrite(dbuf, 1, l, local) <= 0)
{
perror("localfile write");
rv = 0;
break;
}
}
free(dbuf);
fflush(local);
if (localfile != NULL)
fclose(local);
FtpClose(nData);
return rv;
}
/*
* FtpNlst - issue an NLST command and write response to output
*
* return 1 if successful, 0 otherwise
*/
GLOBALDEF int FtpNlst(const char *outputfile, const char *path,
netbuf *nControl)
{
return FtpXfer(outputfile, path, nControl, FTPLIB_DIR, FTPLIB_ASCII);
}
/*
* FtpDir - issue a LIST command and write response to output
*
* return 1 if successful, 0 otherwise
*/
GLOBALDEF int FtpDir(const char *outputfile, const char *path, netbuf *nControl)
{
return FtpXfer(outputfile, path, nControl, FTPLIB_DIR_VERBOSE, FTPLIB_ASCII);
}
/*
* FtpSize - determine the size of a remote file
*
* return 1 if successful, 0 otherwise
*/
GLOBALDEF int FtpSize(const char *path, int *size, char mode, netbuf *nControl)
{
char cmd[256];
int resp,sz,rv=1;
if ((strlen(path) + 7) > sizeof(cmd))
return 0;
sprintf(cmd, "TYPE %c", mode);
if (!FtpSendCmd(cmd, '2', nControl))
return 0;
sprintf(cmd,"SIZE %s",path);
if (!FtpSendCmd(cmd,'2',nControl))
rv = 0;
else
{
if (sscanf(nControl->response, "%d %d", &resp, &sz) == 2)
*size = sz;
else
rv = 0;
}
return rv;
}
/*
* FtpModDate - determine the modification date of a remote file
*
* return 1 if successful, 0 otherwise
*/
GLOBALDEF int FtpModDate(const char *path, char *dt, int max, netbuf *nControl)
{
char buf[256];
int rv = 1;
if ((strlen(path) + 7) > sizeof(buf))
return 0;
sprintf(buf,"MDTM %s",path);
if (!FtpSendCmd(buf,'2',nControl))
rv = 0;
else
strncpy(dt, &nControl->response[4], max);
return rv;
diff --git a/noncore/todayplugins/stockticker/libstocks/csv.c b/noncore/todayplugins/stockticker/libstocks/csv.c
index 86d8607..110df7c 100644
--- a/noncore/todayplugins/stockticker/libstocks/csv.c
+++ b/noncore/todayplugins/stockticker/libstocks/csv.c
@@ -48,359 +48,433 @@ const char *months[12]=
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
};
/*****************************************************************************/
/* Replacement of the strtok function. This one forgets "delim" when it is */
/* between two commas. */
/* Thanks to Julio Lucas who has told me the bug and has proposed me a patch */
/*****************************************************************************/
char *csv_strtok(char *s, char *delim)
{
static char *next=NULL;
char *temp, *first;
int comma=0;
if (s!=NULL) first=s;
else first=next;
temp=first;
if (*temp=='\0') return NULL;
while (*temp!='\0' && ((*temp!=*delim) || comma))
{
if (*temp=='"') comma ^= 1;
temp++;
}
if (*temp=='\0') next=temp;
else
{
*temp='\0';
next=temp+1;
}
return first;
}
/*****************************************************************************/
/* Parses the csv file and return a list of stocks structure. */
/* *csv points on the csv file in memory */
/* count defines the country, because csv depends on the country */
/*****************************************************************************/
stock *parse_csv_file(char *csv)
{
char *line;
char *end_line;
char *ptr;
char *date;
char *time;
char *name;
char *symbol;
stock *StockPtr=NULL;
stock *LastStockPtr=NULL;
/* Used to return the pointer to the list */
stock *FirstStockPtr=NULL;
/* used to see if symbol is valid */
int valid;
char *test;
line = csv;
end_line = csv;
while ((end_line = strstr(line, "\n")))
{
*end_line = 0;
/* Check if symbol valid */
/* if 1 "N/A" then ok because Indices have N/A for volume */
/* if 4 "N/A" then ok because Mutual funds have */
/* if 5 "N/A" then ok because currencies have */
/* So if >5 then stock not valid */
test = line;
valid = 0;
while ( (test = strstr(test, "N/A")) )
{
valid ++;
test = test +3;
}
if (valid < 6)
{
/* This Symbol is valid */
StockPtr = malloc_stock();
ptr = csv_strtok(line, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
symbol = (char *)malloc(strlen(ptr)+1);
if (symbol==NULL)
{
fprintf(stderr,"Memory allocating error (%s line %d)\n"
,__FILE__, __LINE__);
exit(1);
}
strcpy((char *)(symbol), ptr);
StockPtr->Symbol = symbol;
ptr = csv_strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
name = (char *)malloc(strlen(ptr)+1);
if (name==NULL)
{
fprintf(stderr,"Memory allocating error (%s line %d)\n"
,__FILE__, __LINE__);
exit(1);
}
strcpy((char *)(name), ptr);
StockPtr->Name = name;
ptr = csv_strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
sscanf(ptr,"%f",&(StockPtr->CurrentPrice));
ptr = csv_strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
date = (char *)malloc(strlen(ptr)+1);
if (date==NULL)
{
fprintf(stderr,"Memory allocating error (%s line %d)\n"
,__FILE__, __LINE__);
exit(1);
}
strcpy((char *)(date), ptr);
StockPtr->Date = date;
ptr = csv_strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
time = (char *)malloc(strlen(ptr)+1);
if (time==NULL)
{
fprintf(stderr,"Memory allocating error (%s line %d)\n"
,__FILE__, __LINE__);
exit(1);
}
strcpy((char *)(time), ptr);
StockPtr->Time = time;
ptr = csv_strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
sscanf(ptr,"%f",&(StockPtr->Variation));
StockPtr->Pourcentage = 100 * StockPtr->Variation /
(StockPtr->CurrentPrice - StockPtr->Variation);
StockPtr->LastPrice = StockPtr->CurrentPrice - StockPtr->Variation;
ptr = csv_strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
sscanf(ptr,"%f",&(StockPtr->OpenPrice));
ptr = csv_strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
sscanf(ptr,"%f",&(StockPtr->MaxPrice));
ptr = csv_strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
sscanf(ptr,"%f",&(StockPtr->MinPrice));
ptr = csv_strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
StockPtr->Volume = atoi(ptr);
if( !FirstStockPtr )
{
FirstStockPtr = StockPtr;
StockPtr->PreviousStock = 0;
}
StockPtr->NextStock = 0;
if (LastStockPtr)
{
LastStockPtr->NextStock = StockPtr;
StockPtr->PreviousStock = LastStockPtr;
}
LastStockPtr = StockPtr;
}
else
{
/* this symbol is not valid */
/* Set the stock struct just with Symbol, all other are NULL */
/* This can be used to see if the symbol has been reached are not */
StockPtr = malloc_stock();
ptr = csv_strtok(line, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
symbol = (char *)malloc(strlen(ptr)+1);
if (symbol==NULL)
{
fprintf(stderr,"Memory allocating error (%s line %d)\n"
,__FILE__, __LINE__);
exit(1);
}
strcpy((char *)(symbol), ptr);
StockPtr->Symbol = symbol;
if( !FirstStockPtr )
{
FirstStockPtr = StockPtr;
StockPtr->PreviousStock = 0;
}
StockPtr->NextStock = 0;
if (LastStockPtr)
{
LastStockPtr->NextStock = StockPtr;
StockPtr->PreviousStock = LastStockPtr;
}
LastStockPtr = StockPtr;
}
end_line++;
line = end_line;
}
return (FirstStockPtr);
}
/*****************************************************************************/
/* Parses the history quotes file and return a stock structure list. */
/*****************************************************************************/
stock *parse_csv_history_file(char *csv_file)
{
char *line;
char *end_line;
char *ptr;
int day;
char smonth[10];
int month;
int year;
char *date;
int i;
int test;
stock *StockPtr=NULL;
stock *LastStockPtr=NULL;
/* Used to return the pointer to the list */
stock *FirstStockPtr=NULL;
line = csv_file;
end_line = csv_file;
/* do not use the first line */
if (!(end_line = strstr(line, "\n")))
return 0;
*end_line = 0;
end_line++;
line = end_line;
while ((end_line = strstr(line, "\n")))
{
*end_line = 0;
StockPtr = malloc_stock();
/* Date */
ptr = strtok(line, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ free_stock(FirstStockPtr);
+ free_stock(LastStockPtr);
+ return 0;
+ }
sscanf(ptr,"%d-%3s-%d",&day,smonth,&year);
i=0;
#ifdef __UNIX__
while((test=strcasecmp(months[i], smonth))) i++;
#elif __WINDOWS__
while(test=_mbsnbicmp(months[i], smonth, strlen(months[i]))) i++;
#endif
month = i+1;
date = (char *)malloc(DATE_LENGTH);
if (date==NULL)
{
fprintf(stderr,"Memory allocating error (%s line %d)\n"
,__FILE__, __LINE__);
exit(1);
}
sprintf(date,"%.2d%.2d%.2d", year, month, day);
StockPtr->Date = date;
/* Open */
ptr = strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ free_stock(FirstStockPtr);
+ free_stock(LastStockPtr);
+ return 0;
+ }
sscanf(ptr,"%f",&(StockPtr->OpenPrice));
/* High */
ptr = strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ free_stock(FirstStockPtr);
+ free_stock(LastStockPtr);
+ return 0;
+ }
sscanf(ptr,"%f",&(StockPtr->MaxPrice));
/* Low */
ptr = strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ free_stock(FirstStockPtr);
+ free_stock(LastStockPtr);
+ return 0;
+ }
sscanf(ptr,"%f",&(StockPtr->MinPrice));
/* Close */
ptr = strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ free_stock(FirstStockPtr);
+ free_stock(LastStockPtr);
+ return 0;
+ }
sscanf(ptr,"%f",&(StockPtr->LastPrice));
/* Volume */
ptr = strtok(NULL, ",");
if (!ptr)
/* It seems to be an indice */
/* No volume for indices */
StockPtr->Volume = 0;
else
StockPtr->Volume = atoi(ptr);
if( !FirstStockPtr )
{
FirstStockPtr = StockPtr;
StockPtr->PreviousStock = 0;
}
StockPtr->NextStock = 0;
if (LastStockPtr)
{
LastStockPtr->NextStock = StockPtr;
StockPtr->PreviousStock = LastStockPtr;
}
LastStockPtr = StockPtr;
end_line++;
line = end_line;
}
return (FirstStockPtr);
}
diff --git a/noncore/todayplugins/stockticker/libstocks/currency.c b/noncore/todayplugins/stockticker/libstocks/currency.c
index 9a08a9d..e0090e2 100644
--- a/noncore/todayplugins/stockticker/libstocks/currency.c
+++ b/noncore/todayplugins/stockticker/libstocks/currency.c
@@ -1,66 +1,67 @@
/* libstocks - Library to get current stock quotes from Yahoo Finance
*
* Copyright (C) 2000 Eric Laeuffer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#define __CURRENCY_C__
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <stdlib.h>
#include "stocks.h"
/*****************************************************************************/
/* returns the currency exchange rate of "from" currency into */
/* "into" currency. */
/*****************************************************************************/
libstocks_return_code get_currency_exchange(char *from,
char *into,
float *exchange)
{
char *symbol;
stock *data;
libstocks_return_code error;
if((symbol = (char *)malloc(strlen(from)+strlen(into)+3))==NULL)
{
fprintf(stderr,"Memory allocating error (%s line %d)\n"
,__FILE__, __LINE__);
exit(1);
}
strcpy(symbol, from);
strcat(symbol, into);
strcat(symbol, "=X");
error = get_stocks(symbol, &data);
+ free(symbol);
if (error)
{
*exchange = 0;
return(error);
}
free_stocks(data);
*exchange = data->CurrentPrice;
return(error);
}
diff --git a/noncore/todayplugins/stockticker/libstocks/lists.h b/noncore/todayplugins/stockticker/libstocks/lists.h
index 0132317..a0eb434 100644
--- a/noncore/todayplugins/stockticker/libstocks/lists.h
+++ b/noncore/todayplugins/stockticker/libstocks/lists.h
@@ -1,35 +1,36 @@
/* libstocks - Library to get current stock quotes from Yahoo Finance
*
* Copyright (C) 2000 Eric Laeuffer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __LISTS_H__
#define __LISTS_H__
#ifndef __LISTS_C__
#define PUBEXT_LISTS extern
#else
#define PUBEXT_LISTS
#endif
#include "stocks.h"
PUBEXT_LISTS stock *malloc_stock(void);
+PUBEXT_LISTS void free_stock(stock*);
#endif /* __LISTS_H */
diff --git a/noncore/todayplugins/stockticker/libstocks/stocks.c b/noncore/todayplugins/stockticker/libstocks/stocks.c
index eb04ba9..3a26a47 100644
--- a/noncore/todayplugins/stockticker/libstocks/stocks.c
+++ b/noncore/todayplugins/stockticker/libstocks/stocks.c
@@ -144,204 +144,205 @@ libstocks_return_code download_stocks(char *stocks,
break;
default:
stocks_server = (char *)yahoo_us_stocks_server;
break;
}
url_beg = (char *)yahoo_url_beg;
url_end = (char *)yahoo_url_end;
url = (char *)malloc(strlen(url_beg)
+strlen(url_end)
+strlen(stocks)+1);
if (url==NULL)
{
fprintf(stderr,"Memory allocating error (%s line %d)\n"
,__FILE__, __LINE__);
exit(1);
}
strcpy(url, url_beg);
strcat(url, stocks);
strcat(url, url_end);
error=http_get(url, stocks_server, &data);
free(url);
if (error) return error;
*stock_datas = parse_csv_file(data);
free(data);
if (!(*stock_datas)) return ERRPCSV;
return 0;
}
/*****************************************************************************/
/* Gets quotes from yahoo */
/* Choses to fetch European or US depending on the symbol extension */
/* and merges the two lists to one */
/* *stocks points to the stocks to fetch */
/* *stock_datas points to the beginning of the list */
/*****************************************************************************/
libstocks_return_code get_stocks(const char *stocks, stock **stock_datas)
{
char *tok_ptr;
char *eu_quotes=NULL;
char *eu_quotes_temp=NULL;
int lgr_eu_quotes=0;
char *us_quotes=NULL;
char *us_quotes_temp=NULL;
int lgr_us_quotes=0;
char *symbol;
yahoo_source source;
int lgr_symbol=0;
libstocks_return_code error;
stock *stocks_tmp=NULL;
stock *stocks_tmp2=NULL;
stock *stocks_getted=NULL;
stock *last_stock=NULL;
#ifdef DEBUG
printf("*get_stocks\n");
#endif
/* to preserve stocks */
tok_ptr = malloc(strlen(stocks)+1);
if(tok_ptr==NULL)
{
fprintf(stderr,"Memory allocating error (%s line %d)\n"
,__FILE__, __LINE__);
exit(1);
}
strcpy(tok_ptr, stocks);
while( (symbol = strtok(tok_ptr, "+"))!=0)
{
/* clear tok_ptr for next strtok */
tok_ptr = NULL;
/* look for "." in the symbol */
source = find_yahoo_source(symbol);
switch (source)
{
case YAHOO_US:
-
if (us_quotes)
{
lgr_us_quotes = strlen(us_quotes);
lgr_symbol = strlen(symbol);
us_quotes_temp = malloc(lgr_us_quotes + lgr_symbol +2);
if(us_quotes_temp==NULL)
{
- fprintf(stderr,"Memory allocating error (%s line %d)\n"
- ,__FILE__, __LINE__);
+ fprintf(stderr,"Memory allocating error (%s line %d)\n",
+ __FILE__, __LINE__);
exit(1);
}
strcpy(us_quotes_temp, us_quotes);
strcat(us_quotes_temp,"+");
strcat(us_quotes_temp,symbol);
free(us_quotes);
us_quotes = us_quotes_temp;
}
else
{
us_quotes = malloc(strlen(symbol)+1);
if(us_quotes==NULL)
{
- fprintf(stderr,"Memory allocating error (%s line %d)\n"
- ,__FILE__, __LINE__);
+ fprintf(stderr,"Memory allocating error (%s line %d)\n",
+ __FILE__, __LINE__);
exit(1);
}
strcpy(us_quotes, symbol);
}
break;
case YAHOO_EUROPE:
-
if (eu_quotes)
{
lgr_eu_quotes = strlen(eu_quotes);
lgr_symbol = strlen(symbol);
eu_quotes_temp = malloc(lgr_eu_quotes + lgr_symbol +2);
if(eu_quotes_temp==NULL)
{
- fprintf(stderr,"Memory allocating error (%s line %d)\n"
- ,__FILE__, __LINE__);
+ fprintf(stderr,"Memory allocating error (%s line %d)\n",
+ __FILE__, __LINE__);
exit(1);
}
strcpy(eu_quotes_temp, eu_quotes);
strcat(eu_quotes_temp, "+");
strcat(eu_quotes_temp, symbol);
free(eu_quotes);
eu_quotes = eu_quotes_temp;
}
else
{
eu_quotes = malloc(strlen(symbol)+1);
if(eu_quotes==NULL)
{
- fprintf(stderr,"Memory allocating error (%s line %d)\n"
- ,__FILE__, __LINE__);
+ fprintf(stderr,"Memory allocating error (%s line %d)\n",
+ __FILE__, __LINE__);
exit(1);
}
strcpy(eu_quotes, symbol);
}
break;
}
}
free(tok_ptr);
if (us_quotes)
{
/* Gets us quotes */
error = download_stocks(us_quotes, &stocks_tmp, YAHOO_US);
+ free(us_quotes);
if (error) return error;
}
if (eu_quotes)
{
/* Gets european quotes */
error = download_stocks(eu_quotes, &stocks_getted, YAHOO_EUROPE);
+ free(eu_quotes);
if (error) return error;
/* concats lists if needed */
if (stocks_tmp)
{
stocks_tmp2 = stocks_tmp;
while(stocks_tmp2 != NULL)
{
last_stock = stocks_tmp2;
stocks_tmp2 = next_stock(stocks_tmp2);
}
last_stock->NextStock = stocks_getted;
stocks_getted->PreviousStock = last_stock;
}
- else (stocks_tmp = stocks_getted);
+ else
+ (stocks_tmp = stocks_getted);
}
*stock_datas = stocks_tmp;
return(0);
}
diff --git a/rsync/delta.c b/rsync/delta.c
index 323c079..42f3afb 100644
--- a/rsync/delta.c
+++ b/rsync/delta.c
@@ -242,110 +242,112 @@ rs_delta_scan(rs_job_t *job, rs_long_t avail_len, void *p)
* emit the copy command or keep searching. */
/* FIXME: At the moment, if you call with very short buffers,
* then you will get a series of very short LITERAL commands.
* Perhaps this is what you deserve, or perhaps we should try
* to get more readahead and avoid that. */
/* There's some literal data at the start of this window which
* we know is not in any block. */
rs_trace("got %d bytes of literal data", search_pos);
rs_emit_literal_cmd(job, search_pos);
rs_tube_copy(job, search_pos);
}
return RS_RUNNING;
}
static rs_result rs_delta_s_deferred_copy(rs_job_t *job)
{
if (!job->basis_len) {
rs_log(RS_LOG_ERR, "somehow got zero basis_len");
return RS_INTERNAL_ERROR;
}
rs_emit_copy_cmd(job, job->basis_pos, job->basis_len);
rs_scoop_advance(job, job->basis_len);
job->statefn = rs_delta_s_scan;
return RS_RUNNING;
}
/**
* \brief State function that does a slack delta containing only
* literal data to recreate the input.
*/
static rs_result rs_delta_s_slack(rs_job_t *job)
{
rs_buffers_t * const stream = job->stream;
size_t avail = stream->avail_in;
if (avail) {
rs_trace("emit slack delta for %.0f available bytes", (double) avail);
rs_emit_literal_cmd(job, avail);
rs_tube_copy(job, avail);
return RS_RUNNING;
} else {
if (rs_job_input_is_ending(job)) {
job->statefn = rs_delta_s_end;
return RS_RUNNING;
} else {
return RS_BLOCKED;
}
}
}
/**
* State function for writing out the header of the encoding job.
*/
static rs_result rs_delta_s_header(rs_job_t *job)
{
rs_emit_delta_header(job);
if (job->block_len) {
if (!job->signature) {
rs_error("no signature is loaded into the job");
return RS_PARAM_ERROR;
}
job->statefn = rs_delta_s_scan;
} else {
rs_trace("block length is zero for this delta; "
"therefore using slack deltas");
job->statefn = rs_delta_s_slack;
}
return RS_RUNNING;
}
/**
* Prepare to compute a streaming delta.
*/
rs_job_t *rs_delta_begin(rs_signature_t *sig)
{
rs_job_t *job;
job = rs_job_new("delta", rs_delta_s_header);
job->signature = sig;
if ((job->block_len = sig->block_len) < 0) {
rs_log(RS_LOG_ERR, "unreasonable block_len %d in signature",
job->block_len);
+ rs_job_free(job);
return NULL;
}
job->strong_sum_len = sig->strong_sum_len;
if (job->strong_sum_len < 0 || job->strong_sum_len > RS_MD4_LENGTH) {
rs_log(RS_LOG_ERR, "unreasonable strong_sum_len %d in signature",
job->strong_sum_len);
+ rs_job_free(job);
return NULL;
}
return job;
}