mirror of
https://github.com/processone/ejabberd.git
synced 2024-10-01 14:44:07 +02:00
New features :
- edit an item - edit node configuration
This commit is contained in:
parent
bf98fa0c01
commit
363711a370
@ -23,22 +23,50 @@ In the current version of the code, some security checks are not done :
|
|||||||
|
|
||||||
## Usage example with cURL ##
|
## Usage example with cURL ##
|
||||||
|
|
||||||
|
### Errors ###
|
||||||
|
|
||||||
|
HTTP status codes are used as intended. Additionally, the XMPP error stanza can also be set in the body :
|
||||||
|
|
||||||
|
$ curl -i -X POST -u cstar@localhost:encore -d @createnode.xml http://localhost:5280/pshb/localhost
|
||||||
|
HTTP/1.1 409 Conflict
|
||||||
|
Content-Type: text/html; charset=utf-8
|
||||||
|
Content-Length: 95
|
||||||
|
Content-type: application/xml
|
||||||
|
|
||||||
|
<error code='409' type='cancel'><conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error>
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
$ curl -i -X DELETE -u cstar@localhost:encore http://localhost:5280/pshb/localhost/princely_musings
|
||||||
|
HTTP/1.1 404 Not Found
|
||||||
|
Content-Type: text/html; charset=utf-8
|
||||||
|
Content-Length: 101
|
||||||
|
Content-type: application/xml
|
||||||
|
|
||||||
|
<error code='404' type='cancel'><item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error>
|
||||||
|
|
||||||
### Getting the service document ###
|
### Getting the service document ###
|
||||||
|
|
||||||
No authentication necessary. All nodes are listed.
|
No authentication necessary. All nodes are listed.
|
||||||
|
|
||||||
curl -i http://host:port/pshb/domain/
|
$ curl -i http://host:port/pshb/domain/
|
||||||
|
|
||||||
### Getting items from a node ###
|
### Getting items from a node ###
|
||||||
|
|
||||||
No authentication done, and all nodes are accessible.
|
No authentication done, and all nodes are accessible.
|
||||||
|
|
||||||
curl -i http://host:port/pshb/domain/node/
|
$ curl -i http://host:port/pshb/domain/node/
|
||||||
|
|
||||||
|
|
||||||
### Posting a new item ###
|
### Posting a new item ###
|
||||||
|
|
||||||
curl -u jid:password -i -X POST -d @entry.atom http://post:port/pshb/domain/node
|
$ curl -u jid:password -i -X POST -d @entry.atom http://post:port/pshb/domain/node
|
||||||
|
|
||||||
|
User ability to post is based on node configuration.
|
||||||
|
|
||||||
|
### Editing a new item ###
|
||||||
|
|
||||||
|
$ curl -u jid:password -i -X POST -d @entry.atom http://post:port/pshb/domain/node/itemid
|
||||||
|
|
||||||
User ability to post is based on node configuration.
|
User ability to post is based on node configuration.
|
||||||
|
|
||||||
@ -47,11 +75,11 @@ User ability to post is based on node configuration.
|
|||||||
|
|
||||||
An instant node can be created if server configuration allows:
|
An instant node can be created if server configuration allows:
|
||||||
|
|
||||||
curl -X POST -u cstar@localhost:encore -d "" http://localhost:5280/pshb/localhost
|
$ curl -X POST -u cstar@localhost:encore -d "" http://localhost:5280/pshb/localhost
|
||||||
|
|
||||||
or
|
or
|
||||||
|
|
||||||
curl -X POST -u cstar@localhost:encore -d "<pubsub><create node='princely_musings'/></pubsub>" http://localhost:5280/pshb/localhost
|
$ curl -X POST -u cstar@localhost:encore -d "<pubsub><create node='princely_musings'/></pubsub>" http://localhost:5280/pshb/localhost
|
||||||
|
|
||||||
configure element (as per XEP-60) can be passed in the pubsub body.
|
configure element (as per XEP-60) can be passed in the pubsub body.
|
||||||
|
|
||||||
@ -67,13 +95,43 @@ configure element (as per XEP-60) can be passed in the pubsub body.
|
|||||||
</x>
|
</x>
|
||||||
</pubsub>
|
</pubsub>
|
||||||
|
|
||||||
$ curl -X POST -u cstar@localhost:encore -d @createnode.xml http://localhost:5280/pshb/localhost
|
$ curl -i -X POST -u cstar@localhost:encore -d @createnode.xml http://localhost:5280/pshb/localhost
|
||||||
|
HTTP/1.1 200 OK
|
||||||
|
Content-Length: 130
|
||||||
|
Content-Type: application/xml
|
||||||
|
|
||||||
|
<?xml version="1.0" encoding="utf-8"?><pubsub xmlns='http://jabber.org/protocol/pubsub'><create node='princely_musings'/></pubsub>
|
||||||
|
|
||||||
|
### Editing a node configuration ###
|
||||||
|
|
||||||
|
$ cat editnode.xml
|
||||||
|
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
|
||||||
|
<configure node='princely_musings'>
|
||||||
|
<x xmlns='jabber:x:data' type='submit'>
|
||||||
|
<field var='FORM_TYPE' type='hidden'>
|
||||||
|
<value>http://jabber.org/protocol/pubsub#node_config</value>
|
||||||
|
</field>
|
||||||
|
<field var='pubsub#title'><value>Princely Musings (Atom)</value></field>
|
||||||
|
<field var='pubsub#deliver_notifications'><value>1</value></field>
|
||||||
|
<field var='pubsub#deliver_payloads'><value>1</value></field>
|
||||||
|
<field var='pubsub#persist_items'><value>1</value></field>
|
||||||
|
<field var='pubsub#max_items'><value>10</value></field>
|
||||||
|
<field var='pubsub#item_expire'><value>604800</value></field>
|
||||||
|
<field var='pubsub#access_model'><value>roster</value></field>
|
||||||
|
</x>
|
||||||
|
</configure>
|
||||||
|
</pubsub>
|
||||||
|
|
||||||
|
|
||||||
|
$ curl -i -X PUT -u cstar@localhost:encore -d @createnode.xml http://localhost:5280/pshb/localhost/princely_musings
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Deleting a node ###
|
### Deleting a node ###
|
||||||
|
|
||||||
A node is deleted by:
|
A node is deleted by:
|
||||||
|
|
||||||
curl -X DELETE -u cstar@localhost:encore http://localhost:5280/pshb/localhost/princely_musings
|
$ curl -X DELETE -u cstar@localhost:encore http://localhost:5280/pshb/localhost/princely_musings
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
process(LocalPath, #request{auth = Auth} = Request)->
|
process(LocalPath, #request{auth = Auth} = Request)->
|
||||||
?DEBUG("LocalPath = ~p", [LocalPath]),
|
?DEBUG("LocalPath = ~p", [LocalPath]),
|
||||||
UD = get_auth(Auth),
|
UD = get_auth(Auth),
|
||||||
case catch out(Request, Request#request.method, LocalPath,UD) of
|
case out(Request, Request#request.method, LocalPath,UD) of
|
||||||
{'EXIT', Error} ->
|
{'EXIT', Error} ->
|
||||||
?ERROR_MSG("Error while processing ~p : ~n~p", [LocalPath, Error]),
|
?ERROR_MSG("Error while processing ~p : ~n~p", [LocalPath, Error]),
|
||||||
error(500);
|
error(500);
|
||||||
@ -110,25 +110,25 @@ out(Args, 'GET', [Domain,Node]=Uri, _User) ->
|
|||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
out(Args, 'POST', [Domain, Node]=Uri, {User, _Domain}) ->
|
out(Args, 'POST', [_D, _Node]=Uri, {_User, _Domain} = UD) ->
|
||||||
Slug = uniqid(false),
|
publish_item(Args, Uri, uniqid(false), UD);
|
||||||
Payload = xml_stream:parse_element(Args#request.data),
|
|
||||||
[FilteredPayload]=xml:remove_cdata([Payload]),
|
|
||||||
|
|
||||||
%FilteredPayload2 = case xml:get_subtag(FilteredPayload, "app:edited") ->
|
out(Args, 'PUT', [_D, _Node, Slug]=Uri, {_User, _Domain} = UD) ->
|
||||||
% {xmlelement, Name, Attrs, [{cdata, }]}
|
publish_item(Args, Uri, Slug, UD);
|
||||||
case mod_pubsub:publish_item(get_host(Uri),
|
|
||||||
Domain,
|
|
||||||
get_collection(Uri),
|
out(Args, 'PUT', [_Domain, Node]= Uri, {User, UDomain}) ->
|
||||||
jlib:make_jid(User,Domain, ""),
|
Host = get_host(Uri),
|
||||||
Slug,
|
Jid = jlib:make_jid({User, UDomain, ""}),
|
||||||
[FilteredPayload]) of
|
Payload = xml_stream:parse_element(Args#request.data),
|
||||||
{result, [_]} ->
|
ConfigureElement = case xml:get_subtag(Payload, "configure") of
|
||||||
?DEBUG("Publishing to ~p~n",[entry_uri(Args, Domain, Node,Slug)]),
|
false ->[];
|
||||||
{201, [{"location", entry_uri(Args, Domain,Node,Slug)}], Payload};
|
{xmlelement, _, _, SubEls}->SubEls
|
||||||
{error, Error} ->
|
end,
|
||||||
error(Error)
|
case mod_pubsub:set_configure(Host, list_to_binary(Node), Jid, ConfigureElement, Args#request.lang) of
|
||||||
end;
|
{result, []} -> success(200);
|
||||||
|
{error, Error} -> error(Error)
|
||||||
|
end;
|
||||||
|
|
||||||
out(Args, 'GET', [Domain]=Uri, From)->
|
out(Args, 'GET', [Domain]=Uri, From)->
|
||||||
Host = get_host(Uri),
|
Host = get_host(Uri),
|
||||||
@ -150,7 +150,6 @@ out(Args, 'POST', [Domain]=Uri, {User, UDomain})->
|
|||||||
E ->
|
E ->
|
||||||
{list_to_binary(get_tag_attr_or_default("node", E,"")),
|
{list_to_binary(get_tag_attr_or_default("node", E,"")),
|
||||||
get_tag_attr_or_default("type", E,"flat")}
|
get_tag_attr_or_default("type", E,"flat")}
|
||||||
|
|
||||||
end,
|
end,
|
||||||
ConfigureElement = case xml:get_subtag(Payload, "configure") of
|
ConfigureElement = case xml:get_subtag(Payload, "configure") of
|
||||||
false ->[];
|
false ->[];
|
||||||
@ -166,7 +165,7 @@ out(Args, 'POST', [Domain]=Uri, {User, UDomain})->
|
|||||||
++ xml:element_to_string(Result)}
|
++ xml:element_to_string(Result)}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
out(Args, 'DELETE', [Domain, Node] = Uri, {User, UDomain})->
|
out(_Args, 'DELETE', [_Domain, Node] = Uri, {User, UDomain})->
|
||||||
Host = get_host(Uri),
|
Host = get_host(Uri),
|
||||||
Jid = jlib:make_jid({User, UDomain, ""}),
|
Jid = jlib:make_jid({User, UDomain, ""}),
|
||||||
BinNode = list_to_binary(Node),
|
BinNode = list_to_binary(Node),
|
||||||
@ -209,6 +208,26 @@ get_item(Uri, Failure, Success)->
|
|||||||
Success(Item)
|
Success(Item)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
publish_item(Args, [Domain, Node | _R] = Uri, Slug, {User, Domain})->
|
||||||
|
|
||||||
|
Payload = xml_stream:parse_element(Args#request.data),
|
||||||
|
[FilteredPayload]=xml:remove_cdata([Payload]),
|
||||||
|
|
||||||
|
%FilteredPayload2 = case xml:get_subtag(FilteredPayload, "app:edited") ->
|
||||||
|
% {xmlelement, Name, Attrs, [{cdata, }]}
|
||||||
|
case mod_pubsub:publish_item(get_host(Uri),
|
||||||
|
Domain,
|
||||||
|
get_collection(Uri),
|
||||||
|
jlib:make_jid(User,Domain, ""),
|
||||||
|
Slug,
|
||||||
|
[FilteredPayload]) of
|
||||||
|
{result, [_]} ->
|
||||||
|
?DEBUG("Publishing to ~p~n",[entry_uri(Args, Domain, Node,Slug)]),
|
||||||
|
{201, [{"location", entry_uri(Args, Domain,Node,Slug)}], Payload};
|
||||||
|
{error, Error} ->
|
||||||
|
error(Error)
|
||||||
|
end.
|
||||||
|
|
||||||
generate_etag(#pubsub_item{modification={{_, D2, D3}, _JID}})->integer_to_list(D3+D2).
|
generate_etag(#pubsub_item{modification={{_, D2, D3}, _JID}})->integer_to_list(D3+D2).
|
||||||
get_host([Domain|_Rest])-> "pubsub."++Domain.
|
get_host([Domain|_Rest])-> "pubsub."++Domain.
|
||||||
get_collection([_Domain, Node|_Rest])->list_to_binary(Node).
|
get_collection([_Domain, Node|_Rest])->list_to_binary(Node).
|
||||||
@ -284,8 +303,6 @@ error(401)->
|
|||||||
{401, [{"WWW-Authenticate", "basic realm=\"ejabberd\""}],"Unauthorized"};
|
{401, [{"WWW-Authenticate", "basic realm=\"ejabberd\""}],"Unauthorized"};
|
||||||
error(Code)->
|
error(Code)->
|
||||||
{Code, [], ""}.
|
{Code, [], ""}.
|
||||||
error(Code, Error) when is_list(Error) -> {Code, [], Error};
|
|
||||||
error(Code, _Error) -> {Code, [], "Bad request"}.
|
|
||||||
success(200)->
|
success(200)->
|
||||||
{200, [], ""};
|
{200, [], ""};
|
||||||
success(Code)->
|
success(Code)->
|
||||||
|
Loading…
Reference in New Issue
Block a user