Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

lib: Improve constness of string parameters

Avoids warnings and might even aid the optimizer a bit.
  • Loading branch information...
commit 5d1985ad1f9963e86620e1d26134707165d08fda 1 parent 167dae7
@SimonKagstrom authored
View
2  src/lib/buf.c
@@ -47,7 +47,7 @@ void buf_free(struct buf* b)
free(b);
}
-void buf_append_data(struct buf* b, void* data, int len)
+void buf_append_data(struct buf* b, const void* data, int len)
{
buf_extend(b, len);
View
2  src/lib/buf.h
@@ -22,7 +22,7 @@ struct buf {
void* buf_new(void);
void buf_free(struct buf* b);
void buf_extend(struct buf* b, int len);
-void buf_append_data(struct buf* b, void* data, int len);
+void buf_append_data(struct buf* b, const void* data, int len);
void buf_append_u8(struct buf* b, unsigned char data);
void buf_append_u16(struct buf* b, unsigned short data);
void buf_append_u32(struct buf* b, unsigned long data);
View
2  src/lib/commands.c
@@ -126,7 +126,7 @@ int cmd_request_image (SESSION * session, unsigned char *hash,
* The response comes as compressed XML
*
*/
-int cmd_search (SESSION * session, char *searchtext, unsigned int offset,
+int cmd_search (SESSION * session, const char *searchtext, unsigned int offset,
unsigned int limit, channel_callback callback, void *private)
{
CHANNEL *ch;
View
2  src/lib/commands.h
@@ -60,7 +60,7 @@ int cmd_send_cache_hash (SESSION *);
int cmd_token_notify (SESSION *);
int cmd_aeskey (SESSION *, unsigned char *, unsigned char *, channel_callback,
void *);
-int cmd_search (SESSION *, char *, unsigned int, unsigned int, channel_callback,
+int cmd_search (SESSION *, const char *, unsigned int, unsigned int, channel_callback,
void *);
int cmd_requestad (SESSION *, unsigned char);
int cmd_request_image (SESSION *, unsigned char *, channel_callback, void *);
View
20 src/lib/despotify.c
@@ -680,7 +680,7 @@ bool despotify_wait_timeout(struct despotify_session* ds){
*/
struct ds_search_result* despotify_search(struct despotify_session* ds,
- char* searchtext, int maxresults)
+ const char* searchtext, int maxresults)
{
struct ds_search_result* search = NULL;
@@ -1419,7 +1419,7 @@ void despotify_free_track(struct ds_track* t)
*
*/
-static void baseconvert(char *src, char *dest,
+static void baseconvert(const char *src, char *dest,
int frombase, int tobase, int padlen)
{
static const char alphabet[] =
@@ -1456,18 +1456,18 @@ static void baseconvert(char *src, char *dest,
} while (newlen != 0);
}
-void despotify_id2uri(char* id, char* uri)
+void despotify_id2uri(const char* id, char* uri)
{
baseconvert(id, uri, 16, 62, 22);
}
-void despotify_uri2id(char* uri, char* id)
+void despotify_uri2id(const char* uri, char* id)
{
baseconvert(uri, id, 62, 16, 32);
}
-struct ds_link* despotify_link_from_uri(char *uri)
+struct ds_link* despotify_link_from_uri(const char *uri)
{
struct ds_link* link = calloc(1, sizeof(struct ds_link));
@@ -1475,7 +1475,7 @@ struct ds_link* despotify_link_from_uri(char *uri)
link->uri = uri;
if (!strncmp(uri, "spotify:album:", 13)) {
- char* id = uri + 14;
+ const char* id = uri + 14;
if (strlen(id) != 22) /* id must be 22 chars */
return link;
@@ -1484,7 +1484,7 @@ struct ds_link* despotify_link_from_uri(char *uri)
link->arg = id;
} else if (!strncmp(uri, "spotify:artist:", 14)) {
- char* id = uri + 15;
+ const char* id = uri + 15;
if (strlen(id) != 22) /* id must be 22 chars */
return link;
@@ -1493,7 +1493,7 @@ struct ds_link* despotify_link_from_uri(char *uri)
link->arg = id;
} else if (!strncmp(uri, "spotify:search:", 14)) {
- char* searcharg = uri + 15;
+ const char* searcharg = uri + 15;
if (strlen(searcharg) == 0) /* must search for something */
return link;
@@ -1503,7 +1503,7 @@ struct ds_link* despotify_link_from_uri(char *uri)
} else if (!strncmp(uri, "spotify:user:", 12)) {
int userlen = strchr(uri + 13, ':') - (uri + 13);
- char *id = uri + userlen + 23;
+ const char *id = uri + userlen + 23;
if (strlen(id) != 22) /* id must be 22 chars */
return link;
@@ -1512,7 +1512,7 @@ struct ds_link* despotify_link_from_uri(char *uri)
link->arg = id;
} else if (!strncmp(uri, "spotify:track:", 13)) {
- char* id = uri + 14;
+ const char* id = uri + 14;
if (strlen(id) != 22) /* id must be 22 chars */
return link;
View
12 src/lib/despotify.h
@@ -129,8 +129,8 @@ enum ds_link_type {
struct ds_link
{
- char* uri;
- char* arg;
+ const char* uri;
+ const char* arg;
enum ds_link_type type;
};
@@ -283,7 +283,7 @@ void despotify_free_track(struct ds_track* t);
/* Search */
struct ds_search_result* despotify_search(struct despotify_session *ds,
- char *searchtext, int maxresults);
+ const char *searchtext, int maxresults);
struct ds_search_result* despotify_search_more(struct despotify_session *ds,
struct ds_search_result* search,
int offset, int maxresults);
@@ -314,7 +314,7 @@ struct ds_track* despotify_get_current_track(struct despotify_session* ds);
int despotify_get_pcm(struct despotify_session*, struct ds_pcm_data*);
/* URI utils */
-struct ds_link* despotify_link_from_uri(char* uri);
+struct ds_link* despotify_link_from_uri(const char* uri);
struct ds_album_browse* despotify_link_get_album(struct despotify_session* ds, struct ds_link* link);
struct ds_artist_browse* despotify_link_get_artist(struct despotify_session* ds, struct ds_link* link);
@@ -330,8 +330,8 @@ char* despotify_playlist_to_uri(struct ds_playlist* album, char* dest);
char* despotify_search_to_uri(struct ds_search_result* album, char* dest);
char* despotify_track_to_uri(struct ds_track* album, char* dest);
-void despotify_id2uri(char* id, char* uri);
-void despotify_uri2id(char* uri, char* id);
+void despotify_id2uri(const char* id, char* uri);
+void despotify_uri2id(const char* uri, char* id);
/* internal functions */
int despotify_snd_read_stream(struct despotify_session* ds);
Please sign in to comment.
Something went wrong with that request. Please try again.