#include <stdio.h>#include <stdlib.h>#include <string.h>#include "dazukoio.h"#include "dazukoio_core.h"#include "dazuko_transport.h"#include "dazuko_version.h"#include "dazukoio_linux_compat1.h"Go to the source code of this file.
Defines | |
| #define | DAZUKO_FILENAME_MAX_LENGTH 6144 |
| #define | DAZUKO_SET_VERSION(maj, min, rev, rel, txt) |
| #define | DAZUKO_POP_NUMBER(num) |
Functions | |
| static char | char_to_hex (char c) |
| static void | unescape_string (char *string) |
| int | dazuko_get_value (const char *key, const char *string, char *buffer, size_t buffer_size) |
| static struct dazuko_request * | alloc_request (int type, int request_length, int response_length) |
| static void | free_request (struct dazuko_request **request_ref) |
| int | dazukoVersion (struct dazuko_version *version) |
| int | dazukoIOVersion (struct dazuko_version *version) |
| int | dazukoRegister (const char *groupName, const char *mode) |
| static int | process_request (struct dazuko_id *id, char *buffer, size_t buffer_size, struct dazuko_request *request, int reply_required) |
| static void | dazuko_set_version (const char *reply_buffer) |
| static int | dazukoRegister_TS_inner (dazuko_id_t **dazuko_id, const char *groupName, const char *mode) |
| int | dazukoRegister_TS (dazuko_id_t **dazuko_id, const char *groupName, const char *mode) |
| int | dazukoSetAccessMask (unsigned long accessMask) |
| int | dazukoSetAccessMask_TS (dazuko_id_t *dazuko_id, unsigned long accessMask) |
| static int | dazuko_set_path (dazuko_id_t *dazuko_id, const char *path, int type) |
| int | dazukoAddIncludePath (const char *path) |
| int | dazukoAddIncludePath_TS (dazuko_id_t *dazuko_id, const char *path) |
| int | dazukoAddExcludePath (const char *path) |
| int | dazukoAddExcludePath_TS (dazuko_id_t *dazuko_id, const char *path) |
| int | dazukoRemoveAllPaths (void) |
| int | dazukoRemoveAllPaths_TS (dazuko_id_t *dazuko_id) |
| int | dazukoGetAccess (struct dazuko_access **acc) |
| int | dazukoGetAccess_TS (dazuko_id_t *dazuko_id, struct dazuko_access **acc) |
| int | dazukoReturnAccess (struct dazuko_access **acc) |
| int | dazukoReturnAccess_TS (dazuko_id_t *dazuko_id, struct dazuko_access **acc) |
| int | dazukoUnregister (void) |
| int | dazukoUnregister_TS (dazuko_id_t **dazuko_id) |
| int | dazukoInitializeCache (struct dazuko_cache_settings *cs) |
| int | dazukoInitializeCache_TS (dazuko_id_t *dazuko_id, struct dazuko_cache_settings *cs) |
| int | dazukoRemoveAllTrusted (void) |
| int | dazukoRemoveAllTrusted_TS (dazuko_id_t *dazuko_id) |
| int | dazukoRemoveTrusted (const char *token) |
| int | dazukoRemoveTrusted_TS (dazuko_id_t *dazuko_id, const char *token) |
Variables | |
| const char * | DAZUKO_VERSION_STAMP = "\nDazukoVersion=" DAZUKO_VERSION_MAJOR "." DAZUKO_VERSION_MINOR "." DAZUKO_VERSION_REVISION "." DAZUKO_VERSION_RELEASE "\n" |
| const char * | VERSION_STRING |
| dazuko_id_t * | _GLOBAL_DAZUKO = NULL |
| static int | _GLOBAL_DAZUKO_COMPAT1 = 0 |
| static int | _GLOBAL_WITH_REQSTREAM = 0 |
| static int | _GLOBAL_WITH_DEVWRITE = 0 |
| static int | _SET_DAZUKO_VERSION = 0 |
| static struct dazuko_version | _DAZUKO_VERSION |
|
|
Definition at line 59 of file dazukoio_core.c. Referenced by dazukoGetAccess_TS(). |
|
|
Value: { \
if (p1 == NULL) \
{ \
error = 1; \
} \
else \
{ \
p2 = strchr(p1, '.'); \
if (p2 != NULL) \
{ \
*p2 = 0; \
p2++; \
} \
num = atoi(p1); \
p1 = p2; \
} \
}
Referenced by dazuko_set_version(). |
|
|
Value: { \
if (!_SET_DAZUKO_VERSION) \
{ \
_DAZUKO_VERSION.major = maj; \
_DAZUKO_VERSION.minor = min; \
_DAZUKO_VERSION.revision = rev; \
_DAZUKO_VERSION.release = rel; \
snprintf(_DAZUKO_VERSION.text, sizeof(_DAZUKO_VERSION.text), txt); \
_DAZUKO_VERSION.text[sizeof(_DAZUKO_VERSION.text) - 1] = 0; \
_SET_DAZUKO_VERSION = 1; \
} \
}
Definition at line 318 of file dazukoio_core.c. Referenced by dazuko_set_version(), and dazukoRegister_TS_inner(). |
|
||||||||||||||||
|
Definition at line 158 of file dazukoio_core.c. References NULL. Referenced by dazuko_set_path(), dazukoGetAccess_TS(), dazukoInitializeCache_TS(), dazukoRegister_TS_inner(), dazukoRemoveAllPaths_TS(), dazukoRemoveAllTrusted_TS(), dazukoRemoveTrusted_TS(), dazukoReturnAccess_TS(), dazukoSetAccessMask_TS(), and dazukoUnregister_TS(). 00159 {
00160 struct dazuko_request *request;
00161 char *s;
00162
00163 request = (struct dazuko_request *)malloc(sizeof(struct dazuko_request));
00164 if (request == NULL)
00165 return NULL;
00166
00167 memset(request, 0, sizeof(struct dazuko_request));
00168
00169 request->type[0] = (char)type;
00170
00171 s = (char *)malloc(request_length);
00172 if (s == NULL)
00173 {
00174 free(request);
00175 return NULL;
00176 }
00177
00178 memset(s, 0, request_length);
00179
00180 request->buffer = s;
00181
00182 /* Note: buffer and buffer_size should be set after
00183 * calling this function */
00184
00185 if (response_length > 0)
00186 {
00187 s = (char *)malloc(response_length);
00188 if (s == NULL)
00189 {
00190 free(request->buffer);
00191 free(request);
00192 return NULL;
00193 }
00194
00195 memset(s, 0, response_length);
00196
00197 request->reply_buffer = s;
00198 request->reply_buffer_size = response_length;
00199 }
00200
00201 return request;
00202 }
|
|
|
Definition at line 74 of file dazukoio_core.c. Referenced by unescape_string(). 00075 {
00076 /* ugly, but fast */
00077
00078 switch (c)
00079 {
00080 case '1': return 1;
00081 case '2': return 2;
00082 case '3': return 3;
00083 case '4': return 4;
00084 case '5': return 5;
00085 case '6': return 6;
00086 case '7': return 7;
00087 case '8': return 8;
00088 case '9': return 9;
00089 case 'a': case 'A': return 10;
00090 case 'b': case 'B': return 11;
00091 case 'c': case 'C': return 12;
00092 case 'd': case 'D': return 13;
00093 case 'e': case 'E': return 14;
00094 case 'f': case 'F': return 15;
00095 }
00096
00097 return 0;
00098 }
|
|
||||||||||||||||||||
|
Definition at line 124 of file dazukoio_core.c. References NULL. 00125 {
00126 const char *p1;
00127 const char *p2;
00128 size_t size;
00129
00130 if (buffer == NULL || buffer_size < 1)
00131 return -1;
00132
00133 buffer[0] = 0;
00134
00135 if (key == NULL || string == NULL)
00136 return -1;
00137
00138 p1 = strstr(string, key);
00139 if (p1 == NULL)
00140 return -1;
00141
00142 p1 += strlen(key);
00143
00144 for (p2=p1 ; *p2 && *p2!='\n' ; p2++)
00145 continue;
00146
00147 size = p2 - p1;
00148 if (size >= buffer_size)
00149 size = buffer_size - 1;
00150
00151 memcpy(buffer, p1, size);
00152
00153 buffer[size] = 0;
00154
00155 return 0;
00156 }
|
|
||||||||||||||||
|
Definition at line 644 of file dazukoio_core.c. References alloc_request(), dazuko_request::buffer, dazuko_request::buffer_size, free_request(), dazuko_id::id, ITOA_SIZE, NULL, process_request(), and xp_verify_id(). Referenced by dazukoAddExcludePath_TS(), and dazukoAddIncludePath_TS(). 00645 {
00646 struct dazuko_request *request;
00647 size_t size;
00648 char buffer[ITOA_SIZE];
00649
00650 if (dazuko_id == NULL)
00651 return -1;
00652
00653 if (dazuko_id->id < 0)
00654 return -1;
00655
00656 if (xp_verify_id(dazuko_id) != 0)
00657 return -1;
00658
00659 if (path == NULL)
00660 return -1;
00661
00662 size = 1 + 2 + 1 + ITOA_SIZE /* \nID=id */
00663 + 1 + 2 + 1 + strlen(path) /* \nPT=path */
00664 + 1 /* \0 */
00665 ;
00666
00667 request = alloc_request(type, size, 0);
00668 if (request == NULL)
00669 return -1;
00670
00671 snprintf(request->buffer, size, "\nID=%d\nPT=%s", dazuko_id->id, path);
00672 request->buffer[size - 1] = 0;
00673 request->buffer_size = strlen(request->buffer) + 1;
00674
00675 if (process_request(dazuko_id, buffer, sizeof(buffer), request, 0) != 0)
00676 {
00677 free_request(&request);
00678 return -1;
00679 }
00680
00681 free_request(&request);
00682
00683 return 0;
00684 }
|
|
|
Definition at line 332 of file dazukoio_core.c. References dazuko_get_value(), DAZUKO_POP_NUMBER, DAZUKO_SET_VERSION, and ITOA_SIZE. Referenced by dazukoRegister_TS_inner(). 00333 {
00334 char vn_buffer[ITOA_SIZE + DAZUKO_VERSION_TEXT_SIZE];
00335 char vs_buffer[ITOA_SIZE + DAZUKO_VERSION_TEXT_SIZE];
00336 int maj = 0;
00337 int min = 0;
00338 int rev = 0;
00339 int rel = 0;
00340 char *p1;
00341 char *p2;
00342 int error = 0;
00343
00344 #define DAZUKO_POP_NUMBER(num) \
00345 { \
00346 if (p1 == NULL) \
00347 { \
00348 error = 1; \
00349 } \
00350 else \
00351 { \
00352 p2 = strchr(p1, '.'); \
00353 if (p2 != NULL) \
00354 { \
00355 *p2 = 0; \
00356 p2++; \
00357 } \
00358 num = atoi(p1); \
00359 p1 = p2; \
00360 } \
00361 }
00362
00363 if (dazuko_get_value("\nVN=", reply_buffer, vn_buffer, sizeof(vn_buffer)) != 0)
00364 {
00365 error = 1;
00366 }
00367
00368 if (!error && dazuko_get_value("\nVS=", reply_buffer, vs_buffer, sizeof(vs_buffer)) != 0)
00369 {
00370 error = 1;
00371 }
00372
00373 if (!error)
00374 {
00375 p1 = vn_buffer;
00376 DAZUKO_POP_NUMBER(maj);
00377 DAZUKO_POP_NUMBER(min);
00378 DAZUKO_POP_NUMBER(rev);
00379 DAZUKO_POP_NUMBER(rel);
00380 }
00381
00382 if (error)
00383 {
00384 /* this should never occur unless someone used a CVS snapshot */
00385 DAZUKO_SET_VERSION(2, 1, 0, 0, "2.1.0-prex");
00386 }
00387 else
00388 {
00389 DAZUKO_SET_VERSION(maj, min, rev, rel, vs_buffer);
00390 }
00391 }
|
|
|
Definition at line 701 of file dazukoio_core.c. References dazukoAddExcludePath_TS(). 00702 {
00703 return dazukoAddExcludePath_TS(_GLOBAL_DAZUKO, path);
00704 }
|
|
||||||||||||
|
Definition at line 706 of file dazukoio_core.c. References _GLOBAL_DAZUKO_COMPAT1, ADD_EXCLUDE_PATH, dazuko_set_path(), and dazukoAddExcludePath_TS_compat1(). Referenced by dazukoAddExcludePath(). 00707 {
00708 #if !defined(NO_COMPAT1)
00709 if (_GLOBAL_DAZUKO_COMPAT1)
00710 return dazukoAddExcludePath_TS_compat1(dazuko_id, path);
00711 #endif
00712
00713 return dazuko_set_path(dazuko_id, path, ADD_EXCLUDE_PATH);
00714 }
|
|
|
Definition at line 686 of file dazukoio_core.c. References dazukoAddIncludePath_TS(). 00687 {
00688 return dazukoAddIncludePath_TS(_GLOBAL_DAZUKO, path);
00689 }
|
|
||||||||||||
|
Definition at line 691 of file dazukoio_core.c. References _GLOBAL_DAZUKO_COMPAT1, ADD_INCLUDE_PATH, dazuko_set_path(), and dazukoAddIncludePath_TS_compat1(). Referenced by dazukoAddIncludePath(). 00692 {
00693 #if !defined(NO_COMPAT1)
00694 if (_GLOBAL_DAZUKO_COMPAT1)
00695 return dazukoAddIncludePath_TS_compat1(dazuko_id, path);
00696 #endif
00697
00698 return dazuko_set_path(dazuko_id, path, ADD_INCLUDE_PATH);
00699 }
|
|
|
Definition at line 764 of file dazukoio_core.c. References dazukoGetAccess_TS(). 00765 {
00766 return dazukoGetAccess_TS(_GLOBAL_DAZUKO, acc);
00767 }
|
|
||||||||||||
|
Definition at line 769 of file dazukoio_core.c. References _GLOBAL_DAZUKO_COMPAT1, alloc_request(), dazuko_request::buffer, dazuko_request::buffer_size, DAZUKO_FILENAME_MAX_LENGTH, dazuko_get_value(), dazukoGetAccess_TS_compat1_wrapper(), dazukoReturnAccess_TS_compat1_wrapper(), dazuko_access::event, dazuko_access::file_device, dazuko_access::file_gid, dazuko_access::file_mode, dazuko_access::file_size, dazuko_access::file_uid, dazuko_access::filename, dazuko_access::flags, free_request(), GET_AN_ACCESS, dazuko_id::id, ITOA_SIZE, dazuko_access::mode, NULL, dazuko_access::pid, process_request(), dazuko_request::reply_buffer, dazuko_request::reply_buffer_size_used, dazuko_access::set_event, dazuko_access::set_file_device, dazuko_access::set_file_gid, dazuko_access::set_file_mode, dazuko_access::set_file_size, dazuko_access::set_file_uid, dazuko_access::set_filename, dazuko_access::set_flags, dazuko_access::set_mode, dazuko_access::set_pid, dazuko_access::set_uid, dazuko_access::uid, unescape_string(), and xp_verify_id(). Referenced by dazukoGetAccess(). 00770 {
00771 struct dazuko_request *request;
00772 struct dazuko_access *temp_acc;
00773 size_t size;
00774 size_t filename_size;
00775 char buffer[ITOA_SIZE];
00776 #if !defined(NO_COMPAT1)
00777 int compat1_ret;
00778 #endif
00779
00780 if (dazuko_id == NULL)
00781 return -1;
00782
00783 #if !defined(NO_COMPAT1)
00784 if (_GLOBAL_DAZUKO_COMPAT1)
00785 {
00786 compat1_ret = dazukoGetAccess_TS_compat1_wrapper(dazuko_id, acc);
00787
00788 if (compat1_ret == 0 && !(dazuko_id->write_mode))
00789 {
00790 /* we are in read_only mode so we return the access immediately */
00791
00792 dazukoReturnAccess_TS_compat1_wrapper(dazuko_id, acc, 1, 0);
00793
00794 /* this could be dangerous, we do not check if the return was successfull! */
00795 }
00796
00797 return compat1_ret;
00798 }
00799 #endif
00800
00801 if (dazuko_id->id < 0)
00802 return -1;
00803
00804 if (xp_verify_id(dazuko_id) != 0)
00805 return -1;
00806
00807 if (acc == NULL)
00808 return -1;
00809
00810 size = 1 + 2 + 1 + ITOA_SIZE /* \nID=id */
00811 + 1 /* \0 */
00812 ;
00813
00814 request = alloc_request(GET_AN_ACCESS, size,
00815 1 + 2 + 1 + DAZUKO_FILENAME_MAX_LENGTH /* \nFN=filename */
00816 + 1024 /* miscellaneous access attributes */
00817 + 1 /* \0 */
00818 );
00819 if (request == NULL)
00820 return -1;
00821
00822 snprintf(request->buffer, size, "\nID=%d", dazuko_id->id);
00823 request->buffer[size - 1] = 0;
00824 request->buffer_size = strlen(request->buffer) + 1;
00825
00826 temp_acc = (struct dazuko_access *)malloc(sizeof(struct dazuko_access));
00827 if (temp_acc == NULL)
00828 {
00829 free_request(&request);
00830 return -1;
00831 }
00832
00833 memset(temp_acc, 0, sizeof(struct dazuko_access));
00834
00835 filename_size = DAZUKO_FILENAME_MAX_LENGTH + 1;
00836 temp_acc->filename = (char *)malloc(filename_size);
00837 if (temp_acc->filename == NULL)
00838 {
00839 free(temp_acc);
00840 free_request(&request);
00841 return -1;
00842 }
00843
00844 if (process_request(dazuko_id, buffer, sizeof(buffer), request, 1) != 0)
00845 {
00846 free(temp_acc->filename);
00847 free(temp_acc);
00848 free_request(&request);
00849 return -1;
00850 }
00851
00852 if (request->reply_buffer_size_used > 0)
00853 {
00854 if (dazuko_get_value("\nFN=", request->reply_buffer, temp_acc->filename, filename_size) == 0)
00855 {
00856 temp_acc->set_filename = 1;
00857 unescape_string(temp_acc->filename);
00858 }
00859
00860 if (dazuko_get_value("\nEV=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00861 {
00862 temp_acc->event = atoi(buffer);
00863 temp_acc->set_event = 1;
00864 }
00865
00866 if (dazuko_get_value("\nFL=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00867 {
00868 temp_acc->flags = atoi(buffer);
00869 temp_acc->set_flags = 1;
00870 }
00871
00872 if (dazuko_get_value("\nMD=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00873 {
00874 temp_acc->mode = atoi(buffer);
00875 temp_acc->set_mode = 1;
00876 }
00877
00878 if (dazuko_get_value("\nUI=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00879 {
00880 temp_acc->uid = atoi(buffer);
00881 temp_acc->set_uid = 1;
00882 }
00883
00884 if (dazuko_get_value("\nPI=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00885 {
00886 temp_acc->pid = atoi(buffer);
00887 temp_acc->set_pid = 1;
00888 }
00889
00890 if (dazuko_get_value("\nFS=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00891 {
00892 temp_acc->file_size = atol(buffer);
00893 temp_acc->set_file_size = 1;
00894 }
00895
00896 if (dazuko_get_value("\nFU=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00897 {
00898 temp_acc->file_uid = atoi(buffer);
00899 temp_acc->set_file_uid = 1;
00900 }
00901
00902 if (dazuko_get_value("\nFG=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00903 {
00904 temp_acc->file_gid = atoi(buffer);
00905 temp_acc->set_file_gid = 1;
00906 }
00907
00908 if (dazuko_get_value("\nDT=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00909 {
00910 temp_acc->file_device = atoi(buffer);
00911 temp_acc->set_file_device = 1;
00912 }
00913
00914 if (dazuko_get_value("\nFM=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00915 {
00916 temp_acc->file_mode = atoi(buffer);
00917 temp_acc->set_file_mode = 1;
00918 }
00919 }
00920
00921 free_request(&request);
00922
00923 *acc = temp_acc;
00924
00925 return 0;
00926 }
|
|
|
Definition at line 1051 of file dazukoio_core.c. References dazukoInitializeCache_TS(). 01052 {
01053 return dazukoInitializeCache_TS(_GLOBAL_DAZUKO, cs);
01054 }
|
|
||||||||||||
|
Definition at line 1056 of file dazukoio_core.c. References _GLOBAL_DAZUKO_COMPAT1, alloc_request(), dazuko_request::buffer, dazuko_request::buffer_size, dazuko_get_value(), free_request(), dazuko_id::id, INITIALIZE_CACHE, ITOA_SIZE, NULL, process_request(), dazuko_request::reply_buffer, dazuko_request::reply_buffer_size_used, and xp_verify_id(). Referenced by dazukoInitializeCache(). 01057 {
01058 struct dazuko_request *request;
01059 size_t size;
01060 char buffer[ITOA_SIZE];
01061 int cache_available = 0;
01062
01063 if (dazuko_id == NULL)
01064 return -1;
01065
01066 #if !defined(NO_COMPAT1)
01067 if (_GLOBAL_DAZUKO_COMPAT1)
01068 return -1;
01069 #endif
01070
01071 if (dazuko_id->id < 0)
01072 return -1;
01073
01074 if (xp_verify_id(dazuko_id) != 0)
01075 return -1;
01076
01077 if (cs == NULL)
01078 return -1;
01079
01080 size = 1 + 2 + 1 + ITOA_SIZE /* \nID=id */
01081 + 1 + 2 + 1 + ITOA_SIZE /* \nCT=cachettl */
01082 + 1 /* \0 */
01083 ;
01084
01085 request = alloc_request(INITIALIZE_CACHE, size,
01086 1 + 2 + 1 + ITOA_SIZE /* \nCA=cacheavailable */
01087 + 1024 /* miscellaneous cache attributes */
01088 + 1 /* \0 */
01089 );
01090 if (request == NULL)
01091 return -1;
01092
01093 snprintf(request->buffer, size, "\nID=%d\nCT=%lu", dazuko_id->id, cs->ttl);
01094 request->buffer[size - 1] = 0;
01095 request->buffer_size = strlen(request->buffer) + 1;
01096
01097 if (process_request(dazuko_id, buffer, sizeof(buffer), request, 1) != 0)
01098 {
01099 free_request(&request);
01100 return -1;
01101 }
01102
01103 if (request->reply_buffer_size_used > 0)
01104 {
01105 if (dazuko_get_value("\nCA=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
01106 {
01107 cache_available = atoi(buffer);
01108 }
01109 }
01110
01111 free_request(&request);
01112
01113 if (cache_available)
01114 return 0;
01115
01116 return -1;
01117 }
|
|
|
Definition at line 240 of file dazukoio_core.c. References DAZUKO_VERSION_MAJOR, DAZUKO_VERSION_MINOR, DAZUKO_VERSION_RELEASE, DAZUKO_VERSION_REVISION, NULL, and VERSION_STRING. 00241 {
00242 if (version == NULL)
00243 return -1;
00244
00245 memset(version, 0, sizeof(struct dazuko_version));
00246
00247 version->major = atoi(DAZUKO_VERSION_MAJOR);
00248 version->minor = atoi(DAZUKO_VERSION_MINOR);
00249 version->revision = atoi(DAZUKO_VERSION_REVISION);
00250 version->release = atoi(DAZUKO_VERSION_RELEASE);
00251
00252 snprintf(version->text, sizeof(version->text), "%s", VERSION_STRING);
00253 version->text[sizeof(version->text) - 1] = 0;
00254
00255 return 0;
00256 }
|
|
||||||||||||
|
Definition at line 258 of file dazukoio_core.c. References dazukoRegister_TS(). 00259 {
00260 return dazukoRegister_TS(&_GLOBAL_DAZUKO, groupName, mode);
00261 }
|
|
||||||||||||||||
|
Definition at line 546 of file dazukoio_core.c. References _GLOBAL_DAZUKO_COMPAT1, _GLOBAL_WITH_DEVWRITE, _GLOBAL_WITH_REQSTREAM, and dazukoRegister_TS_inner(). Referenced by dazukoRegister(). 00547 {
00548 int rc;
00549
00550 /* prep: enable highest available mode */
00551 _GLOBAL_WITH_REQSTREAM = 1;
00552
00553 _GLOBAL_WITH_DEVWRITE = 0;
00554 #if !defined(NO_COMPAT1)
00555 _GLOBAL_DAZUKO_COMPAT1 = 0;
00556 #endif
00557
00558 /* try to register until success or methods are exhausted */
00559 while (1)
00560 {
00561 /* stop if we succeeded to register */
00562 rc = dazukoRegister_TS_inner(dazuko_id, groupName, mode);
00563 if (rc == 0)
00564 break;
00565
00566 /* try to fallback if possible */
00567
00568 if (_GLOBAL_WITH_REQSTREAM)
00569 {
00570 /* the "ra=" method failed, fallback to "RA=" */
00571
00572 _GLOBAL_WITH_REQSTREAM = 0;
00573 _GLOBAL_WITH_DEVWRITE = 1;
00574 continue;
00575 }
00576
00577 #if !defined(NO_COMPAT1)
00578 if (_GLOBAL_WITH_DEVWRITE)
00579 {
00580 /* the "RA=" method failed, fallback to compat1 */
00581
00582 _GLOBAL_WITH_DEVWRITE = 0;
00583 _GLOBAL_DAZUKO_COMPAT1 = 1;
00584 continue;
00585 }
00586 #endif
00587
00588 /* we ran out of alternatives, return with an error */
00589 break;
00590 }
00591
00592 return rc;
00593 }
|
|
||||||||||||||||
|
Definition at line 398 of file dazukoio_core.c. References _GLOBAL_DAZUKO_COMPAT1, _GLOBAL_WITH_DEVWRITE, _GLOBAL_WITH_REQSTREAM, alloc_request(), dazuko_request::buffer, dazuko_request::buffer_size, dazuko_get_value(), dazuko_set_version(), DAZUKO_SET_VERSION, dazukoRegister_TS_compat1_wrapper(), free_request(), ITOA_SIZE, NULL, process_request(), REGISTER, dazuko_request::reply_buffer, xp_connection_close(), and xp_connection_open(). Referenced by dazukoRegister_TS(). 00399 {
00400 struct dazuko_request *request;
00401 char buffer[ITOA_SIZE];
00402 char regMode[3];
00403 dazuko_id_t *temp_id;
00404 size_t size;
00405 int write_mode = 0;
00406 #if !defined(NO_COMPAT1)
00407 int compat1_ret;
00408 #endif
00409
00410 if (dazuko_id == NULL)
00411 return -1;
00412
00413 /* set default group name if one was not given */
00414 if (groupName == NULL)
00415 groupName = "_GENERIC";
00416
00417 /* set default mode if one was not given */
00418 if (mode == NULL)
00419 mode = "r";
00420
00421 if (strcasecmp(mode, "r") == 0)
00422 {
00423 strncpy(regMode, "R", sizeof(regMode));
00424 write_mode = 0;
00425 }
00426 else if (strcasecmp(mode, "r+") == 0 || strcasecmp(mode, "rw") == 0)
00427 {
00428 strncpy(regMode, "RW", sizeof(regMode));
00429 write_mode = 1;
00430 }
00431 else
00432 {
00433 return -1;
00434 }
00435 regMode[sizeof(regMode) - 1] = 0;
00436
00437 #if !defined(NO_COMPAT1)
00438 /* shortcut for the compat12 layer */
00439 if (_GLOBAL_DAZUKO_COMPAT1)
00440 {
00441 compat1_ret = dazukoRegister_TS_compat1_wrapper(dazuko_id, groupName);
00442
00443 if (compat1_ret == 0)
00444 {
00445 (*dazuko_id)->write_mode = write_mode;
00446
00447 DAZUKO_SET_VERSION(1, 0, 0, 0, "1.x");
00448 }
00449
00450 return compat1_ret;
00451 }
00452 /* fallthrough to the device writing path */
00453 #endif
00454
00455 /* create temporary id */
00456 temp_id = (dazuko_id_t *)malloc(sizeof(dazuko_id_t));
00457 if (temp_id == NULL)
00458 return -1;
00459
00460 memset(temp_id, 0, sizeof(dazuko_id_t));
00461
00462 /* open device */
00463 if (xp_connection_open(temp_id) != 0)
00464 {
00465 free(temp_id);
00466 return -1;
00467 }
00468
00469 /* allocate a request, fill in "RM=" and "GN=" */
00470 size = 1 + 2 + 1 + strlen(regMode) /* \nRM=mode */
00471 + 1 + 2 + 1 + strlen(groupName) /* \nGN=groupName */
00472 + 1 /* \0 */
00473 ;
00474
00475 request = alloc_request(REGISTER, size, 4096);
00476 if (request == NULL)
00477 {
00478 xp_connection_close(temp_id);
00479 free(temp_id);
00480 return -1;
00481 }
00482
00483 snprintf(request->buffer, size, "\nRM=%s\nGN=%s", regMode, groupName);
00484 request->buffer[size - 1] = 0;
00485 request->buffer_size = strlen(request->buffer) + 1;
00486
00487 if (process_request(temp_id, buffer, sizeof(buffer), request, 1) != 0)
00488 {
00489 xp_connection_close(temp_id);
00490 free(temp_id);
00491 free_request(&request);
00492
00493 return -1;
00494 }
00495
00496 if (dazuko_get_value("\nID=", request->reply_buffer, buffer, sizeof(buffer)) != 0)
00497 {
00498 xp_connection_close(temp_id);
00499 free(temp_id);
00500 free_request(&request);
00501
00502 return -1;
00503 }
00504
00505 temp_id->id = atoi(buffer);
00506
00507 if (temp_id->id < 0)
00508 {
00509 xp_connection_close(temp_id);
00510 free(temp_id);
00511 free_request(&request);
00512
00513 return -1;
00514 }
00515
00516 temp_id->write_mode = write_mode;
00517
00518 if (_GLOBAL_WITH_REQSTREAM)
00519 {
00520 dazuko_set_version(request->reply_buffer);
00521 }
00522 else if (_GLOBAL_WITH_DEVWRITE)
00523 {
00524 DAZUKO_SET_VERSION(2, 0, 0, 0, "2.0.x");
00525 }
00526
00527 free_request(&request);
00528
00529 *dazuko_id = temp_id;
00530
00531 return 0;
00532 }
|
|
|
Definition at line 716 of file dazukoio_core.c. References dazukoRemoveAllPaths_TS(). 00717 {
00718 return dazukoRemoveAllPaths_TS(_GLOBAL_DAZUKO);
00719 }
|
|
|
Definition at line 721 of file dazukoio_core.c. References _GLOBAL_DAZUKO_COMPAT1, alloc_request(), dazuko_request::buffer, dazuko_request::buffer_size, dazukoRemoveAllPaths_TS_compat1(), free_request(), ITOA_SIZE, NULL, process_request(), REMOVE_ALL_PATHS, and xp_verify_id(). Referenced by dazukoRemoveAllPaths(). 00722 {
00723 struct dazuko_request *request;
00724 size_t size;
00725 char buffer[ITOA_SIZE];
00726
00727 if (dazuko_id == NULL)
00728 return -1;
00729
00730 #if !defined(NO_COMPAT1)
00731 if (_GLOBAL_DAZUKO_COMPAT1)
00732 return dazukoRemoveAllPaths_TS_compat1(dazuko_id);
00733 #endif
00734
00735 if (dazuko_id->id < 0)
00736 return -1;
00737
00738 if (xp_verify_id(dazuko_id) != 0)
00739 return -1;
00740
00741 size = 1 + 2 + 1 + ITOA_SIZE /* \nID=id */
00742 + 1 /* \0 */
00743 ;
00744
00745 request = alloc_request(REMOVE_ALL_PATHS, size, 0);
00746 if (request == NULL)
00747 return -1;
00748
00749 snprintf(request->buffer, size, "\nID=%d", dazuko_id->id);
00750 request->buffer[size - 1] = 0;
00751 request->buffer_size = strlen(request->buffer) + 1;
00752
00753 if (process_request(dazuko_id, buffer, sizeof(buffer), request, 0) != 0)
00754 {
00755 free_request(&request);
00756 return -1;
00757 }
00758
00759 free_request(&request);
00760
00761 return 0;
00762 }
|
|
|
Definition at line 1119 of file dazukoio_core.c. References dazukoRemoveAllTrusted_TS(). 01120 {
01121 return dazukoRemoveAllTrusted_TS(_GLOBAL_DAZUKO);
01122 }
|
|
|
Definition at line 1124 of file dazukoio_core.c. References _GLOBAL_DAZUKO_COMPAT1, alloc_request(), dazuko_request::buffer, dazuko_request::buffer_size, free_request(), dazuko_id::id, ITOA_SIZE, NULL, process_request(), REMOVE_ALL_TRUSTED, and xp_verify_id(). Referenced by dazukoRemoveAllTrusted(). 01125 {
01126 struct dazuko_request *request;
01127 size_t size;
01128 char buffer[ITOA_SIZE];
01129
01130 if (dazuko_id == NULL)
01131 return -1;
01132
01133 #if !defined(NO_COMPAT1)
01134 if (_GLOBAL_DAZUKO_COMPAT1)
01135 return -1;
01136 #endif
01137
01138 if (dazuko_id->id < 0)
01139 return -1;
01140
01141 if (xp_verify_id(dazuko_id) != 0)
01142 return -1;
01143
01144 size = 1 + 2 + 1 + ITOA_SIZE /* \nID=id */
01145 + 1 /* \0 */
01146 ;
01147
01148 request = alloc_request(REMOVE_ALL_TRUSTED, size, 0);
01149 if (request == NULL)
01150 return -1;
01151
01152 snprintf(request->buffer, size, "\nID=%d", dazuko_id->id);
01153 request->buffer[size - 1] = 0;
01154 request->buffer_size = strlen(request->buffer) + 1;
01155
01156 if (process_request(dazuko_id, buffer, sizeof(buffer), request, 0) != 0)
01157 {
01158 free_request(&request);
01159 return -1;
01160 }
01161
01162 free_request(&request);
01163
01164 return 0;
01165 }
|
|
|
Definition at line 1167 of file dazukoio_core.c. References dazukoRemoveTrusted_TS(). 01168 {
01169 return dazukoRemoveTrusted_TS(_GLOBAL_DAZUKO, token);
01170 }
|
|
||||||||||||
|
Definition at line 1172 of file dazukoio_core.c. References _GLOBAL_DAZUKO_COMPAT1, alloc_request(), dazuko_request::buffer, dazuko_request::buffer_size, free_request(), dazuko_id::id, ITOA_SIZE, NULL, process_request(), REMOVE_TRUSTED, and xp_verify_id(). Referenced by dazukoRemoveTrusted(). 01173 {
01174 struct dazuko_request *request;
01175 size_t size;
01176 char buffer[ITOA_SIZE];
01177
01178 if (dazuko_id == NULL || token == NULL)
01179 return -1;
01180
01181 #if !defined(NO_COMPAT1)
01182 if (_GLOBAL_DAZUKO_COMPAT1)
01183 return -1;
01184 #endif
01185
01186 if (dazuko_id->id < 0)
01187 return -1;
01188
01189 if (xp_verify_id(dazuko_id) != 0)
01190 return -1;
01191
01192 size = 1 + 2 + 1 + ITOA_SIZE /* \nID=id */
01193 + 1 + 2 + 1 + strlen(token) /* \nTT=token */
01194 + 1 /* \0 */
01195 ;
01196
01197 request = alloc_request(REMOVE_TRUSTED, size, 0);
01198 if (request == NULL)
01199 return -1;
01200
01201 snprintf(request->buffer, size, "\nID=%d\nTT=%s", dazuko_id->id, token);
01202 request->buffer[size - 1] = 0;
01203 request->buffer_size = strlen(request->buffer) + 1;
01204
01205 if (process_request(dazuko_id, buffer, sizeof(buffer), request, 0) != 0)
01206 {
01207 free_request(&request);
01208 return -1;
01209 }
01210
01211 free_request(&request);
01212
01213 return 0;
01214 }
|
|
|
Definition at line 928 of file dazukoio_core.c. References dazukoReturnAccess_TS(). 00929 {
00930 return dazukoReturnAccess_TS(_GLOBAL_DAZUKO, acc);
00931 }
|
|
||||||||||||
|
Definition at line 933 of file dazukoio_core.c. References _GLOBAL_DAZUKO_COMPAT1, alloc_request(), dazuko_request::buffer, dazuko_request::buffer_size, dazukoReturnAccess_TS_compat1_wrapper(), free_request(), ITOA_SIZE, NULL, process_request(), RETURN_AN_ACCESS, and xp_verify_id(). Referenced by dazukoReturnAccess(). 00934 {
00935 struct dazuko_request *request;
00936 size_t size;
00937 char buffer[ITOA_SIZE];
00938
00939 if (dazuko_id == NULL)
00940 return -1;
00941
00942 #if !defined(NO_COMPAT1)
00943 if (_GLOBAL_DAZUKO_COMPAT1)
00944 return dazukoReturnAccess_TS_compat1_wrapper(dazuko_id, acc, dazuko_id->write_mode, 1);
00945 #endif
00946
00947 if (dazuko_id->id < 0)
00948 return -1;
00949
00950 if (xp_verify_id(dazuko_id) != 0)
00951 return -1;
00952
00953 if (acc == NULL)
00954 return -1;
00955
00956 if (*acc == NULL)
00957 return -1;
00958
00959 if (dazuko_id->write_mode)
00960 {
00961 size = 1 + 2 + 1 + ITOA_SIZE /* \nID=id */
00962 + 1 + 2 + 1 + ITOA_SIZE /* \nDN=deny */
00963 + 1 /* \0 */
00964 ;
00965
00966 request = alloc_request(RETURN_AN_ACCESS, size, 0);
00967 if (request == NULL)
00968 return -1;
00969
00970 snprintf(request->buffer, size, "\nID=%d\nDN=%d", dazuko_id->id, (*acc)->deny == 0 ? 0 : 1);
00971 request->buffer[size - 1] = 0;
00972 request->buffer_size = strlen(request->buffer) + 1;
00973
00974 if (process_request(dazuko_id, buffer, sizeof(buffer), request, 0) != 0)
00975 {
00976 /* there could be big problems if this happens */
00977
00978 if ((*acc)->filename != NULL)
00979 free((*acc)->filename);
00980 free(*acc);
00981 *acc = NULL;
00982 free_request(&request);
00983 return -1;
00984 }
00985
00986 free_request(&request);
00987 }
00988
00989 if ((*acc)->filename != NULL)
00990 free((*acc)->filename);
00991 free(*acc);
00992 *acc = NULL;
00993
00994 return 0;
00995 }
|
|
|
Definition at line 595 of file dazukoio_core.c. References dazukoSetAccessMask_TS(). 00596 {
00597 return dazukoSetAccessMask_TS(_GLOBAL_DAZUKO, accessMask);
00598 }
|
|
||||||||||||
|
Definition at line 600 of file dazukoio_core.c. References _GLOBAL_DAZUKO_COMPAT1, alloc_request(), dazuko_request::buffer, dazuko_request::buffer_size, dazukoSetAccessMask_TS_compat1(), free_request(), ITOA_SIZE, NULL, process_request(), SET_ACCESS_MASK, and xp_verify_id(). Referenced by dazukoSetAccessMask(). 00601 {
00602 struct dazuko_request *request;
00603 size_t size;
00604 char buffer[ITOA_SIZE];
00605
00606 if (dazuko_id == NULL)
00607 return -1;
00608
00609 #if !defined(NO_COMPAT1)
00610 if (_GLOBAL_DAZUKO_COMPAT1)
00611 return dazukoSetAccessMask_TS_compat1(dazuko_id, accessMask);
00612 #endif
00613
00614 if (dazuko_id->id < 0)
00615 return -1;
00616
00617 if (xp_verify_id(dazuko_id) != 0)
00618 return -1;
00619
00620 size = 1 + 2 + 1 + ITOA_SIZE /* \nID=id */
00621 + 1 + 2 + 1 + ITOA_SIZE /* \nAM=accessMask */
00622 + 1 /* \0 */
00623 ;
00624
00625 request = alloc_request(SET_ACCESS_MASK, size, 0);
00626 if (request == NULL)
00627 return -1;
00628
00629 snprintf(request->buffer, size, "\nID=%d\nAM=%lu", dazuko_id->id, accessMask);
00630 request->buffer[size - 1] = 0;
00631 request->buffer_size = strlen(request->buffer) + 1;
00632
00633 if (process_request(dazuko_id, buffer, sizeof(buffer), request, 0) != 0)
00634 {
00635 free_request(&request);
00636 return -1;
00637 }
00638
00639 free_request(&request);
00640
00641 return 0;
00642 }
|
|
|
Definition at line 997 of file dazukoio_core.c. References dazukoUnregister_TS(). 00998 {
00999 return dazukoUnregister_TS(&_GLOBAL_DAZUKO);
01000 }
|
|
|
Definition at line 1002 of file dazukoio_core.c. References _GLOBAL_DAZUKO_COMPAT1, alloc_request(), dazuko_request::buffer, dazuko_request::buffer_size, dazukoUnregister_TS_compat1_wrapper(), free_request(), ITOA_SIZE, NULL, process_request(), UNREGISTER, xp_connection_close(), and xp_verify_id(). Referenced by dazukoUnregister(). 01003 {
01004 struct dazuko_request *request;
01005 size_t size;
01006 char buffer[ITOA_SIZE];
01007 int error = 0;
01008
01009 if (dazuko_id == NULL)
01010 return -1;
01011
01012 #if !defined(NO_COMPAT1)
01013 if (_GLOBAL_DAZUKO_COMPAT1)
01014 return dazukoUnregister_TS_compat1_wrapper(dazuko_id);
01015 #endif
01016
01017 if (*dazuko_id == NULL)
01018 return -1;
01019
01020 if (xp_verify_id(*dazuko_id) == 0)
01021 {
01022 size = 1 + 2 + 1 + ITOA_SIZE /* \nID=id */
01023 + 1 /* \0 */
01024 ;
01025
01026 request = alloc_request(UNREGISTER, size, 0);
01027 if (request == NULL)
01028 return -1;
01029
01030 snprintf(request->buffer, size, "\nID=%d", (*dazuko_id)->id);
01031 request->buffer[size - 1] = 0;
01032 request->buffer_size = strlen(request->buffer) + 1;
01033
01034 if (process_request(*dazuko_id, buffer, sizeof(buffer), request, 0) != 0)
01035 {
01036 /* there could be big problems if this happens */
01037
01038 error = -1;
01039 }
01040
01041 free_request(&request);
01042 }
01043
01044 xp_connection_close(*dazuko_id);
01045 free(*dazuko_id);
01046 *dazuko_id = NULL;
01047
01048 return error;
01049 }
|
|
|
Definition at line 227 of file dazukoio_core.c. References _DAZUKO_VERSION, _SET_DAZUKO_VERSION, and NULL. 00228 {
00229 if (version == NULL)
00230 return -1;
00231
00232 if (!_SET_DAZUKO_VERSION)
00233 return -1;
00234
00235 memcpy(version, &_DAZUKO_VERSION, sizeof(struct dazuko_version));
00236
00237 return 0;
00238 }
|
|
|
Definition at line 204 of file dazukoio_core.c. References dazuko_request::buffer, NULL, and dazuko_request::reply_buffer. Referenced by dazuko_set_path(), dazukoGetAccess_TS(), dazukoInitializeCache_TS(), dazukoRegister_TS_inner(), dazukoRemoveAllPaths_TS(), dazukoRemoveAllTrusted_TS(), dazukoRemoveTrusted_TS(), dazukoReturnAccess_TS(), dazukoSetAccessMask_TS(), and dazukoUnregister_TS(). 00205 {
00206 struct dazuko_request *request;
00207
00208 if (request_ref == NULL)
00209 return;
00210
00211 request = *request_ref;
00212
00213 if (request == NULL)
00214 return;
00215
00216 if (request->buffer != NULL)
00217 free(request->buffer);
00218
00219 if (request->reply_buffer != NULL)
00220 free(request->reply_buffer);
00221
00222 free(request);
00223
00224 *request_ref = NULL;
00225 }
|
|
||||||||||||||||||||||||
|
Definition at line 263 of file dazukoio_core.c. References _GLOBAL_WITH_DEVWRITE, _GLOBAL_WITH_REQSTREAM, dazuko_reqstream_dim_chunk0(), dazuko_reqstream_hl2ll(), dazuko_reqstream_ll2hl(), NULL, and xp_process_request(). Referenced by dazuko_set_path(), dazukoGetAccess_TS(), dazukoInitializeCache_TS(), dazukoRegister_TS_inner(), dazukoRemoveAllPaths_TS(), dazukoRemoveAllTrusted_TS(), dazukoRemoveTrusted_TS(), dazukoReturnAccess_TS(), dazukoSetAccessMask_TS(), and dazukoUnregister_TS(). 00264 {
00265 unsigned char *llreq = NULL;
00266 int error = 0;
00267 size_t size;
00268
00269 if (_GLOBAL_WITH_REQSTREAM)
00270 {
00271 /* we add an extra 4 bytes as "size of chunk 1" */
00272 size = dazuko_reqstream_dim_chunk0(sizeof(char), sizeof(int), sizeof(void *)) + 4;
00273
00274 llreq = (unsigned char *)malloc(size);
00275 if (llreq == NULL)
00276 return -1;
00277
00278 /* this is especially important for the last 4 bytes */
00279 memset(llreq, 0, size);
00280
00281 if (dazuko_reqstream_hl2ll(request, llreq) != 0)
00282 {
00283 free(llreq);
00284 return -1;
00285 }
00286 snprintf(buffer, buffer_size, "\nra=%lu", (unsigned long)llreq);
00287 }
00288 else if (_GLOBAL_WITH_DEVWRITE)
00289 {
00290 snprintf(buffer, buffer_size, "\nRA=%lu", (unsigned long)request);
00291 }
00292 else
00293 {
00294 /* why are we here? */
00295
00296 return -1;
00297 }
00298
00299 buffer[buffer_size - 1] = 0;
00300
00301 error = xp_process_request(id, buffer, strlen(buffer) + 1);
00302
00303 if (reply_required && !error && _GLOBAL_WITH_REQSTREAM)
00304 {
00305 if (dazuko_reqstream_ll2hl(llreq, request, 1) != 0)
00306 {
00307 /* this could be dangerous if it happens */
00308 error = -1;
00309 }
00310 }
00311
00312 if (llreq != NULL)
00313 free(llreq);
00314
00315 return error;
00316 }
|
|
|
Definition at line 100 of file dazukoio_core.c. References char_to_hex(). Referenced by dazukoGetAccess_TS(). 00101 {
00102 char *p;
00103
00104 for (p=string ; *p ; p++)
00105 {
00106 /* check if we have \x */
00107 if ((*p == '\\') && (*(p+1) == 'x'))
00108 {
00109 /* this is not cheap, but it should not occur often */
00110
00111 /* check if we have two more values following \x */
00112 if (*(p+2) && *(p+3))
00113 {
00114 *p = char_to_hex(*(p+2));
00115 *p <<= 4;
00116 *p |= char_to_hex(*(p+3));
00117
00118 memmove(p + 1, p + 4, strlen(p+4) + 1);
00119 }
00120 }
00121 }
00122 }
|
|
|
Definition at line 71 of file dazukoio_core.c. Referenced by dazukoVersion(). |
|
|
Definition at line 61 of file dazukoio_core.c. |
|
|
|
Definition at line 68 of file dazukoio_core.c. Referenced by dazukoRegister_TS(), dazukoRegister_TS_inner(), and process_request(). |
|
|
Definition at line 67 of file dazukoio_core.c. Referenced by dazukoRegister_TS(), dazukoRegister_TS_inner(), and process_request(). |
|
|
Definition at line 70 of file dazukoio_core.c. Referenced by dazukoVersion(). |
|
|
Definition at line 48 of file dazukoio_core.c. |
|
|
Initial value: DAZUKO_VERSION_MAJOR "." DAZUKO_VERSION_MINOR "." DAZUKO_VERSION_REVISION "-pre" DAZUKO_VERSION_RELEASE Definition at line 51 of file dazukoio_core.c. |
1.4.2