Browse Source

Set the tox user name

Bob Mottram 3 years ago
parent
commit
7cb414044c
3 changed files with 21 additions and 0 deletions
  1. 4 0
      README.md
  2. BIN
      man/toxid.1.gz
  3. 17 0
      src/main.c

+ 4 - 0
README.md

@@ -24,3 +24,7 @@ Then on another system on the same network to discover Tox IDs:
 To create a new tox user named "bar" which will exist in /home/foo/.config.tox
 
     toxid -u foo -n bar
+
+To set the tox username:
+
+    toxid --setuser bar

BIN
man/toxid.1.gz


+ 17 - 0
src/main.c

@@ -225,6 +225,13 @@ void get_tox_name(char * data_file, char * tox_username)
 	tox_kill(tox);
 }
 
+void set_tox_name(char * data_file, char * tox_username)
+{
+	Tox *tox = create_tox(data_file);
+	tox_self_set_name(tox, (const uint8_t *)tox_username, strlen(tox_username), NULL);
+	tox_kill(tox);
+}
+
 int main(int argc, char* argv[])
 {
 	char data_file[256], address[TOX_ADDRESS_SIZE];
@@ -235,6 +242,7 @@ int main(int argc, char* argv[])
 	char search[256];
 	int show_user=0;
 	int new_user=0;
+	int set_user=0;
 
 	/* get the user's home directory */
 	struct passwd *pw = getpwuid(getuid());
@@ -272,6 +280,10 @@ int main(int argc, char* argv[])
 			(strcmp(argv[i], "-s") == 0)) {
 			show_user = 1;
 		}
+		if ((strcmp(argv[i], "--setuser") == 0) ||
+			(strcmp(argv[i], "--set") == 0)) {
+			set_user = 1;
+		}
 	}
 
 	/* create a new user */
@@ -326,6 +338,11 @@ int main(int argc, char* argv[])
 
 	if (tox_data_file_exists(data_file) == 0) return 0;
 
+	if (set_user == 1) {
+		set_tox_name(data_file, tox_username);
+		return 0;
+	}
+
 	if (show_user == 1) {
 		get_tox_name(data_file, tox_username);
 		printf("%s", tox_username);