Commit 5ec81540 authored by Ghislain MARY's avatar Ghislain MARY

Set string arguments as const.

parent 2cb273a5
......@@ -189,6 +189,11 @@ typedef struct bzrtpCallbacks_struct {
*/
typedef struct bzrtpContext_struct bzrtpContext_t;
#ifdef __cplusplus
extern "C" {
#endif
/**
* Create context structure and initialise it
*
......@@ -441,7 +446,7 @@ BZRTP_EXPORT int bzrtp_cache_getZuid(void *dbPointer, const char *selfURI, const
*
* @return 0 on succes, error code otherwise
*/
BZRTP_EXPORT int bzrtp_cache_write(void *dbPointer, int zuid, char *tableName, char **columns, uint8_t **values, size_t *lengths, uint8_t columnsCount);
BZRTP_EXPORT int bzrtp_cache_write(void *dbPointer, int zuid, const char *tableName, const char **columns, uint8_t **values, size_t *lengths, uint8_t columnsCount);
/**
* @brief Read data from specified table/columns from cache adressing it by zuid (ZID/URI binding id used in cache)
......@@ -459,7 +464,7 @@ BZRTP_EXPORT int bzrtp_cache_write(void *dbPointer, int zuid, char *tableName, c
*
* @return 0 on succes, error code otherwise
*/
BZRTP_EXPORT int bzrtp_cache_read(void *dbPointer, int zuid, char *tableName, char **columns, uint8_t **values, size_t *lengths, uint8_t columnsCount);
BZRTP_EXPORT int bzrtp_cache_read(void *dbPointer, int zuid, const char *tableName, const char **columns, uint8_t **values, size_t *lengths, uint8_t columnsCount);
/**
* @brief Perform migration from xml version to sqlite3 version of cache
......@@ -488,4 +493,8 @@ BZRTP_EXPORT int bzrtp_cache_migration(void *cacheXmlPtr, void *cacheSqlite, con
*/
BZRTP_EXPORT int bzrtp_exportKey(bzrtpContext_t *zrtpContext, char *label, size_t labelLength, uint8_t *derivedKey, size_t *derivedKeyLength);
#ifdef __cplusplus
}
#endif
#endif /* ifndef BZRTP_H */
......@@ -513,7 +513,7 @@ int bzrtp_processMessage(bzrtpContext_t *zrtpContext, uint32_t selfSSRC, uint8_t
void bzrtp_SASVerified(bzrtpContext_t *zrtpContext) {
if (zrtpContext != NULL) {
uint8_t pvsFlag = 1;
char *colNames[] = {"pvs"};
const char *colNames[] = {"pvs"};
uint8_t *colValues[] = {&pvsFlag};
size_t colLength[] = {1};
......@@ -535,7 +535,7 @@ void bzrtp_SASVerified(bzrtpContext_t *zrtpContext) {
void bzrtp_resetSASVerified(bzrtpContext_t *zrtpContext) {
if (zrtpContext != NULL) {
uint8_t pvsFlag = 0;
char *colNames[] = {"pvs"};
const char *colNames[] = {"pvs"};
uint8_t *colValues[] = {&pvsFlag};
size_t colLength[] = {1};
bzrtp_cache_write(zrtpContext->zidCache, zrtpContext->zuid, "zrtp", colNames, colValues, colLength, 1);
......
......@@ -548,7 +548,7 @@ int state_keyAgreement_sendingCommit(bzrtpEvent_t event) {
/* in case of cache mismatch, be sure the Previously Verified Sas flag is reset in cache and in the context */
if (zrtpContext->cacheMismatchFlag == 1) {
uint8_t pvsFlag = 0;
char *colNames[] = {"pvs"};
const char *colNames[] = {"pvs"};
uint8_t *colValues[] = {&pvsFlag};
size_t colLength[] = {1};
......@@ -843,7 +843,7 @@ int state_keyAgreement_responderSendingDHPart1(bzrtpEvent_t event) {
/* in case of cache mismatch, be sure the Previously Verified Sas flag is reset in cache and in the context */
if (zrtpContext->cacheMismatchFlag == 1) {
uint8_t pvsFlag = 0;
char *colNames[] = {"pvs"};
const char *colNames[] = {"pvs"};
uint8_t *colValues[] = {&pvsFlag};
size_t colLength[] = {1};
......@@ -2172,7 +2172,7 @@ int bzrtp_deriveSrtpKeysFromS0(bzrtpContext_t *zrtpContext, bzrtpChannelContext_
* return 0 on success, error code otherwise
*/
int bzrtp_updateCachedSecrets(bzrtpContext_t *zrtpContext, bzrtpChannelContext_t *zrtpChannelContext) {
char *colNames[] = {"rs1", "rs2"};
const char *colNames[] = {"rs1", "rs2"};
uint8_t *colValues[2] = {NULL, NULL};
size_t colLength[2] = {RETAINED_SECRET_LENGTH,0};
......
......@@ -466,7 +466,7 @@ int bzrtp_cache_getZuid(void *dbPointer, const char *selfURI, const char *peerUR
*
* @return 0 on succes, error code otherwise
*/
int bzrtp_cache_write(void *dbPointer, int zuid, char *tableName, char **columns, uint8_t **values, size_t *lengths, uint8_t columnsCount) {
int bzrtp_cache_write(void *dbPointer, int zuid, const char *tableName, const char **columns, uint8_t **values, size_t *lengths, uint8_t columnsCount) {
char *stmt=NULL;
int ret,i,j;
sqlite3_stmt *sqlStmt = NULL;
......@@ -570,7 +570,7 @@ int bzrtp_cache_write(void *dbPointer, int zuid, char *tableName, char **columns
*
* @return 0 on succes, error code otherwise
*/
int bzrtp_cache_read(void *dbPointer, int zuid, char *tableName, char **columns, uint8_t **values, size_t *lengths, uint8_t columnsCount) {
int bzrtp_cache_read(void *dbPointer, int zuid, const char *tableName, const char **columns, uint8_t **values, size_t *lengths, uint8_t columnsCount) {
char *stmt=NULL;
int ret,i,j;
sqlite3_stmt *sqlStmt = NULL;
......@@ -709,12 +709,12 @@ int bzrtp_cache_migration(void *cacheXmlPtr, void *cacheSqlite, const char *self
xmlChar *peerUri[128]; /* array to contain all the peer uris found in one node */
/* hopefully they won't be more than 128(it would mean some peer has more than 128 accounts and we called all of them...) */
int peerUriIndex=0; /* index of previous array */
char *zrtpColNames[] = {"rs1", "rs2", "pvs"};
const char *zrtpColNames[] = {"rs1", "rs2", "pvs"};
uint8_t *zrtpColValues[] = {NULL, NULL, NULL};
size_t zrtpColExpectedLengths[] = {32,32,1};
size_t zrtpColLengths[] = {0,0,0};
char *limeColNames[] = {"sndKey", "rcvKey", "sndSId", "rcvSId", "sndIndex", "rcvIndex", "valid"};
const char *limeColNames[] = {"sndKey", "rcvKey", "sndSId", "rcvSId", "sndIndex", "rcvIndex", "valid"};
uint8_t *limeColValues[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
size_t limeColExpectedLengths[] = {32,32,32,32,4,4,8};
size_t limeColLengths[] = {0,0,0,0,0,0,0};
......@@ -853,11 +853,11 @@ int bzrtp_getPeerAssociatedSecrets(bzrtpContext_t *context, uint8_t peerZID[12])
return 0;
}
int bzrtp_cache_write(void *dbPointer, int zuid, char *tableName, char **columns, uint8_t **values, size_t *lengths, uint8_t columnsCount) {
int bzrtp_cache_write(void *dbPointer, int zuid, const char *tableName, const char **columns, uint8_t **values, size_t *lengths, uint8_t columnsCount) {
return BZRTP_ERROR_CACHEDISABLED;
}
int bzrtp_cache_read(void *dbPointer, int zuid, char *tableName, char **columns, uint8_t **values, size_t *lengths, uint8_t columnsCount) {
int bzrtp_cache_read(void *dbPointer, int zuid, const char *tableName, const char **columns, uint8_t **values, size_t *lengths, uint8_t columnsCount) {
return BZRTP_ERROR_CACHEDISABLED;
}
......
......@@ -590,7 +590,7 @@ void test_cache_enabled_exchange(void) {
uint8_t selfZIDalice[12];
uint8_t selfZIDbob[12];
int zuidAlice=0,zuidBob=0;
char *colNames[] = {"rs1", "rs2", "pvs"};
const char *colNames[] = {"rs1", "rs2", "pvs"};
uint8_t *colValuesAlice[3];
size_t colLengthAlice[3];
uint8_t *colValuesBob[3];
......@@ -674,7 +674,7 @@ void test_cache_mismatch_exchange(void) {
uint8_t selfZIDalice[12];
uint8_t selfZIDbob[12];
int zuidAlice=0,zuidBob=0;
char *colNames[] = {"rs1", "rs2", "pvs"};
const char *colNames[] = {"rs1", "rs2", "pvs"};
uint8_t *colValuesAlice[3];
size_t colLengthAlice[3];
uint8_t *colValuesBob[3];
......@@ -786,7 +786,7 @@ void test_cache_sas_not_confirmed(void) {
uint8_t selfZIDalice[12];
uint8_t selfZIDbob[12];
int zuidAlice=0,zuidBob=0;
char *colNames[] = {"rs1", "rs2", "pvs"};
const char *colNames[] = {"rs1", "rs2", "pvs"};
uint8_t *colValuesAlice[3];
size_t colLengthAlice[3];
uint8_t *colValuesBob[3];
......
......@@ -56,7 +56,7 @@ void test_cache_getSelfZID(void) {
uint8_t rs1Value[] = {0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00};
uint8_t rs2Value[] = {0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, 0xff, 0xee};
uint8_t pvsValue[] = {0x1};
char *patternColNames[]={"rs1", "rs2", "pvs", "aux"};
const char *patternColNames[]={"rs1", "rs2", "pvs", "aux"};
uint8_t *patternColValues[] = {rs1Value, rs2Value, pvsValue};
size_t patternColValuesLength[] = {16, 16, 1};
uint8_t *readValues[] = {NULL, NULL, NULL,NULL};
......@@ -100,11 +100,11 @@ void test_cache_getSelfZID(void) {
BC_ASSERT_EQUAL(zuidalicebob, zuidCheck, int, "%d");
/* Then write in cache zrtp table */
BC_ASSERT_EQUAL(bzrtp_cache_write((void *)aliceDB, zuidalicebob, "zrtp", (char **)patternColNames, (uint8_t **)patternColValues, patternColValuesLength, patternLength), 0, int, "%x");
BC_ASSERT_EQUAL(bzrtp_cache_write((void *)aliceDB, zuidalicebob, "zrtp", patternColNames, (uint8_t **)patternColValues, patternColValuesLength, patternLength), 0, int, "%x");
/* Try to write a zuid row in zrtp table while zuid is not present in ziduri table: it shall fail */
BC_ASSERT_EQUAL(bzrtp_cache_write((void *)aliceDB, zuidalicebob+10, "zrtp", (char **)patternColNames, (uint8_t **)patternColValues, patternColValuesLength, patternLength), BZRTP_ZIDCACHE_UNABLETOUPDATE, int, "%x");
BC_ASSERT_EQUAL(bzrtp_cache_write((void *)aliceDB, zuidalicebob+10, "zrtp", patternColNames, (uint8_t **)patternColValues, patternColValuesLength, patternLength), BZRTP_ZIDCACHE_UNABLETOUPDATE, int, "%x");
/* Now read the data and check they're the same */
BC_ASSERT_EQUAL(bzrtp_cache_read((void *)aliceDB, zuidalicebob, "zrtp", (char **)patternColNames, readValues, readLength, patternLength+1), 0, int, "%x");
BC_ASSERT_EQUAL(bzrtp_cache_read((void *)aliceDB, zuidalicebob, "zrtp", patternColNames, readValues, readLength, patternLength+1), 0, int, "%x");
for (i=0; i<patternLength; i++) {
BC_ASSERT_EQUAL(readLength[i], patternColValuesLength[i], int, "%d");
BC_ASSERT_EQUAL(memcmp(readValues[i], patternColValues[i], patternColValuesLength[i]), 0, int, "%d");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment