Example #1
0
char* get_longest_prefix(char **results){
	int i;
	int prefix=0;
	int test=0;
	char *ret=NULL;

	if(results && results[0]){
		prefix=strlen(results[0]);
		for(i=1;results[i];i++){
			test=common_prefix(results[0],results[i]);
			prefix=minimum(prefix,test);
		}
		INIT_MEM(ret,(2*prefix)+1);
		memcpy(ret,results[0],prefix);
		ret[prefix]=0;
		add_slashes(ret,prefix+1);
	}

	return ret;
}
Example #2
0
GNOKII_API gn_error gn_file_phonebook_raw_write(FILE *f, gn_phonebook_entry *entry, const char *memory_type_string)
{
	char escaped_name[2 * GN_PHONEBOOK_NAME_MAX_LENGTH];
	int i;

	add_slashes(escaped_name, entry->name, sizeof(escaped_name), strlen(entry->name));
	fprintf(f, "%s;%s;%s;%d;%d", escaped_name,
		entry->number, memory_type_string,
		entry->location, entry->caller_group);
	if (entry->person.has_person) {
		if (entry->person.honorific_prefixes[0])
			fprintf(f, ";%d;0;0;%s", GN_PHONEBOOK_ENTRY_FormalName,
				entry->person.honorific_prefixes);
		if (entry->person.given_name[0])
			fprintf(f, ";%d;0;0;%s", GN_PHONEBOOK_ENTRY_FirstName,
				entry->person.given_name);
		if (entry->person.family_name[0])
			fprintf(f, ";%d;0;0;%s", GN_PHONEBOOK_ENTRY_LastName,
				entry->person.family_name);
	}
	if (entry->address.has_address) {
		if (entry->address.post_office_box[0])
			fprintf(f, ";%d;0;0;%s", GN_PHONEBOOK_ENTRY_Postal,
				entry->address.post_office_box);
		if (entry->address.extended_address[0])
			fprintf(f, ";%d;0;0;%s", GN_PHONEBOOK_ENTRY_ExtendedAddress,
				entry->address.extended_address);
		if (entry->address.street[0])
			fprintf(f, ";%d;0;0;%s", GN_PHONEBOOK_ENTRY_Street,
				entry->address.street);
		if (entry->address.city[0])
			fprintf(f, ";%d;0;0;%s", GN_PHONEBOOK_ENTRY_City,
				entry->address.city);
		if (entry->address.state_province[0])
			fprintf(f, ";%d;0;0;%s", GN_PHONEBOOK_ENTRY_StateProvince,
				entry->address.state_province);
		if (entry->address.zipcode[0])
			fprintf(f, ";%d;0;0;%s", GN_PHONEBOOK_ENTRY_ZipCode,
				entry->address.zipcode);
		if (entry->address.country[0])
			fprintf(f, ";%d;0;0;%s", GN_PHONEBOOK_ENTRY_Country,
				entry->address.country);
	}

	for (i = 0; i < entry->subentries_count; i++) {
		switch (entry->subentries[i].entry_type) {
		case GN_PHONEBOOK_ENTRY_Birthday:
		case GN_PHONEBOOK_ENTRY_Date:
			fprintf(f, ";%d;0;%d;%04u%02u%02u%02u%02u%02u", entry->subentries[i].entry_type, entry->subentries[i].id,
				entry->subentries[i].data.date.year, entry->subentries[i].data.date.month, entry->subentries[i].data.date.day,
				entry->subentries[i].data.date.hour, entry->subentries[i].data.date.minute, entry->subentries[i].data.date.second);
			break;
		case GN_PHONEBOOK_ENTRY_ExtGroup:
			fprintf(f, ";%d;%d;%d;%03d",
				entry->subentries[i].entry_type,
				entry->subentries[i].number_type,
				entry->subentries[i].id,
				entry->subentries[i].data.id);
			break;
		default:
			add_slashes(escaped_name, entry->subentries[i].data.number, sizeof(escaped_name), strlen(entry->subentries[i].data.number));
			fprintf(f, ";%d;%d;%d;%s",
				entry->subentries[i].entry_type,
				entry->subentries[i].number_type,
				entry->subentries[i].id,
				escaped_name);
			break;
		}
	}
	if ((entry->memory_type == GN_MT_MC ||
		entry->memory_type == GN_MT_DC ||
		entry->memory_type == GN_MT_RC) &&
		entry->date.day != 0)
		fprintf(f, ";%d;0;0;%04u%02u%02u%02u%02u%02u", GN_PHONEBOOK_ENTRY_Date,
			entry->date.year, entry->date.month, entry->date.day, entry->date.hour, entry->date.minute, entry->date.second);
	fprintf(f, "\n");
	return GN_ERR_NONE;
}
bool SettingsManager::save(const QString& path)
{
    QByteArray data = path.toLatin1();

    if(sqlite3_open(data.constData(), &(m_db)))
    {
        sqlite3_close(m_db);
        return false;
    }

#if defined(SQLITE_HAS_CODEC)
    char tmp[9];
    // Grab the obfuscated key
    sqlite3_obfuscate_key(tmp);

    if(SQLITE_OK != sqlite3_key((sqlite3*) m_db, tmp, 8))
    {
        memset(tmp, 0, 9);
        sqlite3_close(m_db);
        return false;
    }
    // Clear the key so it isn't stored in memory
    memset(tmp, 0, 9);
#endif


    QMap<QString, QString>::iterator siter;
    QString query = "BEGIN TRANSACTION;\n";

    sqllite_resultset_t rs;
    int rc;

    for(siter = m_globals.begin(); siter != m_globals.end(); siter++)
    {
        QString k = siter.key();
        QString v = siter.value();

        query += QString("UPDATE Settings SET value='%1' WHERE key='%2';\n").
            arg(add_slashes(v)).
            arg(add_slashes(k));

    }



    QMap<int, QMap<QString, QMap<QString,QStringList> > >::iterator fiter;

    query += QString("DELETE FROM DeviceLists;\n");
    //rs.rows.clear();
    //sqlite3_exec((sqlite3*)m_db, qPrintable(query), NULL, NULL, NULL);

    for(fiter = m_favorites.begin();
        fiter != m_favorites.end();
        fiter++)
    {
        QMap<QString, QMap<QString,QStringList> >::iterator liter;

        int chip = fiter.key();

        for(liter = fiter.value().begin();
            liter != fiter.value().end();
            liter++)
        {
            QString category = liter.key();
            QMap<QString,QStringList> lists = liter.value();
            QMap<QString,QStringList>::iterator viter;

            for(viter = lists.begin(); viter != lists.end(); viter++)
            {
                QString list = viter.key();
                QStringList items = viter.value();

                for(int i = 0; i < items.count(); i++)
                {
                    QString item = items.at(i);

                    query += QString("INSERT INTO DeviceLists (chip,category,key,value) VALUES('%1', '%2', '%3', '%4');\n").
                            arg(chip).
                            arg(add_slashes(category)).
                            arg(add_slashes(list)).
                            arg(add_slashes(item));
                    //qDebug() << query;

                    //sqlite3_exec((sqlite3*)m_db, qPrintable(query), NULL, NULL, NULL);
                }
            }
        }
    }

    query += "END TRANSACTION;\n";

    data = query.toLatin1();
    rc = sqlite3_exec((sqlite3*)m_db, data.constData(), NULL, NULL, NULL);

    sqlite3_close(m_db);

    if(rc == SQLITE_OK)
    {
        // Settings no longer modified after writing back to dB
        m_settings_modified = false;
        return true;
    }

    return false;
}