summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorEduardo de Barros Lima <eblima@gmail.com>2011-01-06 16:10:38 +0000
committerEduardo de Barros Lima <eblima@gmail.com>2011-01-06 16:10:38 +0000
commitadff89807961e743d33adfa5ac106ebca5727cf6 (patch)
tree7544db6e0a3abcb58c29253f724e5460f5667251 /legacy
parentaa2733a4ba6f35e8ed75b23702a646e6733a8d4f (diff)
Add basic cookie support to Ecore_Con_Url.
This commit adds some simple wrapper functions for libcurl cookie-related code to Ecore_Con_Url. It is now possible to enable the cookie engine, clear cookies and dump/load them from files. Cookies in both HTTP header-style and cookie-jar are supported. Patch by Raphael Kubo da Costa <kubo@profusion.mobi> SVN revision: 55934
Diffstat (limited to 'legacy')
-rw-r--r--legacy/ecore/src/lib/ecore_con/Ecore_Con.h11
-rw-r--r--legacy/ecore/src/lib/ecore_con/ecore_con_url.c270
2 files changed, 281 insertions, 0 deletions
diff --git a/legacy/ecore/src/lib/ecore_con/Ecore_Con.h b/legacy/ecore/src/lib/ecore_con/Ecore_Con.h
index 765a553359..c8bc237254 100644
--- a/legacy/ecore/src/lib/ecore_con/Ecore_Con.h
+++ b/legacy/ecore/src/lib/ecore_con/Ecore_Con.h
@@ -531,6 +531,17 @@ EAPI void ecore_con_url_verbose_set(Ecore_Con_Url *url_con,
531EAPI void ecore_con_url_ftp_use_epsv_set(Ecore_Con_Url *url_con, 531EAPI void ecore_con_url_ftp_use_epsv_set(Ecore_Con_Url *url_con,
532 Eina_Bool use_epsv); 532 Eina_Bool use_epsv);
533 533
534EAPI void ecore_con_url_cookies_init(Ecore_Con_Url *url_con);
535EAPI void ecore_con_url_cookies_ignore_old_session_set(Ecore_Con_Url *url_con,
536 Eina_Bool ignore);
537EAPI void ecore_con_url_cookies_clear(Ecore_Con_Url *url_con);
538EAPI void ecore_con_url_cookies_session_clear(Ecore_Con_Url *url_con);
539EAPI void ecore_con_url_cookies_file_add(Ecore_Con_Url *url_con,
540 const char * const file_name);
541EAPI Eina_Bool ecore_con_url_cookies_jar_file_set(Ecore_Con_Url *url_con,
542 const char * const cookiejar_file);
543EAPI void ecore_con_url_cookies_jar_write(Ecore_Con_Url *url_con);
544
534/** 545/**
535 * @} 546 * @}
536 */ 547 */
diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con_url.c b/legacy/ecore/src/lib/ecore_con/ecore_con_url.c
index 645698ffce..1d6fcf584d 100644
--- a/legacy/ecore/src/lib/ecore_con/ecore_con_url.c
+++ b/legacy/ecore/src/lib/ecore_con/ecore_con_url.c
@@ -1079,6 +1079,276 @@ ecore_con_url_ftp_upload(Ecore_Con_Url *url_con,
1079} 1079}
1080 1080
1081/** 1081/**
1082 * Enables the cookie engine for subsequent HTTP requests.
1083 *
1084 * After this function is called, cookies set by the server in HTTP responses
1085 * will be parsed and stored, as well as sent back to the server in new HTTP
1086 * requests.
1087 *
1088 * @note Even though this function is called @c ecore_con_url_cookies_init(),
1089 * there is no symmetrical shutdown operation.
1090 *
1091 * @param url_con Ecore_Con_Url instance which will be acted upon.
1092 */
1093EAPI void
1094ecore_con_url_cookies_init(Ecore_Con_Url *url_con)
1095{
1096#ifdef HAVE_CURL
1097 if (!url_con)
1098 return;
1099
1100 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1101 {
1102 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL,
1103 "ecore_con_url_cookies_init");
1104 return;
1105 }
1106
1107 curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIEFILE, "");
1108#else
1109 (void)url_con;
1110#endif
1111}
1112
1113/**
1114 * Controls whether session cookies from previous sessions shall be loaded.
1115 *
1116 * Session cookies are cookies with no expire date set, which usually means
1117 * they are removed after the current session is closed.
1118 *
1119 * By default, when Ecore_Con_Url loads cookies from a file, all cookies are
1120 * loaded, including session cookies, which, most of the time, were supposed
1121 * to be loaded and valid only for that session.
1122 *
1123 * If @p ignore is set to @c EINA_TRUE, when Ecore_Con_Url loads cookies from
1124 * the files passed to @c ecore_con_url_cookies_file_add(), session cookies
1125 * will not be loaded.
1126 *
1127 * @param url_con Ecore_Con_Url instance which will be acted upon.
1128 * @param ignore If @c EINA_TRUE, ignore session cookies when loading cookies
1129 * from files. If @c EINA_FALSE, all cookies will be loaded.
1130 *
1131 * @see ecore_con_url_cookies_file_add()
1132 */
1133EAPI void
1134ecore_con_url_cookies_ignore_old_session_set(Ecore_Con_Url *url_con, Eina_Bool ignore)
1135{
1136#ifdef HAVE_CURL
1137 if (!url_con)
1138 return;
1139
1140 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1141 {
1142 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL,
1143 "ecore_con_url_cookies_ignore_old_session_set");
1144 return;
1145 }
1146
1147 curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIESESSION, ignore);
1148#else
1149 (void)url_con;
1150 (void)ignore;
1151#endif
1152}
1153
1154/**
1155 * Clears currently loaded cookies.
1156 *
1157 * The cleared cookies are removed and will not be sent in subsequent HTTP
1158 * requests, nor will they be written to the cookiejar file set via
1159 * @c ecore_con_url_cookies_jar_file_set().
1160 *
1161 * @note This function will initialize the cookie engine if it has not been
1162 * initialized yet.
1163 *
1164 * @param url_con Ecore_Con_Url instance which will be acted upon.
1165 *
1166 * @see ecore_con_url_cookies_session_clear()
1167 * @see ecore_con_url_cookies_ignore_old_session_set()
1168 */
1169EAPI void
1170ecore_con_url_cookies_clear(Ecore_Con_Url *url_con)
1171{
1172#ifdef HAVE_CURL
1173 if (!url_con)
1174 return;
1175
1176 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1177 {
1178 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL,
1179 "ecore_con_url_cookies_clear");
1180 return;
1181 }
1182
1183 curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIELIST, "ALL");
1184#else
1185 (void)url_con;
1186#endif
1187}
1188
1189/**
1190 * Clears currently loaded session cookies.
1191 *
1192 * Session cookies are cookies with no expire date set, which usually means
1193 * they are removed after the current session is closed.
1194 *
1195 * The cleared cookies are removed and will not be sent in subsequent HTTP
1196 * requests, nor will they be written to the cookiejar file set via
1197 * @c ecore_con_url_cookies_jar_file_set().
1198 *
1199 * @note This function will initialize the cookie engine if it has not been
1200 * initialized yet.
1201 *
1202 * @param url_con Ecore_Con_Url instance which will be acted upon.
1203 *
1204 * @see ecore_con_url_cookies_clear()
1205 * @see ecore_con_url_cookies_ignore_old_session_set()
1206 */
1207EAPI void
1208ecore_con_url_cookies_session_clear(Ecore_Con_Url *url_con)
1209{
1210#ifdef HAVE_CURL
1211 if (!url_con)
1212 return;
1213
1214 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1215 {
1216 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL,
1217 "ecore_con_url_cookies_session_clear");
1218 return;
1219 }
1220
1221 curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIELIST, "SESS");
1222#else
1223 (void)url_con;
1224#endif
1225}
1226
1227/**
1228 * Adds a file to the list of files from which to load cookies.
1229 *
1230 * Files must contain cookies defined according to two possible formats:
1231 *
1232 * @li HTTP-style header ("Set-Cookie: ...").
1233 * @li Netscape/Mozilla cookie data format.
1234 *
1235 * Please notice that the file will not be read immediately, but rather added
1236 * to a list of files that will be loaded and parsed at a later time.
1237 *
1238 * @note This function will initialize the cookie engine if it has not been
1239 * initialized yet.
1240 *
1241 * @param url_con Ecore_Con_Url instance which will be acted upon.
1242 * @param file_name Name of the file that will be added to the list.
1243 *
1244 * @see ecore_con_url_cookies_ignore_old_session_set()
1245 */
1246EAPI void
1247ecore_con_url_cookies_file_add(Ecore_Con_Url *url_con, const char * const file_name)
1248{
1249#ifdef HAVE_CURL
1250 if (!url_con)
1251 return;
1252
1253 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1254 {
1255 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL,
1256 "ecore_con_url_cookies_file_add");
1257 return;
1258 }
1259
1260 curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIEFILE, file_name);
1261#else
1262 (void)url_con;
1263 (void)file_name;
1264#endif
1265}
1266
1267/**
1268 * Sets the name of the file to which all current cookies will be written when
1269 * either cookies are flushed or Ecore_Con is shut down.
1270 *
1271 * Cookies are written following Netscape/Mozilla's data format, also known as
1272 * cookie-jar.
1273 *
1274 * @note This function will initialize the cookie engine if it has not been
1275 * initialized yet.
1276 *
1277 * @param url_con Ecore_Con_Url instance which will be acted upon.
1278 * @param cookiejar_file File to which the cookies will be written.
1279 *
1280 * @return @c EINA_TRUE is the file name has been set successfully,
1281 * @c EINA_FALSE otherwise.
1282 *
1283 * @see ecore_con_url_cookies_jar_write()
1284 */
1285EAPI Eina_Bool
1286ecore_con_url_cookies_jar_file_set(Ecore_Con_Url *url_con, const char * const cookiejar_file)
1287{
1288#ifdef HAVE_CURL
1289 CURLcode ret;
1290
1291 if (!url_con)
1292 return EINA_FALSE;
1293
1294 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1295 {
1296 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL,
1297 "ecore_con_url_cookies_jar_file_set");
1298 return EINA_FALSE;
1299 }
1300
1301 ret = curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIEJAR,
1302 cookiejar_file);
1303 if (ret != CURLE_OK)
1304 {
1305 ERR("Setting the cookie-jar name failed: %s",
1306 curl_easy_strerror(ret));
1307 return EINA_FALSE;
1308 }
1309
1310 return EINA_TRUE;
1311#else
1312 return EINA_FALSE;
1313 (void)url_con;
1314 (void)cookiejar_file;
1315#endif
1316}
1317
1318/**
1319 * Writes all current cookies to the cookie jar immediately.
1320 *
1321 * A cookie-jar file must have been previously set by
1322 * @c ecore_con_url_jar_file_set, otherwise nothing will be done.
1323 *
1324 * @note This function will initialize the cookie engine if it has not been
1325 * initialized yet.
1326 *
1327 * @param url_con Ecore_Con_Url instance which will be acted upon.
1328 *
1329 * @see ecore_con_url_cookies_jar_file_set()
1330 */
1331EAPI void
1332ecore_con_url_cookies_jar_write(Ecore_Con_Url *url_con)
1333{
1334#ifdef HAVE_CURL
1335 if (!url_con)
1336 return;
1337
1338 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1339 {
1340 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL,
1341 "ecore_con_url_cookies_jar_write");
1342 return;
1343 }
1344
1345 curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIELIST, "FLUSH");
1346#else
1347 (void)url_con;
1348#endif
1349}
1350
1351/**
1082 * Toggle libcurl's verbose output. 1352 * Toggle libcurl's verbose output.
1083 * 1353 *
1084 * If @p verbose is @c EINA_TRUE, libcurl will output a lot of verbose 1354 * If @p verbose is @c EINA_TRUE, libcurl will output a lot of verbose