Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
zmap
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ensembl-gh-mirror
zmap
Commits
abe3ca7a
Commit
abe3ca7a
authored
18 years ago
by
rds
Browse files
Options
Downloads
Patches
Plain Diff
tidy up some of the parsing and add a finalised request
parent
97f35d0f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/zmapApp/zmapAppremote.c
+148
-178
148 additions, 178 deletions
src/zmapApp/zmapAppremote.c
with
148 additions
and
178 deletions
src/zmapApp/zmapAppremote.c
+
148
−
178
View file @
abe3ca7a
...
...
@@ -27,9 +27,9 @@
*
* Exported functions: None
* HISTORY:
* Last edited: Mar
6
1
2
:1
1
2007 (
edgrif
)
* Last edited: Mar
7
1
7
:1
2
2007 (
rds
)
* Created: Thu May 5 18:19:30 2005 (rds)
* CVS info: $Id: zmapAppremote.c,v 1.2
3
2007-03-0
6
1
2:16:09 edgrif
Exp $
* CVS info: $Id: zmapAppremote.c,v 1.2
4
2007-03-0
8
1
1:47:46 rds
Exp $
*-------------------------------------------------------------------
*/
...
...
@@ -60,14 +60,22 @@ typedef struct
GQuark
start
;
GQuark
end
;
GQuark
source
;
}
appRemoteAllStruct
,
*
appRemoteAll
;
}
AppRemoteAllStruct
,
*
AppRemoteAll
;
typedef
struct
{
ZMapAppContext
app_context
;
int
code
;
gboolean
handled
;
GString
*
message
;
}
ResponseContextStruct
,
*
ResponseContext
;
typedef
struct
{
GTimer
*
timer
;
ZMapAppContext
app_context
;
ZMapAppContextState
state_flag
;
}
t
imerContextStruct
,
*
t
imerContext
;
}
T
imerContextStruct
,
*
T
imerContext
;
static
gboolean
start
(
void
*
userData
,
ZMapXMLElement
element
,
...
...
@@ -77,12 +85,12 @@ static gboolean end(void *userData,
ZMapXMLParser
parser
);
static
char
*
appexecuteCommand
(
char
*
command_text
,
gpointer
app_context
,
int
*
statusCode
);
static
gboolean
createZMap
(
ZMapAppContext
app
,
a
ppRemoteAll
obj
);
static
gboolean
createZMap
(
ZMapAppContext
app
,
A
ppRemoteAll
obj
,
ResponseContext
response
);
static
void
destroyNotifyData
(
gpointer
destroy_data
);
/* closing from remote */
static
gboolean
closingTimedOut
(
GTimer
*
timer
);
static
gboolean
setupRemoteCloseHandler
(
ZMapAppContext
app_context
);
static
gboolean
setupRemoteCloseHandler
(
ZMapAppContext
app_context
,
AppRemoteAll
request
,
ResponseContext
response
);
static
gboolean
remoteCloseHandler
(
gpointer
data
);
static
gboolean
confirmCloseRequestResponseReceived
(
ZMapAppContext
app_context
);
static
void
remoteCloseDestroyNotify
(
gpointer
data
);
...
...
@@ -167,21 +175,20 @@ void zmapAppRemoteInstaller(GtkWidget *widget, gpointer app_context_data)
static
gboolean
confirmCloseRequestResponseReceived
(
ZMapAppContext
app_context
)
{
gboolean
received
=
TRUE
;
char
*
response
=
NULL
;
#ifdef RDS_DONT_INCLUDE
received
=
FALSE
;
if
(
app_context
->
xremoteClient
)
{
char
*
request
=
"<zmap action=
\"
closing
\"
/>"
;
zMapXRemoteSendRemoteCommand
(
app_context
->
xremoteClient
,
request
);
char
*
request
=
"<zmap action=
\"
finalised
\"
/>"
;
zMapXRemoteSendRemoteCommand
(
app_context
->
xremoteClient
,
request
,
&
response
);
received
=
TRUE
;
/* I'm not sure on the library call to get the response, did I write one?
* Not super important though... */
}
else
received
=
TRUE
;
/* This is the best we can do here. */
#endif
return
received
;
}
...
...
@@ -203,7 +210,7 @@ static gboolean closingTimedOut(GTimer *timer)
static
gboolean
remoteCloseHandler
(
gpointer
data
)
{
ZMapAppContext
app_context
=
NULL
;
t
imerContext
tc
=
(
t
imerContext
)
data
;
T
imerContext
tc
=
(
T
imerContext
)
data
;
gboolean
remove
=
FALSE
;
app_context
=
tc
->
app_context
;
...
...
@@ -223,7 +230,7 @@ static gboolean remoteCloseHandler(gpointer data)
static
void
remoteCloseDestroyNotify
(
gpointer
data
)
{
t
imerContext
tc
=
(
t
imerContext
)
data
;
T
imerContext
tc
=
(
T
imerContext
)
data
;
ZMapAppContext
app_context
=
NULL
;
app_context
=
tc
->
app_context
;
...
...
@@ -232,7 +239,7 @@ static void remoteCloseDestroyNotify(gpointer data)
((
zMapManagerCount
(
app_context
->
zmap_manager
)
==
0
)
&&
confirmCloseRequestResponseReceived
(
app_context
)))
{
/* first clean up the
t
imerContext */
/* first clean up the
T
imerContext */
g_timer_destroy
(
tc
->
timer
);
tc
->
app_context
=
NULL
;
g_free
(
tc
);
...
...
@@ -243,50 +250,54 @@ static void remoteCloseDestroyNotify(gpointer data)
return
;
}
static
gboolean
setupRemoteCloseHandler
(
ZMapAppContext
app_context
)
static
gboolean
setupRemoteCloseHandler
(
ZMapAppContext
app_context
,
AppRemoteAll
request_data
,
ResponseContext
response_data
)
{
gboolean
good
=
FALSE
;
TimerContext
timer_data
;
guint
timeoutId
=
0
,
interval
=
1000
;
timerContext
data
=
NULL
;
data
=
g_new0
(
timerContextStruct
,
1
);
data
->
app_context
=
app_context
;
data
->
timer
=
g_timer_new
();
gboolean
handled
=
FALSE
;
/* possibly a good idea to check whether we have a client, although
* it goes on latter before sending the request, but also to stop
* random close requests... i.e. zmap must have been started as
* zmap --win_id 0xNNNNNNN
*/
if
(
/* app_context->xremoteClient != NULL && */
(
timeoutId
=
g_timeout_add_full
(
G_PRIORITY_DEFAULT_IDLE
,
interval
,
remoteCloseHandler
,
(
gpointer
)
data
,
remoteCloseDestroyNotify
)))
if
(
app_context
->
xremoteClient
!=
NULL
&&
(
timer_data
=
g_new0
(
TimerContextStruct
,
1
)))
{
if
(
app_context
->
propertyNotifyEventId
)
g_signal_handler_disconnect
(
app_context
->
app_widg
,
app_context
->
propertyNotifyEventId
);
app_context
->
propertyNotifyEventId
=
data
->
state_flag
=
0
;
good
=
TRUE
;
timer_data
->
app_context
=
app_context
;
timer_data
->
timer
=
g_timer_new
();
if
((
timeoutId
=
g_timeout_add_full
(
G_PRIORITY_DEFAULT_IDLE
,
interval
,
remoteCloseHandler
,
(
gpointer
)
timer_data
,
remoteCloseDestroyNotify
)))
{
if
(
app_context
->
propertyNotifyEventId
)
g_signal_handler_disconnect
(
app_context
->
app_widg
,
app_context
->
propertyNotifyEventId
);
app_context
->
propertyNotifyEventId
=
timer_data
->
state_flag
=
0
;
g_string_append_printf
(
response_data
->
message
,
"zmap is closing, wait for finalised request."
);
response_data
->
handled
=
handled
=
TRUE
;
}
}
return
goo
d
;
return
handle
d
;
}
/* This should just be a filter command passing to the correct
function defined by the action="value" of the request */
static
char
*
appexecuteCommand
(
char
*
command_text
,
gpointer
app_context
,
int
*
statusCode
){
ZMapAppContext
app
=
(
ZMapAppContext
)
app_context
;
static
char
*
appexecuteCommand
(
char
*
command_text
,
gpointer
app_context_data
,
int
*
statusCode
)
{
ZMapXMLParser
parser
;
ZMapAppContext
app_context
=
(
ZMapAppContext
)
app_context_data
;
char
*
xml_reply
=
NULL
;
int
code
=
ZMAPXREMOTE_INTERNAL
;
/* unknown command if this isn't changed */
ZMapXMLParser
parser
=
NULL
;
gboolean
cmd_debug
=
FALSE
;
gboolean
parse_ok
=
FALSE
;
GList
*
list
=
NULL
;
AppRemoteAllStruct
request_data
=
{
0
}
;
ResponseContextStruct
response_data
=
{
0
};
ZMapXMLObjTagFunctionsStruct
startH
[]
=
{
{
"zmap"
,
start
},
{
NULL
,
NULL
}
...
...
@@ -296,116 +307,95 @@ static char *appexecuteCommand(char *command_text, gpointer app_context, int *st
{
NULL
,
NULL
}
};
g_cle
ar
_
er
ror
(
&
(
app
->
info
)
);
parser
=
zMapXMLP
ar
s
er
Create
(
&
request_data
,
FALSE
,
cmd_debug
);
parser
=
zMapXMLParserCreate
(
&
list
,
FALSE
,
cmd_debug
);
zMapXMLParserSetMarkupObjectTagHandlers
(
parser
,
startH
,
endH
);
parse_ok
=
zMapXMLParserParseBuffer
(
parser
,
command_text
,
strlen
(
command_text
));
response_data
.
code
=
ZMAPXREMOTE_INTERNAL
;
/* unknown command if this isn't changed */
response_data
.
message
=
g_string_sized_new
(
256
);
if
(
parse_ok
&&
(
list
!=
NULL
))
if
((
parse_ok
=
zMapXMLParserParseBuffer
(
parser
,
command_text
,
strlen
(
command_text
))))
{
appRemoteAll
appOpen
=
(
appRemoteAll
)(
list
->
data
);
switch
(
appOpen
->
action
){
case
ZMAP_APP_REMOTE_OPEN_ZMAP
:
if
(
createZMap
(
app
,
appOpen
))
code
=
ZMAPXREMOTE_OK
;
else
code
=
ZMAPXREMOTE_BADREQUEST
;
break
;
case
ZMAP_APP_REMOTE_CLOSE_ZMAP
:
if
(
setupRemoteCloseHandler
(
app
))
{
code
=
ZMAPXREMOTE_OK
;
app
->
info
||
(
app
->
info
=
g_error_new
(
g_quark_from_string
(
__FILE__
),
code
,
"zmap is closing"
));
}
else
{
code
=
ZMAPXREMOTE_FORBIDDEN
;
app
->
info
||
(
app
->
info
=
g_error_new
(
g_quark_from_string
(
__FILE__
),
code
,
"closing zmap is not allowed via xremote"
));
}
break
;
default:
break
;
}
switch
(
request_data
.
action
)
{
case
ZMAP_APP_REMOTE_OPEN_ZMAP
:
if
((
response_data
.
handled
=
createZMap
(
app_context_data
,
&
request_data
,
&
response_data
)))
response_data
.
code
=
ZMAPXREMOTE_OK
;
else
response_data
.
code
=
ZMAPXREMOTE_BADREQUEST
;
break
;
case
ZMAP_APP_REMOTE_CLOSE_ZMAP
:
if
((
response_data
.
handled
=
setupRemoteCloseHandler
(
app_context
,
&
request_data
,
&
response_data
)))
response_data
.
code
=
ZMAPXREMOTE_OK
;
else
{
response_data
.
code
=
ZMAPXREMOTE_FORBIDDEN
;
g_string_append_printf
(
response_data
.
message
,
"closing zmap is not allowed via xremote"
);
}
break
;
default:
break
;
}
if
(
!
(
response_data
.
message
->
str
)
&&
response_data
.
handled
)
g_string_append_printf
(
response_data
.
message
,
"Request handled, but no message set. Probably a data error."
);
else
if
(
!
response_data
.
handled
)
zMapLogWarning
(
"%s"
,
"Request not handled!"
);
}
else
if
(
!
parse_ok
)
else
{
code
=
ZMAPXREMOTE_BADREQUEST
;
app
->
info
=
g_error_new
(
g_quark_from_string
(
__FILE__
),
code
,
"%s"
,
zMapXMLParserLastErrorMsg
(
parser
)
);
response_data
.
code
=
ZMAPXREMOTE_BADREQUEST
;
g_string_append_printf
(
response_data
.
message
,
"%s"
,
zMapXMLParserLastErrorMsg
(
parser
));
}
/* Now check what the status is */
switch
(
code
)
switch
(
response_data
.
code
)
{
case
ZMAPXREMOTE_INTERNAL
:
{
code
=
ZMAPXREMOTE_UNKNOWNCMD
;
app
->
info
||
(
app
->
info
=
g_error_new
(
g_quark_from_string
(
__FILE__
),
code
,
"<!-- request was %s -->%s"
,
command_text
,
"unknown command"
));
response_data
.
code
=
ZMAPXREMOTE_UNKNOWNCMD
;
if
(
!
response_data
.
message
->
str
)
g_string_append_printf
(
response_data
.
message
,
"<!-- request was %s -->%s"
,
command_text
,
"unknown command"
);
break
;
}
case
ZMAPXREMOTE_BADREQUEST
:
{
app
->
info
||
(
app
->
info
=
g_error_new
(
g_quark_from_string
(
__FILE__
),
code
,
"<!-- request was %s -->%s"
,
command_text
,
"bad request"
));
if
(
!
response_data
.
message
->
str
)
g_string_append_printf
(
response_data
.
message
,
"<!-- request was %s -->%s"
,
command_text
,
"bad request"
);
break
;
}
case
ZMAPXREMOTE_FORBIDDEN
:
{
app
->
info
=
g_error_new
(
g_quark_from_string
(
__FILE__
),
code
,
"%s"
,
"forbidden request"
);
if
(
!
response_data
.
message
->
str
)
g_string_append_printf
(
response_data
.
message
,
"%s"
,
"forbidden request"
);
break
;
}
default:
{
/* If the info isn't set then someone forgot to set it */
if
(
!
app
->
info
)
if
(
!
response_data
.
message
->
str
)
{
code
=
ZMAPXREMOTE_INTERNAL
;
app
->
info
=
g_error_new
(
g_quark_from_string
(
__FILE__
),
code
,
"<!-- request was %s -->%s"
,
command_text
,
"CODE error on the part of the zmap programmers."
);
g_string_append_printf
(
response_data
.
message
,
"<!-- request was %s -->%s"
,
command_text
,
"CODE error on the part of the zmap programmers."
);
}
break
;
}
}
/* We should have a info object by now, pass it on. */
xml_reply
=
g_strdup
(
app
->
info
->
message
);
*
statusCode
=
code
;
xml_reply
=
response_data
.
message
->
str
;
*
statusCode
=
response_data
.
code
;
g_string_free
(
response_data
.
message
,
FALSE
);
/* Free the parser!!! */
zMapXMLParserDestroy
(
parser
);
...
...
@@ -414,13 +404,16 @@ static char *appexecuteCommand(char *command_text, gpointer app_context, int *st
}
static
gboolean
createZMap
(
ZMapAppContext
app
,
a
ppRemoteAll
obj
)
static
gboolean
createZMap
(
ZMapAppContext
app
,
A
ppRemoteAll
obj
,
ResponseContext
response_data
)
{
gboolean
executed
=
FALSE
;
char
*
sequence
=
g_strdup
(
g_quark_to_string
(
obj
->
sequence
));
zmapAppCreateZMap
(
app
,
sequence
,
obj
->
start
,
obj
->
end
)
;
executed
=
TRUE
;
response_data
->
handled
=
executed
=
TRUE
;
/* that screwy rabbit */
g_string_append_printf
(
response_data
->
message
,
app
->
info
->
message
);
/* Clean up. */
if
(
sequence
)
...
...
@@ -437,86 +430,63 @@ static void destroyNotifyData(gpointer destroy_data)
zMapXRemoteNotifyData
destroy_me
=
(
zMapXRemoteNotifyData
)
destroy_data
;
app
=
destroy_me
->
data
;
app
->
propertyNotifyData
=
NULL
;
g_free
(
destroy_me
);
/* user_data->data points to parent
* hold onto this parent.
* cleanup user_data = NULL;
* free(user_data)
*/
return
;
}
static
gboolean
start
(
void
*
user
D
ata
,
static
gboolean
start
(
void
*
user
_d
ata
,
ZMapXMLElement
element
,
ZMapXMLParser
parser
)
{
GList
**
list
=
NULL
;
AppRemoteAll
all_data
=
(
AppRemoteAll
)
user_data
;
gboolean
handled
=
FALSE
;
appObjType
type
;
type
=
ZMAP_APP_REMOTE_ALL
;
switch
(
type
){
case
ZMAP_APP_REMOTE_ALL
:
ZMapXMLAttribute
attr
=
NULL
;
if
((
attr
=
zMapXMLElementGetAttributeByName
(
element
,
"action"
))
!=
NULL
)
{
ZMapXMLAttribute
attr
=
NULL
;
appRemoteAll
objAll
=
g_new0
(
appRemoteAllStruct
,
1
);
if
((
attr
=
zMapXMLElementGetAttributeByName
(
element
,
"action"
))
!=
NULL
)
{
GQuark
action
=
zMapXMLAttributeGetValue
(
attr
);
if
(
action
==
g_quark_from_string
(
"new"
))
objAll
->
action
=
ZMAP_APP_REMOTE_OPEN_ZMAP
;
if
(
action
==
g_quark_from_string
(
"close"
)
||
(
action
==
g_quark_from_string
(
"shutdown"
)))
objAll
->
action
=
ZMAP_APP_REMOTE_CLOSE_ZMAP
;
}
/* Add obj to list */
list
=
((
GList
**
)
userData
);
*
list
=
g_list_append
(
*
list
,
objAll
);
GQuark
action
=
zMapXMLAttributeGetValue
(
attr
);
if
(
action
==
g_quark_from_string
(
"new"
))
all_data
->
action
=
ZMAP_APP_REMOTE_OPEN_ZMAP
;
if
(
action
==
g_quark_from_string
(
"close"
)
||
action
==
g_quark_from_string
(
"shutdown"
))
all_data
->
action
=
ZMAP_APP_REMOTE_CLOSE_ZMAP
;
}
break
;
default:
break
;
}
else
zMapXMLParserRaiseParsingError
(
parser
,
"Attribute 'action' is required for element 'zmap'."
);
return
handled
;
}
static
gboolean
end
(
void
*
user
D
ata
,
static
gboolean
end
(
void
*
user
_d
ata
,
ZMapXMLElement
element
,
ZMapXMLParser
parser
)
{
GList
**
list
=
NULL
;
gboolean
handled
=
FALSE
;
appObjType
type
=
ZMAP_APP_REMOTE_ALL
;
AppRemoteAll
all_data
=
(
AppRemoteAll
)
user_data
;
gboolean
handled
=
TRUE
;
ZMapXMLElement
child
;
ZMapXMLAttribute
attr
;
if
((
child
=
zMapXMLElementGetChildByName
(
element
,
"segment"
))
!=
NULL
)
{
if
((
attr
=
zMapXMLElementGetAttributeByName
(
child
,
"sequence"
))
!=
NULL
)
all_data
->
sequence
=
zMapXMLAttributeGetValue
(
attr
);
list
=
((
GList
**
)
userData
);
if
((
attr
=
zMapXMLElementGetAttributeByName
(
child
,
"start"
))
!=
NULL
)
all_data
->
start
=
strtol
(
g_quark_to_string
(
zMapXMLAttributeGetValue
(
attr
)),
(
char
**
)
NULL
,
10
);
else
all_data
->
start
=
1
;
switch
(
type
){
case
ZMAP_APP_REMOTE_ALL
:
{
ZMapXMLElement
child
=
NULL
;
appRemoteAll
appOpen
=
(
appRemoteAll
)((
*
list
)
->
data
);
if
((
child
=
zMapXMLElementGetChildByName
(
element
,
"segment"
))
!=
NULL
)
{
ZMapXMLAttribute
attr
=
NULL
;
if
((
attr
=
zMapXMLElementGetAttributeByName
(
child
,
"sequence"
))
!=
NULL
)
appOpen
->
sequence
=
zMapXMLAttributeGetValue
(
attr
);
if
((
attr
=
zMapXMLElementGetAttributeByName
(
child
,
"start"
))
!=
NULL
)
appOpen
->
start
=
strtol
(
g_quark_to_string
(
zMapXMLAttributeGetValue
(
attr
)),
(
char
**
)
NULL
,
10
);
else
appOpen
->
start
=
1
;
if
((
attr
=
zMapXMLElementGetAttributeByName
(
child
,
"end"
))
!=
NULL
)
appOpen
->
end
=
strtol
(
g_quark_to_string
(
zMapXMLAttributeGetValue
(
attr
)),
(
char
**
)
NULL
,
10
);
else
appOpen
->
end
=
0
;
}
if
((
attr
=
zMapXMLElementGetAttributeByName
(
child
,
"end"
))
!=
NULL
)
all_data
->
end
=
strtol
(
g_quark_to_string
(
zMapXMLAttributeGetValue
(
attr
)),
(
char
**
)
NULL
,
10
);
else
all_data
->
end
=
0
;
}
handled
=
TRUE
;
break
;
default:
break
;
}
return
handled
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment