]>
git.saurik.com Git - cycript.git/blob - Connector.cpp
7 #include <sys/socket.h>
8 #include <netinet/in.h>
11 #include <apr-1/apr_thread_proc.h>
16 #import <CoreFoundation/CFLogUtilities.h>
24 apr_status_t
CYPoolDLClose_(void *data
) {
25 void *handle(reinterpret_cast<void *>(data
));
30 static void * APR_THREAD_FUNC
Cyrver(apr_thread_t
*thread
, void *data
) {
31 CYServer
*server(reinterpret_cast<CYServer
*>(data
));
34 int socket(_syscall(accept(server
->socket_
, NULL
, NULL
)));
36 if (void *handle
= dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY
| RTLD_LOCAL
)) {
38 _aprcall(apr_pool_create(&pool
, NULL
));
40 apr_pool_cleanup_register(pool
, handle
, &CYPoolDLClose_
, &apr_pool_cleanup_null
);
42 if (void (*CYHandleClient_
)(apr_pool_t
*, int) = reinterpret_cast<void (*)(apr_pool_t
*, int)>(dlsym(handle
, "CYHandleClient")))
43 (*CYHandleClient_
)(pool
, socket
);
45 apr_pool_destroy(pool
);
47 CFLog(kCFLogLevelError
, CFSTR("CY:Error: cannot load: %s"), dlerror());
54 static void Unlink() {
57 sprintf(path
, "/tmp/.s.cy.%u", pid
);
62 _aprcall(apr_initialize());
64 CYServer
*server(new CYServer());
65 server
->socket_
= _syscall(socket(PF_UNIX
, SOCK_STREAM
, 0));
67 struct sockaddr_un address
;
68 memset(&address
, 0, sizeof(address
));
69 address
.sun_family
= AF_UNIX
;
72 sprintf(address
.sun_path
, "/tmp/.s.cy.%u", pid
);
75 _syscall(bind(server
->socket_
, reinterpret_cast<sockaddr
*>(&address
), SUN_LEN(&address
)));
77 _syscall(listen(server
->socket_
, 0));
79 apr_threadattr_t
*attr
;
80 _aprcall(apr_threadattr_create(&attr
, server
->pool_
));
83 _aprcall(apr_thread_create(&thread
, attr
, &Cyrver
, server
, server
->pool_
));
85 CFLog(kCFLogLevelError
, CFSTR("CY:Error: cannot bind unix domain socket"));