Subversion Repositories RepoView

Rev

Rev 11 | Rev 14 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 11 Rev 12
Line 1... Line 1...
1
/* $Id: repo.c 11 2024-08-21 04:31:55Z nishi $ */
1
/* $Id: repo.c 12 2024-08-21 05:05:19Z nishi $ */
2
 
2
 
3
#include "rv_repo.h"
3
#include "rv_repo.h"
4
 
4
 
5
#include "../config.h"
5
#include "../config.h"
6
 
6
 
Line 13... Line 13...
13
#include <stdio.h>
13
#include <stdio.h>
14
#include <string.h>
14
#include <string.h>
15
#include <fcntl.h>
15
#include <fcntl.h>
16
#include <sys/stat.h>
16
#include <sys/stat.h>
17
#include <sys/wait.h>
17
#include <sys/wait.h>
-
 
18
#include <signal.h>
18
 
19
 
19
char* rv_construct_repouser(const char* reponame, const char* username) {
20
char* rv_construct_repouser(const char* reponame, const char* username) {
20
	char cbuf[2];
21
	char cbuf[2];
21
	cbuf[0] = REPO_USER_DELIM;
22
	cbuf[0] = REPO_USER_DELIM;
22
	cbuf[1] = 0;
23
	cbuf[1] = 0;
Line 207... Line 208...
207
				d[i] = 0;
208
				d[i] = 0;
208
			} else if(d[i] == '\n' || d[i] == 0) {
209
			} else if(d[i] == '\n' || d[i] == 0) {
209
				char oldc = d[i];
210
				char oldc = d[i];
210
				d[i] = 0;
211
				d[i] = 0;
211
				count++;
212
				count++;
212
				if(count > 1 && strlen(d + incr + 1) > 0 && d[incr] != 0) {
213
				if(count > 1 && d[incr] != 0 && strlen(d + incr + 1) > 0) {
213
					char* pathname = d + incr + 1;
214
					char* pathname = d + incr + 1;
214
					if(phase == 0 && pathname[strlen(pathname) - 1] == '/') {
215
					if(phase == 0 && pathname[strlen(pathname) - 1] == '/') {
215
						handler(d + incr + 1);
216
						handler(d + incr + 1);
216
					} else if(phase == 1 && pathname[strlen(pathname) - 1] != '/') {
217
					} else if(phase == 1 && pathname[strlen(pathname) - 1] != '/') {
217
						handler(d + incr + 1);
218
						handler(d + incr + 1);
Line 224... Line 225...
224
				incr = i + 1;
225
				incr = i + 1;
225
				if(oldc == 0) break;
226
				if(oldc == 0) break;
226
			}
227
			}
227
		}
228
		}
228
		phase++;
229
		phase++;
-
 
230
		incr = 0;
-
 
231
		count = 0;
229
		if(phase == 1) goto repeat;
232
		if(phase == 1) goto repeat;
230
		free(d);
233
		free(d);
231
	}
234
	}
232
	free(svnpath);
235
	free(svnpath);
233
	return true;
236
	return true;
234
}
237
}
235
 
238
 
236
char* rv_read_file(const char* repouser, char* path) {
239
char* rv_read_file(const char* repouser, char* path) {
-
 
240
	if(rv_get_filesize(repouser, path) > 1024 * 128) return NULL;
237
	char* svnpath = rv_strcat3(SVN_ROOT, "/", repouser);
241
	char* svnpath = rv_strcat3(SVN_ROOT, "/", repouser);
238
	int pipes[2];
242
	int pipes[2];
239
	pipe(pipes);
243
	pipe(pipes);
240
	pid_t pid = fork();
244
	pid_t pid = fork();
241
	if(pid == 0) {
245
	if(pid == 0) {
Line 244... Line 248...
244
		char* cmd[] = {"svnlook", "cat", svnpath, (char*)path, NULL};
248
		char* cmd[] = {"svnlook", "cat", svnpath, (char*)path, NULL};
245
		execvp("svnlook", cmd);
249
		execvp("svnlook", cmd);
246
		_exit(0);
250
		_exit(0);
247
	} else {
251
	} else {
248
		close(pipes[1]);
252
		close(pipes[1]);
249
		char cbuf[2];
253
		char cbuf[1024];
250
		cbuf[1] = 0;
-
 
251
		char* d = malloc(1);
254
		char* d = malloc(1024 * 128);
252
		d[0] = 0;
255
		int incr = 0;
-
 
256
		bool bin = false;
253
		while(1) {
257
		while(1) {
254
			int n = read(pipes[0], cbuf, 1);
258
			int n = read(pipes[0], cbuf, 1024);
-
 
259
			if(cbuf[0] == 0) {
-
 
260
				bin = true;
-
 
261
				kill(pid, SIGKILL);
-
 
262
				break;
-
 
263
			}
255
			if(n == 0) break;
264
			if(n == 0) break;
256
			char* tmp = d;
265
			memcpy(d + incr, cbuf, n);
257
			d = rv_strcat(tmp, cbuf);
266
			d[incr + n] = 0;
258
			free(tmp);
267
			incr += n;
259
		}
268
		}
260
		int status;
269
		int status;
261
		waitpid(pid, &status, 0);
270
		waitpid(pid, &status, 0);
262
		if(WEXITSTATUS(status) != 0) {
271
		if(WEXITSTATUS(status) != 0) {
263
			free(d);
272
			free(d);
264
			free(svnpath);
273
			free(svnpath);
265
			return NULL;
274
			return NULL;
266
		}
275
		}
-
 
276
		if(bin) {
-
 
277
			free(d);
-
 
278
			return NULL;
-
 
279
		}
267
		return d;
280
		return d;
268
	}
281
	}
269
}
282
}