WFTK_EXPORT char * repos_context_save (XML * repository)
{
WFTK_ADAPTOR * ad;
XML * context;
char * ret;
char * mark;
const char * line;
const char * end;
struct _repos_remote * sock = (struct _repos_remote *) xml_getbin (repository);
if (sock) { /* Remote. */
xml_setf (sock->parms, "outgoing", "context\n");
_repos_send (sock);
line = _repos_receive (sock);
if (*line == '-') return NULL;
line = strchr (line, '-') + 1;
ret = strdup (line);
mark = strstr (ret, " ++done++");
if (mark) *mark = '\0';
else {
mark = strchr (ret, '\n');
if (mark) *mark = '\0';
}
return (ret);
}
context = wftk_session_getcontext (repository);
if (!context) {
context = xml_create ("context");
wftk_session_setcontext (repository, context);
}
if (*xml_attrval (context, "key")) { /* This context has already been saved. */
repos_mod (repository, "_sessions", context, NULL);
} else {
repos_add (repository, "_sessions", context);
}
return (strdup (xml_attrval (context, "key")));
}
|
WFTK_EXPORT XML * repos_context_switch (XML * repository, const char * contextid)
{
WFTK_ADAPTOR * ad;
XML * temp;
XML * context;
const char * line;
const char * end;
XML * field;
XML * mark;
struct _repos_remote * sock = (struct _repos_remote *) xml_getbin (repository);
if (sock) { /* Remote. */
xml_setf (sock->parms, "outgoing", "context %s\n", contextid);
_repos_send (sock);
line = _repos_receive (sock);
if (*line == '-') {
wftk_session_setcontext (repository, NULL);
return NULL;
}
line = strchr (line, '\n') + 1;
temp = xml_create ("t");
xml_set (temp, "r", "");
while (line[0] != '>' || line[1] != '>') {
end = strchr (line, '\n');
if (end) {
xml_attrncat (temp, "r", line, end - line + 1);
} else {
xml_attrcat (temp, "r", line);
break;
}
line = end + 1;
}
context = xml_parse (xml_attrval (temp, "r"));
xml_free (temp);
xml_set (sock->parms, "buffer", "");
wftk_session_setcontext (repository, context);
return (context);
}
context = repos_get (repository, "_sessions", contextid);
wftk_session_setcontext (repository, context);
return (context);
}
|
WFTK_EXPORT void repos_context_set (XML * repository, const char * valname, const char * value)
{
WFTK_ADAPTOR * ad;
XML * context;
const char * line;
const char * end;
XML * field;
XML * mark;
struct _repos_remote * sock = (struct _repos_remote *) xml_getbin (repository);
if (sock) { /* Remote. */
xml_setf (sock->parms, "outgoing", "set % %s\n", valname, value);
_repos_send (sock);
line = _repos_receive (sock);
xml_set (sock->parms, "buffer", "");
return;
}
context = wftk_session_getcontext (repository);
if (!context) {
context = xml_create ("context");
wftk_session_setcontext (repository, context);
}
xmlobj_set (context, NULL, valname, value);
}
WFTK_EXPORT char * repos_context_get (XML * repository, const char * valname)
{
WFTK_ADAPTOR * ad;
XML * context;
char * ret;
char * mark;
const char * line;
const char * end;
struct _repos_remote * sock = (struct _repos_remote *) xml_getbin (repository);
if (sock) { /* Remote. */
xml_setf (sock->parms, "outgoing", "read %s\n", valname);
_repos_send (sock);
line = _repos_receive (sock);
if (*line == '-') return NULL;
line = strchr (line, ' ') + 1;
ret = strdup (line);
mark = strchr (ret, ' ');
if (mark) *mark = '\0';
else {
mark = strchr (ret, '\n');
if (mark) *mark = '\0';
}
return (ret);
}
context = wftk_session_getcontext (repository);
if (!context) {
context = xml_create ("context");
wftk_session_setcontext (repository, context);
return NULL;
}
return (xmlobj_get (context, NULL, valname));
}
|
| This code and documentation are released under the terms of the GNU license. They are copyright (c) 2001-2005, Vivtek. All rights reserved except those explicitly granted under the terms of the GNU license. |