"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "SOPE/mod_ngobjweb/sns.c" between
opengroupware-5.5rc2.tar.gz and opengroupware-5.5rc3.tar.gz

About: OpenGroupware is a branch of the "traditional" OpenGroupware collaboration system (developed in Objective-C on SOPE). Release candidate.

sns.c  (opengroupware-5.5rc2):sns.c  (opengroupware-5.5rc3)
skipping to change at line 35 skipping to change at line 35
extern int HEAVY_LOG; extern int HEAVY_LOG;
//#define HTTP_DETAIL_LOG 1 //#define HTTP_DETAIL_LOG 1
#define SNS_HTTP_METHOD "POST" #define SNS_HTTP_METHOD "POST"
#define SNS_LOOKUP_URL "/snsd2/wa/lookupSession" #define SNS_LOOKUP_URL "/snsd2/wa/lookupSession"
#define SNS_REQLINE "reqline" #define SNS_REQLINE "reqline"
#define SNS_APPNAME "appname" #define SNS_APPNAME "appname"
#define SNS_COOKIES "cookies" #define SNS_COOKIES "cookies"
static inline int _isPlistBreakChar(unsigned char c) #ifdef APLOG_USE_MODULE
{ APLOG_USE_MODULE(ngobjweb);
if (!apr_isalnum(c)) return 1; #endif
switch (c) {
case '_': case '@': case '#': case '$':
case '.': case '=': case ';': case ',':
case '{': case '}': case '(': case ')':
case '<': case '>': case '/': case '\\':
case '"':
return 1;
default:
return 0;
}
}
static void _getSNSAddressForRequest(request_rec *_rq, struct sockaddr **_sns, static void _getSNSAddressForRequest(request_rec *_rq, struct sockaddr **_sns,
ngobjweb_dir_config *_cfg) ngobjweb_dir_config *_cfg)
{ {
//extern struct sockaddr *sns; //extern struct sockaddr *sns;
struct sockaddr *result = NULL; //sns; struct sockaddr *result = NULL; //sns;
const char *socket; const char *socket;
*_sns = NULL; *_sns = NULL;
if (_rq == NULL) { if (_rq == NULL) {
fprintf(stderr, "%s: missing request ...\n", __PRETTY_FUNCTION__); fprintf(stderr, "%s: missing request ...\n", __PRETTY_FUNCTION__);
return; return;
} }
if (_cfg == NULL) { if (_cfg == NULL) {
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_ERR, 0, _rq->server,
"SNS: missing directory config for request .."); "SNS: missing directory config for request ..");
return; return;
} }
if ((socket = _cfg->snsPort)) { if ((socket = _cfg->snsPort)) {
long int port; long int port;
char *end, *pos; char *end, *pos;
if (_cfg->snsPortDomain == AF_UNIX) { if (_cfg->snsPortDomain == AF_UNIX) {
result = apr_palloc(_rq->pool, sizeof(struct sockaddr_un)); result = apr_palloc(_rq->pool, sizeof(struct sockaddr_un));
skipping to change at line 112 skipping to change at line 99
result = apr_palloc(_rq->pool, sizeof(struct sockaddr_in)); result = apr_palloc(_rq->pool, sizeof(struct sockaddr_in));
memset(result, 0, sizeof(struct sockaddr_in)); memset(result, 0, sizeof(struct sockaddr_in));
snsi = (struct sockaddr_in *)result; snsi = (struct sockaddr_in *)result;
snsi->sin_addr.s_addr = apr_inet_addr((char *)host); snsi->sin_addr.s_addr = apr_inet_addr((char *)host);
snsi->sin_family = AF_INET; snsi->sin_family = AF_INET;
snsi->sin_port = htons((short)(port & 0xFFFF)); snsi->sin_port = htons((short)(port & 0xFFFF));
if (snsi->sin_addr.s_addr == -1) { if (snsi->sin_addr.s_addr == -1) {
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_ERR, 0, _rq->server,
"SNS: couldn't convert snsd IP address: %s", host); "SNS: couldn't convert snsd IP address: %s", host);
} }
if (HEAVY_LOG && 0) { if (HEAVY_LOG && 0) {
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_ERR, 0, _rq->server,
"SNS: connect IP address: %s", host); "SNS: connect IP address: %s", host);
} }
} }
else { else {
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_ERR, 0, _rq->server,
"SNS: unknown socket domain %i for SNS server " "SNS: unknown socket domain %i for SNS server "
"(address=%s) !!!", "(address=%s) !!!",
_cfg->snsPortDomain, _cfg->snsPort); _cfg->snsPortDomain, _cfg->snsPort);
} }
} }
*_sns = result; *_sns = result;
} }
static void _logSNSConnect(request_rec *_rq, struct sockaddr *sns) { static void _logSNSConnect(request_rec *_rq, struct sockaddr *sns) {
if (sns == NULL) { if (sns == NULL) {
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_INFO, 0, _rq->server,
"found no SNS socket address ..."); "found no SNS socket address ...");
return; return;
} }
if (sns->sa_family == AF_INET) { if (sns->sa_family == AF_INET) {
struct sockaddr_in *snsi = (struct sockaddr_in *)sns; struct sockaddr_in *snsi = (struct sockaddr_in *)sns;
if (HEAVY_LOG) { if (HEAVY_LOG) {
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_INFO, 0, _rq->server,
"SNS: connecting INET socket (family=%d, ip=%s:%i) ...", "SNS: connecting INET socket (family=%d, ip=%s:%i) ...",
sns->sa_family, sns->sa_family,
inet_ntoa(snsi->sin_addr), inet_ntoa(snsi->sin_addr),
ntohs(snsi->sin_port)); ntohs(snsi->sin_port));
} }
} }
else if (sns->sa_family == AF_UNIX) { else if (sns->sa_family == AF_UNIX) {
if (HEAVY_LOG) { if (HEAVY_LOG) {
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_INFO, 0, _rq->server,
"SNS: connect UNIX socket (family=%d) ...", "SNS: connect UNIX socket (family=%d) ...",
sns->sa_family); sns->sa_family);
} }
} }
else { else {
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_ERR, 0, _rq->server,
"SNS: unknown socket address family: %d.", "SNS: unknown socket address family: %d.",
sns->sa_family); sns->sa_family);
} }
} }
void *_sendSNSQuery(request_rec *_rq, const char *_line, void *_sendSNSQuery(request_rec *_rq, const char *_line,
const char *_cookie, const char *_cookie,
int *_domain, size_t *_len, int *_domain, size_t *_len,
const char *_appName, const char *_appName,
ngobjweb_dir_config *_cfg) ngobjweb_dir_config *_cfg)
skipping to change at line 194 skipping to change at line 181
if (_line == NULL) _line = ""; if (_line == NULL) _line = "";
if (_cookie == NULL) _cookie = ""; if (_cookie == NULL) _cookie = "";
/* setup connection */ /* setup connection */
{ {
_logSNSConnect(_rq, sns); _logSNSConnect(_rq, sns);
fd = socket(sns->sa_family, SOCK_STREAM, 0); fd = socket(sns->sa_family, SOCK_STREAM, 0);
if (fd < 0) { if (fd < 0) {
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_ERR, 0, _rq->server,
"SNS: could not setup socket to SNS: %s.", "SNS: could not setup socket to SNS: %s.",
strerror(errno)); strerror(errno));
return NULL; return NULL;
} }
if (connect(fd, sns, if (connect(fd, sns,
(sns->sa_family == AF_INET) (sns->sa_family == AF_INET)
? sizeof(struct sockaddr_in) ? sizeof(struct sockaddr_in)
: sizeof(struct sockaddr_un)) != 0) { : sizeof(struct sockaddr_un)) != 0) {
if (HEAVY_LOG) { if (HEAVY_LOG) {
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_ERR, 0, _rq->server,
"could not connect sns daemon %s: %s.", "could not connect sns daemon %s: %s.",
sns->sa_family == AF_UNIX sns->sa_family == AF_UNIX
? ((struct sockaddr_un *)sns)->sun_path ? ((struct sockaddr_un *)sns)->sun_path
: "via ip", : "via ip",
strerror(errno)); strerror(errno));
} }
close(fd); close(fd);
return NULL; return NULL;
} }
toSNS = NGBufferedDescriptor_newWithOwnedDescriptorAndSize(fd, 1024); toSNS = NGBufferedDescriptor_newWithOwnedDescriptorAndSize(fd, 1024);
if (toSNS == NULL) { if (toSNS == NULL) {
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_ERR, 0, _rq->server,
"could not allocate buffered descriptor."); "could not allocate buffered descriptor.");
close(fd); close(fd);
return NULL; return NULL;
} }
} }
/* send request */ /* send request */
{ {
char c = 50; // SNSLookupSession char c = 50; // SNSLookupSession
int len = strlen(_line); int len = strlen(_line);
if (HEAVY_LOG) { if (HEAVY_LOG) {
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_INFO, 0, _rq->server,
"SNS: line %s cookie '%s'", _line, _cookie); "SNS: line %s cookie '%s'", _line, _cookie);
} }
/* send message code */ /* send message code */
if (!NGBufferedDescriptor_safeWrite(toSNS, &c, 1)) { if (!NGBufferedDescriptor_safeWrite(toSNS, &c, 1)) {
failed = 1; failed = 1;
goto finish; goto finish;
} }
/* send request line + space + appname */ /* send request line + space + appname */
skipping to change at line 268 skipping to change at line 255
if ((len = strlen(_appName)) > 0) { if ((len = strlen(_appName)) > 0) {
if (!NGBufferedDescriptor_safeWrite(toSNS, _appName, len)) { if (!NGBufferedDescriptor_safeWrite(toSNS, _appName, len)) {
failed = 5; failed = 5;
goto finish; goto finish;
} }
} }
// send cookie // send cookie
len = strlen(_cookie); len = strlen(_cookie);
if (len > 2000) { if (len > 2000) {
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_INFO, 0, _rq->server,
"WARNING: cookie length > 2000 bytes (%i bytes): %s", "WARNING: cookie length > 2000 bytes (%i bytes): %s",
len, _cookie); len, _cookie);
} }
if (!NGBufferedDescriptor_safeWrite(toSNS, &len, sizeof(len))) { if (!NGBufferedDescriptor_safeWrite(toSNS, &len, sizeof(len))) {
failed = 6; failed = 6;
goto finish; goto finish;
} }
if (len > 0) { if (len > 0) {
if (!NGBufferedDescriptor_safeWrite(toSNS, _cookie, len)) { if (!NGBufferedDescriptor_safeWrite(toSNS, _cookie, len)) {
failed = 7; failed = 7;
goto finish; goto finish;
} }
} }
if (!NGBufferedDescriptor_flush(toSNS)) { if (!NGBufferedDescriptor_flush(toSNS)) {
failed = 8; failed = 8;
goto finish; goto finish;
} }
if (HEAVY_LOG) { if (HEAVY_LOG) {
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_INFO, 0, _rq->server,
"SNS: reading response .."); "SNS: reading response ..");
} }
// recv response // recv response
{ {
char *buffer; char *buffer;
int domain; int domain;
int size; int size;
buffer = apr_palloc(_rq->pool, 1000); buffer = apr_palloc(_rq->pool, 1000);
memset(buffer, 0, 1000); memset(buffer, 0, 1000);
if (!NGBufferedDescriptor_safeRead(toSNS, &domain, sizeof(domain))) { if (!NGBufferedDescriptor_safeRead(toSNS, &domain, sizeof(domain))) {
failed = 9; failed = 9;
goto finish; goto finish;
} }
if (HEAVY_LOG) { if (HEAVY_LOG) {
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_INFO, 0, _rq->server,
"SNS: domain: %i ..", domain); "SNS: domain: %i ..", domain);
} }
if (!NGBufferedDescriptor_safeRead(toSNS, &size, sizeof(size))) { if (!NGBufferedDescriptor_safeRead(toSNS, &size, sizeof(size))) {
failed = 10; failed = 10;
goto finish; goto finish;
} }
if (HEAVY_LOG) { if (HEAVY_LOG) {
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_INFO, 0, _rq->server,
"SNS: size: %i ..", size); "SNS: size: %i ..", size);
} }
if (size > 1024) { if (size > 1024) {
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_ERR, 0, _rq->server,
"SNS: size of returned address is too big (%i bytes) !", "SNS: size of returned address is too big (%i bytes) !",
size); size);
goto finish; goto finish;
} }
if (!NGBufferedDescriptor_safeRead(toSNS, buffer, size)) { if (!NGBufferedDescriptor_safeRead(toSNS, buffer, size)) {
failed = 11; failed = 11;
goto finish; goto finish;
} }
if (HEAVY_LOG) { if (HEAVY_LOG) {
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_INFO, 0, _rq->server,
"SNS: got address in domain %i, size is %i bytes !", "SNS: got address in domain %i, size is %i bytes !",
domain, size); domain, size);
} }
*_domain = domain; *_domain = domain;
*_len = size; *_len = size;
if (toSNS) { if (toSNS) {
NGBufferedDescriptor_free(toSNS); NGBufferedDescriptor_free(toSNS);
toSNS = NULL; toSNS = NULL;
} }
return buffer; return buffer;
} }
finish: finish:
if (failed) { if (failed) {
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, _rq->server, ap_log_error(APLOG_MARK, APLOG_ERR, 0, _rq->server,
"SNS: lookup request failed (code=%i) !", failed); "SNS: lookup request failed (code=%i) !", failed);
} }
if (toSNS) { if (toSNS) {
NGBufferedDescriptor_free(toSNS); NGBufferedDescriptor_free(toSNS);
toSNS = NULL; toSNS = NULL;
} }
} }
return NULL; return NULL;
} }
 End of changes. 20 change blocks. 
35 lines changed or deleted 22 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS