⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 capi.c

📁 浏览器的源代码,可移植到嵌入式设备.
💻 C
📖 第 1 页 / 共 2 页
字号:
 */gint a_Capi_open_url(DilloWeb *web, CA_Callback_t Call, void *CbData){   gint buf_size;   char *cmd, *server, *buf;   char *url_str = URL_STR(web->url);   gint use_cache = 0, safe = 0, reload = 0, ret = 0;   _MSG("  a_Capi_open_url:: web->Image=%p\n", web->Image);   if (a_Capi_url_uses_dpi(url_str, &server) && !Call) {      MSG("  url_str = %s\n", url_str);      if (g_strncasecmp(url_str, "dpi:/", 5) == 0) {         /* safety check... */         safe = Capi_verify_dpi_url_request(web);         /* make "dpi:/" prefixed urls always reload. */         a_Url_set_flags(web->url, URL_FLAGS(web->url) | URL_E2EReload);         reload = 1;      } else {         /* reload test */         reload = (!a_Capi_get_buf(web->url, &buf, &buf_size) ||                   (URL_FLAGS(web->url) & URL_E2EReload));         safe = 1;      }      _MSG("  reload=%d URL_E2EReload=%d\n", reload,           (URL_FLAGS(web->url) & URL_E2EReload));      if (safe && reload) {         /* Send dpip command */         cmd = a_Capi_dpi_build_cmd(web->url, server);         a_Capi_dpi_send_cmd(web, web->bw, cmd, server, 1);         g_free(cmd);         /* test the new dpi-cache connection! */         use_cache = 1;      } else if (safe && !reload) {         use_cache = 1;      }      g_free(server);   } else {      use_cache = 1;   }   if (use_cache)      ret = a_Cache_open_url(web, Call, CbData);   else      a_Web_free(web);   return ret;}/* * Get the cache's buffer for the URL, and its size. * Return: 1 cached, 0 not cached. */gint a_Capi_get_buf(const DilloUrl *Url, gchar **PBuf, gint *BufSize){   return a_Cache_get_buf(Url, PBuf, BufSize);}/* * Send a dpi cmd. * (For instance: add_bookmark, open_url, send_preferences, ...) */gint a_Capi_dpi_send_cmd(DilloWeb *web, void *bw, char *cmd, char *server,                         gint flags){   dpi_conn_t *conn;   DataBuf *dbuf;   //**/sleep(1);   //**/a_Interface_msg(bw, cmd);   if (flags & 1) {      /* open a new connection to server */      /* Create a new connection data struct and add it to the list */      conn = Capi_dpi_conn_new(web, bw, server, cmd);      Capi_dpi_conn_ref(conn);      /* start the CCC operations */      a_Capi_ccc(OpStart, 1, BCK, conn->InfoSend, conn, server);   } else {      /* Re-use an open connection */      conn = Capi_dpi_conn_find(server);      if (conn) {         /* found */         dbuf = a_Chain_dbuf_new(cmd, strlen(cmd), 0);         a_Capi_ccc(OpSend, 1, BCK, conn->InfoSend, dbuf, NULL);         g_free(dbuf);      } else {         MSG(" ERROR: [a_Capi_dpi_send_cmd] No open connection found\n");      }   }   return 0;}/* * CCC function for the CAPI module */void a_Capi_ccc(int Op, int Branch, int Dir, ChainLink *Info,                void *Data1, void *Data2){   dpi_conn_t *conn;   a_Chain_debug_msg("a_Capi_ccc", Op, Branch, Dir);   if (Branch == 1) {      if (Dir == BCK) {         /* Command sending branch */         switch (Op) {         case OpStart:            Info->LocalKey = Data1;            a_Chain_link_new(Info, a_Capi_ccc, BCK, a_Dpi_ccc, 2, 1);            a_Chain_bcb(OpStart, Info, Data2, NULL);            break;         case OpSend:            a_Chain_bcb(OpSend, Info, Data1, NULL);            break;         case OpEnd:            a_Chain_bcb(OpEnd, Info, NULL, NULL);            Capi_dpi_conn_unref(Info->LocalKey);            g_free(Info);            break;         case OpStop:         case OpAbort:            MSG(" Not implemented\n");            break;         }      } else {  /* FWD */         /* Command sending branch (status) */         switch (Op) {         case OpSend:            if (!Data2) {               g_warning("Capi.c: Opsend [1F] Data2 = NULL\n");            } else if (strcmp(Data2, "SockFD") == 0) {               /* start the receiving branch */               dpi_conn_t *conn = Info->LocalKey;               conn->SockFD = *(int*)Data1;               a_Capi_ccc(OpStart, 2, BCK, a_Chain_new(),Info->LocalKey, NULL);            } else if (strcmp(Data2, "DpidOK") == 0) {               /* send the data inmediatly! */               Capi_dpi_conn_resume();            } else if (strcmp(Data2, "DpidEAGAIN") == 0) {               /* set a timeout function to retry later... */               if (dpi_conn_timeout_id == 0)                  dpi_conn_timeout_id =                     gtk_timeout_add(250, (GtkFunction) Capi_dpi_conn_timeout,                                     NULL);            }            break;         case OpStop:         case OpAbort:            conn = Info->LocalKey;            if (Data1 && !strcmp(Data1, "ERR_dpid"))               a_Interface_msg(conn->bw, "ERROR: can't start dpid daemon!");            Capi_dpi_conn_unref(conn);            g_free(Info);            break;         }      }   } else if (Branch == 2) {      if (Dir == BCK) {         /* Server listening branch (status) */         switch (Op) {         case OpStart:            {            dpi_conn_t *conn = Data1;            Info->LocalKey = Data1;            Capi_dpi_conn_ref(conn);            conn->InfoRecv = Info;            a_Chain_link_new(Info, a_Capi_ccc, BCK, a_Dpi_ccc, 3, 2);            a_Chain_bcb(OpStart, Info, &conn->SockFD, "SockFD");            break;            }         case OpStop:         case OpAbort:            Capi_dpi_conn_unref(Info->LocalKey);            MSG(" Not implemented\n");            break;         }      } else {  /* FWD */         /* Server listening branch */         switch (Op) {         case OpSend:            conn = Info->LocalKey;            if (conn->Flags & ABORTED ||                (conn->web && !a_Web_valid(conn->web))) {               /* there's no client for this transfer!*/               _MSG("  ** Capi 2F catched an invalid 'web' structure\n");               /* this flag is used just in case the same memory address                * is reused for a new 'web' and the test passes */               conn->Flags &= ABORTED;               /* Make the dpi module stop this transfer */               a_Chain_bcb(OpStop, Info, conn->url, NULL);            } else if (strcmp(Data2, "send_status_message") == 0) {               a_Interface_msg(conn->bw, Data1);            } else if (strcmp(Data2, "chat") == 0) {               a_Interface_msg(conn->bw, Data1);               a_Bookmarks_chat_add(NULL, NULL, Data1);            } else if (strcmp(Data2, "start_send_page") == 0) {               /* start the pipe-writing chain */               a_Capi_ccc(OpStart, 3, BCK, a_Chain_new(), Info->LocalKey,NULL);               /* let the dpi know the reading end of the pipe */               a_Chain_bcb(OpSend, Info, &conn->DpiPipe[0], conn->web->url);            } else if (strcmp(Data2, "send_page_2eof") == 0) {               a_Capi_ccc(OpSend, 3, BCK, conn->InfoPipe, Data1, NULL);            } else if (strcmp(Data2, "reload_request") == 0) {               a_Nav_reload(conn->bw);            }            break;         case OpEnd:            {            dpi_conn_t *conn = Info->LocalKey;            a_Chain_del_link(Info, BCK);            conn->InfoRecv = NULL;            Capi_dpi_conn_unref(conn);            if (conn->InfoSend) {               /* Propagate OpEnd to the sending branch too */               a_Capi_ccc(OpEnd, 1, BCK, conn->InfoSend, NULL, NULL);            }            if (conn->InfoPipe) {               /* Propagate OpEnd to the pipe branch too */               a_Capi_ccc(OpEnd, 3, BCK, conn->InfoPipe, NULL, NULL);            }            g_free(Info);            break;            }         case OpStop:         case OpAbort:            MSG(" Not implemented\n");            break;         }      }   } else if (Branch == 3) {      if (Dir == BCK) {         /* Pipe writing branch */         switch (Op) {         case OpStart:            {            dpi_conn_t *conn = Data1;            Info->LocalKey = Data1;            Capi_dpi_conn_ref(conn);            conn->InfoPipe = Info;            if (pipe(conn->DpiPipe)) {               MSG(" Error with pipe\n");               return;            }            a_Chain_link_new(Info, a_Capi_ccc, BCK, a_IO_ccc, 3, 3);            a_Chain_bcb(OpStart, Info, &conn->DpiPipe[1], "SockFD");            break;            }         case OpSend:            a_Chain_bcb(OpSend, Info, Data1, NULL);            break;         case OpEnd:            a_Chain_bcb(OpEnd, Info, NULL, NULL);            Capi_dpi_conn_unref(Info->LocalKey);            g_free(Info);            break;         case OpStop:         case OpAbort:            Capi_dpi_conn_unref(Info->LocalKey);            MSG(" Not implemented\n");            break;         }      } else {  /* FWD */         /* Pipe branch (status) */      }   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -