2003-12-05 08:57:32 -08:00
|
|
|
/* by Azundris, with thanks to Corey Donohoe <atmos@atmos.org> */
|
|
|
|
|
|
|
|
#include "ipc.h"
|
2004-03-27 12:59:42 -08:00
|
|
|
#include "util.h"
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2003-12-31 14:15:33 -08:00
|
|
|
#include <string.h>
|
2003-12-05 08:57:32 -08:00
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include <Ecore.h>
|
|
|
|
#include <Ecore_Ipc.h>
|
|
|
|
|
2004-03-27 12:59:42 -08:00
|
|
|
#include <Edb.h>
|
|
|
|
|
2003-12-05 08:57:32 -08:00
|
|
|
#include "Ecore_Config.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
static int _ecore_config_ipc_ecore_get_string(char **m,char **r) {
|
2003-12-05 08:57:32 -08:00
|
|
|
char *q;
|
|
|
|
int l=0;
|
|
|
|
|
|
|
|
if(!m||!*m)
|
|
|
|
return ECORE_CONFIG_ERR_NODATA;
|
|
|
|
if(!r)
|
|
|
|
return ECORE_CONFIG_ERR_FAIL;
|
|
|
|
q=*m;
|
|
|
|
if(*q!='s')
|
|
|
|
return ECORE_CONFIG_ERR_TYPEMISMATCH;
|
|
|
|
q++;
|
|
|
|
l=(*(q++))<<8;
|
|
|
|
l+=*(q++);
|
|
|
|
*r=q;
|
|
|
|
q+=l;
|
|
|
|
*m=q;
|
|
|
|
E(1,"IPC/eCore: got string-%d \"%s\"\n",l,*r);
|
|
|
|
return ECORE_CONFIG_ERR_SUCC; }
|
|
|
|
|
|
|
|
|
2004-03-27 12:59:42 -08:00
|
|
|
char *_ecore_config_ipc_global_prop_list(Ecore_Config_Server *srv, const long serial) {
|
|
|
|
E_DB_File *db;
|
|
|
|
char **keys;
|
|
|
|
int key_count, x;
|
|
|
|
estring *s;
|
|
|
|
int f;
|
2004-03-27 13:58:01 -08:00
|
|
|
char *buf, *p, *type, *data;
|
2004-03-27 12:59:42 -08:00
|
|
|
|
|
|
|
s=estring_new(8192);
|
|
|
|
f=0;
|
|
|
|
if((p=getenv("HOME"))) { /* debug-only ### FIXME */
|
|
|
|
if ((buf=malloc(PATH_MAX*sizeof(char)))) {
|
|
|
|
snprintf(buf,PATH_MAX,"%s/.e/config.db",p);
|
|
|
|
db=e_db_open_read(buf);
|
|
|
|
if (!(db=e_db_open_read(buf)))
|
|
|
|
if (!(db=e_db_open_read(buf=PACKAGE_DATA_DIR "/system.db")))
|
|
|
|
return ECORE_CONFIG_ERR_NOFILE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
keys = e_db_dump_key_list(buf, &key_count);
|
|
|
|
free(buf);
|
|
|
|
|
|
|
|
for (x = 0; x < key_count; x++) {
|
|
|
|
type = e_db_type_get(db, keys[x]);
|
|
|
|
if (!type) type = "?";
|
|
|
|
|
2004-03-27 13:58:01 -08:00
|
|
|
if (!strcmp(type, "int"))
|
|
|
|
estring_appendf(s,"%s%s: integer",f?"\n":"",keys[x]);
|
|
|
|
else if (!strcmp(type, "float"))
|
|
|
|
estring_appendf(s,"%s%s: float",f?"\n":"",keys[x]);
|
|
|
|
else if (!strcmp(type, "str")) {
|
|
|
|
data = e_db_str_get(db, keys[x]);
|
|
|
|
if (data) {
|
|
|
|
if (ecore_config_guess_type(data)==PT_RGB)
|
|
|
|
estring_appendf(s,"%s%s: colour",f?"\n":"",keys[x]);
|
|
|
|
else
|
|
|
|
estring_appendf(s,"%s%s: string",f?"\n":"",keys[x]);
|
|
|
|
free(data);
|
|
|
|
} else {
|
|
|
|
estring_appendf(s,"%s%s: string",f?"\n":"",keys[x]);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
estring_appendf(s,"%s%s: unknown",f?"\n":"",keys[x]);
|
|
|
|
|
2004-03-27 12:59:42 -08:00
|
|
|
if (type) free(type);
|
|
|
|
f=1;
|
|
|
|
}
|
|
|
|
e_db_close(db);
|
|
|
|
free(keys);
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-03-27 12:59:42 -08:00
|
|
|
return estring_disown(s);}
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
static int _ecore_config_ipc_ecore_send(Ecore_Ipc_Event_Client_Data *e,int code,char *reply) {
|
2003-12-05 08:57:32 -08:00
|
|
|
static int our_ref=0;
|
|
|
|
int len=reply?strlen(reply)+1:0;
|
|
|
|
our_ref++;
|
|
|
|
E(1,"IPC/eCore: replying [0,0] %d IRT %d => %d {\"%s\":%d}\n",our_ref,e->ref,code,reply?reply:"",len);
|
|
|
|
return ecore_ipc_client_send(e->client,0,0,our_ref,e->ref,code,reply,len); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
static int _ecore_config_ipc_ecore_handle_request(Ecore_Ipc_Server *server,Ecore_Ipc_Event_Client_Data *e) {
|
2003-12-05 08:57:32 -08:00
|
|
|
Ecore_Config_Server *srv;
|
2004-03-01 15:11:28 -08:00
|
|
|
long serial;
|
2004-03-08 07:03:40 -08:00
|
|
|
int ret;
|
|
|
|
char *r,*k,*v,*m;
|
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
srv=_ecore_config_server_convert(server);
|
|
|
|
serial=e->minor;
|
2004-03-08 07:03:40 -08:00
|
|
|
ret=ECORE_CONFIG_ERR_FAIL;
|
|
|
|
r=NULL;
|
2004-03-01 15:11:28 -08:00
|
|
|
m=(char *)e->data;
|
2003-12-05 08:57:32 -08:00
|
|
|
E(1,"IPC/eCore: client sent: [%d,%d] #%d (%d) @ %p\n",e->major,e->minor,e->ref,e->size,server);
|
|
|
|
|
|
|
|
switch(e->major) {
|
|
|
|
case IPC_PROP_LIST:
|
2004-03-01 15:11:28 -08:00
|
|
|
r=_ecore_config_ipc_prop_list(srv, serial);
|
2003-12-05 08:57:32 -08:00
|
|
|
break;
|
2004-03-27 12:59:42 -08:00
|
|
|
case IPC_GLOBAL_PROP_LIST:
|
|
|
|
r=_ecore_config_ipc_global_prop_list(srv, serial);
|
|
|
|
break;
|
2003-12-05 08:57:32 -08:00
|
|
|
case IPC_PROP_DESC:
|
2004-03-01 15:11:28 -08:00
|
|
|
if(_ecore_config_ipc_ecore_get_string(&m,&k)==ECORE_CONFIG_ERR_SUCC)
|
|
|
|
r=_ecore_config_ipc_prop_desc(srv, serial,k);
|
2003-12-05 08:57:32 -08:00
|
|
|
break;
|
|
|
|
case IPC_PROP_GET:
|
2004-03-01 15:11:28 -08:00
|
|
|
if(_ecore_config_ipc_ecore_get_string(&m,&k)==ECORE_CONFIG_ERR_SUCC)
|
|
|
|
r=_ecore_config_ipc_prop_get(srv, serial,k);
|
2003-12-05 08:57:32 -08:00
|
|
|
break;
|
|
|
|
case IPC_PROP_SET:
|
2004-03-01 15:11:28 -08:00
|
|
|
if(_ecore_config_ipc_ecore_get_string(&m,&k)==ECORE_CONFIG_ERR_SUCC) {
|
|
|
|
if(_ecore_config_ipc_ecore_get_string(&m,&v)==ECORE_CONFIG_ERR_SUCC)
|
|
|
|
return _ecore_config_ipc_ecore_send(e,_ecore_config_ipc_prop_set(srv, serial,k,v),NULL); }
|
2003-12-05 08:57:32 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IPC_BUNDLE_LIST:
|
2004-03-01 15:11:28 -08:00
|
|
|
r=_ecore_config_ipc_bundle_list(srv);
|
2003-12-05 08:57:32 -08:00
|
|
|
break;
|
|
|
|
case IPC_BUNDLE_NEW:
|
2004-03-01 15:11:28 -08:00
|
|
|
if(_ecore_config_ipc_ecore_get_string(&m,&k)==ECORE_CONFIG_ERR_SUCC)
|
|
|
|
return _ecore_config_ipc_ecore_send(e,k?_ecore_config_ipc_bundle_new(srv, k):ECORE_CONFIG_ERR_FAIL,NULL);
|
2003-12-05 08:57:32 -08:00
|
|
|
break;
|
|
|
|
case IPC_BUNDLE_LABEL_SET:
|
2004-03-01 15:11:28 -08:00
|
|
|
if(_ecore_config_ipc_ecore_get_string(&m,&k)==ECORE_CONFIG_ERR_SUCC)
|
|
|
|
return _ecore_config_ipc_ecore_send(e,k?_ecore_config_ipc_bundle_label_set(srv, serial,k):ECORE_CONFIG_ERR_FAIL,NULL);
|
2003-12-05 08:57:32 -08:00
|
|
|
break;
|
|
|
|
case IPC_BUNDLE_LABEL_FIND:
|
2004-03-01 15:11:28 -08:00
|
|
|
if(_ecore_config_ipc_ecore_get_string(&m,&k)==ECORE_CONFIG_ERR_SUCC)
|
|
|
|
return _ecore_config_ipc_ecore_send(e,_ecore_config_ipc_bundle_label_find(srv, k),NULL);
|
2003-12-05 08:57:32 -08:00
|
|
|
break;
|
|
|
|
case IPC_BUNDLE_LABEL_GET:
|
2004-03-01 15:11:28 -08:00
|
|
|
r=_ecore_config_ipc_bundle_label_get(srv, serial);
|
2003-12-05 08:57:32 -08:00
|
|
|
break; }
|
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
ret=_ecore_config_ipc_ecore_send(e,r?ECORE_CONFIG_ERR_SUCC:ECORE_CONFIG_ERR_FAIL,r);
|
2003-12-05 08:57:32 -08:00
|
|
|
if(r) {
|
|
|
|
free(r);
|
|
|
|
return ret; }
|
|
|
|
return ECORE_CONFIG_ERR_NOTFOUND; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
static int _ecore_config_ipc_client_add(void *data,int type,void *event) {
|
|
|
|
Ecore_Ipc_Server **server;
|
|
|
|
Ecore_Ipc_Event_Client_Data *e;
|
|
|
|
server=(Ecore_Ipc_Server **)data;
|
|
|
|
e=(Ecore_Ipc_Event_Client_Data *)event;
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
if (*server != ecore_ipc_client_server_get(e->client))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
E(1,"IPC/eCore: Client connected. @ %p\n",server);
|
|
|
|
return 1; }
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
static int _ecore_config_ipc_client_del(void *data, int type, void *event) {
|
|
|
|
Ecore_Ipc_Server **server;
|
|
|
|
Ecore_Ipc_Event_Client_Data *e;
|
|
|
|
server=(Ecore_Ipc_Server **)data;
|
|
|
|
e=(Ecore_Ipc_Event_Client_Data *)event;
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
if (*server != ecore_ipc_client_server_get(e->client))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
E(1,"IPC/eCore: Client disconnected. @ %p\n",server);
|
|
|
|
return 1; }
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
static int _ecore_config_ipc_client_sent(void *data,int type,void *event) {
|
|
|
|
Ecore_Ipc_Server **server;
|
|
|
|
Ecore_Ipc_Event_Client_Data *e;
|
|
|
|
server=(Ecore_Ipc_Server **)data;
|
|
|
|
e=(Ecore_Ipc_Event_Client_Data *)event;
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
if (*server != ecore_ipc_client_server_get(e->client))
|
|
|
|
return 1;
|
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
_ecore_config_ipc_ecore_handle_request(*server,e);
|
2003-12-05 08:57:32 -08:00
|
|
|
return 1; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
int _ecore_config_mod_init(char *pipe_name, void **data) {
|
|
|
|
Ecore_Ipc_Server **server;
|
2003-12-05 08:57:32 -08:00
|
|
|
struct stat st;
|
|
|
|
char *p;
|
2004-03-01 15:11:28 -08:00
|
|
|
int port;
|
2004-02-15 06:50:23 -08:00
|
|
|
char socket[PATH_MAX];
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
server=(Ecore_Ipc_Server **)data;
|
|
|
|
port=0;
|
2003-12-05 08:57:32 -08:00
|
|
|
if(!server)
|
|
|
|
return ECORE_CONFIG_ERR_FAIL;
|
|
|
|
|
2003-12-17 03:05:29 -08:00
|
|
|
/* if(*server)
|
|
|
|
return ECORE_CONFIG_ERR_IGNORED; */
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
ecore_init();
|
|
|
|
if(ecore_ipc_init()<1)
|
|
|
|
return ECORE_CONFIG_ERR_FAIL;
|
|
|
|
|
|
|
|
if((p=getenv("HOME"))) { /* debug-only ### FIXME */
|
2003-12-19 07:35:45 -08:00
|
|
|
int stale;
|
|
|
|
stale=1;
|
2003-12-05 08:57:32 -08:00
|
|
|
while (stale) {
|
2004-02-15 06:50:23 -08:00
|
|
|
snprintf(socket,PATH_MAX,"%s/.ecore/%s/%d",p,pipe_name,port);
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-02-15 06:50:23 -08:00
|
|
|
if(!stat(socket,&st)) {
|
|
|
|
E(0,"IPC/eCore: pipe \"%s\" already exists!?\n",socket);
|
2003-12-17 03:05:29 -08:00
|
|
|
/* if(unlink(buf))
|
|
|
|
E(0,"IPC/eCore: could not remove pipe \"%s\": %d\n",buf,errno); }}*/
|
2003-12-05 08:57:32 -08:00
|
|
|
port++;
|
|
|
|
} else {
|
|
|
|
stale = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*server=ecore_ipc_server_add(ECORE_IPC_LOCAL_USER,pipe_name,port,NULL);
|
2004-03-01 15:11:28 -08:00
|
|
|
ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD, _ecore_config_ipc_client_add, server);
|
|
|
|
ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL, _ecore_config_ipc_client_del, server);
|
|
|
|
ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DATA,_ecore_config_ipc_client_sent,server);
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-02-15 14:43:48 -08:00
|
|
|
if(server) {
|
2004-02-15 06:50:23 -08:00
|
|
|
E(1,"IPC/eCore: Server is listening on %s.\n", pipe_name);
|
2003-12-31 14:15:33 -08:00
|
|
|
}
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
return ECORE_CONFIG_ERR_SUCC; }
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
int _ecore_config_mod_exit(void **data) {
|
|
|
|
int ret;
|
|
|
|
Ecore_Ipc_Server **server;
|
|
|
|
ret=ECORE_CONFIG_ERR_SUCC;
|
|
|
|
server=(Ecore_Ipc_Server **)data;
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
if(!server)
|
|
|
|
return ECORE_CONFIG_ERR_FAIL;
|
|
|
|
|
|
|
|
if(*server) {
|
|
|
|
ecore_ipc_server_del(*server);
|
|
|
|
*server=NULL; }
|
|
|
|
|
|
|
|
ecore_ipc_shutdown();
|
|
|
|
|
|
|
|
return ret; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
int _ecore_config_mod_poll(void **data) {
|
|
|
|
Ecore_Ipc_Server **server;
|
|
|
|
server=(Ecore_Ipc_Server **)data;
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
if(!server)
|
|
|
|
return ECORE_CONFIG_ERR_FAIL;
|
|
|
|
|
|
|
|
ecore_main_loop_iterate();
|
|
|
|
|
|
|
|
return ECORE_CONFIG_ERR_SUCC; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|