2 * Copyright (c) 2016-2019 S. Gilles <sgilles@math.umd.edu>
4 * Permission to use, copy, modify, and/or distribute this software
5 * for any purpose with or without fee is hereby granted, provided
6 * that the above copyright notice and this permission notice appear
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
13 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
14 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26 #include <curl/curl.h>
27 #include <yajl_parse.h>
33 main(int argc
, char **argv
)
41 long long target_ll
= 0;
43 uint_fast8_t purge_arg
= 0;
46 struct curl_httppost
*post
= 0;
47 struct curl_httppost
*postend
= 0;
51 setlocale(LC_ALL
, "");
53 while ((opt
= getopt(argc
, argv
, "c:g:t:p")) != -1) {
74 fprintf(stderr
, "course-id is mandatory\n");
81 fprintf(stderr
, "one of -t, -p is mandatory\n");
83 } else if (target_arg
&&
85 fprintf(stderr
, "both -t and -p provided, ignoring -p\n");
89 curl_global_init(CURL_GLOBAL_DEFAULT
);
91 if (!(url_base
= get_url_base())) {
94 /* Error should have already been printed */
98 if (!(auth_token
= get_auth_token())) {
101 /* Error should have already been printed */
106 target_ll
= strtoll(target_arg
, 0, 0);
107 len
= snprintf(0, 0, "%lld", target_ll
);
110 ret
= errno
= EOVERFLOW
;
115 if (!(target
= malloc(len
+ 1))) {
121 sprintf(target
, "%lld", target_ll
);
123 if (curl_formadd(&post
, &postend
, CURLFORM_PTRNAME
,
124 "move_assignments_to", CURLFORM_PTRCONTENTS
,
128 perror(L("curl_formadd"));
133 len
= snprintf(0, 0, "%s/api/v1/courses/%s/assignment_groups/%s",
134 url_base
, course_id
, group_id
);
137 ret
= errno
= EOVERFLOW
;
142 if (!(built_uri
= malloc(len
+ 1))) {
148 sprintf(built_uri
, "%s/api/v1/courses/%s/assignment_groups/%s",
149 url_base
, course_id
, group_id
);
151 if ((ret
= send_and_id_scan(built_uri
, auth_token
, post
, "DELETE",
157 printf("%s\n", deleted_id
);
168 curl_global_cleanup();